Sign in to follow this  
b34r

OpenGL gl_LightSource[].position weirdness

Recommended Posts

Hi, I'm must have overlooked something but it seems gl_LightSource[].position.xyz returns the light position transformed by the MODELVIEW matrix. In OpenGL if I'm not mistaken this MODELVIEW = ModelMatrix * CameraMatrix (or the other way around ymmv). Now, that may sound stupid but how am I supposed to use this position to make a point light? I cannot compute the diffuse term since the light is in camera space already (and model space but that's not a problem). My problem might come from the fact that I do not use Glut but my own set of matrice and that somehow GL expect to be able to split the MODELVIEW computation chain (?). I'm 100% sure my matrice are corrects, they're working fine in fixed OGL, DX and soft renderer... By providing the light position transformed by the camera to my shader I get the expected result but I'd rather use the uniform constants whenever possible. Could this be a Catalyst bug? ATi being the #1 crappy driver king that might not be surprising. Any idea?

Share this post


Link to post
Share on other sites
no, its completely correct :

Quote:
from http://www.mevis.de/~uwe/opengl/glLight.html
GL_POSITION
params contains four integer or floating-point values that specify the position of the light in homogeneous object coordinates. Both integer and floating-point values are mapped directly. Neither integer nor floating-point values are clamped.
The position is transformed by the modelview matrix when glLight is called (just as if it were a point), and it is stored in eye coordinates. If the w component of the position is 0.0, the light is treated as a directional source. Diffuse and specular lighting calculations take the light's direction, but not its actual position, into account, and attenuation is disabled. Otherwise, diffuse and specular lighting calculations are based on the actual location of the light in eye coordinates, and attenuation is enabled. The default position is (0,0,1,0); thus, the default light source is directional, parallel to, and in the direction of the -z axis.

Share this post


Link to post
Share on other sites
Thanks,

I must admit I didn't really know where to look at in order to get confirmation of this. So, how do they implement free point light in GL? I'm a little bit confused.

With one matrix (modelview), untransformed vertice and the light position in the modelview there is no way I see to make a point light...unless it is linked to the camera.

Right now I see how to do a directional light but that's the less useful light type \:... Well, I guess I'll use uniforms for now.
Thanks again.

Share this post


Link to post
Share on other sites

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