Jump to content

Voxel Direct Lighting on the GPU


Josh

3,341 views

 Share

We left off on voxels when I realized the direct lighting needed to be performed on the GPU. So I had to go and implement a new clustered forward renderer before I could do anything else. Well, I did that and now I finally have voxel lighting calculation being performed with the same code that renders lighting. This gives us the data we need to perform cone step tracing for real-time dynamic global illumination.

Image2.thumb.jpg.622a818878c37434b40c7cab7c20d48f.jpg

The shadows you see here are calculated using the scene shadowmaps, not by raycasting other voxels:

Image1.thumb.jpg.a52554af408d9282d2a67fecf745d18f.jpg

I created a GPU timer to find out how much time the lighting took to process. On the CPU, a similar scene took 368 milliseconds to calculate direct lighting. On the GPU, on integrated graphics, (so I guess it was still the CPU!) this scene took 11.61064 milliseconds to process. With a discrete GPU this difference would increase, a lot. So that's great, and we're now at the third step in the diagram below:

scheme.png.1959d4c596fabb734cbbd03c20153028.thumb.png.c0a34dab2f94d1709e1449ec30964c43.png

Next we will move this data into a downsampled cube texture and start performing the cone step tracing that gives us fast real-time GI.

  • Like 2
 Share

4 Comments


Recommended Comments

Here's the scene using a higher voxel resolution. It looks interesting!

Image1.thumb.jpg.7cdd4ad4b29fa26b08b4153d94c19403.jpg

This is a 256x256x256 grid with a voxel size of 10 cm, so that gives you an idea of how much area that can cover. It's bigger than I thought it would be. Then you can have maybe 3-4 of these at bigger sizes, cascading out around the camera.

  • Like 2
Link to comment

Great work!  How much memory does the voxel grid use and is it stored on the GPU?  I'm thinking about large open worlds; would you generate all voxel data at large voxel sizes, then simply update in real-time the higher density voxel grid around the camera?

Link to comment
3 hours ago, SpiderPig said:

Great work!  How much memory does the voxel grid use and is it stored on the GPU?  I'm thinking about large open worlds; would you generate all voxel data at large voxel sizes, then simply update in real-time the higher density voxel grid around the camera?

At a resolution of 256x256x256 voxels, each grid will require 384 mb VRAM.

  • Like 1
Link to comment

Whew, that was difficult! I changed the the direct lighting routine to use transform feedback to render the direct lighting into a vertex buffer instead of using a texture, which was creating a lot of waste. The next step is to take the lit voxels and put them into a 3D texture. This is one of the hardest features I've ever implemented.

  • Like 1
Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...