0

I just have some questions about deferred shading. I have gotten to the point where I have the Color, Position ,Normal and textures from the Multiple Render Targets. My questions pertain to what I do next. To make sure that I have gotten the correct data from the textures I have put a plane on the screen and rendered the textures onto that plane. What I don't understand is how to manipulate those textures so that the final output is shaded with lighting. Do I need to render a plane or a quad that takes up the screen and apply all the calculations onto that plane? If I do that I am kind of confused how I would be able to get multiple lights to work this way since the "plane" would be a renderable object so for each light I would need to re-render the plane. Am I thinking of this incorrectly?

Raki
  • 329
  • 3
  • 18
Devvy
  • 167
  • 2
  • 7
  • I just thought of this, do I make a final texture and do all the calculations onto that texture? That makes sense...hmmm, I will try that – Devvy Oct 20 '14 at 01:43

1 Answers1

1

You need to render some geometry to represent the area covered by the light(s). The lighting term for each pixel of the light is accumulated into a destination render target. This gives you your lit result.

There are various ways to do this. To get up and running, a simple / easy (and hellishly slow) method is to render a full-screen quad for each light.

Basically:

  • Setup: Render all objects into the g-buffer, storing the various object properties (albedo, specular, normals, depth, whatever you need)
  • Lighting: For each light:
    • Render some geometry to represent the area the light is going to cover on screen
    • Sample the g-buffer for the data you need to calculate the lighting contribution (you can use the vpos register to find the uv)
    • Accumulate the lighting term into a destination render target (the backbuffer will do nicely for simple cases)

Once you've got this working, there's loads of different ways to speed it up (scissor rect, meshes that tightly bound the light, stencil tests to avoid shading 'floating' regions, multiple lights drawn at once and higher level techniques such as tiling).

There's a lot of different slants on Deferred Shading these days, but the original technique is covered thoroughly here : http://http.download.nvidia.com/developer/presentations/2004/6800_Leagues/6800_Leagues_Deferred_Shading.pdf

Mark Simpson
  • 23,245
  • 2
  • 44
  • 44
  • 1
    Thank you! I will be accepting this as the answer. I was asking this question mostly because I couldn't seem to get the final render to work and I was wondering if maybe I was misunderstanding how to get to that point. Come to find out I was just binding the wrong vertex data when I was trying to render my point light and calculating the data from that. Thankfully I figured it out and can continue with this I can't believe I wasn't binding the vertex array before drawing – Devvy Oct 20 '14 at 02:46