PDA

View Full Version : Rendering more than one light.



Baggio
06-22-2005, 07:55 AM
I can render one light with no problems, everything works great but now I have to render more than one light. Now, I know that I have to render my scene again for each light (obviously, just the geometry affected by that particular light) but I don't know what blend and/or depth mode I should activate before I render each light so that everything works right. BTW, there is no base pass, I calculate everything in my shader.

Thanks in advance.

fpo
06-22-2005, 08:53 AM
The most efficient way is to render a depth only pass first (disable color write and enbale depth write). Then disable depth write and enable color write and render the lights with additive blending (GL_ONE,GL_ONE). Just take care with ambient lihting (should only happen in first light at each geometry).

To get even better use deferred shading where the lighting pass(es) are totaly independent from geometry (each light pass uses a single screen aligned quad).

And make sure to use light scissor as in this other post:
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=013474

Korval
06-22-2005, 10:55 AM
I can render one light with no problems, everything works great but now I have to render more than one light. Now, I know that I have to render my scene again for each light (obviously, just the geometry affected by that particular light) but I don't know what blend and/or depth mode I should activate before I render each light so that everything works right.Why do you have to render your scene again for each light? Nobody's forcing you to do this. Well, nobody but stencil shadows anyway.

If you have the shader room to spare, you can most certainly render multiple lights in one frame.

BTW, to answer the thrust of your question, lights are additive. However, this works best if everything stays in floating-point, and you allow for real HDR. If you don't, then adding is probably going to saturate quickly when you have many lights.

zed
06-22-2005, 12:49 PM
i find u get a bit more headroom with ONE ONE_MINUS_SRC_COLOR

Baggio
06-24-2005, 05:38 AM
Cool, thanks for the help guys. So, now I suppose I will have to separate the ambient and the lighting pass. Now, should I still the first pass with the the color write disabled? I was thinking about replacing that pass with the ambient pass, is that a good idea? or would doing the depth pass only first, then ambient, then lighting be faster even if it is one more pass?

fpo
06-24-2005, 06:09 AM
The good thing on doing first pass with depth only is that on nvidia cards you are supposed to get double the fillrate if writing to a single buffer. If you do depth and color (ambient) you will not get the speedup (will be like a regular pass).

One thing you can do to avoid the extra ambient pass is to use the depth only first and then on first lighting pass do it with blend (ONE,ZERO) adding ambient term to the lighting shader. Then on following lighting passes you use blend (ONE,ONE) and forget about ambient term (pass ambient 0). The only problem with this is the parts without any lighting (ambient only)... you will have to render them separated.