# How are lights rendered as geometry in deferred shading?

1. So my problem is that: At the last stage of implementing this I had problem with this sentence, " the lights in the scene are rendered as geometry". What does this mean?

2. Why do I store depth info for the model in an earlier stage?

3. What is texture projection ?

I had try to read many tutorials, but every time I end up coming here because I find what I need.

-

1. "The lights in the scene are rendered as geometry" means that you draw a polygon mesh that encloses the light's region of influence. For example, if it's a point light you draw a sphere of the light's radius. For a spotlight you draw a cone, etc.

The reason to do this is you are trying to select exactly those pixels on the screen that the light will have an effect on. You could simply render each light as a full-screen quad, hitting every pixel on screen; you must do this for a directional light, since it has no finite region of influence, but for point and spot lights this would be very inefficient, because in many cases, the light will only affect a few pixels, so you waste a lot of time processing pixels that have no effect from the light.

By drawing a mesh in the shape of the light's region of influence, you put the GPU to work to pick out just the pixels you need to draw.

2. To evaluate the lighting equations for a pixel, you need to know where that pixel is in space. It's possible to store the world-space position in a floating-point G-buffer, but that's wasteful. The world-space position of a pixel can be reconstructed from its screen-space XY position and the depth buffer, using a little math. The depth requires much less space than the full position. You store depth so you can reconstruct position later.

3. Texture projection is a method of generating UVs for a texture map that make it look like the texture is being projected onto the geometry, such as by a film projector. In the context of deferred shading, texture projection can be used to project full-screen buffers (G-buffer, depth buffer) from the camera onto the light source geometry, generating UVs that match the screen-space XY coordinates, so that each pixel drawn will sample exactly the same pixel in the full-screen buffers. However, the `VPOS` pixel shader semantic (in D3D9 HLSL) can be used to get the screen-space position of the pixel directly. Texture projection is also used when applying a spotlight shadow map.

-
thank you so much – Mohammad Ahmed Aug 1 '12 at 12:40
@MohammadAhmed remember to accept his answer. – Jonathan Dickinson Aug 1 '12 at 13:33
@JonathanDickinson Ok I accepted it :) – Mohammad Ahmed Aug 2 '12 at 13:03