PDA

View Full Version : Multi-texturing equation question.



JMSDKS
04-18-2006, 03:31 PM
Hello. I am trying to implement a simple multi-texturing equation but can't seem to find the combiner selection that I need. I am using an ATI card so some of the new ATI extensions are available to me as well. My equation is...

Arg0 + Arg0 * Arg1 but I want Arg1 to basically go from -1.0 to +1.0. My whole intent is to have a base color (Arg0) and an intensity multiplier (Arg1). If Arg1 is -1.0 then the final color is basically black while if Arg1 is +1.0 then the final color is twice the base color. I was using three texture units with GL_MODULATE and GL_ADD but I would like to reduce the number of units.

Any help would be appreciated.

Thanks.

MalcolmB
04-18-2006, 05:52 PM
Why not just use a shader? If you want to use a slightly older extension to support older video cards (ATI Radeon 8500 and up) you can use ATI_fragment_shader.

Serge K
04-18-2006, 06:52 PM
So, you want this function:

Arg0 + Arg0·2·(Arg1-0.5) // (Arg1-0.5) => [-0.5, 0.5]

// simple math:
Arg0 + Arg0·2·(Arg1-0.5) = 2·Arg1·Arg0

Can be done with 2 texture units (OpenGL >=1.3 or GL_EXT_texture_env_combine).

// for the first texture (Arg1)
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

// next texture unit (Arg0)
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_OPERAND0_RGB, GL_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_ALPHA );
glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE, 2 );

JMSDKS
04-19-2006, 10:31 AM
MalcomB - I have done some shader work in the past and I agree it would be much better to do it that way. But I find that programmable shaders are slower for some reason and my current video card does not have programmable shaders plus ultimately we plan on embedding this and programmability may not be embeddable.

Serge K - I will try your code out. Thanks for the reply.

I appreciate the responses.