Lighting Algorithms
For realtime 3D rendering
The Equation
Phong Reflection Model
The Equation
Phong Reflection Model
Illumination = ambient light + the sum of all light's reflection towards the viewer
Easy concept, complex math
Main point: it's costly
Early methods
Offline rendering
- Gouraud Shading, a kind of vertex-based lighting
- Calculate light at points, interpolate between points
- Light Maps
- "Baked In" lighting that uses multitexturing
- Calculated in level or model editor with raytracing, results saved in file
- Static geometry, not moving
Gouraud
Baked into vertices themselves, common in PSX and N64 era
Light Maps
*
=
http://www.cs.bath.ac.uk/~pjw/NOTES/pics/lightmap.html
Forward Rendering
The "brute force" way
Two streams of input: meshes and lights
Output: 2D representation of mesh on-screen
- For each mesh,
- add up each light's contribution
- multiply total light by diffuse texture color
Forward Rendering
Looks good, but costly
Games either used offline lighting entirely or used forward rendering very sparingly
Forward Rendering
http://www.polycount.com/forum/showthread.php?t=104415
Deferred Rendering
Apply lighting to only seen pixels
Save lighting calculation as last step
Render model information to screen, light as last step
Forward Rendering cost:
N meshes * M lights
Deferred Rendering cost:
N meshes + N lights + static cost of creating G-Buffer
Deferred Rendering
Two stages:
Stage 1:
- Two streams of input, lights and meshes again
- Output: a set of fullscreen textures known as a Geometry Buffer, or "G-Buffer"
Stage 2:
- Input: G-Buffer
- For each light, do calculation on G-buffer
- Output: Final lit scene
Deferred Rendering
G-Buffer: Diffuse, Normal, Depth
Fully lit scene in bottom right
http://www.neuroproductions.be/uploads/openglGame/DeferredShadingOpengl.jpg
Deferred Rendering
G-Buffer: Diffuse, Normal, Depth, Light
Fully lit scene on bottom
http://3.bp.blogspot.com/-RuoVTYRh-wE/Teq7UVwSN8I/AAAAAAAABMY/VlfL8R6wGJA/s1600/deferredshading101.png
Deferred Rendering
Some disadvantages:
Can't blend transparent objects
- Engines that do mix forward and deferred
G-buffer takes up a lot of memory
"Forward+" Rendering
Most recent, still experimental
Extension of both Forward and Deferred
Essentially, Forward + Light Culling
"Forward+" Rendering
Most recent, still experimental
Extension of both Forward and Deferred
Essentially, Forward + Light Culling
Same as Forward Rendering, with intermediate step:
Screen is subdivided into clusters or tiles
Cull lights by drawing them as sphere and placing them into list of lights on cluster or tile
Draw only with lights for pixel that cluster is in
"Forward+" Rendering
Lighting Algorithms
By tdhoward
Lighting Algorithms
- 590