Advertisement

GLSL Linker Problem

Started by June 29, 2004 07:29 PM
7 comments, last by TheGibberingFool 20 years, 5 months ago
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.
__________________________________Peter Lewis ([email=me_AT_pjblewis.com]E-mail[/email] | Portfolio)
Which graphics card do you use? GeForce FX series I think...
I'm not sure but I think they don't support dynamic array access (which you use) in pixel shader.
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
Advertisement
It seems to come up with a completely different error on ATI cards too. Apparently "L, N and P are being written in the vertex shader and not read in the fragment shader", which they clearly are.

It would suck if that kind of array access didn't work in GLSL (seems to be hardware independant, so I assume it's a fault with the language). Anyone know of a way I can do this?
__________________________________Peter Lewis ([email=me_AT_pjblewis.com]E-mail[/email] | Portfolio)
Quote: Original post by TheGibberingFool
It seems to come up with a completely different error on ATI cards too. Apparently "L, N and P are being written in the vertex shader and not read in the fragment shader", which they clearly are.


If the vertex shader isn't compiled successfully and the fragment shader is compile sucessfully then you will get a linking error because there is no valid vertex shader (fixed function OpenGL).
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
It's the other way around - the fragment shader won't link. The vertex shader compiles just fine. This is the weird bit.
__________________________________Peter Lewis ([email=me_AT_pjblewis.com]E-mail[/email] | Portfolio)
Quote: Original post by TheGibberingFool
It's the other way around - the fragment shader won't link. The vertex shader compiles just fine. This is the weird bit.


Yeah, sorry. On ATI (and I also think for nVidia, except Radoen 6800) hardware I'm sure that this won't work (dynamic array access) in pixel shaders.
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
Advertisement
Poo.


Thanks for the help. Any way I can get around this? As you might be able to see, I'm getting the lighting data from the OpenGL lights, and I was hoping to pass the geometry through each light source dynamically.

Can anyone suggest a workaround?
__________________________________Peter Lewis ([email=me_AT_pjblewis.com]E-mail[/email] | Portfolio)
You could use your own lighting-management. Passing all lighting values as uniforms.
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
Aye, I'm working on that now. I've been faffing with it since my last post but I just get black. It compiles and links fine though, so thanks for your help Corrail! :)
__________________________________Peter Lewis ([email=me_AT_pjblewis.com]E-mail[/email] | Portfolio)

This topic is closed to new replies.

Advertisement