Texture units question

Hello all,
I am trying to find a way to do a sum of textures (each texture allocated to a texture unit) such as:

Cout = W1CT1 + W2CT2 + W3*CT3
Where w1 + w2 + w3 = 1.0 (Wi for texture unit i)
And CTi is the RGB texel value for texture unit i.

I do not want to use shaders.
I also don’t want to change the alpha for each texel in the texture itself (it is a constant 1).
I guess there is probably a way to do it by using GL_tex_env_combine, but I am so confused by the amount of the new tokens in the spec. :confused:
I will be glad if someone has an idea or give me a link to source code showing how to use this extension.

Many thanks,

Yossi

http://www.ati.com/developer/sdk/rage128sdk/Multex/OGLMultex.html

this should help, you would use the constants for your weighting

Thanks a lot ‘CrazyButcher’,
The utility shows visually the pileline in the GL_tex_env_combine extension.
Still, I don’t see a simple way (if any) to scale the texture RGB and to add it to the previous texture unit RGB.
To do scaling I must use GL_MODULATE and to do the addition I must use GL_ADD, but I can’t do both.
Did i miss something?

Thanks again,
Yossi

Still, I don’t see a simple way (if any) to scale the texture RGB and to add it to the previous texture unit RGB.
There may be some TEV extensions that let you do what you’re doing, but I don’t recall any. The standard multitexture pipeline typically isn’t good enough to do many interesting things. So yes, you’re probably going to need shaders.

With standard TexEnv and
ATI_texture_env_combine3

float myWeight1[4], myWeight2[4], myWeight3[4];

glActiveTexture(GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, myWeight1);

glActiveTexture(GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE_ADD_ATI);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, myWeight2);

glActiveTexture(GL_TEXTURE2);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE_ADD_ATI);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, myWeight3);

It should be possible to use crossbar for this.

Thanks folks for your help,
I think I found a way to do what I want.
With some simple math you can find weights that when using the combiner in GL_INTERPOLATE_EXT mode, are equivalent to the sum of the textures multiplied by the original weights.
I will post it soon.

Thanks,
Yossi

Hi Yossi,

Just check http://www.delphi3d.net/articles/viewarticle.php?article=terraintex.htm

It explain this in details and also have source coude (in delphi - but OpenGL commands are the same :slight_smile: )

Ido