Deferred Lighting
Deferred lighting will help us overcome performance issues with large numbers of lights in a scene, and will also allow us to implement normal mapping, specular highlights, The description at http://www.infinity-universe.com/Infinity/index.php?option=com_content&task=view &id=105&Itemid=27 is a useful reference, as is the Panda3D Fireflies tutorial.
Buffer Layout
The G-Buffers (generic buffers) we'll be using are as follows:
| Red channel | Green channel | Blue channel | Alpha channel | |
|---|---|---|---|---|
| Buffer 1 | Basic lighting R | Basic lighting G | Basic lighting B | Depth |
| Buffer 2 | Diffuse color R | Diffuse color G | Diffuse color B | Self-illumination |
| Buffer 3 | Normal X | Normal Y | Velocity X | Velocity Y |
| Buffer 4 | Extinction | ? | Specular amount | Material ID |
- Basic lighting
-
- Filled by a standard forward lighting pass
- Depth
-
- Filled with the contents of the depth buffer from the forward lighting pass
- Diffuse color
-
- The diffuse reflection color of the material at each pixel
- Self-illumination
-
- The self-illumination amount for the material at each pixel (illumination is performed by multiplying this by the diffuse color)
- Normal
-
- The X and Y components of the normal vector of the surface at each pixel (the Z component is calculated using
sqrt(1 - X**2 - Y**2)) - Velocity
-
- The difference between the view-space coordinate of this pixel from last frame and the view-space coordinate of this pixel in the current frame (only X and Y components) - used for motion blur
- Extinction
-
- The atmospheric extinction value for this pixel (TODO: How is this determined? What does it depend on? How is it used?)
- Specular amount
-
- The amount of specular reflection of the surface at this pixel
- Material ID
- Used to determine which material to use for this pixel (this can change which BRDF equation is used, how the above fields are interpreted, etc)
- The X and Y components of the normal vector of the surface at each pixel (the Z component is calculated using
If possible, all channels should be 16-bit floats.
A possible use for the remaining channel is to split the Extinction value into a red and blue component, generating the green component by averaging the two. That could possibly give us more accurate atmospheric scattering, but we'd have to look at what usual values for color extinction are.
Issues
There are several issues with using deferred lighting, listed below. Creative solutions welcomed.
Transparency
According to all the documentation I've been able to find, deferred lighting is incompatible with rendering transparent objects; they suggest rendering all transparent objects over top of the scene in a final pass, and using standard direct lighting on them. We may be able to make this slightly better by applying the nearest n lights (where n is the maximum number of lights the OpenGL implementation allows; generally rather small) to each transparent object when rendering.
Antialiasing
Deferred lighting is also incompatible with FSAA, or multisampling in general, according to everything I've found. This causes major visual glitches for things like power lines. The only proposed solution so far is to use edge detection and a blur filter as a post-processing step, but that won't fix missing pixels for very thin objects. (like power lines)