diff options
| author | Martin Lehoux <martin@lehoux.net> | 2020-04-04 19:41:57 -0700 |
|---|---|---|
| committer | Martin Lehoux <martin@lehoux.net> | 2020-04-04 19:41:57 -0700 |
| commit | 13be7ded788fe88d5ac8d6759273516652bf1a80 (patch) | |
| tree | 57d7eabb022e500e8b06089fb935c4a17c7cfbb3 /hitable.go | |
| parent | d233910be5eb6bdf9bb9deb6ffa0fa79f659e902 (diff) | |
feat - Add Lambertian material
Diffstat (limited to 'hitable.go')
| -rw-r--r-- | hitable.go | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -3,9 +3,10 @@ package main import "math" type HitRecord struct { - time float64 - point Vec3D - normal Vec3D + time float64 + point Vec3D + normal Vec3D + material Material } type Hitable interface { @@ -16,7 +17,7 @@ type Hitable interface { type HitableList []Hitable func (hitable_list HitableList) Hit(ray Ray, t_min float64, t_max float64) HitRecord { - closest_hit := HitRecord{T_MAX, Vec3D{}, Vec3D{}} + closest_hit := HitRecord{T_MAX, Vec3D{}, Vec3D{}, nil} for _, hitable := range hitable_list { hit := hitable.Hit(ray, t_min, closest_hit.time) if hit.time > 0 { @@ -31,8 +32,9 @@ func (hitable_list HitableList) Hit(ray Ray, t_min float64, t_max float64) HitRe } type Sphere struct { - center Vec3D - radius float64 + center Vec3D + radius float64 + material Material } func (sphere Sphere) Normal(point Vec3D, ray Ray) Vec3D { @@ -55,12 +57,12 @@ func (sphere Sphere) Hit(ray Ray, t_min float64, t_max float64) HitRecord { time := (-b - root) / (2.0 * a) if t_min < time && time < t_max { point := ray.PointAt(time) - return HitRecord{time, point, sphere.Normal(point, ray)} + return HitRecord{time, point, sphere.Normal(point, ray), sphere.material} } time = (-b + root) / (2.0 * a) if t_min < time && time < t_max { point := ray.PointAt(time) - return HitRecord{time, point, sphere.Normal(point, ray)} + return HitRecord{time, point, sphere.Normal(point, ray), sphere.material} } } return HitRecord{} |
