PDA

View Full Version : Texture Splatting



halo
11-11-2005, 05:53 PM
I am attempting to switch from using vertex alpha to texture splatting, to draw my terrain layers.

The base layer is just a solid pass, using modulate texture blending, with a 2x scale:

glTexEnvi GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE
glTexEnvi GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE
glTexEnvf GL_TEXTURE_ENV,GL_RGB_SCALE,2.0Layers on top of the base layer are rendered with blend enabled:

glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA
glDepthMask GL_FALSETexture unit 0 is the alpha mask texture:

glActiveTextureARB GL_TEXTURE0
glEnable GL_TEXTURE_2D
glBindTexture GL_TEXTURE_2D,alphatexture
glTexEnvf GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE0_ALPHA,GL_TEXTURE0
glTexEnvi GL_TEXTURE_ENV,GL_OPERAND0_ALPHA,GL_SRC_ALPHATextu re unit 1 is the texture I want drawn:

glActiveTextureARB GL_TEXTURE1
glEnable GL_TEXTURE_2D
glBindTexture GL_TEXTURE_2D,texture
glTexEnvi GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE
glTexEnvi GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE
glTexEnvf GL_TEXTURE_ENV,GL_RGB_SCALE,2.0
glTexEnvf GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_PRIMARY_COLOR
glTexEnvf GL_TEXTURE_ENV,GL_OPERAND0_RGB,GL_SRC_COLOR
glTexEnvf GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE1
glTexEnvf GL_TEXTURE_ENV,GL_OPERAND1_RGB,GL_SRC_COLOR
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE0_ALPHA,GL_TEXTURE0
glTexEnvi GL_TEXTURE_ENV,GL_OPERAND0_ALPHA,GL_SRC_ALPHA
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE1_ALPHA,GL_TEXTURE0
glTexEnvi GL_TEXTURE_ENV,GL_OPERAND1_ALPHA,GL_SRC_ALPHAHowev er, when I try this, the top-most terrain layer is drawn solid, regardless of the alpha mask texture. Are my texture blend modes correct?

Oh, and I make my mask texture like this:

glTexImage2D GL_TEXTURE_2D,0,GL_ALPHA,resolution,resolution,0,G L_ALPHA,GL_UNSIGNED_BYTE,alphamap

halo
11-11-2005, 09:29 PM
It works, I was doing something stupid.

I will leave this up, since it contains a lot of good info.