Jump to content
  • Advertisement
Sign in to follow this  
Civilwar

2 GLSL questions

This topic is 2590 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 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.

Share this post


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

Share this post


Link to post
Share on other sites

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.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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?


Share this post


Link to post
Share on other sites

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?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!