Add material support

This commit is contained in:
Phireh 2021-08-22 17:24:33 +02:00
commit 58ffcff459
7 changed files with 112 additions and 36 deletions

View file

@ -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