Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

Your Answer


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.