From bd3bbdd239fd91056442384bfe3a86b2b8c0e68e Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 24 Jun 2024 17:26:09 +0100 Subject: chapter 9 --- ray.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'ray.go') diff --git a/ray.go b/ray.go index cd4f6aa..18c8a39 100644 --- a/ray.go +++ b/ray.go @@ -10,17 +10,22 @@ type Ray struct { } func (r Ray) At(t float64) Vec3 { - return r.Origin.Add(r.Direction.Mul(Splat(t))); + return r.Origin.Add(r.Direction.Mul(SplatVec3(t))); } -func (r Ray) Colour(world Hittable) Vec3 { - hit := world.Hit(r, Interval{0, maths.Inf(1)}) +func (r Ray) Colour(world Hittable, md uint) Vec3 { + if md <= 0 { + return SplatVec3(0); + } + + hit := world.Hit(r, Interval{0.001, maths.Inf(1)}) if hit.Valid { - return hit.N.Add(Splat(1)).Div(Splat(2)); + dir := hit.N.Add(RandomVec3OnUnitSphere()); + return Ray{hit.P, dir}.Colour(world, md - 1).Div(SplatVec3(10)); } unit_dir := r.Direction.Unit(); a := (unit_dir.Y + 1) / 2; - return Vec3{0.5, 0.7, 1.0}.Mul(Splat(a)). - Add(Splat(1).Mul(Splat(1.0 - a))); + return Vec3{0.5, 0.7, 1.0}.Mul(SplatVec3(a)). + Add(SplatVec3(1).Mul(SplatVec3(1.0 - a))); } -- cgit v1.2.1