aboutsummaryrefslogtreecommitdiff
path: root/lib/vec3.rb
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-06-13 14:38:50 +0100
committerNat Lasseter <user@4574.co.uk>2024-06-13 14:38:50 +0100
commit69e0357135a49157ed7a8c2e57c331e960422e15 (patch)
tree2402ef255cf24afff14ac653826386e615faee8b /lib/vec3.rb
parentb976ce98be7275bf92e01f6c86bf2b694530481e (diff)
Chapter 11
Diffstat (limited to 'lib/vec3.rb')
-rw-r--r--lib/vec3.rb7
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