GPU Voxelization

For my GI Algorithm I had to voxelize my geometry, so I made a simple tool which converts a mesh to a 3D Voxel texture, where the alpha component represents a voxel. You can store any information like normals, diffuse etc in the RGB components if you wish.

Source code:
https://github.com/tobspr/RenderPipeline/tree/master/Toolkit/Voxelizer

It runs fully on the GPU, using Compute Shaders, so It’s very fast. It just needs a bit time to write the result to disk.
Put your geometry in a folder convert/, then hit voxelize.py. You can use the show_voxels.py to control the result.

a 128x128x128 voxel grid comes out as 47 KB png, so baking lightmap information into is very memory friendly. You can also generate lightmap texture coordinates based on the voxels

Example of the sponza scene (128x128x128 Voxel grid):

Amazing!

Update

Just hit voxelizer_gui.py, you need PyQt4 to run it

Interesting! :slight_smile:

I don’t have the knowledge to assess how impressive this is, I fear, but it does seem very cool!

Update

  • I’ve changed the algorithm, it is now much faster, arround 20ms to generate the voxels, and 3 seconds to extract and write a 512x512x512 voxel grid to disk. I think 3 seconds is okay, as the voxel texture is 16348 * 8192 pixels (although only 7 mb). You could now use the voxelizer to generate voxels in realtime, for example for animated models, as you can skip the extensive disk-write step then.
  • Also this algorithm allows much larger grids (namely 256 and 512), for an example sponza scene with 512 grid see the screenshot below
  • The tool for displaying the voxels is a bit buggy, but it is enough to control the result
  • Simplified the gui, as not all options are required with the new algorithm

Hi Tobias,

this is an amazing work. How you’ll find the idea to make it dynamic?

For example, using a dynamic voxel grid like LOD. The nearer to the object(s) the finer the grid. And with procedural textures it would be possible to have a deep LOD.
And if it will be possible to use procedural geometry like parametric meshes, then it will be possible to ‘zoom-in’ to infinity.

To avoid disk-rw maybe it is possible only use RAM-read/write processing or only with GPU (shadering).

Kind Regards

PriNova

Hi, that is definetly possible! The voxlization time for the whole scene is 10-20 ms, so when splitting it would work very fast … you could have a look at sparse voxel octrees … I’ll implement them for my GI too, they allow a theroretically unlimited size of the voxel tree, if you combine that with mipmaps, you have a lod system :slight_smile:

If you do everything on the gpu, as I currently do, you won’t have to write the textures to disk, which saves you a lot of time.