Finalizing Shaders and Real-time Global Illumination Progress
I'm finalizing the shaders, and I was able to pack a lot of extra data into a single entity 4x4 matrix:
- Orthogonal 4x4 matrix
- RGBA color
- Per-entity texture mapping offset (U/V), scale (U/V), and rotation
- Bitwise entity flags for various settings
- Linear and rotational velocity (for motion blur)
- Skeleton ID
All of that info can be fit into just 64 bytes. The shaders now use a lot of snazzy new function like this:
void ExtractEntityInfo(in uint id, out mat4 mat, out vec4 color, out int skeletonID, out uint flags) mat4 ExtractCameraProjectionMatrix(in uint cameraID, in int eye)
So all the storage / decompression routines are in one place instead of hard-coding a lot of matrix offset in different shaders.
A per-entity linear and angular velocity is being calculated and sent to the rendering thread. This is not related to the entity velocity in the physics simulation, although they will most often be the same. Rather, this is just a measure of the distance the entity moved since the last world render, so it will work with any motion, physics or otherwise.
In the video below, the linear velocity is being added to the camera position to help predict the region of the GI lighting area, so the camera stays roughly in the center as the GI updates. A single 128x128x128 volume texture is being used here, with a voxel size of 0.25 meters. In the final version, you probably want to use 3-4 stages, maybe using a 64x64x64 texture for each stage.
Performance of our voxel cone step tracing is quite good, with FPS in the mid-hundreds on a mid-range notebook GPU. The last big question is how to handle dynamic objects, particular fast-moving dynamic objects. I have some ideas but I'm not sure how hard this is going to be. My first attempt was slow and ugly. You can probably guess which dragon is static and which is dynamic:
It is a difficult problem. I would like the solution to be as cool as the rest of this system as I finish up this feature. Also, I think you will probably want to still use SSAO so dynamic objects blend into the GI lighting better.
Everyone should have access to fast real-time global illumination for games.
- 8
- 1
8 Comments
Recommended Comments