Sdf return *Material change, 2x perf boost
This commit is contained in:
parent
264a759ac5
commit
71c86e3570
4 changed files with 72 additions and 53 deletions
|
|
@ -6,8 +6,8 @@ type Sphere struct {
|
|||
material Material
|
||||
}
|
||||
|
||||
func (s Sphere) Distance(p Vector3) (float64, Material) {
|
||||
return p.Length() - s.radius, s.material
|
||||
func (s Sphere) Distance(p Vector3) (float64, *Material) {
|
||||
return p.Length() - s.radius, &s.material
|
||||
}
|
||||
|
||||
// Box
|
||||
|
|
@ -16,9 +16,9 @@ type Box struct {
|
|||
material Material
|
||||
}
|
||||
|
||||
func (s Box) Distance(p Vector3) (float64, Material) {
|
||||
func (s Box) Distance(p Vector3) (float64, *Material) {
|
||||
q := p.Abs().Sub(s.dimensions)
|
||||
return q.Max(0.0).Length() + min(max(q.X, max(q.Y, q.Z)), 0.0), s.material
|
||||
return q.Max(0.0).Length() + min(max(q.X, max(q.Y, q.Z)), 0.0), &s.material
|
||||
}
|
||||
|
||||
// Plane
|
||||
|
|
@ -27,6 +27,6 @@ type Plane struct {
|
|||
material Material
|
||||
}
|
||||
|
||||
func (s Plane) Distance(p Vector3) (float64, Material) {
|
||||
return p.Dot(s.normal), s.material
|
||||
func (s Plane) Distance(p Vector3) (float64, *Material) {
|
||||
return p.Dot(s.normal), &s.material
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue