2 GLSL questions

Started by
7 comments, last by V-man 12 years, 5 months ago
Hi again.

  1. I know how to combine two textures using mix function, but what to do, if I need to combine three or more textures?
  2. I am using VBOs to display mesh. On vertex arrays, textures should be activated with glClientActiveTexture, but it seems that this doesn't "transfer" texture to shader, it don't work. It only works if I use glActiveTexture, but then I can't have more then one set of texture coordinates. I need to have two sets, one for "visible" textures and one for the "mask" texture. Is it possible to pass two texture coordinates to shader? If so, how?
Thanks for answers.

Advertisement
If you have two colors, x and y, all mix does is take (1-a)*x + a*y. You can combine colors any way you want and don't have to use the mix function. i.e. x+y, x-y, x*y or whatever gives the result you want.

If you have more colors you just have to calculate how much of each color you want and how you want to combine them and write an expression for it.

To get another set of texture coordinates you just have to create a new VBO with the new set of coordinates and bind it while drawing just like you did with the first set. Or pack another set into your vertex structure in the VBO you already have. Depending on which way you do things.

Hope this helps.
Cheers.

To get another set of texture coordinates you just have to create a new VBO with the new set of coordinates and bind it while drawing just like you did with the first set. Or pack another set into your vertex structure in the VBO you already have. Depending on which way you do things.

No no, I already have two sets in VBO. I just need to use both sets in shader.

I have one large mesh and there are two textures in each point. To know how much of each texture use, I have one big "mask" texture and I set one texture to alpha value of mask and other one to (1-alpha) value, like this

gl_FragColor = mix(texture2D(texmat0,gl_TexCoord[0].xy), texture2D(texmat1,gl_TexCoord[0].xy), 1-texture2D(mskalpha,gl_TexCoord[0].xy).a);

But, mask texture should have different texture coordinates then material textures, but now it shares one set.

Not sure how you set things up or which GL version you use but you need to bind the second set of texture coordinates to an attribute in the shader. Then you can pass it from the vertex shader in gl_TexCoord[1] just like you did with gl_TexCoord[0].

When you have your second set you can choose which one to use when you do your texture lookups.

... but you need to bind the second set of texture coordinates to an attribute in the shader.


How??


http://www.opengl.or...i/Vertex_Arrays


glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(MyVertex), &vertex[0].x);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(MyVertex), &vertex[0].nx);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(MyVertex), &vertex[0].s0);
glClientActiveTexture(GL_TEXTURE1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(MyVertex), &vertex[0].s1);
glClientActiveTexture(GL_TEXTURE2);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(MyVertex), &vertex[0].s2);
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

http://www.opengl.or...i/Vertex_Arrays


glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(MyVertex), &vertex[0].x);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(MyVertex), &vertex[0].nx);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(MyVertex), &vertex[0].s0);
glClientActiveTexture(GL_TEXTURE1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(MyVertex), &vertex[0].s1);
glClientActiveTexture(GL_TEXTURE2);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(MyVertex), &vertex[0].s2);



You didn't even read the question, did you?


I think it works now, it was necessary to call both glActiveTexture and glClientActiveTexture.

You didn't even read the question, did you?


Of course I did. I also wrote that Wiki page. glClientActiveTexture does the job followed by a glEnableClientState(GL_TEXTURE_COORD_ARRAY) and then a call to glTexCoordPointer.

Did you understand his question?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement