PDA

View Full Version : Help Setting up Multitexturing environment with glTexEnvf()



09-17-2005, 11:38 PM
I have four textures and use four texture units,one as scale ,others as texture,like this:
(Let t0 , t1 ,t2 ,t3 hold rgb(note:[0,255]) , and td as result(display on screen))

float sum = t0.r + t0.g + t0.b ;
float scal_r = t0.r/sum ;
float scal_g = t0.g/sum ;
float scal_b = t0.b/sum ;

td.r = t1.r*scal_r + t2.r*scal_g + t3.r*scal_b;
td.g = t1.g*scal_r + t2.g*scal_g + t3.g*scal_b;
td.b = t1.b*scal_r + t2.b*scal_g + t3.b*scal_b;

What can do with glTexEnvf() function ?

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, texid0);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, texid1);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_CO MBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_INT ERPOLATE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_PRE VIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SR C_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT,GL_TEX TURE);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_EXT,GL_SR C_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB_EXT,GL_TEX TURE);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND2_RGB_EXT,GL_SR C_ALPHA);

.
.
.

Thanks any way.

Sorry for my poor English.

dorbie
09-18-2005, 11:55 PM
Your math looks closer to several dot products, after swizzles :-(.

You can't do what you want with combiners you might be able to get closer with DOT3 with more combiner units and maybe crossbar, you'd need r g b components for t1 t2 t3 in the same texture unit and you'd need to deal with the implicit signed scale and bias in the DOT3 but combining the multiple DOT3 results to an rgb triplet again takes a swizzle/mask that isn't available.

I think you'll have to go for a shader instead because your requirements are so specific.

A shader will easily let you do this with the needed swizzles into three DOT3 instructions and the copies to combine the results to output as an rgb triplet.

Alternatively preswizzle t1 t2 and t3 to have exclusive r g and b components and to a color masked dot3 multipass for simple combiner hardware.

zeckensack
09-19-2005, 04:45 AM
I agree totally with dorbie. And I'd like to add one thing.
This code of yours:

float sum = t0.r + t0.g + t0.b ;
float scal_r = t0.r/sum ;
float scal_g = t0.g/sum ;
float scal_b = t0.b/sum ;This should not be done in the combiner/shader in any case. This begs for preprocessing (i.e. the texture sample would directly yield scal_r;scal_g;scal_b).

09-20-2005, 02:50 PM
Thank all,I have done uising a shader.