View Full Version : How to avoid saturation with multi-pass lighting?

05-01-2008, 02:33 AM

is there a way to avoid saturation with multi-pass lighting (i.e. where a triangle is rendered N times for N light sources affecting it, using glBlendFunc (GL_ONE, GL_ONE) for each except the first pass)?

(Please don't propose deferred shading, that's not what I am looking for. :))

05-01-2008, 04:28 AM
The correct way is to use a floating point render target then tone map.

For older hardware there is a hack called smooth blend:

05-01-2008, 06:19 AM
(Please don't propose deferred shading, that's not what I am looking for. :))

You right it's not, if your stuck using RGB8 then the only way is to lower the intensity of the lights, but more importantly reduce the number of lights used at any one point as no more than 4-5 is ever needed (Main with ambience, limited area, fill, highlight and effect if your doing that stuff).

but as sqrt[-1] said the best way is using floating point textures.

05-01-2008, 12:40 PM

05-01-2008, 05:13 PM
Either I have understood something wrong, or I cannot render volume shadows if I use a texture as render target (to get an fp render target). Binding a stencil buffer to it failed when I tried to.


It's possible to get that too, as I describe in this old thread: http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=008447

Same thing in short: Start from white, render with negative colors, modulate lights instead of adding them and negate the final result.

The link is dead. Someone mind explaining this to me a little more detailed? I cannot figure it from that short remark.

05-06-2008, 08:21 AM
you need to setup your fbo with a depth/stencil render buffer, like this:

glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, x, y );

05-07-2008, 11:51 AM
I tried that, didn't work.

I'd like to know more about that inverse blending technique.

05-07-2008, 02:17 PM
Don't forget that you also need to bind the GL_DEPTH24_STENCIL8_EXT texture to the STENCIL_ATTACHMENT_EXT target.

05-07-2008, 07:17 PM
Did you try the smooth blend hack I mentioned above?

First geometry pass : ONE, ZERO
all other passes: ONE, ONE_MINUS_SRC_COLOR

05-08-2008, 12:53 AM
Yes I did, thanks for the hint. I have run into problems when using multi-light per pixel shaders with that method though (see other thread).