aboutsummaryrefslogtreecommitdiff
path: root/lib/ray.rb
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-06-12 22:51:25 +0100
committerNat Lasseter <user@4574.co.uk>2024-06-12 22:51:25 +0100
commit1bc4829392b3c91737fbe4ddccd81098ac9d8a12 (patch)
treec2339a79b1fdaf82955a5e38ed35a7f0a9481f21 /lib/ray.rb
parent51416f5dfac39b6ede8340b57b9bed4eb3edc646 (diff)
chap 9.3
Diffstat (limited to 'lib/ray.rb')
-rw-r--r--lib/ray.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/ray.rb b/lib/ray.rb
index 47f2b26..c1679a5 100644
--- a/lib/ray.rb
+++ b/lib/ray.rb
@@ -10,9 +10,12 @@ class Ray
@origin + (@direction * time)
end
- def colour(world)
- if rec = world.hit(self, Interval.new(0, Float::INFINITY))
- return (Colour.new(1,1,1) + rec.normal) * 0.5
+ def colour(world, depth)
+ return Colour.new if depth <= 0
+
+ if rec = world.hit(self, Interval.new(0.0001, Float::INFINITY))
+ dir = Vec3.random_unit(rec.normal)
+ return Ray.new(rec.point, dir).colour(world, depth - 1) * 0.5
end
unit_dir = direction.unit