diff options
| -rw-r--r-- | color.go | 5 | ||||
| -rw-r--r-- | hitable.go | 6 |
2 files changed, 6 insertions, 5 deletions
@@ -18,8 +18,9 @@ func LinearBlend(color1 Color, color2 Color, param float64) Color { func RayColor(ray Ray, hitable Hitable) Color { hit := hitable.Hit(ray) - if hit.time > 0 { - return Color{1.0, 0.0, 0.0} + 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) } 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) @@ -19,7 +19,7 @@ type Sphere struct { } func (sphere Sphere) Normal(point Vec3D) Vec3D { - return (SubVec3D(point, sphere.center)).Unit() + return SubVec3D(point, sphere.center).Unit() } func (sphere Sphere) Hit(ray Ray) HitRecord { @@ -31,7 +31,7 @@ func (sphere Sphere) Hit(ray Ray) HitRecord { if discriminant < 0 { return HitRecord{} } - time := (-b - math.Sqrt(discriminant)) / 2.0 / a + time := (-b - math.Sqrt(discriminant)) / (2.0 * a) point := ray.PointAt(time) - return HitRecord{time, point, SubVec3D(point, sphere.Normal(point))} + return HitRecord{time, point, sphere.Normal(point)} } |
