Add material support
This commit is contained in:
parent
6d98c22890
commit
58ffcff459
7 changed files with 112 additions and 36 deletions
13
vec3.hpp
13
vec3.hpp
|
|
@ -76,6 +76,13 @@ struct vec3 {
|
|||
{
|
||||
return vec3(random_double(min, max), random_double(min, max), random_double(min, max));
|
||||
}
|
||||
|
||||
// Check if all vector components are near zero
|
||||
bool near_zero() const
|
||||
{
|
||||
double s = 1e-8;
|
||||
return (fabs(x) < s) && (fabs(y) < s) && (fabs(z) < s);
|
||||
}
|
||||
};
|
||||
|
||||
/* Type aliases */
|
||||
|
|
@ -175,4 +182,10 @@ vec3 random_in_hemisphere(const vec3& normal)
|
|||
return -in_unit_sphere;
|
||||
}
|
||||
|
||||
// Reflect like a metallic material
|
||||
vec3 reflect(const vec3& v, const vec3 n)
|
||||
{
|
||||
return v - 2*dot(v,n)*n;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue