aboutsummaryrefslogtreecommitdiff
path: root/ray.go
diff options
context:
space:
mode:
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();