GL_TEXTURE Matrix

Started by
7 comments, last by KDSBest 17 years ago
Hi, if i use glMatrixMode(GL_TEXTURE) with shader, do i have to calculate the shader transformation in the shader or can i use the shader as normal and opengl does the calculation? If i have to calculate it in the shader, how? Thx
Advertisement
IF you want to you can do the math on the CPU side and upload the data with the GL_TEXTURE matrix for the specified texture unit of your choice and then just use that data in your shader. Or you can do the math in the vertex shader and not have to bother with the GL_TEXTURE matrix mode. All depends on what you want to do or feel comfortable with.
I want to do it in the vertex shader, but du i have to multiply texcoords with the GL_TEXTURE_MATRIX in the shader or not?
You don't have to do anything just use the texture coordinates you uploaded to the texturecoordinate array if you are using VBO or VA. If you are using immediate mode than the values you sent to glTexCoord2f() will be what is used.

//in the VSgl_TexCoord[0] = gl_MultiTexCoord0;//now in the fsvec2 texCoord   = vec2(gl_TexCoord[0]);vec4 image      = texture2D(texture, texCoord);


and you can use the texcoords in your sampler functions.

Now if this isn't what you are referring to, please state the question or what it is you are trying to do...

I just wanted to know if i use GL_TEXTURE, if i have to use it in the shader or if opengl use it before my shader is used.

But thx for your time my shader works nice.
If you upload data to the texture matrix than OpenGL will use that data as texture coordinates as normal. But you need to make sure you select the unit you uploaded them to. e.g.

glActiveTexture(GL_TEXTURE5);glMatrixMode(GL_TEXTURE);glLoadIdentity();glLoadMatrixf(MATRIX_BIAS);			glMultMatrixf(modelProjectionMatrix);	glMatrixMode(GL_MODELVIEW);	


Now if you want those texture coordinates in the shader you just call

vec4 texCoord5 = gl_TextureMatrix[5];

and do whatever math you like to on them or if you did the math you needed on the CPU when you uploaded them than just use what is above... HTH
Mars, I suspect you've got the wrong end of the stick here, although to be honest the clarity of the post isn't that great either.

What I suspect KDSBest is trying to ask is when you supply texture coordinates to a shader are they multiplied by the GL_TEXTURE matrix before the vertex shader is run; the answer is no.

The default GL_TEXTURE matrix is the indentity matrix, which is why in most programs simply passing the texture coordinates down to the fragment/pixel shader does The Right Thing(tm).

However, if you change the texture matrix at all and you want your coordinates to be effected by it you have to multiply it by that matrix;

gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;


Basically, when you run a vertex shader anything vertex related is now under your control, the fixed function pipeline doesn't do anything at all any more.
Yeah, I was thinking he wanted to know how to upload the texture coordinates with the texture matrix. e.g. shadow mapping.
THx phantom this, was exactly the answer i was looking for.

And great THx to you MARS for your nice answers.

This topic is closed to new replies.

Advertisement