Opacity Maps

Using multitexturing, I want to load/display a normal map and an opacity map together. I would like the opacity to be determined by the RGB intensity of the image. I can handle loading and displaying the normal map, but I don’t even know where to start for the opacity map. (The maps are two seperate files.)

If anyone knows how to do this, please help.

Thanks.

so, you have two RGB pixmaps: one with the picture and one with the opacity information.

with multitexturing, you want have, say, texture unit 0 to hold RGB and texture unit 1 to hold opacity (alpha)

am i right? if i’m, try the following.

load as usual your pixmaps into temporary RGB buffers.

upload to opengl the picture into unit 0, as GL_RGB.

convert the opacity RGB map to a alpha map, using some law.

upload the alpha texture to unit 1 as GL_ALPHA.

it depends on your application wich law to use. a simple law could be this:

opacity = (r+g+b)/3

opacity is your destination GL_ALPHA texture.
r,g,b come from the opacity map you have loaded.

this law considers the average intensity (not the perceptual intensity) of the opacity map, and builds a alpha value accordingly.

i suggest to experiment with laws to get the best result.

Dolo//\ightY

[This message has been edited by dmy (edited 05-11-2000).]

Ok, I can load both maps now, but what about displaying them? Do I have to change the texture environment mode, or enable blending?

does the opacity map have to be geometrically uncoupled in respect to the RGB map?

i mean, do you need to move, or better slide them separately without restrictions?

if it is NOT so, then you don’t need multitexturing: just merge the image RGB and the opacity RGB into a single RGBA texture.

but more important, what you’re trying to render? some special effect like a “last american hero” holographic view?

…wich would be a good effect indeed… hmmm… i have to test this!

Dolo//\ightY

PS: i read again your first post: you’re talking about a “normal map”.
when you say normal i suppose you mean a RGB pixmap wich is treated as colors by opengl.
if it is not what you meant, tell me.

Dolo//\ightY

[This message has been edited by dmy (edited 05-15-2000).]

Well, I would like the maps to be seperate. That way I can apply the opacity map to objects with different color maps.

As for what I am trying to render… In 3d Studio MAX, you can apply opacity maps to your objects. It just allows different amounts of transparency on one object.

As for the normal map, it is for colors.

So, as an example, let’s say I want to draw a rectangle with a color map on it. Then, lets say I want the rectangle to be more transparent on the edges. My opacity map would define that.

How you explained to load the maps seems fine, now I just need to know how to display the opacity map correctly. Do I need to change the texture environment mode, or enable blending? If I do, how should I set them up?

hmmm… i’m not sure if it is possible, but i’ll give it a try.

if you will to render several primitives (wich is almost always the case ), you have to enable alpha blending.

texture environment should be set to GL_MODULATE, the standard approach for texture.

the first unit must be a GL_RGB texture, the second GL_ALPHA.

this should work. i’ll try on my own ASAP.

Dolo//\ightY

[This message has been edited by dmy (edited 05-16-2000).]

Neat. If you get it to work, please let me know. And if it’s not too much trouble, maybe you could show me some sample code.

So what’s up guys?? DiD you find some interesting trick with these alpha maps?

An interested coder…

I’m still waiting for a response from dmy. I guess he’s trying to get it working, but I am not sure.

I’ve been trying myself to get it working, but so far I can’t. I hope someone can figure it out soon.

ok, it’s possible!
i just finished the test, i’ll email you the exe in a few seconds.

here i post the meaningful code:

glBlendFunc(BLEND_ALPHA);
glEnable(GL_BLEND);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
alpha.use(); // glBindTexture(…)

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
image.use(); // glBindTexture(…)

then you draw the primitives by setting the texture coordinates of eevery TU:

glColor3f(1,1,1);

glBegin(GL_QUADS);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);
glVertex2f(-1,-1);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1,0);
glVertex2f(+1,-1);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1,1);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1,1);
glVertex2f(+1,+1);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,1);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,1);
glVertex2f(-1,+1);

glEnd();

it was not the way i first thought: you set the first TU to be processed (TU 0) as the alpha map.
the second TU (TU 1) then gets the alpha values from the first TU.

if i thougt better before, i would found why:
the current color fragment is made of r,g,b AND alpha values.

in modulate mode, the fragments are multiplied in cascade, so:

texture.r=tu0.rtu1.r
texture.g=tu0.g
tu1.g
texture.b=tu0.btu1.b
texture.a=tu0.a
tu1.a

the TU0 has RGB=glColor (set to 1,1,1) and alpha channel wich varies from 0 to 1.

the TU1 instead has fixed alpha=1 and RGB is variable.

so from the calcs you get the final texture made out of TU0[alpha] and TU1[RGB].

hey, good looking indeed

Dolo//\ightY

PS: oops… just saw you have no email.
post or edit your address and i’ll send.

[This message has been edited by dmy (edited 05-19-2000).]

Send it to hammer81z@netzero.net and thanks a lot!!

Oh, and could you send the code with the exe? I want to make sure I am loading the images correctly.

Thanks again!