How to optimize a Minecraft-like Voxel system?

I wasn’t sure how to translate my knowledge of using noise on continuous meshes (where you can augoment vertex coordinates directly with noise values). Here, you need everything “quantized” to the block size.

However, I figured it out, and I’d say.NOW I’m cookin’ with gas:

Fast chunk generation time (will get slower when I add caves), “real” terrain w/ Fractal Brownian Motion, and good view distance (will only get better from here - actually, not even close to pushing the limits in this test) :smiley:

Edit:
For reference, here is the literal code, but it’s NOT what I’ll be using - I just cooked this up for more prototyping to get the result above. It still has to deal with caves (which I have a few approaches I’m experimenting with):

from bge import logic, types, events
from opensimplex import OpenSimplex
from time import time
#from mathutils import Vector

seed = 123
chunkSize = 16 # Chunks will be NxNxN blocks
noiseScale = 0.005 # Sample noise at smaller/larger scale
threshold = -0.2 # If noise sample > this, add a block


blockSpacing = 1 # Generally, don't change this....


noise = OpenSimplex(seed)
n2 = noise.noise2d
n3 = noise.noise3d


s = logic.getCurrentScene()

b = types.KX_BatchGroup([s.addObject("Cube.002")])


def remapVal(x, in_min = -1, in_max = 1, out_min = -20, out_max = 20):
    return (
        (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
    )


def fbm(x,y,z=0,octaves=8,lacunarity=2,gain=0.5):
    #noise = PerlinNoise3(nsx, nsy, nsz, table_size, seed)
    amp = 1
    freq = 1
    total = 0
    for i in range(octaves):
        total += amp * n3(x * freq, y * freq, z * freq)
        amp *= gain
        freq *= lacunarity
    return total

t = time()

# Surface only noise crawl
for x in range(chunkSize*8):
    for y in range(chunkSize*8):
            h = int( 
                remapVal( fbm(x*noiseScale,y*noiseScale, 0*noiseScale) )
            )

            o = s.addObject("Cube")
            o.worldPosition = x,y,h

I will ofc, be switching to mathutils’ noise offerings, et al. Again: this was just hacked together from what I already had.

Decided to take another screenshot with some color, b/c I’m so damn pleased with these results:

Looking back from the opposite corner:

Low framerates are just simply due to the fact I haven’t applied previously implemented optimizations to this approach and these were taken on my AMD APU. Mainly, I’m just super happy with the terrain results at this stage. By tweaking some of the variables/function params, I can get plenty of variation for biomes. The only thing this can’t do yet is overhangs, but I think i can solve this with my cave generator.

Nevertheless, this last screenshot shows just how far Fractal Brownian Motion can go without much effort…Planes to foothills. I have yet to see what lies beyond, as I’m working on other problems now.