PDA

View Full Version : multiple lights GL_MAX_FRAGMENT_UNIFORM_COMPONENTS



Schnulla
08-03-2010, 08:37 AM
Hi,

in my fragment shader I have some uniform arrays like
this for my directional and positional light sources:

#define MAX_LIGHT_SOURCES 8
uniform vec4 LSAmbientGlobal;
uniform vec4 LSAmbient[MAX_LIGHT_SOURCES];
uniform vec4 LSDiffuse[MAX_LIGHT_SOURCES];
uniform vec4 LSSpecular[MAX_LIGHT_SOURCES];
uniform vec4 LSPosition[MAX_LIGHT_SOURCES];
uniform vec3 LSNearFarAttenuation[MAX_LIGHT_SOURCES];
uniform int LSCount;

uniform vec4 MatAmbient;
uniform vec4 MatDiffuse;
uniform vec4 MatSpecular;
uniform float MatShininess;
There should be at least 64 uniform floats available
and according to this statistics (http://www.kludx.com/capability.php?capability=404) there are at least
two ATI Mobility cards with only 64 uniform floats.

Now my question:
The code above would exceed this limit of 64 floats.
I do not really care about these cards but a general
question raised up for me. If I want a lot of lights
(maybe even more than 8), how to bypass this limitation?

Anyone knows a good tutorial with some sample code
that targets this limitation?

Help is really appreciated! :)

ravage
08-03-2010, 01:34 PM
Deffered lighting. you could store the light data into a texture and read from it.

multipass with additive blending rather than trying to do all the calculations in the shader.

There's probably more but those are the ones that came to mind.

nickels
08-03-2010, 02:56 PM
I ran into the same problem a few months back, although I hit the limit on varying parameters.... Shadowmapping space limitations brought the forward approach to its knees.

In short, the (a) way to go is deferred rendering:
deferred stalker (http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter09.html)

I've had great success with it:
deferred (http://www.youtube.com/dneckels#p/a/u/0/-k7_mzpVNUk)

I have only good things to say about how the deferred approach simplified my shader setup. I guess it has some achilles heels (transparency, for instace), but....

Dark Photon
08-03-2010, 05:56 PM
I have only good things to say about how the deferred approach simplified my shader setup. I guess it has some achilles heels (transparency, for instace), but....
Yeah, also consider whether you need MSAA. Research carefully before you just decide to go Deferred Shading. Like everything, has it's pros and cons.

Also consider whether Deferred Lighting (Light Pre-Pass) is what you'd rather have, or whether it might be more efficient for you.

Also consider whether you'll really have 8 simultaneous lights, or whether that's an extreme example you'll almost never see, and can work around if you ever do.

Schnulla
08-04-2010, 04:29 AM
Thanks a lot!