Jump to content
  • Advertisement
Sign in to follow this  
PSQ_Goblin

Matrices in GLSL

This topic is 4699 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! I have done a PP GLSL Shader. And it all works nicely as long as I dont translate enything. So I guess the problem is that my lightpos and parhaps camerapos is in the wrong space. What are the correct matrices to use? My VS code: void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; vLightDir = gl_ModelViewMatrixInverse * (uLightPos - gl_Vertex); vNormal = gl_Normal; vTexCoord = gl_MultiTexCoord0.xy; vHalfDir = vLightDir + (gl_ModelViewMatrix * gl_Vertex); } PS. I'm using the gluLookAt(), and uLightPos is in world space coords.

Share this post


Link to post
Share on other sites
Advertisement
You'd better transform all your cam, light,to the model local space in your C or C++ code but not VS, This will save your time also.
You can use the inverse object local matrix to transform the light and camera into the object local space!
Matrix local2World
Matrix world2Local
world2Local=local2World.inverse()
World2local.transformVertex(lightPos)
World2local.transformVertex(camPos)
The transform of vertex and normal is not same, this very important!

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!