Multitexturing question

Hi,

I’ve done a fake gaussian blur effect using opengl. The core of the algorithm simply draws the texture to be blurred multiple times in additive mode with some weight and texture coordinates shift applied to it.

To optimize it I tried to pack passes using multitexturing. The texture equation should be :
C® = w(0) * C(0) + w(1) * C(1) + … + w * C(n)

Where C® is the resulting color, w(n) are the kernel weights and C(n) are the colors from the different texture units.

Currently I render my textures two by two, pairing by weight (the kernel is symetric around its center), did not found a texture_env setup to specify the texture equation above using more texture units, so I’m asking to you

Thanks.

These should help:
http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt
http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_crossbar.txt

I already use texture_env_combine, and just realised that my setup is not equivalent to the non-multitexture one :stuck_out_tongue:

Texture unit 0:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT_ARB);

Texture unit 1:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);

The weighting factor is loaded in the texture unit’s environment color.

This gives wrong results :
C(r) = C(1) * w(1) + ((C(0) * w(0)) * (1 - w(1)))

So is it possible to implement this blending equation at all without using pixel shaders or register combiners ?

[This message has been edited by flupke (edited 07-11-2003).]

I don’t think so for the general case, no.

Your basic problem is after texture zero you need to modulate each texture sample by a unique color and then add the results to the previous texture unit. Fundamentally unextended texture operations must operate on the input from the previous operation and only apply a limited set of operations.

The modulate addition is one of the basic features combiner texture operations bring to the party.

With combiners you should be able to apply the combiner operation to any number of texture units provided that you can supply kernel values for in colors (which of course you can).

There are naturally limitations w.r.t. clamping & signed kernel values, none are insurmountable but a more sophisticated approach would be required with these simple extensions.

I found a way to render that effect using all available texture units (big speedup ) with hardware that support texture_env_combine by modifying the weights :
w(0) = w(0) / ((1 - w(1)) * (1 - w(2)) * … * (1 - w(n)))
w(1) = w(1) / ((1 - w(2)) * (1 - w(3)) * … * (1 - w(n)))

w(n) = w(n)

with TU0 set as TU0 above and [TU1 ; TUn] set as TU1 above.

It was a pretty simple math question, I just post the solution here in case someone was trying to optimize his opengl-based blur effect like me

[This message has been edited by flupke (edited 07-14-2003).]