# OpenGL Spot Light weird problem !

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

## 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 on other sites
can u check if (cosTheta-light.cosSigma) is not zero there where u should get less light?

##### Share on other sites
Quote:
 Original post by furrymastercan 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 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.

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 12
• 12
• 20
• 12
• 13
• ### Forum Statistics

• Total Topics
632152
• Total Posts
3004466

×