8c20f7ae7956 — Leonard Ritter 4 months ago
* test planet
2 files changed, 97 insertions(+), 14 deletions(-)

M testing/test_cascade_dmc_cc.sc
M testing/testfragment.sc
M testing/test_cascade_dmc_cc.sc +97 -13
@@ 47,22 47,22 @@ VISUALIZE_IDS := false
 POST_TRANSFORM := false # true is worse
 OCCLUSION_CULLING := false
 FOG := true
-USE_3x3x3_MIPMAPS := true
+USE_3x3x3_MIPMAPS := false
 USE_FLAT_SHADING := true
 BALANCE_QUADS := true
-USE_COMPLEX_SURFACE := true
+USE_COMPLEX_SURFACE := false
 USE_LOD_ISO_OFFSET := true
 HIGH_QUALITY_FEATURES := true
 SOFT_WORLD_SAMPLING := false
 USE_SOFT_LOD_SAMPLING := false
-USE_CATMULL_CLARK := true
+USE_CATMULL_CLARK := false
 BLOCKY_WORLD := false
 
 FETCH_UV_OFFSET := 0.5
 #FETCH_UV_OFFSET := 0.0
 
 # to reach fog density D at depth Z, FOG_RATE = -log2(1 - D)/Z
-FOG_RATE := 0.01 # 50% at 100 units
+FOG_RATE := 0.02 # 50% at 100 units
 
 let MAX_VERTICES = (20 * (1 << 20))
 

          
@@ 78,9 78,9 @@ let GROUP_SIZE = 4
 let MAX_SECTOR_LOD_I = 2
 let SECTOR_GROUP_SIZE = (1 << MAX_SECTOR_LOD_I)
 
-let SUBDIVIDE_RADIUS = 4
+let SUBDIVIDE_RADIUS = 6
 
-MAX_CASCADE_DEPTH := 6 # MAX_WORLD_LOD_I - MAX_SECTOR_LOD_I
+MAX_CASCADE_DEPTH := 7 # MAX_WORLD_LOD_I - MAX_SECTOR_LOD_I
 SECTOR_CAPACITY := MAX_CASCADE_DEPTH * 10000
 CASCADE_SIZE := (1 << MAX_CASCADE_DEPTH)
 CASCADE_CENTER := (CASCADE_SIZE // 2)

          
@@ 94,12 94,15 @@ let BINDING_BUF_DISPATCH_CMD = 6
 let BINDING_IMG_ZBUFFER = 7
 let BINDING_IMG_WORLD_IN = 8
 let BINDING_IMG_WORLD_OUT = 9
+let BINDING_IMG_WORLD_INOUT = 10
 
 let UNIFORM_LEVEL = 1
 let UNIFORM_PROGRAM = 2
-let UNIFORM_SCREEN_SAMPLER = 3
+let UNIFORM_MOUSE_STATE = 3
+let UNIFORM_SCREEN_SAMPLER = 4
 let UNIFORM_WORLD_SAMPLER = 7
 
+
 let LEVELS = 8
 
 let SEARCH_R = 5

          
@@ 143,6 146,9 @@ buffer vertex-out : Vertices
 uniform smp-screen : sampler2D
     location = UNIFORM_SCREEN_SAMPLER
 
+uniform mouse-state : i32
+    location = UNIFORM_MOUSE_STATE
+
 fn simple-sphere (p)
     (length p) - 0.5
 

          
@@ 288,6 294,24 @@ fn matmapf (p)
         elseif 0
             scale := 100.0
             (nine-spheres (p / scale)) * scale
+        elseif 1
+            #p := p * 0.2
+            let d =
+                ((triquad-noise3 p) * 2.0 - 1.0) - 0.05
+
+            #let d =
+                min d
+                    ((triquad-noise3 (p / (vec3 100 2.0 2.0))) * 2.0 - 1.0) * 100.0 - 10.0
+
+            R := ((length p) - 30.0)
+            let d =
+                max
+                    max
+                        (length p) - 200.0
+                        d
+                    -R
+            #d * scale
+            d
         else
             scale := 300.0
             DD := (doubletori (p / scale)) as f32 * scale

          
@@ 308,7 332,7 @@ fn matmapf (p)
 
                         (deref d) * 40.0
                 else
-                    DD
+                    (abs DD) - 10.0
 
 
                 #Z - 30.0

          
@@ 670,6 694,10 @@ uniform world-out : WORLD_IMAGETYPE
     binding = BINDING_IMG_WORLD_OUT
     \ coherent writeonly restrict
 
+uniform world-inout : WORLD_IMAGETYPE
+    binding = BINDING_IMG_WORLD_INOUT
+    \ coherent restrict
+
 uniform smp-world : sampler3D
     location = UNIFORM_WORLD_SAMPLER
 

          
@@ 737,6 765,41 @@ fn generate-world ()
     imageStore world-out ipos (vec4 density 0 0 0)
     ;
 
+inline density->sdf (d)
+    0.5 - d
+
+inline sdf->density (d)
+    clamp (0.5 - d) 0.0 1.0
+
+fn update-world()
+    local_size GROUP_SIZE GROUP_SIZE GROUP_SIZE
+    ipos := (uvec3 gl_GlobalInvocationID.xyz)
+    #if (any? (ipos >= WORLD_SIZE))
+        return;
+    rd := (2.0 / (vec3 WORLD_SIZE))
+    fpos := (vec3 ipos) * rd - 1.0
+    pos := (fpos + 0.5 * rd) * WORLD_SCALE
+
+    d0 := (density->sdf (copy ((imageLoad world-inout ipos) . r)))
+    d := d0
+
+    origin := pos - 2.0 * (shglobals.view-inverse @ 3) . xyz
+    origin := origin - (shglobals.view-inverse @ 2) . xyz * 20.0
+
+    brush := ((length origin) - 5.0)
+
+    let d =
+        if (mouse-state & 4)
+            sdSmoothOr d brush 5.0
+        elseif (mouse-state & 1)
+            sdSmoothAnd d -brush 2.0
+        else d
+
+    if (d != d0)
+        imageStore world-inout ipos (vec4 (sdf->density d) 0 0 0)
+
+    ;
+
 #uniform lodlevel : i32
 
 #vvv print

          
@@ 1008,11 1071,6 @@ fn generate-cell-verts ()
                 static-if USE_LOD_ISO_OFFSET
                     0.5 / z - d
                 else (0.5 - d)
-            #do
-                origin := 2.0 * ((uv - 0.5) * WORLD_SCALE - (shglobals.view-inverse @ 3) . xyz)
-                origin := origin - (shglobals.view-inverse @ 2) . xyz * 5.0
-                max d
-                    (- ((length origin) - 30.0)) * 0.25
             d
 
         local cd : (array f32 8)

          
@@ 1624,6 1682,32 @@ inline main ()
             else
                 GL.GenerateTextureMipmap world
 
+        # edit world
+        # generate world
+        local mx = 0; local my = 0
+        mstate := (SDL_GetMouseState &mx &my)
+        if (mstate != 0)
+            #print mstate
+            let pg-updateworld = (compute-program update-world)
+            GL.UseProgram pg-updateworld
+            GL.Uniform mouse-state (mstate as i32)
+            GL.BindImageTexture BINDING_IMG_WORLD_INOUT world 0 GL.TRUE 0
+                GL.READ_WRITE
+                WORLD_PIXELFMT
+            GL.DispatchCompute (unpack ((WORLD_SIZE + GROUP_SIZE - 1) // GROUP_SIZE))
+            GL.MemoryBarrier (GL.TEXTURE_FETCH_BARRIER_BIT | GL.SHADER_IMAGE_ACCESS_BARRIER_BIT)
+            static-if USE_3x3x3_MIPMAPS
+                # generate mipmaps
+                let pg-genworldlod = (compute-program generate-world-lod)
+                GL.UseProgram pg-genworldlod
+                for lod in (range 1 (MAX_WORLD_LOD_I + 1))
+                    GL.BindImageTexture BINDING_IMG_WORLD_IN world (lod - 1) GL.TRUE 0 GL.READ_ONLY WORLD_PIXELFMT
+                    GL.BindImageTexture BINDING_IMG_WORLD_OUT world lod GL.TRUE 0 GL.WRITE_ONLY WORLD_PIXELFMT
+                    GL.DispatchCompute (unpack (((WORLD_SIZE >> (lod as u32)) + GROUP_SIZE - 1) // GROUP_SIZE))
+                    GL.MemoryBarrier (GL.TEXTURE_FETCH_BARRIER_BIT | GL.SHADER_IMAGE_ACCESS_BARRIER_BIT)
+            else
+                GL.GenerateTextureMipmap world
+
         # update terrain
 
         collect-sectors;

          
M testing/testfragment.sc +0 -1
@@ 262,7 262,6 @@ inline render-fragment-shader (func opts
                 cam_yaw += (ftoangle ((event.motion.xrel as f32) * pi * MOUSE_SPEED_X))
                 cam_pitch += (ftoangle ((event.motion.yrel as f32) * pi * MOUSE_SPEED_Y))
                 cam_pitch = (clamp cam_pitch (ftoangle (pi * -0.5)) (ftoangle (pi * 0.5)))
-
         case SDL_KEYDOWN
             let sym = (deref event.key.keysym.sym)
             switch (bitcast sym (typeof SDLK_f))