Ok, I have an old shader that demonstrates the problem. (I know the actual lighting calculations are incorrect, but this was simply at test shader). If I change all the gl_LightSource[i] entries in the PointLight function, to gl_LightSource[0], everything works fine for one light (when I only call it once of course). If I leave the i in each entry, I get “ERROR: LineNumber: [ : array must be redeclared with a size before being indexed with a variable” on each line that uses the array index in PointLight.
This shader should produce 292 (lights) + 112 (Point light uniforms if unrolled completely) + 20 (in main) + 6 (globally defined) = 106 uniforms for this script to compile.
uniform sampler2D tex0;
varying vec3 Normal, EyeCoordsPosition;
void PointLight( in int i,
in vec3 lEyeCoordsPosition,
in vec3 lEyeCoordsNormal,
inout vec4 lAmbient,
inout vec4 lDiffuse,
inout vec4 lSpecular )
{
float SpecularPowerFactor = 0.0;
vec3 LightVector = normalize( gl_LightSource[i].position.xyz - lEyeCoordsPosition.xyz );
float NormalDotLightVector = max( 0.0, dot( lEyeCoordsNormal, LightVector ) );
if( NormalDotLightVector > 0.0 )
{
vec3 EyeVector = normalize( -lEyeCoordsPosition );
vec3 Reflection = normalize( -reflect( LightVector, lEyeCoordsNormal ) );
SpecularPowerFactor = pow( max( dot( Reflection, EyeVector ), 0.0 ), gl_FrontMaterial.shininess );
}
lAmbient += gl_LightSource[i].ambient;
lDiffuse += gl_LightSource[i].diffuse * NormalDotLightVector;
lSpecular += gl_LightSource[i].specular * SpecularPowerFactor;
}
void main( void )
{
vec4 Ambient = vec4( 0.0, 0.0, 0.0, 1.0 );
vec4 Diffuse = vec4( 0.0, 0.0, 0.0, 1.0 );
vec4 Specular = vec4( 0.0, 0.0, 0.0, 1.0 );
vec4 texture = texture2D( tex0, gl_TexCoord[0].xy );
{
PointLight( 0, EyeCoordsPosition, Normal, Ambient, Diffuse, Specular );
PointLight( 1, EyeCoordsPosition, Normal, Ambient, Diffuse, Specular );
}
vec4 LightContribution = Ambient * texture * gl_FrontMaterial.ambient +
Diffuse * gl_FrontMaterial.diffuse +
Specular * gl_FrontMaterial.specular;
gl_FragColor = LightContribution;
}
I agree, that it would be adventageous to strip everything unnecessary, but as you pointed out it would be more effort to specialize these scripts. Which I could find out that branching/looping is broken entirely for my vid. card. Something I don’t currently want to do since I have dozens of scripts already set up in my app and compiled differently. It may eat a couple of days to change the shaders’ binding to the game, and modification of the shader code themselves only to end up back here.
Also, I am looking to buy a new card in the near future and am trying to determine whether or not to stay with ATI because I have noticed many posts on this forum of guys having problems with developing on their ATI cards.
I am trying to determine what I could get away with on this hardware for now and whether it is worth it to try a different brand if it is inherently more developer-friendly.
That is why I am asking for you guys’ experience with this. Some people say it works, others seem to be having the same problems as I am. If there is someone out there that has this HW and has it working, can they post a SIMPLE fragment shader that can be easily adapted to test with??
Thanks
// Mike