CG error
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.
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.
Post some code if you are still having trouble.
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;
}
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;
}
which fragment profile do you use ?
I've successfully compiled your shader code using the ps_2_0 profile, with CG 1.3b2...
I've successfully compiled your shader code using the ps_2_0 profile, with CG 1.3b2...
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?
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?
No idea. Perhaps a CG bug, check the bug list. Have you already tried with the latest CG version ?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement