05
Nov
09

Deferred Lighting + SSAO + VSM v1.0

Just an update on a school/personal project. The scene is rendered using deferred lighting, screen space ambient occlusion and variance shadow mapping. There are 300 local lights and 1 global light contributing to all the colors; I just randomly pick the local lights’ position and size to get some interesting looks. Next I want to add some textures and implement ATI’s Tatarchuk “Dynamic Parallax Occlusion Mapping with Approximate Soft Shadows” for the floor and such =P.

Deferred shading is a shading algorithm where information is stored to several intermediate buffers instead of straight to the color buffer. Many times, in forward rendering, lighting calculations will be spent on fragments that end up being overwritten by occluding objects in the scene. The idea behind deferred shading is that we hold off on lighting calculations until needed.

1) Render all the geometry of your scene to a G-Buffer. The G-Buffer will hold fragment normals, positions and any other information you’d need to have later on for your lighting calculation. Usually the following step-up will get you far enough along to see some results…
Render Target1: gl_FragData[0] = 3DPosition.x, 3DPosition.y, 3DPosition.z, Free
Render Target2: gl_FragData[1] = Diffuse.r, Diffuse.g, Diffuse.b, Specular
Render Target3: gl_FragData[2] = Normal.x, Normal.y, Normal.z, Free
However, you’ll want to optimize this setup based on your hardware caps.
Tip: Storing only Normal.x and Normal.y you can re-derive Normal.z later knowing that it has unit length.
Tip: You derive Position.xyz for each pixel by using 2D screen coordinates and a reconstructed linear depth.
2) Now that you have the G-Buffer you can run your global lighting shader by passing in the G-Buffer and exciting each pixel on the screen with a full-screen quad. The global lighting shader will use the information from the g-buffer to light everything on screen.
3) Local lighting works the same way. “Excite” only the pixels you want to light by rending small spheres or cones or whatever. This will, in-turn, ignite the fragment shader to work on only parts of the scene that are effected by each local light.
4) Sky’s the limit… do what ever post-processing effect you want. Just know that the idea here is run calculation on as few pixels as possible. If you have 100 HUGE local lights that fill the entire screen 100xtimes over, you’re missing the point.
There are many optimizations to be have, I’ll touch on these later.

PS: I created the cloth using springs and Verlet integration.

Advertisement

0 Responses to “Deferred Lighting + SSAO + VSM v1.0”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.