Multitexturing and blending
by Max Robinson · in Torque Game Engine · 09/10/2003 (7:37 pm) · 7 replies
Hopefully I will solve this problem like I solved the last one, by realising that it was already working, but so far no luck.
I got multitexuring using multiple TMUs working, but its blending all wrong. Instead of adding the 2 bitmaps onto eachother like it does without using TMUs, it does a multiply blend or something, where they screen eachother, only showing areas that overlap.
Here's an example:
The broken multi-TMU version:

Working version that just rerenders over and over:

You see what I mean.
Here's what I do to set up TMUs:
I got multitexuring using multiple TMUs working, but its blending all wrong. Instead of adding the 2 bitmaps onto eachother like it does without using TMUs, it does a multiply blend or something, where they screen eachother, only showing areas that overlap.
Here's an example:
The broken multi-TMU version:

Working version that just rerenders over and over:

You see what I mean.
Here's what I do to set up TMUs:
//------------------------------------ // ACTIVATE TMU #0 //------------------------------------ glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, mDataBlock->textureHandle[0].getGLName()); if(mDataBlock->texInvAlpha[0]) glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); else glBlendFunc( GL_SRC_ALPHA,GL_ONE); glClientActiveTextureARB(GL_TEXTURE0_ARB); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(vertex), &(m_rVerts[0].point)); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), &(m_rVerts[0].texCoord)); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_FLOAT, sizeof(vertex), &(m_rVerts[0].color)); glMatrixMode ( GL_TEXTURE ); glPushMatrix (); glLoadIdentity (); glTranslatef (horizontalTextureShift[0] + (mSin(horizontalTextureShiftTheta[0]) * mDataBlock->horizontalTexMovementVariance[0]), verticalTextureShift[0] + (mSin(verticalTextureShiftTheta[0]) * mDataBlock->verticalTexMovementVariance[0]), 0.0f ); glScalef (mDataBlock->horizontalTexWrap[0],mDataBlock->verticalTexWrap[0],0.0f); //glPopMatrix(); //------------------------------------ // ACTIVATE TMU #1 //------------------------------------ glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, mDataBlock->textureHandle[1].getGLName()); if(mDataBlock->texInvAlpha[1]) glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); else glBlendFunc( GL_SRC_ALPHA, GL_ONE); glClientActiveTextureARB(GL_TEXTURE1_ARB); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(vertex), &(m_rVerts[0].point)); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), &(m_rVerts[0].texCoord)); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_FLOAT, sizeof(vertex), &(m_rVerts[0].color)); glMatrixMode ( GL_TEXTURE ); glPushMatrix (); glLoadIdentity (); glTranslatef (horizontalTextureShift[1] + (mSin(horizontalTextureShiftTheta[1]) * mDataBlock->horizontalTexMovementVariance[1]), verticalTextureShift[1] + (mSin(verticalTextureShiftTheta[1]) * mDataBlock->verticalTexMovementVariance[1]), 0.0f ); glScalef (mDataBlock->horizontalTexWrap[1],mDataBlock->verticalTexWrap[1],0.0f);
#2
That should make them add.
09/11/2003 (6:58 am)
Yeah, what he said. You need to do something like this for the 2nd glTexEnvi() call:glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);
That should make them add.
#3
09/11/2003 (3:14 pm)
Sadly that didn't work, I've tried a few other things, such as doing glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_ADD);, changing the original glTexEnvi to replace, add, etc. More often than not it seems to do the modulate operation, even if both are set to ADD for example.
#4
09/11/2003 (3:47 pm)
Head on over to www.ati.com/developer/sdk/rage128sdk/Multex/OGLMultex.html and try that program out. A little experimentation with that and you should be able to figure out the settings you want for your effect.
#6
09/12/2003 (12:32 am)
Mark -- Excellent tool. I've been playing around with the ARB multitexture extension and this thing saves me a lot of time. *Pokes around on ATI's website* They got a lot of cool stuff there, like a high-res normal map generator. Neat!
#7
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ARB, GL_PREVIOUS);
the source might be a _EXT, I forget.
09/12/2003 (10:41 am)
Oh, I think you need to set what you want it to blend with.glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ARB, GL_PREVIOUS);
the source might be a _EXT, I forget.
Torque Owner Mz
#2. Here's your problem:
You need to set that as appropriate for each TMU. If you use GL_MODULATE mode, you're going to get the multiplication effect you describe. The GL_BLEND stuff only blends your result with what's already in the buffer - it doesn't control blending between different TMUs.