Spot Light weird problem !

Started by
2 comments, last by MegaPixel 13 years, 7 months ago
Hi all,

I reached the point where the same function in hlsl works, but

in cg with opengl doesn't.

It's a very simple function that is going to calculate shading based on the spot cut off angle in the shader. This same func is called by another func

that is calculating the overall lighting.

The behaviour is that in hlsl I can see the smooth fall-off (thanks to the pow

func), but in CG using opengl I get hard edges.

I did some tests and it seems is going through just the first two if leaving the 3rd line like if it's not there. I

tried eliminating the two if statements, seeing what was happening, but then

I could see completely black. I'm sure the values of the cos of the angles are

correct since I checked them.

Those two screen will outline better the problem:

CG: http://img837.imageshack.us/i/spotlightcg.jpg/

HLSL: http://img541.imageshack.us/i/spotlighthlsl.jpg/

And here is the code of such a function:

float get_spotLight_influence(in Light light                             ,in float3 p ){		float cosTheta = dot(normalize(get_light_dir(light,p)),-normalize(light.lightDir));		if( cosTheta > light.cosPhi )		return 1.f;	if( cosTheta < light.cosSigma )	    return 0.f;			return pow((cosTheta-light.cosSigma)/(light.cosSigma-light.cosPhi),50.f);	//this line seems to be never reached at all in CG}


Any help would be appreciated, thanks
Advertisement
can u check if (cosTheta-light.cosSigma) is not zero there where u should get less light?
If I helped you rate me
Quote:Original post by furrymaster
can u check if (cosTheta-light.cosSigma) is not zero?


Yeah I could actually is a good point ! But even then I should at least see some fall-

off where it's not 0 and artifacts where it is ! Plus why eventually in hlsl is not 0 ?... you can see clearly that in hlsl works perfectly !

Cheers
Ok I've found the bug:

cosPhi was greater than cosSigma giving me a negative value from the subtraction

cosSigma-cosPhi. The strange thing is that in hlsl was working anyway !!!!!!! But in

CG no! I tried the contrary (i.e. cosPhi-cosSigma) in CG and it was working !!!! I switched back to hlsl and dx to see if it was working and it was working anyway !!!

That's a mistery to me !! is something is matematically wrong should be

wrong no matter which language you use or I'm missing something.

D'hO !

Btw thanks to you anyway, you really pointed me on the right direction.

This topic is closed to new replies.

Advertisement