This one is a quick & dirty demo of a typical fat-gbuffer approach to deferred lighting using OpenGL and GLSL.
By deferring the lighting until after the primary geometry passes, we are allowed the headroom to calculate a lambertian lighting equation many hundreds of times in screen space per frame. The practical limit for light count in this demo is about 2056. So you can have up to 2056 visible dynamic lights in the scene at any one time.
So we make a primary pass of scene geometry to the gbuffer. We render to two buffers at one time currently. We render the viewspace normal and surface depth to one target, and the diffuse color to the other. In a second pass we sort the lights based on visibility and whether the camera is inside the light or not, then we stream the lights in as simple boxes which are the size of the light radius. With this vertex format we also pass camera position, light position, light color, light radius, and attenuation parameters. As the lights are streamed in, the world in view space is reconstructed and the result is passed per pixel to the back buffer.
Because this is a pre-cursor to a proof of concept demo, this obviously does not make use of MSAA.
The source code and executable can be found at:
http://www.moogenstudios.com/wp-content ... ferred.rar
Single Point Light:
Several hundred point lights:
Demo: Deferred Lighting in OpenGL
Moderator: Coders of Rage
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Demo: Deferred Lighting in OpenGL
Goddamn. You win, sir. I hope to screw around with it (try to learn some of it) when I get home.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Demo: Deferred Lighting in OpenGL
On a general related note, you might be interested in http://www.bungie.net/Inside/publications.aspx#pub23083
Lighting Research at Bungie
Author: Hao Chen, Natalya Tatarchuk
Straight out of Siggraph '09, Hao Chen and Natalya Tartartuk talk shop on lighting research at Bungie. Their presentation focuses on high-quality real time lighting with advanced atmospheric rendering and continuous time of day, as well as efficient prefilterable soft shadows. It also takes a look at fast methods for generation of pre-computed global illumination using modern GPUs.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: Demo: Deferred Lighting in OpenGL
I've actually read that one. There's quite a massive number of indirect illumination papers out there. Instant radiosity proves to be the only real efficient method of doing indirect illumination in real time since it's very low frequency. That's actually where this next demo is going, there's actually code in there now that reads to and from flux buffers which will be used to generate the VPL's which will ultimately contribute to all of the indirect term.