aboutsummaryrefslogtreecommitdiff
path: root/ray.go
diff options
context:
space:
mode:
Diffstat (limited to 'ray.go')
-rw-r--r--ray.go17
1 files changed, 11 insertions, 6 deletions
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)));
}