Skip to main content
added 375 characters in body
Source Link

On your first pass, you're additively blending your object into the stuff that's already in the render target. Since your object is presumably opaque, you want to make sure the stuff that's in the render target beneath your object is occluded. You could do this by setting your blend mode to glBlendFunc(GL_ONE, GL_ZERO) and rendering the object completely black, then proceeding with what you've already written. This will cost an extra rendering pass, and is non ideal.

A better solution, I think, is to render the first lighting pass with glBlendFunc(GL_ONE, GL_ZERO) and then all subsequent lighting passes with glBlendFunc(GL_ONE, GL_ONE). That way the first lighting pass will stomp anything already in the render target (effectively occluding what's behind the object) and the remaining lighting passes will add their light contribution onto the object the way you expect.

EDIT: Regarding the OPs update about only seeing the first rendering pass: make sure you set the depth compare function to something that will allow multiple fragments at the same depth to pass. You must use GL_LEQUAL or GL_EQUAL for each pass after the first (assuming your depth buffer is such that 1.0f represents the far plane and 0.0f represents the near plane).

On your first pass, you're additively blending your object into the stuff that's already in the render target. Since your object is presumably opaque, you want to make sure the stuff that's in the render target beneath your object is occluded. You could do this by setting your blend mode to glBlendFunc(GL_ONE, GL_ZERO) and rendering the object completely black, then proceeding with what you've already written. This will cost an extra rendering pass, and is non ideal.

A better solution, I think, is to render the first lighting pass with glBlendFunc(GL_ONE, GL_ZERO) and then all subsequent lighting passes with glBlendFunc(GL_ONE, GL_ONE). That way the first lighting pass will stomp anything already in the render target (effectively occluding what's behind the object) and the remaining lighting passes will add their light contribution onto the object the way you expect.

On your first pass, you're additively blending your object into the stuff that's already in the render target. Since your object is presumably opaque, you want to make sure the stuff that's in the render target beneath your object is occluded. You could do this by setting your blend mode to glBlendFunc(GL_ONE, GL_ZERO) and rendering the object completely black, then proceeding with what you've already written. This will cost an extra rendering pass, and is non ideal.

A better solution, I think, is to render the first lighting pass with glBlendFunc(GL_ONE, GL_ZERO) and then all subsequent lighting passes with glBlendFunc(GL_ONE, GL_ONE). That way the first lighting pass will stomp anything already in the render target (effectively occluding what's behind the object) and the remaining lighting passes will add their light contribution onto the object the way you expect.

EDIT: Regarding the OPs update about only seeing the first rendering pass: make sure you set the depth compare function to something that will allow multiple fragments at the same depth to pass. You must use GL_LEQUAL or GL_EQUAL for each pass after the first (assuming your depth buffer is such that 1.0f represents the far plane and 0.0f represents the near plane).

Source Link

On your first pass, you're additively blending your object into the stuff that's already in the render target. Since your object is presumably opaque, you want to make sure the stuff that's in the render target beneath your object is occluded. You could do this by setting your blend mode to glBlendFunc(GL_ONE, GL_ZERO) and rendering the object completely black, then proceeding with what you've already written. This will cost an extra rendering pass, and is non ideal.

A better solution, I think, is to render the first lighting pass with glBlendFunc(GL_ONE, GL_ZERO) and then all subsequent lighting passes with glBlendFunc(GL_ONE, GL_ONE). That way the first lighting pass will stomp anything already in the render target (effectively occluding what's behind the object) and the remaining lighting passes will add their light contribution onto the object the way you expect.