CG error

Started by
5 comments, last by hello_there 19 years, 7 months ago
I keep getting a Invalid parameter handle error when i run my CG shader. Everything was running fine then i moved some stuff to a seperate function to make it easier to work with and now i get that error. What causes that error cause i can't find anything wrong with my shader.
____________________________________________________________How could hell be worse?
Advertisement
You need to provdide more info. So the shader worked fine before rearranging everything? Perhaps you accidentally changed the name of a parameter (remember that its case sensitive). Did you change anything on the C++ at all?

Post some code if you are still having trouble.

- Thomas Cowellwebsite | journal | engine video

Here's the fragment shader. This is the only thing i changed. I put it into a seperate function so i could add more lights. The entry function is
FragmentLight_F()

void computeLighting(float3 lightColor,
float3 lightPosition,
float3 P,
float3 N,
float3 eyePosition,
float shininess,
float3 attenValues,
out float3 diffuseResult,
out float3 specularResult)
{
// Compute the diffuse term
float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);
diffuseResult = lightColor * diffuseLight;

// Compute the specular term
float3 V = normalize(eyePosition - P);
float3 H = normalize(L + V);
float specularLight = pow(max(dot(N, H), 0), shininess);
if (diffuseLight <= 0) specularLight = 0;
specularResult = lightColor * specularLight;
}

float AttenLight(float3 P,float3 atten,float3 lightP)
{
float d = distance(P,lightP);
return 1 / (atten[0] + atten[1] * d + atten[2] * d * d);
}

void FragmentLight_F(float2 TexCoord0 : TEXCOORD0,
float4 position : TEXCOORD1,
float3 normal : TEXCOORD2,

out float4 color : COLOR,

uniform float3 globalAmbient,
uniform float3 lightColor,
uniform float3 lightPosition,
uniform float3 eyePosition,
uniform float shininess,
uniform float3 attenValues,
uniform sampler2D Texture : TEXUNIT0)
{
float3 P = position.xyz;
float3 N = normal;

float attenuation = AttenLight(P,attenValues,lightPosition);

float3 diffuse;
float3 specular;

computeLighting(lightColor,lightPosition,
P,N,eyePosition,shininess,attenValues,diffuse,specular);

color.xyz = tex2D(Texture, TexCoord0)*(globalAmbient + diffuse + specular);
color.w = 1;
}
____________________________________________________________How could hell be worse?
which fragment profile do you use ?

I've successfully compiled your shader code using the ps_2_0 profile, with CG 1.3b2...

Gregory Jaegy[Homepage]
Not sure what profile i'm using i just use
cgGLGetLatestProfile(CG_GL_FRAGMENT);
I got it to work i put
float attenuation = AttenLight(P,attenValues,lightPosition);
in the
computeLighting()
function where it should be and now it works. I only put it in
FragmentLight_F()
function to test the other function. It might be because i don't have the latest CG version.

What would cause an error like that though?
____________________________________________________________How could hell be worse?
No idea. Perhaps a CG bug, check the bug list. Have you already tried with the latest CG version ?
Gregory Jaegy[Homepage]
I havn't tried the latest version yet. i'll try it out.
____________________________________________________________How could hell be worse?

This topic is closed to new replies.

Advertisement