Jump to content
  • Advertisement
Sign in to follow this  

splattering, blending 3 textures with multitexturing, combined with primary color

This topic is 4236 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

Hello, I am currently writing a terrain engine. Because the terrain will be very huge, I am not able to use a single big texture all over the terrain. I have to combine/blend the terrain texture on the fly. So here is the exact problem: I am drawing terrain tiles as triangles. The corners define the texture that is used. So there may be tiles that have 3 different textures. In that case, I need the following effect: Let T1,T2,T3 be the tree different textures of the corner C1,C2,C3, then alls points should be painted by a linear combination of alls those 3 textures, blended together. If have sand in the upper left corner, water in the upper right and mud in the lower corner, then the corner areas should pretty strong look like the texture in their corresponding corners, while the middle of the triangle should contain all the 3 textures blended together. I hope you've got the point now. I've tried this with 2 textures using multitexturing and it works well. I tried to enhance this to 3 textures, but it doesn't seem to work: First I combine two corners, so there is one with sand, and two with water. Now I need to replace one water corner with mud in unit 2. There I take the result of texture unit 1 and repeat the same I've done in texture unit 1. But this doesn't give the linear combination I need. It seems that unit 2 uses all previous inputs, but not the result of unit 1. I don't know whats happening exactly - but the corner of the first unit disappears completely, so there is something wrong. Here is my try with 3 textures, that gives a strange result: (you get the working version with 2 texture if you comment out everything related to texture unit 2) NOTE: ----- - I am using colors inside color arrays to do the blending with the primary color. - my test textures are named: base, grass and zero #ifndef CTEST_H_INCLUDED #define CTEST_H_INCLUDED #include "MImagePool.h" #include "CImage3D.h" #include "MGsgGl.h" GLfloat pfVertexData[] = { 1.0, -1.0, 0.0, 1.0, 1.0, 0.0, -1.0, 1.0, 0.0, }; GLfloat pfTexCoords[] = { 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, }; // each corner has a dominating color... GLbyte pbColors1[] = { 255, 255, 255, 255, 000, 000, 000, 000, 000, 000, 000, 000, }; GLbyte pbColors2[] = { 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, }; GLbyte pbColors3[] = { 000, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, }; GLint iVertices = 3; // glGetIntegerv with GL_MAX_TEXTURE_UNITS_ARB class CTest { public: GLuint iBufferNames[5]; CImage base; CImage grass; CImage white; CImage alpha; CImage alpha1; CImage alpha2; CImage zero; CTest() { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); int max_textures; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max_textures); glGenBuffersARB(5, iBufferNames); glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[0]); glBufferDataARB(GL_ARRAY_BUFFER_ARB, ( iVertices * 3 )*sizeof(GLfloat), pfVertexData, GL_STATIC_DRAW_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[1]); glBufferDataARB(GL_ARRAY_BUFFER_ARB, ( iVertices * 3 )*sizeof(GLfloat), pfTexCoords, GL_STATIC_DRAW_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[2]); glBufferDataARB(GL_ARRAY_BUFFER_ARB, ( iVertices * 4 ) * sizeof(GLbyte), pbColors1, GL_STATIC_DRAW_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[3]); glBufferDataARB(GL_ARRAY_BUFFER_ARB, ( iVertices * 4 ) * sizeof(GLbyte), pbColors2, GL_STATIC_DRAW_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[4]); glBufferDataARB(GL_ARRAY_BUFFER_ARB, ( iVertices * 4 ) * sizeof(GLbyte), pbColors3, GL_STATIC_DRAW_ARB); bool b1 = base.open("base.tga"); bool b2 = grass.open("grass.tga"); bool b3 = alpha.open("alpha.tga"); bool b4 = white.open("white.tga"); bool b5 = alpha1.open("inner.tga"); bool b6 = alpha2.open("outer.tga"); bool b7 = zero.open("zero.tga"); glEnableClientState(GL_TEXTURE_2D); base.glGenTexture(); grass.glGenTexture(); alpha.glGenTexture(); alpha1.glGenTexture(); alpha2.glGenTexture(); white.glGenTexture(); zero.glGenTexture(); glDisableClientState(GL_TEXTURE_2D); } void draw() { draw1(); } void draw1() { //glEnable(GL_BLEND); glClientActiveTextureARB(GL_TEXTURE0_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[1]); glTexCoordPointer(2,GL_FLOAT, 0, 0); // use the color of the first corner (defined at beginning) glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[2]); glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0); glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); base.select(); // glBindTexture ... glClientActiveTextureARB(GL_TEXTURE1_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[1]); glTexCoordPointer(2,GL_FLOAT, 0, 0); // use the color of the second corner (defined at beginning) glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[3]); glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0); glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR); grass.select();// glBindTexture ... glClientActiveTextureARB(GL_TEXTURE2_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[1]); glTexCoordPointer(2,GL_FLOAT, 0, 0); // use the color of the third corner (defined at beginning) glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[4]); glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0); glActiveTextureARB(GL_TEXTURE2_ARB); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR); zero.select();// glBindTexture ... glEnableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, iBufferNames[0]); glVertexPointer(3, GL_FLOAT, 0, NULL); glDrawArrays(GL_TRIANGLES, 0, 3 ); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); } }; #endif

Share this post


Link to post
Share on other sites
Advertisement
Hello again,

I've noted something interesting: The texturing stages don't seems to work like I thought they would...

When I do the following:

unit0: just load a texture
unit1: do a GL_INTERPOLATE: OUT = Arg0 * (Arg2) + Arg1 * (1-Arg2)

which delivers the correct intermediate result. Now here is something odd: in unit 2 I do:

GL_INTERPOLATE: Arg0 * (Arg2) + Arg1 * (1-Arg2)
with: Arg0: texture
and: Arg1: previous
and: Arg2: overall 0

This should then just put through the output from the previous stages, but it doesn't. What I see is the INPUT from the first stage. What am I doing wrong??

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hello,

I think I got now to the point:

Lets say unit 0 and 1 combine two textures in the way I want it. It is possible to use the RESULT (what the user would see without any further texturing units) in a further combine operation in unit 2 at all?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!