From 2e77c2e411ea2ccc7432878434cd9033ea20712a Mon Sep 17 00:00:00 2001 From: Crizomb Date: Sat, 27 Sep 2025 04:25:17 +0200 Subject: [PATCH] No center, just translated --- src/primitives_sdf.go | 9 +++------ src/ray_marching.go | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/primitives_sdf.go b/src/primitives_sdf.go index 12d30f1..ba173ab 100644 --- a/src/primitives_sdf.go +++ b/src/primitives_sdf.go @@ -2,34 +2,31 @@ package main // Sphere type Sphere struct { - center Vector3 radius float64 material Material } func (s Sphere) Distance(p Vector3) (float64, Material) { - return p.Sub(s.center).Length() - s.radius, s.material + return p.Length() - s.radius, s.material } // Box type Box struct { - center Vector3 dimensions Vector3 material Material } func (s Box) Distance(p Vector3) (float64, Material) { - q := p.Sub(s.center).Abs().Sub(s.dimensions) + 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 } // Plane type Plane struct { normal Vector3 - height float64 material Material } func (s Plane) Distance(p Vector3) (float64, Material) { - return p.Dot(s.normal) - s.height, s.material + return p.Dot(s.normal), s.material } diff --git a/src/ray_marching.go b/src/ray_marching.go index 17d36e2..8e7806b 100644 --- a/src/ray_marching.go +++ b/src/ray_marching.go @@ -34,8 +34,8 @@ func init() { sphereMat := RED_MAT sphereMat.specularFac = 0.5 - sphere := Sphere{Vector3{0, 100, 5}, 10, sphereMat} - plane := Plane{Vector3{0, 0, 1}, 0, WHITE_GREY_GRID_MAT} + sphere := TranslatedSDF{Sphere{10, sphereMat}, Vector3{0, 100, 5}} + plane := Plane{Vector3{0, 0, 1}, WHITE_GREY_GRID_MAT} scene = SmoothUnionSDF{sphere, plane, 2}