Skip to main content

Progress

ยท 2 min read

Shading placeholderโ€‹

Added shading based on world coordinate positions. This was mostly a test of adding new uniforms and vertex shader outputs to the shader program.

alt text

Voxelsโ€‹

Added a voxel model. Very inefficient at this point, but "correct."

alt text

Bug! ๐Ÿ›โ€‹

Tried increasing the resolution and found bugs :)

alt text

Guess: missing array data?

Manually counting the input data matches the generated positions array and checking against the runtime data...

  • 4416 voxels * 6 faces/voxel * 8 positions/face => 105984 positiions
  • 4416 voxels * 6 faces/voxel * 6 indices/face => 158976 indices

...seems correct.

Guess: too many draw calls?

Seems impossible as this is a single mesh.

Investigation: is it always the same voxels that are missing?

Flipping the order of the voxels during generation changes the missing voxels. Not sure what to conclude from this yet.

alt text

Drawing just the Z+ face on the voxels seems to work correctly. The same seems to be true when rendering any one of the six faces.

alt text

...but if as soon as 3 faces are rendered together, voxels seem to be lost.

Guess: too many indicies

Yup. The code is using u16 which has a max representable value of 256*256 = 65,536. There are 158,976 indices.

Changing to a u32 index buffer addresses the problem.

alt text

Resolution

Bumping the render code to always use u32 seems fine for this stage of development. Using the larger buffer size affords more flexibility, which is a higher priority right now than optimization for memory or performance.

Voxel chunking and optimizing away invisible faces need to be done regardless. After that is done, it should be easier to move back to a u16 index buffer.

A larger modelโ€‹

With the bug fixed, here's a sine + cosine generated voxel heightmap of 128x128x32 resolution.

alt text