Jump to content
  • Advertisement
Sign in to follow this  
KDSBest

OpenGL GL_TEXTURE Matrix

This topic is 4113 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, 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 VS
gl_TexCoord[0] = gl_MultiTexCoord0;

//now in the fs
vec2 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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Yeah, I was thinking he wanted to know how to upload the texture coordinates with the texture matrix. e.g. shadow mapping.

Share this post


Link to post
Share on other sites
THx phantom this, was exactly the answer i was looking for.

And great THx to you MARS for your nice answers.

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!