Take the 2-minute tour ×

I have two light sources on my scene. I created two fbo's which store depth textures for these lights. A render loop looks like this:

bind fbo1
save depth values for first light 
unbind fbo1

bind fbo2
save depth values for second light
unbind fbo2

enable additive blending

bind first depth texture
render scene
bind second depth texture
render scene

disable additive blending

For one light source the program works fine. For many light sources I use an additive blending to acumulate lighting results but then some objects become transparent (for example when an object which is further away from the camera is drawn before an object which is closer to the camera). How to resolve that problem ? How should I accumulate lighting effects for many light sources (many shadow maps) ? P.S. I use OpenGL/GLSL 3.3+

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Ensure depth testing is enabled when you perform your additive blending passes. This will prevent pixels from being blended into the framebuffer if they are behind another object. You will have to initialize the depth buffer first, of course. This can be done with a depth-only pass at the start of the frame (enable depth testing and writing, but disable color writes). The depth pass can also be combined with the first lighting pass; just render opaque rather than using additive blending for that first pass.

share|improve this answer
add comment

Your Answer


