add Dielectric material

This commit is contained in:
Fabien Freling 2021-05-27 21:48:57 +02:00
parent a596058a0d
commit dde1f91f01
3 changed files with 29 additions and 5 deletions

View file

@ -116,6 +116,13 @@ pub fn random_in_hemisphere(rng: *Random, normal: Vec3) Vec3 {
}
}
pub fn refract(uv: Vec3, n: Vec3, etai_over_etat: f32) Vec3 {
const cos_theta = math.min(uv.mul_s(-1).dot(n), 1.0);
const r_out_perp = uv.add(n.mul_s(cos_theta)).mul_s(etai_over_etat);
const r_out_parallel = n.mul_s(-math.sqrt(math.absFloat(1.0 - r_out_perp.length_squared())));
return r_out_perp.add(r_out_parallel);
}
pub const Point3 = Vec3;
const assert = @import("std").debug.assert;