So, I’ve been busy the last month learning about other methods for rendering the voxels, specially on the GPU, I came across a method called raymarching which use signed distance functions (SDF) to create scenes, it is really powerfull and easy to write, you can create shadows, reflections and other effects with a few lines of code:

In raymarching you use a traditional ray casting method only that instead of advancing at a constant step you advance by searching the minimum distance to a solid in the whole scene:

Image by

The main problem with this is that you need to check the distance to all the objects in the scene to determinate how much you need to move, this is ok for 2 or 3 objects in the scene but not for a real (game) scene, you need a way to obtain just the object that falls in the ray direction, you can achieve this by many ways, the simplest one being using a raycast algorithm (Like this fast voxel traversal by Amanatides and Woo) in a grid to obtain the objects and then perform raymarching to get the pixel and other properties of the object. This improves the rendering time and let you have more complex scenes.

This works pretty well but since I need only small voxels (cubes) and no the others SDF so I wrote a small program in C++ to do raycasting on a voxels grid, this image contains a 64x64x64 grid but it supports bigger scenes at +60fps:

So I’m not going to continue what I had in JS using the greedy merging geometry (ala minecraft) but I will continue in C++, I have some issues right now, the main being sending all the voxels data to the GPU is rather slow, I tried writting a software renderer solution but with no luck so far due to speed issues, I’m also reading about OpenCL and CUDA but I’m not sure yet if I should use those. One thing that I’m sure is that I need to migrate the data from a raw array of voxels to a sparse voxels octree.

Anyways, this is still the beginning of this project (and this is by far the hardest thing I’ve ever tried), so I’m feeling a little patient and happy for now 🙂