[osg-users] How to translate the light posiotion from world space to eye space in glsl
guilianzhang at 163.com
Mon Sep 8 20:27:15 PDT 2008
To make phong shading using shaders(in GLSL), I have to pass the the light position to the vertex shader, But the position of the vertex will be in eyespace (after multiplication with the ModelView matrix). So I need the light position in eye-space as well. Which is the best way of obtaining the correct light position? Either I need the vertex position to be in world space, I do in this way:
mat4 modelMatrix = osg_ViewMatrixInverse* gl_ModelViewMatrix ;
WorldPos=modelMatrix * gl_Vertex;
WorldNrm=normalize(normalmatrix * gl_Normal);
though it works well to get the world space coordinate of each vertex, but to compute specular of object I have to know the eye position, since we are not in eye coordinates the eye postion is no longer (0,0,0), must the eye coordinate be passed by uniform?
Or I need the light position in eye space. I try to translate the light position into eye coordinate in this way:
Pos_light0 = osg_ViewMatrix *light0_pos ;
Pos_light0 = light0_pos * osg_ViewMatrix ;
but it seems not work.
What are the general strategy for this problem?
Thanks very much!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the osg-users