Jump to content
  • Advertisement
Sign in to follow this  
MegaPixel

OpenGL Spot Light weird problem !

This topic is 2995 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

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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!