diff options
author | Nat Lasseter <user@4574.co.uk> | 2024-06-24 22:12:44 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2024-06-24 22:12:44 +0100 |
commit | d248e30d365d5e401d5cd372aa415fb2f9a39326 (patch) | |
tree | 58c5602ec20ad39ff34640503c7a4d35c4e563cb /ray.go | |
parent | bd3bbdd239fd91056442384bfe3a86b2b8c0e68e (diff) |
Chapter 10
Diffstat (limited to 'ray.go')
-rw-r--r-- | ray.go | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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(); |