aboutsummaryrefslogtreecommitdiff
path: root/ray.go
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-06-24 22:12:44 +0100
committerNat Lasseter <user@4574.co.uk>2024-06-24 22:12:44 +0100
commitd248e30d365d5e401d5cd372aa415fb2f9a39326 (patch)
tree58c5602ec20ad39ff34640503c7a4d35c4e563cb /ray.go
parentbd3bbdd239fd91056442384bfe3a86b2b8c0e68e (diff)
Chapter 10
Diffstat (limited to 'ray.go')
-rw-r--r--ray.go8
1 files changed, 6 insertions, 2 deletions
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();