diff options
| author | Martin Lehoux <martin@lehoux.net> | 2020-04-04 19:10:08 -0700 |
|---|---|---|
| committer | Martin Lehoux <martin@lehoux.net> | 2020-04-04 19:10:08 -0700 |
| commit | 23d71549ebf82d9065de978f50d911bc51931635 (patch) | |
| tree | 1edde1bf0c646c8a45c2b7cfca40940a08320473 /color.go | |
| parent | ba7682a761343302fd65f315b0406abc470c482f (diff) | |
feat - Add ray bouncing
Diffstat (limited to 'color.go')
| -rw-r--r-- | color.go | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -18,11 +18,23 @@ func LinearBlend(color1 Color, color2 Color, param float64) Color { } } -func RayColor(ray Ray, hitable_list HitableList) Color { +func AttenuateColor(attenuation Color, color Color) Color { + return Color{ + attenuation.r * color.r, + attenuation.g * color.g, + attenuation.b * color.b, + } +} + +func RayColor(ray Ray, hitable_list HitableList, depth int) Color { + if depth > MAX_DEPTH { + return Color{0.0, 0.0, 0.0} + } hit := hitable_list.Hit(ray, T_MIN, T_MAX) if hit.time > 0.0 { - vec := AddVec3D(hit.normal, Vec3D{1.0, 1.0, 1.0}) - return LinearBlend(Color{vec.x, vec.y, vec.z}, Color{0.0, 0.0, 0.0}, 0.5) + direction := AddVec3D(hit.normal, RandomInUnitSphere()) + scattered := Ray{hit.point, direction} + return AttenuateColor(Color{0.5, 0.5, 0.5}, RayColor(scattered, hitable_list, depth+1)) } param := 0.5 * (ray.direction.Unit().y + 1) return LinearBlend(Color{0.5, 0.7, 1.0}, Color{1.0, 1.0, 1.0}, param) |
