Voxel Cone Tracing Global Illumination in OpenGL 4.3

Voxel Cone Tracing Global Illumination in OpenGL 4.3


Here is an implementation of global illumination (GI) using voxel cone tracing, as described by Cyril Crassin et al. in Interactive Indirect Illumination Using Voxel Cone-Tracing, with the Crytek Sponza model used for content.

This demo served both as a means to familiarize myself with voxel cone tracing and as a testbed for performance experiments with the voxel storage: plain 3D textures, real-time compressed 3D textures, and 3D textures aligned with the diffuse sample rays were tested. Sparse voxel octrees were not implemented due to time constraints, but would have been nice to have as a baseline reference. Compared to SVO in the context of voxel cone tracing (as opposed to ray casting, where SVO is a clear winner), 3D textures allow for easier filtering, direct lookups without evaluating the octree structure, and potentially better cache and memory bandwidth utilization (depending on cone size and scene density). The clear downside is the space requirement: 3D textures can’t scale to larger scenes or smaller, more detailed voxels. There may be ways to work around this deficiency: sparse textures (GL_AMD_sparse_texture), compression, or hybrid schemes that mix tree structures with 3D textures.

You can download the demo from this link.
The zip file includes the binaries files as well as the source code (Visual Studio 2010 project).

The demo requires the OpenGL 4.3 support. On my GTX 680 with R310.70, the demo runs at around 30 FPS:

Voxel Cone Tracing Global Illumination in OpenGL 4.3

Voxel Cone Tracing Global Illumination in OpenGL 4.3
Visualization of the voxels

source | via

14 thoughts on “Voxel Cone Tracing Global Illumination in OpenGL 4.3”

  1. Alex Nankervis

    Sorry to the folks who are trying to build the source code and are having trouble. I didn’t expect the demo to get much attention so I didn’t include all of the dependencies. Also, the version linked has an incompatibility with Windows 8. You can find a buildable version that is compatible with Win8 here (also includes a newly-built executable):

    http://naixela.com/alex/updated_demos.zip

    It’s in the projects/gi folder. If building and running from Visual Studio, you will need to set the debug working directory to:

    “$(ProjectDir)../..”

    So that it can find the data files. The demo uses somewhere between 1 and 2GB of VRAM, so if you get single-digit performance or a black screen, that is probably the cause.

  2. JeGX Post Author

    … I didn’t expect the demo to get much attention …

    It’s the Geeks3D effect 😉

  3. 3Dude

    GTX560: 11fps
    GTX670: black screen 🙁

    tried limiting grid dim from 256 to 128 and 64 but no luck. So it seems not a memory problem.

  4. pz

    Unfortunately:

    0.000: RenderGLSL: starting…
    0.185: RenderGLSL: failed to create window
    0.186: failed to create GLSL renderer

    file log.txt

    I have GTX 570 and Phenom II 955 BE CPU with Windows 7 x64.

  5. Alex Nankervis

    11 fps might be right for a 560, depending on the resolution you run at. A 680m is only getting about 18 at 1920×1200, for comparison.

    Make sure you guys have the latest beta driver from NVIDIA. They only very, very recently started including OpenGL 4.3 support. You’ll get the “failed to create GLSL renderer” error in the log if you don’t have GL 4.3 support.

    Some performance notes:
    25ms to draw the scene (the actual cone tracing part)
    9.4ms to clear the voxel textures prior to updating (ouch! wish there was a better way)
    3.8ms to generate the voxels
    12.7ms to generate the anisotropic voxel mipmaps
    4ms for other stuff

    So over half of the time is spent recreating the voxels from scratch, which obviously does not need to happen each frame.

  6. Gary Long

    Hi Alex,

    Thanks for the source code.
    Would voxelization with conservative rasterization be faster than rendering the scene in 6 directions?

  7. Gary Long

    I heard that you can re-use this technique to get soft-shadows for very low cost.

    Would this just be done by tracing the cone in the direction of the light and gathering alpha values instead of color values?

  8. Alex Nankervis

    Hi Gary,

    Conservative rasterization would likely be faster. I’m rendering the scene 6 times just for simplicity. You’d need to add a geometry shader stage to expand the triangles plus some extra clipping code in the fragment shader to get efficient conservative rasterization, and then you’d also pick the major axis in the geometry shader to rasterize against and have the fragment shader output to all touched voxels. I think either the original VCT paper or a related paper on fast voxelization talks about this – it’s pretty straightforward aside from how intrusive conservative rasterization can be. I think you end up with only one or two voxels exported per rasterized pixel, depending on how many slices along the major axis the triangle is crossing.

    Regarding soft shadows, I think you just get these for free. If there’s an occluder, it should block (partially or entirely) the transfer of light when tracing a cone. Also, area lights (if voxelized along with everything else) will naturally provide softer lighting. The effect isn’t that pronounced in my demo though – either because I’m not casting enough cones (I’m only doing a few, very coarse cones per pixel) or because I may have just gotten part of the implementation wrong 🙂

    Alex

  9. Gary Long

    Thanks for the reply Alex,

    According to Crassin’s thesis “Gigavoxels” he generates soft shadows using an additional single cone to capture the existing opacity values. The difference (which I still cannot quite understand how to implement) is that instead of a pixel on the surface that accumulates the values, it is instead a volume. The shape of the cone seems to be different for each type of light. For point lights, he has the apex of the cone starting at the point light.

    I’m still trying to work out how this could be implemented for a directional light, like the one in your implementation. One thing I have read that is done in ray-tracing is to transform the cone to use spherical coordinates.

  10. Alex Nankervis

    You could probably do soft shadows that way. I don’t think the performance would be very good, though. For each pixel, you’d need to trace a cone for each point light, so it wouldn’t scale well to a lot of lights. Also the cones would be fairly narrow, which is bad for performance. The specular cone in my demo takes as long to trace as all 5 diffuse cones combined. Or are you thinking of something else?

    With a global illumination approach, soft shadows and ambient occlusion should occur naturally, given enough accuracy / resolution. I’m only using 5 very wide diffuse cones per pixel to approximate the hemisphere of incoming light that hits each pixel. Any number of light sources can be stored into the voxels and will be picked up by those 5 cones without any extra work. With more, narrower cones you should start to see soft shadowing better. Performance would be bad, unless you distribute the cones across multiple adjacent pixels (the UE4 presentation talks about this). Also, the voxels in my demo might not be of high enough resolution to get good looking soft shadows. I don’t think I was able to reproduce the quality of ambient occlusion in Crassin’s paper, so maybe I’m doing something wrong or differently (there is a lot of room for interpretation… amount and distribution of the cones, voxel resolution, how and what you integrate in the mipmaps).

    Also, to clarify about the light sources in my demo: surfaces are lit by the directional light prior to being converted to voxels, so what goes into the voxel octree already has direct lighting from the sun. Later, a single bounce of that direct light is computed using VCT. The cubes are voxelized as emissive surfaces, so any lighting you see them contributing to the scene comes from the VCT only (they aren’t treated as point lights). Ideally, if I supported multiple light bounces in the demo, I would have the sky and cubes both voxelized as emissive surfaces and no cheating with the directional light / shadow map.

  11. Gary Long

    According to Crassin’s presentation:

    http://nvidia.fullviewmedia.com/siggraph2012/ondemand/SB134.html

    at 19 minutes into the video, he talks about how he implements soft shadows by tracing a single cone towards a single light source. I guess you’re correct that with multiple light sources, this would become more expensive as you would have to trace more cones per light source.

    There must be some way to blend the natural shadowing effect that comes with the GI with a shadow-map (maybe fade out the shadow-map with distance.

Comments are closed.