PDA

View Full Version : Errors setting Uniform Vars



Tom Speed
02-06-2005, 08:06 AM
Hi All,

I'm getting GL_INVALID_OPERATION Errors when trying to set some Uniform Vars. The shaders are linked & compiled just fine and glGetUniformLocationARB() is returning valid Locations. Any ideas what's causing the Errors?

What's confusing is, look at LightPosition & Specular, both are vec3, both use glUniform3fARB(), both have valid Locations, 1 is called directly after the other, yet 1 pops an error, the other doesn't!

Cheers!
Tom

The Shaders:

//**VERT SHADER**
uniform vec3 LightPosition;
uniform vec3 LightColor;
uniform vec3 EyePosition;
uniform vec3 Specular;
uniform vec3 AmbientColor;
uniform float Kd;

varying vec3 DiffuseColor;
varying vec3 SpecularColor;

void main(void)
{
vec3 ecPosition = vec3 (gl_ModelViewMatrix * gl_Vertex);
vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
vec3 lightVec = normalize(LightPosition - ecPosition);
vec3 viewVec = normalize(EyePosition - ecPosition);
vec3 Hvec = normalize(viewVec + lightVec);

float spec = abs(dot(Hvec, tnorm));
spec = pow(spec, 16.0);

DiffuseColor = LightColor * vec3 (Kd * abs(dot(lightVec, tnorm)));
DiffuseColor = clamp(AmbientColor + DiffuseColor, 0.0, 1.0);
SpecularColor = clamp((LightColor * Specular * spec), 0.0, 1.0);

gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}


//**FRAG SHADER**
varying vec3 DiffuseColor;
varying vec3 SpecularColor;

uniform vec2 Scale;
uniform vec2 Threshold;
uniform vec3 SurfaceColor;

void main (void)
{
float ss = fract(gl_TexCoord[0].s * Scale.s);
float tt = fract(gl_TexCoord[0].t * Scale.t);

if ((ss > Threshold.s) && (tt > Threshold.t)) discard;

vec3 finalColor = SurfaceColor * DiffuseColor + SpecularColor;
gl_FragColor = vec4 (finalColor, 1.0);
} The Errors I get:

ShaderName : Lattice
Uniform Var Name : Specular
glGetUniLoc() : 6
GL Set command : glUniform3fARB()
Values Set : 0.200000003, 0.200000003, 0.200000003
glGetError() : GL_INVALID_OPERATION

ShaderName : Lattice
Uniform Var Name : LightPosition
glGetUniLoc() : 4
GL Set command : glUniform3fARB()
Values Set : 0.000000000, 4.00000000, 3.00000000
glGetError() : 0

ShaderName : Lattice
Uniform Var Name : EyePosition
glGetUniLoc() : 1
GL Set command : glUniform3fARB()
Values Set : 0.000000000, 1.50000000, 8.00000000
glGetError() : GL_INVALID_OPERATION

ShaderName : Lattice
Uniform Var Name : AmbientColor
glGetUniLoc() : 0
GL Set command : glUniform3fARB()
Values Set : 0.200000003, 0.200000003, 0.200000003
glGetError() : GL_INVALID_OPERATION

ShaderName : Lattice
Uniform Var Name : Kd
glGetUniLoc() : 2
GL Set command : glUniform1fARB()
Values Set : 0.800000012
glGetError() : 0

ShaderName : Lattice
Uniform Var Name : SurfaceColor
glGetUniLoc() : 7
GL Set command : glUniform3fARB()
Values Set : 0.899999976, 0.699999988, 0.200000003
glGetError() : GL_INVALID_OPERATION

ShaderName : Lattice
Uniform Var Name : Scale
glGetUniLoc() : 5
GL Set command : glUniform2fARB()
Values Set : 10.0000000, 10.0000000
glGetError() : GL_INVALID_OPERATION

ShaderName : Lattice
Uniform Var Name : Threshold
glGetUniLoc() : 8
GL Set command : glUniform2fARB()
Values Set : 0.129999995, 0.129999995
glGetError() : GL_INVALID_OPERATION

ShaderName : Lattice
Uniform Var Name : LightColor
glGetUniLoc() : 3
GL Set command : glUniform3fARB()
Values Set : 0.899999976, 0.800000012, 0.899999976
glGetError() : 0

Relic
02-06-2005, 11:21 PM
It doesn't help to show the shader and logfile alone, show the code which produces the error.