Hopefully before really raymarching testing
This commit is contained in:
parent
d2f0abff6a
commit
6ed5b21890
5 changed files with 206 additions and 27 deletions
34
primitives_sdf.go
Normal file
34
primitives_sdf.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
// Sphere
|
||||
type Sphere struct {
|
||||
center Vector3
|
||||
radius float64
|
||||
color Color
|
||||
}
|
||||
|
||||
func (s Sphere) Distance(p Vector3) (float64, Color) {
|
||||
return p.Sub(s.center).Length(), s.color
|
||||
}
|
||||
|
||||
// Box
|
||||
type Box struct {
|
||||
center Vector3
|
||||
dimensions Vector3
|
||||
color Color
|
||||
}
|
||||
|
||||
func (s Box) Distance(p Vector3) (float64, Color) {
|
||||
q := p.Sub(s.center).Abs().Sub(s.dimensions)
|
||||
return q.Max(0.0).Length() + min(max(q.X, max(q.Y, q.Z)), 0.0), s.color
|
||||
}
|
||||
|
||||
type Plane struct {
|
||||
normal Vector3
|
||||
height float64
|
||||
color Color
|
||||
}
|
||||
|
||||
func (s Plane) Distance(p Vector3) (float64, Color) {
|
||||
return p.Dot(s.normal) + s.height, s.color
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue