sustractive transparency?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
yin nadie

sustractive transparency?

Post by yin nadie »

let's see. i've got a beautiful particle explosion. I would like to add some black greasy smoke to it. Problem is: everything i try results in additive transparency, so the only kind of smoke I can create isn't black at all. Which flags should i turn on/off in the material?
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

can you post the code so that we can see how you did you explosion?

Sorry I don't know anything about subtractive transparency
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

Sounds like a feature that I would expect - if my understanding of it is correct, its the opposite to "additive blending", and is like having the 2 features in adobe photoshop - "colour dodge" and "colour burn".

One adds colour values to the existing colours, one subtracts them. I would have thought they go hand in hand.
yin nadie

Post by yin nadie »

Well. I think the Photoshop/GIMP 'burn' is sustractive transparency. The idea is: the purely additive transparency makes the white pixels white and the black ones transparent; sustractive transparency is the othrer way around (black pixels become black, white pixels become transparent)

Let's see, the code for the particles explosion is:

void createExplosion( f64 x, f64 y, f64 z )
{
scene::IParticleEmitter* em;
scene::ISceneNodeAnimator* anim;
scene::IParticleAffector* paf;

/* THIS partibcle system is the explosion Should have and has additive transparency*/

scene::IParticleSystemSceneNode* fuego = smgr->addParticleSystemSceneNode( false, 0, -1, core::vector3df(x, y, z), core::vector3df(0, 0, 0), core::vector3df(1.0f, 1.0f, 1.0f) );
fuego->setParticleSize( core::dimension2d<f32>(15.0f, 15.0f) );
em = fuego->createBoxEmitter( core::aabbox3df(-5, 0,-5, 5, 2, 5), core::vector3df(0.0f, 0.0f, 0.0f), 10, 20, video::SColor(255, 0, 0, 0), video::SColor(255, 255, 255, 255), 1000, 2000, 0);
fuego->setEmitter( em );
em->drop();
anim = smgr->createDeleteAnimator( 1000 );
fuego->addAnimator(anim);
anim->drop();
anim = smgr->createTextureAnimator( tex_explosion, 100, false );
fuego->addAnimator(anim);
anim->drop();
paf = fuego->createFadeOutParticleAffector( video::SColor(0, 0, 0, 0), 10);
fuego->addAffector(paf);
paf->drop();
fuego->setMaterialFlag( video::EMF_LIGHTING, false );
fuego->setMaterialType( video::EMT_TRANSPARENT_VERTEX_ALPHA );

/* THIS particle system is the black smoke. should have sustractive transparency */

scene::IParticleSystemSceneNode* humo = smgr->addParticleSystemSceneNode( false, 0, -1, core::vector3df(x, y, z), core::vector3df(0, 0, 0), core::vector3df(1.0f, 1.0f, 1.0f) );
humo->setParticleSize( core::dimension2d<f32>(15.0f, 15.0f) );
em = humo->createBoxEmitter( core::aabbox3df(-5, 0,-5, 5, 2, 5), core::vector3df(0.0f, 0.02f, 0.0f), 10, 20, video::SColor(255, 0, 0, 0), video::SColor(255, 255, 255, 255), 1000, 2000, 0);
humo->setEmitter( em );
em->drop();
anim = smgr->createDeleteAnimator( 1000 );
humo->addAnimator(anim);
anim->drop();
anim = smgr->createTextureAnimator( tex_humo, 100, false );
humo->addAnimator(anim);
anim->drop();
paf = humo->createFadeOutParticleAffector( video::SColor(0, 0, 0, 0), 10);
humo->addAffector(paf);
paf->drop();
humo->setMaterialFlag( video::EMF_LIGHTING, false );
humo->setMaterialType( video::EMT_TRANSPARENT_VERTEX_ALPHA );
}

I have tried several combinations with the material flags and types of the second particle system, but never managed to make the particles darken the background instead of lighting it up

That was it.
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Maybe this post helps: http://irrlicht.sourceforge.net/phpBB2/ ... =lock#9038
As I understood you can modify any pixel in texture after locking it.
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

yin nadie wrote:Well. I think the Photoshop/GIMP 'burn' is sustractive transparency.
...
I have tried several combinations with the material flags and types of the second particle system, but never managed to make the particles darken the background instead of lighting it up
I just think that's really strange. I don't really know what's going on behind the scenes, but I thought making "subtractive blending" would be as simple as taking the code for the "additive blending" and flipping some equasion around.
Guest

Post by Guest »

In OpenGL, blending boils down to:

finalPixelColor = srcPixel * srcBlend + dstPixel * dstBlend;

...where srcPixel is a pixel in the source texture and dstPixel is a pixel in the destination buffer (basically what you see on the screen). SrcBlend and dstBlend specify how each pixel is copied into the destination buffer and how the pixel interacts with what is already in the dest. buffer. SrcBlend and dstBlend can be any number of things, for the most part (some blend funcs are not supported as either src or dest):

GL_ZERO
GL_ONE
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA
GL_DST_COLOR
GL_SRC_COLOR
etc.

So, in OpenGL, additive blending looks like this:

glBlendFunc( GL_ONE, GL_ONE ); // src texture, dest buffer

Which just means...multiply each pixel in the source texture by one (which really does nothing) and then add that to the destinatation buffer pixel (which is basically what you see on the screen), which is also multiplied by one. Additive is great for energy-like effects

Subtractive blending is something like (but don't quote me on it):

glBlendFunc( GL_ZERO, GL_ONE_MINUS_SRC_COLOR );//src texture, dest buffer

The src pixel in the texture times zero is, well zero, so, ignore that part of it. The rest takes each pixel in the destination buffer and subtracts out the color of the pixel in the source texture.

The other way to do it is to put an alpha channel into your texture. With an alpha channel, you can specify what parts of the texture are solid, see-through, or some blend of transparency. Black smoke and fog usually seem to be done this way as far as I can tell.

In OpenGL, it looks like this:

glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); //src texture, dest buffer

IrrLicht is not OpenGL, so how do you do this in IrrLicht? Well, to be honest, I'm new at IrrLicht but not 3D graphics programming...so I don't have an answer for that yet. But, as far as I can tell, Materials generally need some improvements?
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

Anonymous wrote:The other way to do it is to put an alpha channel into your texture. With an alpha channel, you can specify what parts of the texture are solid, see-through, or some blend of transparency. Black smoke and fog usually seem to be done this way as far as I can tell.
Well when yin nadie asked for this feature, it occured to me that it shouldn't be hard to do and made me wonder why it wasn't there already.

HOWEVER, I can't remember when I've actually seen subtractive blending in a video game, and smoke is generally done with bilboards whose image of a dust cloud has a transparency layer (as described above). Goldeneye 007 on the N64 did it this way, and slowly rotated the different clouds (on the z axis relative to the camera) in opposite directions to each other as they slowly rose up. The effect is very convincing.
yin nadie
Posts: 43
Joined: Wed Mar 31, 2004 1:03 pm
Location: Seville, Spain
Contact:

Post by yin nadie »

weeeel... thanks, Guest, whoever you are. I'll be trying the alpha channel thing. Hope it works...

and about games using sustractive transparency... here'n'now i can remember Finl Fantasy VIII, in the animation for the Ifrit summoning. that for sure. but there's more.
Nessie

Post by Nessie »

Subtractive Blending, as described in the above post (doh, that was me), is rare, I think. I did see one effect in Soldier of Fortune for the PC, the one for a burning enemy, that used subtractive blending.

If used excessively, it looks odd in my opinion.

for your black smoke, I'd just use an Alpha Channel. Plenty of decent art programs should allow you to add an alpha channel to a texture. TGA and PNG are common formats that support alpha channels.

..and, if the art program is decent and supports layer, you should be able to put some random texture underneath your smoke puff to test what it would look like in-game. Not necessarily a biggie, but you might find a decent preview handy for creating a decent looking smoke texture.

Finally, to do it correctly, you might have to depth sort the particles. As in, transparent objects should technically be sorted from furthest to nearest...then rendered from furthest to nearest. Order isn't relevant for pure additive objects. It will make some difference if textures with alpha channels. I'm sort of guessing you won't want to tackle that though...Quake3 didn't. :P
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Maybe you're interested in the EMT_TRANSPARENT_ALPHA_CHANNEL bug that I found:

http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=16466
Evil Mr Sock
Posts: 37
Joined: Fri Jul 02, 2004 5:36 pm
Location: Albany, NY
Contact:

Post by Evil Mr Sock »

In your code, you use creatTextureAnimator - that first parameter, an array of textures, what should that look like?

Code: Select all

irr::video::ITexture * TextureArray [2] (driver->getTexture("1.bmp"),
                                         driver->getTexture("2.bmp") ); 
This is what I thought it would be... but apparently it's very, very wrong.
Could anyone show me how this should be declared?
------------------------------------------
A monkey poured coffee in my boots.
------------------------------------------
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Code: Select all

irr::video::ITexture* TextureArray[2] = {driver->getTexture("1.bmp"), 
                                         driver->getTexture("2.bmp") }; 
Post Reply