Basic functional raytracer

This commit is contained in:
David 2021-08-23 00:37:57 +02:00
commit c37be6798f
5 changed files with 159 additions and 33 deletions

View file

@ -188,4 +188,22 @@ vec3 reflect(const vec3& v, const vec3 n)
return v - 2*dot(v,n)*n;
}
vec3 refract (const vec3& uv, const vec3& n, double etai_over_etat)
{
double cos_theta = fmin(dot(-uv, n), 1.0);
vec3 r_out_perp = etai_over_etat * (uv + cos_theta*n);
vec3 r_out_parallel = -sqrt(fabs(1.0 - r_out_perp.length_squared())) * n;
return r_out_perp + r_out_parallel;
}
vec3 random_in_unit_disk()
{
while (true)
{
auto p = vec3(random_double(-1,1), random_double(-1,1), 0);
if (p.length_squared() >= 1) continue;
return p;
}
}
#endif