PDA

View Full Version : glTexEnvi Blending Problem.



H.Stony
06-19-2005, 02:00 AM
i want to use multitexturing to reach such textureffect.
http://awx.dyndns.org/uploads/whatiwant.jpg
the textures are patterns except the alpha texture. i have tried to use GL_BLEND but the result was, that all texture layers were blended also if i use GL_REPLACE with the first layer.

how would you manage this. examples? i need it to texture a big terrain (terrain texture examples?). what paramaters of glTexEnv do i need to get the needed result?

i aim on such a texture:
http://members.gamedev.net/vertexnormal/images/roadturb1.jpg

thanks h.stony

CrazyButcher
06-19-2005, 04:55 AM
look into GL_ARB_texture_env_combine
http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt

this extension allows a lot more control over how textures are blend

this little app by ATI lets you visually play with setups
http://www.ati.com/developer/sdk/rage128sdk/Multex/OGLMultex.html

depending on if your card has 4 texture units or 2 you will need to do different

4:
tex0 = grass tex = RGB/ALPHA: replace tex
tex1 = alpha tex = RGB: replace previous ALPHA: replace tex
tex2 = dirt tex = RGB: interpolate previous & tex based on previous alpha
tex3 = any tex = RGB/ALPHA: modulate previous with primary color (to get vertex lighting)

2:
first pass:
tex0 = grass tex = modulate

second pass: glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

tex0 = alpha tex = replace tex
tex1 = dirt tex = RGB: modulate tex with primary color ALPHA: replace previous
tex0

using GL_ARB_texture_env_crossbar or GL_NV_texture_env_combine4 you can get texture unit useage down to 3 for the first one

H.Stony
06-28-2005, 07:26 AM
@ crazy butcher..it seems that i am too stupid to realize your idea..

is this another possibility?
my Current Code:
TEXTURE0 is the gras
TEXTURE1 is the alpha
TEXTURE2 is the detail dirt map

the result: also the grass is blended :-(

glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textur_liste[0]);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);

glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textur_liste[1]);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, GL_SRC_ALPHA);

glActiveTexture(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textur_liste[2]);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);

CrazyButcher
06-28-2005, 11:45 AM
you must set
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB )

for every unit in which you want to use the special combiner setups, also you must specify COMBINE_ALPHA and such manually, please have a look at the ati link it illustrates the extension quite well

H.Stony
06-29-2005, 02:55 AM
// The Gras
/*glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textur_liste[0]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PREVIOUS_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA);
*/

// The Alpha map
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textur_liste[1]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PREVIOUS_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA);

// The Detailtexture
glActiveTexture(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textur_liste[2]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PREVIOUS_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA);The detail and the Gras Texture are patterns.

The result with all 3 layers:
http://www.awx.at/eitsch/hilfe/result1.jpg
The Result with disabled gras layer:
http://www.awx.at/eitsch/hilfe/result2.jpg

The Textures:
http://www.awx.at/eitsch/hilfe/alpha.jpg
http://www.awx.at/eitsch/hilfe/gras.jpg
http://www.awx.at/eitsch/hilfe/detail.jpg

i have tested it in the ATI texEnv Simulator but there are only 2 layers but it looks like a combining problem beetween gras and the others.

i am getting silly with this stuff. please help....

V-man
06-29-2005, 05:59 AM
The result seems strange.
If texture unit 0 was disable, then it generates a white color.
In texture unit 1, you modulate with current texture and previous (which is white).
In texture unit 2, you modulate with current texture and previous.

It looks a little strange because I think it should produce a darker color or near black.

BTW, modulation take 2 operands.
Interpolation uses 3 operands.