PDA

View Full Version : Texture matrices in GLSL



EG
05-18-2004, 12:29 AM
How can the fixed-function equivalent of texture matrices be implemented in GLSL? I was under the impression that having in the vertex shader a


gl_TexCoord[0] = gl_TextureMatrix[0]*glMultiTexCoord0;would be enough, but apparently it isn't (texture gets stretched very differently on the mesh when the shader is active)... what am I missing?

Relic
05-18-2004, 07:43 AM
Should just work the way you use it, except that glMultiTexCoord0 needs to be gl_MultiTexCoord0.

If you haven't changed the matrix with
something like
glActiveTexture(GL_TEXTURE0);
glLoadMatrixf(myTextureMatrix);
there should be the identity matrix in it

- Does the shader work if you replace this with glLoadIdentity()?
- Does it work if you just don't multiple with the matrix at all.

If you suspect a driver bug, update the drivers.

EG
05-18-2004, 11:03 AM
Thanks for confirming the point!

After assuming this part as being right, and much head scratching on the rest, I finally found what was wrong: I was using the texture matrix for reflection purposes, thus with a projective part.
Apparently the drivers automatically take that into account when the texture matrix is used directly, but when using a vertex shader (or doing the transformation "manually" CPU-side) you have to perform the division by the projective component explicitly (or use texture2DProj in the fragment shader).