From d248e30d365d5e401d5cd372aa415fb2f9a39326 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 24 Jun 2024 22:12:44 +0100 Subject: Chapter 10 --- ray.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'ray.go') diff --git a/ray.go b/ray.go index 18c8a39..2d7f29c 100644 --- a/ray.go +++ b/ray.go @@ -7,6 +7,7 @@ import ( type Ray struct { Origin Vec3 Direction Vec3 + Valid bool } func (r Ray) At(t float64) Vec3 { @@ -20,8 +21,11 @@ func (r Ray) Colour(world Hittable, md uint) Vec3 { hit := world.Hit(r, Interval{0.001, maths.Inf(1)}) if hit.Valid { - dir := hit.N.Add(RandomVec3OnUnitSphere()); - return Ray{hit.P, dir}.Colour(world, md - 1).Div(SplatVec3(10)); + scat := hit.Mat.Scatter(r, hit); + if scat.Valid { + return scat.Colour(world, md - 1).Mul(hit.Mat.Attenuation()); + } + return SplatVec3(0); } unit_dir := r.Direction.Unit(); -- cgit v1.2.1