8bit transparency

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
genesys
Posts: 75
Joined: Tue Nov 02, 2004 6:49 pm
Contact:

8bit transparency

Post by genesys »

Hi!

Can you tell me how i can make a material in Irrlicht with 8bit transparency? This should be completely normal for a game engine... but somehow it seems that it's not possible with irrlicht materials:
What i want is to use an 8bit grayscale picture or an 8bit channel of a 32bit RGBA picture as alphatransparency.

Irrlicht provides the following materials for transparency:

EMIT_TRANSPARENT_ADD_COLOR
EMIT_TRANSPARENT_ALPHA_CHANNEL
EMIT_TRANSPARENT_VERTEX_ALPHA

We can ignore transparent_vertex_alpha because it creates transparency from vertexalpha and this is not what i want.

EMIT_TRANSPARENT_ADD_COLOR just add's the color values of the texture to the colorvalues of the background/backgroundobjects - so this is as well not what i'm searching for.

EMIT_TRANSPARENT_ALPHA_CHANNEL creates transparency from alpha channel, but only 1BIT transparency. Means black is transparent and everything else is opaque.

But i need gradual, 8bit transparency! I tried to achieve it by making an own material type. I set the following flags:

pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);

pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);

pID3DDevice->SetRenderState(D3DRS_ZWRITEENALBE, TRUE);



But it's still not working!

Please help me!
Thx!
don_Pedro
Posts: 84
Joined: Fri Jun 10, 2005 1:34 pm
Location: Poland
Contact:

Post by don_Pedro »

EMT_TRANSPARENT_ALPHA_CHANNEL is what you need anyway, just try

Code: Select all

driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
before loading texture with alpha channel.
genesys
Posts: 75
Joined: Tue Nov 02, 2004 6:49 pm
Contact:

Post by genesys »

hum
Last edited by genesys on Wed Oct 05, 2005 3:01 pm, edited 1 time in total.
genesys
Posts: 75
Joined: Tue Nov 02, 2004 6:49 pm
Contact:

Post by genesys »

why is this needed?

won't it decrease performance for objects which don't use 8bit transparency as well?
don_Pedro
Posts: 84
Joined: Fri Jun 10, 2005 1:34 pm
Location: Poland
Contact:

Post by don_Pedro »

Because if a texture is being converted from 32 bit to 16 bit it just can't still have 8 bit alpha chanell, no place for that, it uses 1 bit instead and 15 for a color definition.
I think there wouldn't be slowing down on any modern computer, if you use all the textures 32bit, at least I didn't noticed that. Modern cards should be now optimized to display them properly, but nothing stops you from create opaque textures as 16 bit and transparent as 32 bit, just switch the flags.
Guest

Post by Guest »

oh - so it uses 5bit for every color channel? is't that suboptimal (5 bit sounds... uncomfortable for me ;) )?

however - you helped me a lot!
Thank you very much!
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

If you know much about pixelformats (and I don't btw...) you know they can be a real bitch, especially 16 bit color. There are like 5 or 6 different ways to repesent 16 bits as a rgb color, and almost none of them correlate with each other. Now, in the modern age, we have 32bit color, which not only provides a lot of colors, but provides an even 8 bits per color, making it easier to mess with colors, I highly recomend setting the ETCF_ALWAYS_32_BIT flag to true.
don_Pedro
Posts: 84
Joined: Fri Jun 10, 2005 1:34 pm
Location: Poland
Contact:

Post by don_Pedro »

You are absolutely right, pfo. However as long, as Irrlicht does everything in that matter for you, you can use 16 bit if you really want. On the other hand I think some of new video cards could be actually faster with 32 bit, than 16.
genesys
Posts: 75
Joined: Tue Nov 02, 2004 6:49 pm
Contact:

Post by genesys »

But if you set all the textures to 32bit, this means also that you can use only half the textures you coul'd use with 16bit's (according to videocard memory) - or half the resolution...
don_Pedro
Posts: 84
Joined: Fri Jun 10, 2005 1:34 pm
Location: Poland
Contact:

Post by don_Pedro »

That's true, so you should decide yourself what's more important or let user to chose giving additional options for a program. It all depends on what is a program and what is a target users group.
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

genesys: yeah, you're right, you would halve the ammount of memory being used, but really, how many textures are you using? Do you think it can max out a 16MB video card? How about a 32MB one? Mine's got 64MB, I'd be impressed if I managed to max that out with a game that I wrote :) If you really want to manage texture memory, you can turn the flag on and off for different textures. At the very least, turn it on for transparent textures and off afterwards.
ThommyE
Posts: 48
Joined: Sun Sep 18, 2005 3:02 pm
Location: germany/badnerlaendle

Post by ThommyE »

genesys wrote:But if you set all the textures to 32bit, this means also that you can use only half the textures you coul'd use with 16bit's (according to videocard memory) - or half the resolution...
if you use half resolution your videomemory will reduce to a quater... since your' changing 2 dimension at once..
128x128x32=524288
128x128x16=262144
64x64x32=131072
common mistake but if your really intrested in saving video memory its pretty important.
athlon2400xp+,geforce4200ti, 0.2Tb hd+64mb extern, 512mb ram, linux FC5 2.6.16-1.2096, 100%gates-free system
BlackNinjaGames
Posts: 31
Joined: Mon Sep 05, 2005 4:47 pm
Contact:

Post by BlackNinjaGames »

Hello. I am having the same problem. I used the steps above, but it still doesnt work properly.

My targa is 32-bit, so that's not the problem. I seem to be having the problem of it either being fully opaque or fully transparent (1-bit). I do, however, have the flag enabled. I can tell, becuase if i make my alpha dark, it is invisible, but when its light grey, its still there.

Here's my code:

Code: Select all

		flare[i].billboardData = CGraphicsGlobal::smgr->addBillboardSceneNode(0, core::dimension2d<f32>(flare[i].size, flare[i].size*20));

		CGraphicsGlobal::driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
		flare[i].billboardData->setMaterialTexture(0,CGraphicsGlobal::driver->getTexture("Graphics\\Explosion\\flare.tga"));

		flare[i].billboardData->setMaterialFlag(video::EMF_LIGHTING, false);
		flare[i].billboardData->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
		flare[i].billboardData->setVisible(true);
(its for an explosion, if you cant tell) I need this flare to be translucent, not either on or off.

Any ideas?
Post Reply