Basic functional raytracer
This commit is contained in:
parent
9870dc128e
commit
c37be6798f
5 changed files with 159 additions and 33 deletions
18
vec3.hpp
18
vec3.hpp
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue