PDA

View Full Version : Multitexturing to Multi-pass texturing



Bumper
05-12-2004, 07:27 AM
Hello all,

I would like to deal with multi-pass texturing in order my program can render a heavy textured mesh on any hardware.

But I have difficulties to replace my multitexturing code (just 2 textures for testing) by multi-pass rendeing using 1 texture each pass. The rendered image simply do not look as the 1-pass version of it.

Here some points I don't understand:

1) Why must I have to use glBlend() for multi-pass, since glTexEnv should (See 2) blend the texture correctly? and what parameters should I specify for glBlendFunc()?

2) Why glTexEnv calls don't work with multi-pass? Should I have to emulate glTexEnv using just glBlendFunc() ??? it seams impossible.

3) May be my problem came from ARB_texture_env_combine which don't work with just 1 pass?

4) Solution? (I don't want using Pixel Shader).

My code for multitexturing

// For Unit 0
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_REPLACE);
glBindTexture(...);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, ...);

// For Unit 1
// Same as unit 0 but replacing GL_REPLACE by GL_MODULATE and add:
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.f);

// Render the mesh
glDrawElements(...);

// For Unit 1
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

// Disable Unit 0
// Same as for unit 1Multi-pass texturing which don't work...

// For the first pass
glDisable(GL_LIGHTING);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_REPLACE);
glBindTexture(...);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, ...);

// Render 1
glDrawElements(...);

// For the second pass
glEnable(GL_LIGHTING);
glDepthFunc(GL_EQUAL);
glDepthMask(GL_FALSE);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.f);
glBindTexture(...);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, ...);

// Render 2
glEnable(GL_BLEND);
glBlendFunc(???, ???);
glDrawElements(...);
glDisable(GL_BLEND);

// Restore states & clean all (depth mask, etc.)Thanks a lot in advance if someone could help me.

yooyo
05-12-2004, 07:52 AM
glTexEnv affects color of incoming fragment. If you wat to render exactly same image using single pass multitexturing and multipass texturing you have to
setup blend func bettween pass0 and pass1 to produce same result as glTexEnv in stage1.

Ostsol
05-12-2004, 07:53 AM
If you just want to multiply two texture with multi-pass rendering, just render the textures with GL_REPLACE and set your blend parameters to (GL_DST_COLOR, GL_ZERO). This will multiply the new pixel with the existing one in the framebuffer. You can also just use GL_TEXTURE0_ARB for both texture coordinates and texture units.

Bumper
05-12-2004, 08:10 AM
Thanks for those fast replies

Ostsol> I want to reproduce effect created with multitexturing (add, substract, multiply, modulate 2X, modulate 4X, etc.)

yooyo> So I could'nt use glTexEnv in n-pass to produce the same result as glTexEnv in 1-pass?
Is it possible to reproduce modulate 2X and 4X effect without using glTexEnv and multitexturing?

dorbie
05-12-2004, 08:27 AM
Bumper, you are replacing texenv with glBlendFunc and possibly glBlendEquationEXT.

These do not have equivalent functionality. It is up to you to figure out what the second texenv was and how to reproduce that with the blend hardware.

For example if your second texenv was GL_MODULATE you would want to make the second pass GL_REPLACE and use a glBlendFunc(GL_ZERO, GL_SRC); Other texenv operations would require different combinations of texenv and blending and may require pass reordering or may be impossible.

You need to look at the arithmetic of the texenv and the blend and understand how to accomplish your desired arithmetic with a combination of the above functions and pass reordering.