aboutsummaryrefslogtreecommitdiff
path: root/lib/ray.rb
diff options
context:
space:
mode:
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