diff options
author | Nat Lasseter <user@4574.co.uk> | 2024-06-12 22:51:25 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2024-06-12 22:51:25 +0100 |
commit | 1bc4829392b3c91737fbe4ddccd81098ac9d8a12 (patch) | |
tree | c2339a79b1fdaf82955a5e38ed35a7f0a9481f21 /lib/ray.rb | |
parent | 51416f5dfac39b6ede8340b57b9bed4eb3edc646 (diff) |
chap 9.3
Diffstat (limited to 'lib/ray.rb')
-rw-r--r-- | lib/ray.rb | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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 |