gl_lightSource initial values?

I want to implement multiple light support for my shader with use of gl_lightSource[i] to get my lights.

I know that maximal 8 lights are supported, and that the number of lights cannot be passed to the shader by a uniform variable to use in a for loop for calculating my lightning for the number of lights.

So we have 2 possibilities:

  1. Create 8 versions of each shader to calculate the shader with the respective numbers of lights.

  2. Or to always calculate 8 lights.

I really dislike point 1, but for point 2, I need to know what are the initial values of the Lights.

For example we have a Model with our Shader lit by 3 lights.
gl_LightSource[i]; 0 <= i <= 7;

Only 3 lights are active, what are the other lights Colours ?

like: gl_lightsource[i].diffuse ?,

I assume the initial values should be 0,0,0,0

with this knowledge I could do: (pseudocode)

for (int i=0; i = 7; i++) {
if (!gl_lightsource.diffuse == 0) {
//calculate lightning
}
}

So that I will have a better performance.

Anyone knows those values ?

The minimum is 8 lights in the fixed pipeline. You can of course exceed this using your own uniforms. You are of course limited by the number of instructions supported.
If you are going to do this in the vertex shader, you can use a dynamic loop I beleive. Even SM 2 hardware support dynamic loops in the VS but perhaps you risk having problems on old ATI SM 2 GPUs.

thanks for the reply

if dynamic loops are supported, this would be the best case, then if the engine can pass the number of lightsources to the vertex shader it would work fine,

We have a fixed hardware system with Geforce7950 Graphic cards, so this should not be an issue.
Will check it out tomorrow at work.

I found the initial values -.-, should have seen it earlier
opengl sdk

djmj10: Only 3 lights are active, what are the other lights Colours ?

as far as i know only the 1st light contains diffuse(1,1,1,1) all others are set to (0,0,0,0) in the fixed function pipe. and you should consider the possibility to turn off a light at runtime for example to simulate some switch or something or if the bounding sphere of the light is out of frustum and it wont influence the scene. the engine could set them as f.e. 3 lights form 0-2 and then you break the loop if first diffuse 0 is hit.

@_NK47

thats what I meant, stoping the lightning calculations when diffuse specular and ambient is found being at initial values

I need a shader performance tool to test it, will check the internet for it, because ShaderDesigner does not work fine with lightnings, and Rendermonkey cannot use gl_LightSources

And we use geforce8800gt as lowest graphic card

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.