Archived

This topic is now archived and is closed to further replies.

Basiror

indepth tutorial for multitex + blending

Recommended Posts

Basiror    241
hi i am writing my terrain renderer at the moment i got perfect blending between the base and detail layers via multiple passes 1. render the base layer 2. render the detail layers with alpha blending and splatting that works fine but i want to do it in a single pass so i did some research about arb_tex_env_combine i understand the theory if it now but id like to check out some sample code of a terrain renderer with this extensions because the description of the functions isn t that good for example it mentions args 0... args3 but nowhere links it to the paramaters i have to pass to the texenv function just a little code snippet to get these things sorted please thx in advance

Share this post


Link to post
Share on other sites
MatrixCubed    199
This is how I do it ...


// Load the extensions glActiveTextureARB and lMultiTexCoord2fARB

// iBaseTex and iDetailTex are GL texture IDs


// Set the base texture

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, iBaseTex);

// Set the detail texture

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, iDetailTex);

// For each polygon

for ( ; ; )
{
// Set u,v coordinates per base and detail texture

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u, v);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, u, v);
}


Hope that helps



[edited by - MatrixCubed on August 10, 2003 6:51:54 PM]

Share this post


Link to post
Share on other sites
_walrus    126
quote:
Original post by Basiror
hi i am writing my terrain renderer at the moment

i got perfect blending between the base and detail layers via multiple passes

1. render the base layer
2. render the detail layers with alpha blending and splatting

that works fine but i want to do it in a single pass

so i did some research about arb_tex_env_combine

i understand the theory if it now but id like to check out some sample code of a terrain renderer with this extensions because the description of the functions isn t that good

for example it mentions args 0... args3 but nowhere links it to the paramaters i have to pass to the texenv function

just a little code snippet to get these things sorted please

thx in advance



Pretty much this extension will allow you to specify the way your textures are combined togehter. the args it mentions come from the primary color, texture of the current texture unit, a specifed constant or prior texture color. Although there is an extension (ARB_texture_env_crossbar) that will allow you to access a texture as an arg from any texture unit (not neccessarly the current or preious one). In the following example i''m taking the primary color( color of the polygon ) and multiplying it with the texture specifed in texture unit 0. then i''m adding the second texture to the result. Sorry if this is not correct (it''s late and im rushing to bed plus i havne''t used this extension in a while) but the idea and concept of it is there.


void setupUpCombiner()
{
glActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_PRIMARY_COLOR_ARB);

glActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, COMBINE_RGB_ARB, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_PREVIOUS_ARB);

}





Share this post


Link to post
Share on other sites
Basiror    241
quote:
Original post by MatrixCubed
This is how I do it ...


// Load the extensions glActiveTextureARB and lMultiTexCoord2fARB

// iBaseTex and iDetailTex are GL texture IDs


// Set the base texture

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, iBaseTex);

// Set the detail texture

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, iDetailTex);

// For each polygon

for ( ; ; )
{
// Set u,v coordinates per base and detail texture

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u, v);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, u, v);
}


Hope that helps



[edited by - MatrixCubed on August 10, 2003 6:51:54 PM]




just a note what you posted is a simple example of multitexturing

not really what i was asking for

my concerns were about using the tex env combine



@ WALRUS:

thx i think thats enough to figure the rest out thx

Share this post


Link to post
Share on other sites
Basiror    241
one last question on this topic

the code underneath works perfect
but what i wonder about is what does the OPERANTn_RGB_EXT do?

is this the row of the performed operations or what?


glActiveTextureARB(GL_TEXTURE0_ARB);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,dirt.texID);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,grass.texID);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR_EXT);
//glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);

//glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);

//glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA);



glBegin(GL_QUADS);
glColor4f(1,1,1,1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);glVertex3f(0,-128,64);
glColor4f(1,1,1,1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,1);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,1);glVertex3f(0,-128,128);
glColor4f(1,1,1,0);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,1);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1,1);glVertex3f(64,-128,128);
glColor4f(1,1,1,1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1,0);glVertex3f(64,-128,64);

Share this post


Link to post
Share on other sites
Basiror    241
i really wonder whethere all this texture combining is worth it at all

doesn t all the texture unit state changes slow the engine down more than several passes of alpha blending?

Share this post


Link to post
Share on other sites
exa_einstein    122
it won''t slow anything: just try to compute it yourself, is it better to draw ALL POLYGON PIXELS once more (small 100*100 poly has 10000PIXELS!!!!!), or just send some small integers to your card and let it process it with multitexturing, which is ACCELERATED (-> much more faster)?

Share this post


Link to post
Share on other sites
He was asking whether the texture combiners slow everything not the multitexturing, and blending is also hardware accelerated. I use the GL_ARB_texture_env_combine and GL_ARB_texture_env_dot3 extensions and they are very fast.

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
Basiror    241
i draw my terrain differently now

first i draw the entire terrain with detail textures if needed
and then i look for texture switches and blend those with alpha blending in a second pass
that way i reduce texture switching a lot more than with multitexturing and combining

Share this post


Link to post
Share on other sites