Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Scene Voxels culling vs Volume culling

edited May 2021 in Codea Craft Posts: 2

I noticed there is a difference in the culling between volumes and scene.voxels

I’ve built a pretty satisfying noise tree for “cave” generation, I’m trying to create a generated side scrolling runner generated by noise, but my problem currently is that I cannot utilize the voxels engine as a 2D Surface because of the current culling behavior, to help explain what I mean, i added two screenshots, one of the initial tryout and one of an example project show casing the problem.



Blocks on the edges of the voxel system do not get rendered, and as a result, the terrain looks empty from a side view, comparing it with a normal volume entity (orange blocks), these are rendered as expected.
Now I realize this is probably for performance purposes, as the terrains are not meant to be viewed from the side,but can I somehow control this?

Another option I considered was to try to build a noise tree that flattens the closest z-indices, but I failed at that.

Here is the code of the example project:

— Main

-- VolumeSet

function makeScene()
    -- Create the scene
    scene = craft.scene()

    -- Move the main camera = vec3(0, 0, -10)

    -- Adjust the scene lighting
    scene.sun.rotation = quat.eulerAngles(45,0,45)
    scene.ambientColor = color(90,90,90)

    -- Turn on fog and set distances and color
    --scene.fogEnabled = true
    --scene.fogNear = 10
    --scene.fogFar = 50
    --scene.fogColor = color(255,255,255)

    -- Get the sky material and change the sky and horizon colors
    local skyMaterial = = color(44, 158, 241)
    skyMaterial.horizon = color(121, 144, 226)

    viewer =, vec3(0,10,0), 10, 5, 1200)

function makeBlocks()
    local basic = scene.voxels.blocks:new("Basic")
    basic.setTexture(ALL, "Blocks:Cotton Blue")

    local red = scene.voxels.blocks:new("Red")
    red.setTexture(ALL, "Blocks:Cotton Red")
function makeVol()
    local e = scene:entity()
    local v = e:add(craft.volume, 16, 32, 4)
    cx, cy, cz = v:size()
    b = v:blockID('Red')
    floor = craft.noise.const(b)
    air = craft.noise.const(0)
    v:set(0,0,0, v:blockID('Red'))

    scene.voxels:resize(vec3(28, 1, 28))
    scene.voxels.coordinates = vec3(0,0,0)

    scene.voxels:generate(readProjectTab("NoiseTree"), "generateTerrain")
function setup()

function update(dt)
        -- Update the scene (including physics, voxels and other systems)

function draw()

        -- Draw the scene (must be done within the draw function)

-- Noise tree seed = 0 function generateTerrain(chunk) cx, cy, cz = chunk:size() air = craft.noise.const(0) floor = craft.noise.const(chunk:blockID('Basic')) local n = noiseTree() chunk:setWithNoise(n) end function invert(n) local i = craft.noise.invert() i:setSource(0, n) local a = craft.noise.add() a:setSource(0, craft.noise.const(1)) a:setSource(1, i) return a end local function turb(n, f, s , p) local t = craft.noise.turbulence() t:setSource(0, n) t.frequency = f or 6 t.seed = s or math.random(0, 10000) t.power = p or 5.6 return t end -- Cache noise values in 2D space to reduce expensive computations function cache2D(chunk, input) local cache = craft.noise.chunkCache2D(chunk) cache:setSource(0, input) return cache end function split(a, b, p) local s = s:setSource(0, a) s:setSource(1, b) s:setSource(2, craft.noise.gradient()) s:setBounds(p, 1.0) return s end function checker(n) local s = s:setSource(0, craft.noise.const(0)) s:setSource(1, craft.noise.const(1)) s:setSource(2, n) s:setBounds(0.8, 1.0) return s end function mult(n, m) local mn = craft.noise.multiply() mn:setSource(0, n) mn:setSource(1, m) return mn end function mapp(a, b, n) local s = s:setSource(0, a) s:setSource(1, b) s:setSource(2, n) s:setBounds(0.5, 10) return s end function bounds(n) depth = 1 local s = s:setSource(0, n) s:setSource(1, floor) s:setSource(2, craft.noise.gradient()) s:setBounds(1.0 - depth / (cy + 0.0), 1.0) local s2 = s2:setSource(0, floor) s2:setSource(1, s) s2:setSource(2, craft.noise.gradient()) s2:setBounds(1.0 - (cy - 2) / (cy + 0.0), 1.0) return s2 end function noiseTree() local n = craft.noise.gradient() local zero = craft.noise.const(0) local n2 = invert(n) n = split(n, n2, 0.5) n = turb(n, 0.5, 2, 0.2) n = mult(n, craft.noise.const(1.5)) n = invert(n) n = checker(n) n = mapp(air, floor, n) n = bounds(n) return n end
Sign In or Register to comment.