Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I implemented deferred rendering in my little engine using framebuffers but there is no dynamic lighting for now. The g-buffer contains positions and normals in view space and albedo.

To implement real time lighting, I guess that I need to perform one pass for each light. Given the position and shape of a light, how can find all pixels affected by the light? I want to support point lights, spot lights and directional lights.

share|improve this question
    
Since point lights are just sphere, you render a sphere of a size of a spotlight on the position of light. And what you get in pixel shader for this are pixels affected by this light. Spot lights are similar, and directional lights are rendered as fullscreen quad (since everything is affected by them) –  Kikaimaru Mar 27 '13 at 18:45
add comment

1 Answer

up vote 0 down vote accepted

In deferred shading, one usually just draws some geometry that bounds the light's area of effect in world space, such as a polygonal sphere or cone that encloses the point or spot light's mathematical sphere or cone.

The simplest thing to do is draw the back faces of this geometry (front face culling) with the depth test reversed (greater-than instead of less-equal). Then any pixels that are between the camera and the back faces of the light geometry will get shaded.

This also shades pixels between the camera and the front faces of the light geometry, which are outside the light and therefore don't need to be shaded. There are various optimizations that can be done to remove these pixels, such as a depth bounds test or stencil masking.

For a directional light, you do a full-screen pass.

share|improve this answer
    
What comes to my mind for excluding pixels in front of the light volume is to draw the sphere with back face culling again and use the opposite depth test. But how can I prevent shading pixels inside the light geometry which are occluded by walls, for example? –  danijar Mar 27 '13 at 20:50
    
Well, once you've already shaded the pixels in front of the light volume you can't un-shade them, so drawing the light a second time doesn't help. As for pixels inside the light geometry that are occluded by walls - now you're talking about shadow casting, which is a whole other can of worms. It can be done using shadow maps for spot lights, and omnidirectional shadow maps for point lights. But that's really a completely separate issue. –  Nathan Reed Mar 27 '13 at 21:11
    
Thanks for your explanations, though I realized that deferred lighting is a hard fake. –  danijar Mar 27 '13 at 21:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.