diff options
Diffstat (limited to 'lib/vec3.rb')
-rw-r--r-- | lib/vec3.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/vec3.rb b/lib/vec3.rb index 3069b65..478fe4c 100644 --- a/lib/vec3.rb +++ b/lib/vec3.rb @@ -60,6 +60,13 @@ class Vec3 self - normal * dot(normal) * 2 end + def refract(normal, etaratio) + costheta = [(-self).dot(normal), 1.0].min + rout_perp = (self + normal * costheta) * etaratio + rout_parr = normal * -((1.0 - rout_perp.mag_sqr).abs ** 0.5) + rout_perp + rout_parr + end + def in_unit_sphere? mag_sqr < 1 end |