Probleme with 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.
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Probleme with transparency

Post by LEFRANCAIS »

Hello

When i use
"Node->setMaterialType(EMT_TRANSPARENT_VERTEX_ALPHA)", the transparency is 50%.

I try "Node->getMaterial(0).AmbientColor.setAlpha(alpha)" with
alpha between 0 and 255,but it dosnt work.
My question is how to make node 20% or x% transparent?

Thanks a lot.
POi

Post by POi »

I would also like to know how to make the whole node more or less transparent. Not only some parts of the texture.
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

smgr->getMeshManipulator()->setVertexColorAlpha(mesh->getMesh(0), 128);
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Post by LEFRANCAIS »

Thank you for reply, but it dosn't work for my.
This is my code

Code: Select all

#include <windows.h>
#include <commctrl.h>           
#include <stdio.h>
#include "irrlicht.h"

using namespace irr;
using namespace scene;
using namespace video;

ICameraSceneNode* Camera = 0;
IrrlichtDevice *Ecran = 0;
IMesh *mesh=0;
IAnimatedMesh *Bateau = 0;
ISceneManager *smgr= 0;
ISceneNode *Node =0;
IVideoDriver *Driver=0;


int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
	Ecran=createDevice(EDT_OPENGL   ,core::dimension2d<s32>(640,480),32,false,false,false);
	Driver=		 Ecran->getVideoDriver();
	smgr=		 Ecran->getSceneManager();
	Camera = smgr->addCameraSceneNodeFPS(0,100,20);
	Bateau=smgr->getMesh("M_man1.3ds");
	mesh=Bateau->getMesh(0);
	s32 Alpha=0;

	smgr->getMeshManipulator()->setVertexColorAlpha(mesh, Alpha);
//	mesh->setMaterialFlag(EMF_WIREFRAME,true);//test 
	Node=smgr->addOctTreeSceneNode(mesh);
	Node->setMaterialType(EMT_TRANSPARENT_VERTEX_ALPHA);

	while(Ecran->run())
	{
		Driver->beginScene(true, true, SColor(0,0,0,0));
		Alpha++;if(Alpha>255) Alpha=0;
		smgr->getMeshManipulator()->setVertexColorAlpha(mesh, Alpha);
		smgr->drawAll();
		Driver->endScene();
	}
	Ecran->drop();
	return 0;
}
What is wrong?
POi

Post by POi »

Have the same problem here ... when i set the alpha to 128 i get a semitransparent mesh but when i go lower <128 the mesh turns white??
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Post by LEFRANCAIS »

i always have semitransparent mesh and my mesh is never white.
How do you make this??
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

LEFRANCAIS: Try EMT_TRANSPARENT_REFLECTION_2_LAYER
Thulsa Doom
Posts: 63
Joined: Thu Aug 05, 2004 9:40 am
Location: Germany

Post by Thulsa Doom »

POi wrote:Have the same problem here ... when i set the alpha to 128 i get a semitransparent mesh but when i go lower <128 the mesh turns white??
Hi this sounds very familiar to me!

Maybe even worse:
I use the EDT_DIRECTX9 driver, have a custom sceneNode as background and a *.3ds mesh in the front. Further I use E_TEXTURE_CREATION_FLAG:: ETCF_ALWAYS_32_BIT and all textures are *.tga with rgb and alpha channels. The background texture is set to E_MATERIAL_TYPE::EMT_SOLID, alpa opaque, the texture of the mesh in front is set to E_MATERIAL_TYPE::EMT_TRANSPARENT_ALPHA_CHANNEL alpha 128.

Now:
If I rotate my background only, sometimes my mesh becomes partially opaque white colored! This observation is independent of the actual value of the alpha channel of the mesh's texture. It seem's to be dependent of the color variation of the background somehow. If I switch to E_MATERIAL_TYPE::EMT_SOLID for the mesh also, the effect vanishes.

???
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Post by LEFRANCAIS »

thx for reply,
i try with EMT_TRANSPARENT_REFLECTION_2_LAYER but no change.
my model is always 50% transparent.
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Yea, now I see. It's a problem definatly. The only way I could achieve some kind of the effect you want is:

Code: Select all

video::SMaterial glass;
   while(Ecran->run()) 
   { 
      Driver->beginScene(true, true, SColor(0,0,0,0)); 
      Alpha++;if(Alpha>255) Alpha=0; 
      glass.EmissiveColor  = video::SColor(Alpha, Alpha, Alpha, Alpha);
      Node->getMaterial(0)=glass;
      smgr->drawAll(); 
      Driver->endScene(); 
   } 
But this is only for solid-colored mesh, e.g. no texture (and only with EmissiveColor!). So this is unacceptable I think...
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Post by LEFRANCAIS »

thx puh,but that 's only change the emissive color from black (0,0,0) to
white (255,255,255) and transparency will not change.

try this:

Code: Select all

       Alpha++;if(Alpha>255) Alpha=0; 
       glass.EmissiveColor  = video::SColor(Alpha, 0, 0, 0);
       Node->getMaterial(0)=glass;  
if i only change alpha transparency, there is no change.

And thx for your help
POi

Post by POi »

The funny thing is if a shadow hits the mesh the parts that are shadowed actually get more transparent .... and sometimes vanish totaly when alpha = 0 so i'll try to make my model all black and se what happens.
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Post by LEFRANCAIS »

i set a white texture to my mesh but transparency do not work.
With a black texture, nothing is visible.
POi, have you some result?
Guest

Post by Guest »

Not much luck ... if i set a grey texture (R 128 G 128 B 128) then i get a better result but not ok. And if an object gets in front of the "transparent" mesh it also gets transparent.

With the opengl driver the effect is much better but it stays at 50% transparent no matter what the alpha value is.
LEFRANCAIS
Posts: 28
Joined: Wed Oct 08, 2003 9:09 am
Location: Annecy - FRANCE

Post by LEFRANCAIS »

Somebody know's another way to modify transparency value? :(
thx for your help
Post Reply