Multitexture extension and selective transformation

Hi,

I have two textures and I am merging these two textures based on a color value in texture2 using shader program. I render this on screen like :

//------------------------------

::glLoadIdentity();

// Apply zoom
::glScaled(zoomX, zoomY,1.0);

myShader->begin();
myShader->sendUniform1i(“myTexture1”, 0);
myShader->sendUniform1i(“myTexture2”, 1);

glBegin(GL_QUADS);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 1.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 1.0);
glVertex3f(-1.0, 1.0, 0.0);

	glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0);


glEnd();
myShader->end();
//------------------------------

Here when I am applying scaling, it is applied to both texture 1 and texture 2. But I want to apply the scaling only to texture1 and not 2 and still merge these two on color value on texture 2. I am using multitexture extension.

How can I achieve it ?

Thanks,
MSB

Well, this has nothing to do with shaders. Simply use the texture matrix and select the appropriate texture unit for each.

Something like:

glActiveTextureARB (GL_TEXTURE0_ARB);
glMatrixMode (GL_TEXTURE);
glLoadIdentity();
// do some transformations ie scaling
glActiveTextureARB (GL_TEXTURE1_ARB);
glLoadIdentity();
// do some other scalings

might works. But what I don’t remember is how to insert this code when using MultiTexCoord***. Try to put that code before glBegin(…).

This works perfectly with vertex array though.

Hope that helps.

Thanks for your reply. But It didnt work :frowning:
I wonder if its because of shader programme which i am using.

I tried following just before glBegin :

///---------------------
::glMatrixMode(GL_MODELVIEW);
::glLoadIdentity();

::glActiveTextureARB(GL_TEXTURE0_ARB);
::glEnable(GL_TEXTURE_2D);
::glBindTexture(GL_TEXTURE_2D,texture1); ::glMatrixMode (GL_TEXTURE);
::glLoadIdentity();
// Apply zoom
::glScaled(2.0,2.0,1.0);
//------------------------------
::glActiveTextureARB(GL_TEXTURE1_ARB);
::glEnable(GL_TEXTURE_2D);
::glBindTexture(GL_TEXTURE_2D,texture2);
::glMatrixMode (GL_TEXTURE);
::glLoadIdentity();
//------------------------------

My vertex shader is like following :

void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;

gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
}

It looks like it is skipping the texture matrix ? I am not sure if texture matrix will be considered before texuture mapping or not.

Originally posted by mayursb:
[b]

It looks like it is skipping the texture matrix ? I am not sure if texture matrix will be considered before texuture mapping or not.[/b]
If you are using vertex shader you have to multiply your tex. coordinates with tex. matrix manualy…

i.e. :
gl_TexCoord[0]=gl_TextureMatrix[0]*gl_MultiTexCoord0;

Ok. I did following ->

void main(void)
{
gl_TexCoord[0] = gl_TextureMatrix[0]*gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

But the result was not as expected. That may be because I didnt change the texture mapping. I really doubt whether this can be achieved using multitexture at all. But multitexturing is useful for me for combining the two textures based on color value in one of them. But this also means that whatever transformation i do in model view is applied to both the textures. Now my problem is how to apply transformation only to one texture and not another and still get the result as I would have got if I had applied model view transformation. !!!

Any suggestions ?

Sorry for my error (I just know nothing about shaders).

I have another maybe-solution.
You can see textures coordinats as this:

s = scale_factor * real_s + translation
t = scale_factor * real_t + translation

where s and t are the new texture coordinates and real_s and real_t are the old ones (those you specified). With some maths, you can do almost everything you want.

This must work :slight_smile:

That would work and probably be more efficient, it really depends on the types of transformations you want to support (this is one of the advantages of vertex programs), but it’s worth pointing out that the matrix multiplication posted was nonsense, when you multiply with a matrix you have do more that just multiply by the coordinate by the first row, it’s a full texture coordinate vector transform through the matrix.

And it absolutely can be done with multitexture, you have independent matrices and interpolants (although not necessarily as many as you have texture units you typically have at least 4 fully supported units including matrices and interpolators).

Originally posted by dorbie:
but it’s worth pointing out that the matrix multiplication posted was nonsense, when you multiply with a matrix you have do more that just multiply by the coordinate by the first row, it’s a full texture coordinate vector transform through the matrix.

I have to admit that I have never worked with texture matrix in vertex shader but in GLSLSpec is written:
uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];

so I think that gl_TextureMatrix[0] is not the first row of the tex. matrix but the first texture matrix itself

D’oh, my bad. That was a total brain fart. You are right. I was thinking assembly style longhand.

:frowning: I am also new to shading language. I am not sure how to make shader affect only one texture and not another.
Today I posted this probem in detail in shading language forum under name “texture transformation and merging”.