PDA

View Full Version : Two textures on one sphere.



01-10-2001, 03:53 PM
I've got a sphere texturized with one texture, now I'm trying to add another over top of the first and make it transparent. Sorta like a cloud layer over a plant texture.
how do I do this?

j
01-10-2001, 05:49 PM
Either use the ARB_multitexture extension, or draw the sphere twice, using blending the second time.

j

coco
01-10-2001, 07:42 PM
well, a little more detailed explanation whould be to do something like this:

-clearbuffers
-prepare matrices

-glDisable(GL_BLENDING);

-setup texture 1
-render sphere

-glDepthFunc(GL_LEQUAL);
-glEnable(GL_BLENDING);

-setup texture 2
-if (texture 2 has alpha channel) then
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-else // do aditive
- glBlendFunc(GL_ONE,GL_ONE);
-endif
-render sphere

-swapbuffers


Those blending functions are just two examples, but should be the two most common.

Serge K
01-10-2001, 11:22 PM
> if (texture 2 has alpha channel)
then - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

Yes, this function is the most common.
But IMHO, in this way you are just wasting useful computational resources! http://www.opengl.org/discussion_boards/ubb/tongue.gif (j/k)

You can create your texture with premultiplied pixels. In this case you can put an additive (for example - gloss map) part into the very same texture:

At = A; // dest. alpha value.
RGBt = (A * RGB) + RGBadd

glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );

01-11-2001, 01:58 PM
Originally posted by coco:
well, a little more detailed explanation whould be to do something like this:

-clearbuffers
-prepare matrices

-glDisable(GL_BLENDING);

-setup texture 1
-render sphere

-glDepthFunc(GL_LEQUAL);
-glEnable(GL_BLENDING);

-setup texture 2
-if (texture 2 has alpha channel) then
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-else // do aditive
- glBlendFunc(GL_ONE,GL_ONE);
-endif
-render sphere

-swapbuffers


Those blending functions are just two examples, but should be the two most common.

OK. this sorta worked. I have no idea what you mean by alpha channel for a texture, I assume its somewhat similiar to how a gif has one color that is transparent. anyhow,
I create the one texturized sphere, and then created the cloud sphere surrounding the first sphere, and slightly larger. I then textured it, and did the blending, with the GL_ONE, GL_ONE blendfunc and got a semi- transparent texture with quad lines visible in the non-transparent part of the second texture.. am I making any sense? So, basically it did work, but why are the polygon lines showing up in the second texture? If any of you guys could send me a simple sample (w/code) on how to do this, it would help alot.
http://www.opengl.org/discussion_boards/ubb/smile.gif

coco
01-11-2001, 08:31 PM
Serge K:
Well, that's right. I'm not sure how many hardware implementations will benefit from something like this, but in theory it's more optimizable by the driver.

dex44:
alpha channel is like a Red channel, or a Green or a Blue channel, but instead of containing color information it contains transparency implementation, where the lower the alpha for a pixel the more translucent it is. For example, in 8bit alpha, alpha=64 will give you 25% opaque pixel, where alpha=192 will give you a 75% opaque pixel (25% translucent). Anyway, the final pixel color depends in other factors, such as alpha testing and blending functions.
An RGBA image differs from a RGB image in that it uses four bytes per pixel instead of three in order to fit the alpha channel.


[This message has been edited by coco (edited 01-11-2001).]

Serge K
01-11-2001, 11:20 PM
Originally posted by coco:
Well, that's right. I'm not sure how many hardware implementations will benefit from something like this, but in theory it's more optimizable by the driver.


http://www.opengl.org/discussion_boards/ubb/biggrin.gif
It's not about hardware implementations...
I just wanted to say that one can minimize number of the rendering passes with the smart blending function. http://www.opengl.org/discussion_boards/ubb/cool.gif

aceka
01-18-2001, 11:10 PM
Does anyone has some exemple about this !
If anyone has , please send it in aceka@yahoo.com

Thanks !