Sign in to follow this  

CG error

This topic is 4854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

This topic is 4854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this