bf242858abf2 — Leonard Ritter a month ago
* last work on voxel BVH
1 files changed, 24 insertions(+), 10 deletions(-)

M testing/voxel_bvh.sc
M testing/voxel_bvh.sc +24 -10
@@ 20,7 20,7 @@ fn df (p)
             sdSphere p 0.8
             sdSphere (p - (vec3 0.3 -0.3 0)) 0.8
         sdTorus (vec3 (p.x - 0.3) 0 (p.y + 0.3)) (vec2 0.4 0.1)
-    #sdOr
+    sdOr
         sdBox op (vec3 0.3)
         sdSub
             sdBox p (vec3 0.6)

          
@@ 32,7 32,7 @@ fn df (p)
         q := (((vec2 x y) / 3.0) * 2.0 - 1.0) * 0.8
         sdOr d
             sdSphere (p - (vec3 q 0)) (0.0625 + (i as f32 / 16.0) * 0.0625)
-    sdSmoothOr
+    #sdSmoothOr
         sdTorus ((p - (vec3 -0.5 0 0)) . xzy) (vec2 0.35 0.05)
         sdTorus ((p - (vec3 0.5 0 0)) . xzy) (vec2 0.35 0.05)
         0.6

          
@@ 77,6 77,11 @@ fn sqvolume (bounds)
     let w h = (x2 - x1) (y2 - y1)
     w * w + h * h
 
+fn perimeter (bounds)
+    let x1 y1 x2 y2 = (unpack bounds)
+    let w h = (x2 - x1) (y2 - y1)
+    2 * (w + h)
+
 for x y in (dim MAPDIM MAPDIM)
     p := ((vec2 x y) / (MAPDIM - 1)) * 2.0 - 1.0
     d := (df (vec3 p 0.0))

          
@@ 209,6 214,9 @@ fn descend (level sat outp bounds numblo
     inline split (score b1 b2 r1 r2 splitf)
         c := (r1 + r2) // 2
         w := (r2 - r1 + 1) // 2
+        let b = (volume bounds)
+        let v = (volume sat bounds)
+        let pp = (perimeter bounds)
         inline testsplit (w x bestscore b1 b2)
             let lbounds rbounds = (splitf x)
             let lbounds = (tighten sat lbounds)

          
@@ 220,13 228,19 @@ fn descend (level sat outp bounds numblo
 
             let lsq = (sqvolume lbounds)
             let rsq = (sqvolume rbounds)
+
+            let lp = (perimeter lbounds)
+            let rp = (perimeter rbounds)
             #e0 := (abs (hv1 - hv2))
             #e1 := (abs (vv1 - vv2))
 
             #score := lsq + rsq + ((lb - lv) + (rb - rv)) ** 2
             #score := (sqrt ((lsq + rsq) as f32)) + ((lb - lv) ** 2 + (rb - rv) ** 2) as f32
             let lm rm = (lb - lv) (rb - rv)
-            score := lm ** 2 + rm ** 2 #+ lm * rm
+            #score := lm ** 2 + rm ** 2 #+ lm * rm
+            score := lm ** 2 + rm ** 2 + lm * rm * w
+            #score := (lb / b) ** 2 + (rb / b) ** 2
+            #score := lm * rm * w
 
             #score := (lb - lv) + (rb - rv)
             #score := (lb / lv) ** 2 + (rb / rv) ** 2

          
@@ 283,13 297,13 @@ fn descend (level sat outp bounds numblo
                 else
                     _ vb1 vb2
             else
-                let hv1 = (sqvolume hb1)
-                let hv2 = (sqvolume hb2)
-                let vv1 = (sqvolume vb1)
-                let vv2 = (sqvolume vb2)
-                e0 := hv1 + hv2
-                e1 := vv1 + vv2
-                if (e0 > e1)
+                let hv1 = (perimeter hb1)
+                let hv2 = (perimeter hb2)
+                let vv1 = (perimeter vb1)
+                let vv2 = (perimeter vb2)
+                e0 := hv1 ** 2 + hv2 ** 2
+                e1 := vv1 ** 2 + vv2 ** 2
+                if (e0 < e1)
                     _ hb1 hb2
                 else
                     _ vb1 vb2