I'm getting a linker problem with my shader scripts... I'm trying to tell the shader's vertex and fragment programs which light to use, which works fine in the vertex program, but for some reason plugging the variable into the fragment shader breaks the linker. The error message is pretty... meaningless really.
Replacing gl_FrontLightProduct[LightF] with gl_FrontLightProduct[0] works, for example. Any hard coded value does, but putting the variable in there busts it. Even weirder so is that if I create the variable in there myself (i.e. make and set it locally within the function) it works fine.
Can anyone help me with this?
The vertex shader: (works fine)
Quote:
varying vec3 L;
varying vec3 N;
varying vec3 P;
uniform int LightV;
void main(void)
{
P = vec3(gl_ModelViewMatrix * gl_Vertex);
L = normalize(gl_LightSource[LightV].position.xyz-P);
N = normalize(gl_NormalMatrix * gl_Normal);
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
The fragment shader: (b0rked)
Quote:
varying vec3 L;
varying vec3 N;
varying vec3 P;
uniform sampler2D myTexture;
uniform int LightF;
void main (void)
{
vec3 E = normalize(-P);
vec3 R = normalize(-reflect(L,N));
float NL = max( dot( N, L ), 0.0 );
float RE = pow( max( dot( R, E ), 0.0 ), 0.3 * gl_FrontMaterial.shininess );
vec4 Iamb = gl_FrontLightProduct[LightF].ambient;
vec4 Idiff = gl_FrontLightProduct[LightF].diffuse * NL;
vec4 Ispec = gl_FrontLightProduct[LightF].specular * RE;
gl_FragColor = ( gl_FrontLightModelProduct.sceneColor + Iamb + Idiff + Ispec ) * texture2D(myTexture, vec2(gl_TexCoord[0]));
}
The linker report:
Quote:
Fragment info
-------------
Internal error: assembly compile error for fragment shader at offset 3660:
-- error message --
line 82, column 11: error: invalid operand variable
line 83, column 1: error: invalid statement
line 88, column 11: error: invalid operand variable
line 104, column 11: error: invalid operand variable
-- internal assembly text --
!!FP1.0
# cgc version 1.2.1001, build date Apr 29 2004 21:58:55
# command line args: -q -profile fp30 -entry main -oglsl -D__GLSL_CG_DATA_TYPES -D__GLSL_CG_STDLIB -D__GLSL_SAMPLER_RECT
#vendor NVIDIA Corporation
#version 1.0.02
#profile fp30
#program main
#semantic gl_FrontMaterial
#semantic gl_FrontLightModelProduct
#semantic gl_FrontLightProduct
#semantic myTexture
#semantic LightF
#var float4 gl_FragColor : $vout.COL : COL : -1 : 1
#var float4 gl_FrontMaterial.emission : : : -1 : 0
#var float4 gl_FrontMaterial.ambient : : : -1 : 0
#var float4 gl_FrontMaterial.diffuse : : : -1 : 0
#var float4 gl_FrontMaterial.specular : : : -1 : 0
#var float gl_FrontMaterial.shininess : : : -1 : 1
#var float4 gl_FrontLightModelProduct.sceneColor : : : -1 : 1
#var float4 gl_FrontLightProduct[0].ambient : : : -1 : 1
#var float4 gl_FrontLightProduct[0].diffuse : : : -1 : 1
#var float4 gl_FrontLightProduct[0].specular : : : -1 : 1
#var float4 gl_FrontLightProduct[1].ambient : : : -1 : 1
#var float4 gl_FrontLightProduct[1].diffuse : : : -1 : 1
#var float4 gl_FrontLightProduct[1].specular : : : -1 : 1
#var float4 gl_FrontLightProduct[2].ambient : : : -1 : 1
#var float4 gl_FrontLightProduct[2].diffuse : : : -1 : 1
#var float4 gl_FrontLightProduct[2].specular : : : -1 : 1
#var float4 gl_FrontLightProduct[3].ambient : : : -1 : 1
#var float4 gl_FrontLightProduct[3].diffuse : : : -1 : 1
#var float4 gl_FrontLightProduct[3].specular : : : -1 : 1
#var float4 gl_FrontLightProduct[4].ambient : : : -1 : 1
#var float4 gl_FrontLightProduct[4].diffuse : : : -1 : 1
#var float4 gl_FrontLightProduct[4].specular : : : -1 : 1
#var float4 gl_FrontLightProduct[5].ambient : : : -1 : 1
#var float4 gl_FrontLightProduct[5].diffuse : : : -1 : 1
#var float4 gl_FrontLightProduct[5].specular : : : -1 : 1
#var float4 gl_FrontLightProduct[6].ambient : : : -1 : 1
#var float4 gl_FrontLightProduct[6].diffuse : : : -1 : 1
#var float4 gl_FrontLightProduct[6].specular : : : -1 : 1
#var float4 gl_FrontLightProduct[7].ambient : : : -1 : 1
#var float4 gl_FrontLightProduct[7].diffuse : : : -1 : 1
#var float4 gl_FrontLightProduct[7].specular : : : -1 : 1
#var float3 L : $vin.TEX0 : TEX0 : -1 : 1
#var float3 N : $vin.TEX1 : TEX1 : -1 : 1
#var float3 P : $vin.TEX2 : TEX2 : -1 : 1
#var sampler2D myTexture : : texunit 0 : -1 : 0
#var int LightF : : : -1 : 1
DECLARE gl_FrontMaterial$emission;
DECLARE gl_FrontMaterial$ambient;
DECLARE gl_FrontMaterial$diffuse;
DECLARE gl_FrontMaterial$specular;
DECLARE gl_FrontMaterial$shininess;
DECLARE LightF;
DECLARE gl_FrontLightProduct$0$ambient;
DECLARE gl_FrontLightProduct$0$diffuse;
DECLARE gl_FrontLightProduct$0$specular;
DECLARE gl_FrontLightProduct$1$ambient;
DECLARE gl_FrontLightProduct$1$diffuse;
DECLARE gl_FrontLightProduct$1$specular;
DECLARE gl_FrontLightProduct$2$ambient;
DECLARE gl_FrontLightProduct$2$diffuse;
DECLARE gl_FrontLightProduct$2$specular;
DECLARE gl_FrontLightProduct$3$ambient;
DECLARE gl_FrontLightProduct$3$diffuse;
DECLARE gl_FrontLightProduct$3$specular;
DECLARE gl_FrontLightProduct$4$ambient;
DECLARE gl_FrontLightProduct$4$diffuse;
DECLARE gl_FrontLightProduct$4$specular;
DECLARE gl_FrontLightProduct$5$ambient;
DECLARE gl_FrontLightProduct$5$diffuse;
DECLARE gl_FrontLightProduct$5$specular;
DECLARE gl_FrontLightProduct$6$ambient;
DECLARE gl_FrontLightProduct$6$diffuse;
DECLARE gl_FrontLightProduct$6$specular;
DECLARE gl_FrontLightProduct$7$ambient;
DECLARE gl_FrontLightProduct$7$diffuse;
DECLARE gl_FrontLightProduct$7$specular;
DECLARE gl_FrontLightModelProduct$sceneColor;
MOVR R0.x, {3, 0, 0, 0};
MULR H0.x, LightF, R0;
>>> MOVR R0, c[INVALID.x - 2];
ARL? vr7.x, H0;
MOVR R1.xyz, f[TEX0];
DP3R R2.x, f[TEX1], R1;
ADDR R0, gl_FrontLightModelProduct$sceneColor, R0;
MAXR R1.x, R2, {0, 0, 0, 0};
>>> MULR R1, c[INVALID.x - 1], R1.x;
ADDR R0, R0, R1;
MULR R1.xyz, f[TEX1], R2.x;
MULR R1.xyz, R1, {2, 0, 0, 0}.x;
ADDR R1.xyz, f[TEX0], -R1;
DP3R R1.w, -R1, -R1;
RSQR R1.w, R1.w;
MULR R1.xyz, R1.w, -R1;
DP3R R1.w, -f[TEX2], -f[TEX2];
RSQR R1.w, R1.w;
MULR R2.xyz, R1.w, -f[TEX2];
DP3R R1.x, R1, R2;
MOVR R1.y, {0.3, 0, 0, 0}.x;
MAXR R1.x, R1, {0, 0, 0, 0};
MULR R1.y, gl_FrontMaterial$shininess.x, R1;
POWR R1.x, R1.x, R1.y;
>>> MULR R1, c[INVALID.x], R1.x;
ADDR o[COLR], R0, R1;
END
# 26 instructions, 3 R-regs, 1 H-regs
As I said, any help is really appreciated.