PDA

View Full Version : Texture alpha between multitexture passes



halo
12-10-2004, 08:13 PM
Let's say I had a metal wall texture with some "holes" in it. I use a 32-bit TGA to provide an alpha channel. Underneath the metal is a cubic map, so when you move by the wall, you only see some parts of the wall with the reflective cubic map. It's a really nice effect.

I can easily do this in two passes. Is there a way to do it using one-pass multitexturing? I want a full range of alpha values, so it's a blend, not a mask.

sqrt[-1]
12-11-2004, 12:01 AM
Sure,

First stage : Bind diffuse with alpha holes

RGB : Diffuse texture
Alpha: Alpha holes

Second stage: Bind cube map

RGB : Lerp between the previous color and the cube map by the previous alpha
Alpha: (probably) Use primary alpha

halo
12-11-2004, 08:23 AM
Ummm...I have no idea what that means.

sqrt[-1]
12-11-2004, 04:49 PM
This is the advanced forum??

Ok just do this:

//Satge 0
glActiveTextureARB(GL_TEXTURE0)
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, /* funky texture with alpha holes */ );

//Modulate the texture by the vertex color
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_CO MBINE)
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULAT E)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_PREVIOU S)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB,GL_SRC_CO LOR)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE )
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB,GL_SRC_CO LOR)

//Modulate the vertex alpha by the texture alpha
// (May want to just use texture alpha -depends on your case)
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA,GL_MODUL ATE)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA,GL_PREVI OUS)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA,GL_SRC_ ALPHA)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA,GL_TEXTU RE)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_ALPHA,GL_SRC_ ALPHA)

//Stage 1
glActiveTextureARB(GL_TEXTURE1)

glEnable(GL_TEXTURE_CUBE_MAP);

//Enable reflection texturegen here

glBindTexture(GL_TEXTURE_CUBE_MAP, /* funky reflective cube map */ );

//Lerp between the two textures by the previous textures' (and vertex) alpha
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_CO MBINE)
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_INTERPO LATE)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_TEXTURE )
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB,GL_SRC_CO LOR)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_PREVIOU S)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB,GL_SRC_CO LOR)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB,GL_PREVIOU S)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND2_RGB,GL_SRC_AL PHA)

//Just use the primary alpha
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA,GL_REPLA CE)
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA,GL_PRIMA RY_COLOR)
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA,GL_SRC_ ALPHA)

halo
12-11-2004, 05:42 PM
Sweet, thanks.