Page 1 of 2

Probleme with transparency

Posted: Tue Oct 19, 2004 9:56 am
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.

Posted: Tue Oct 19, 2004 2:27 pm
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.

Posted: Tue Oct 19, 2004 2:49 pm
by puh
smgr->getMeshManipulator()->setVertexColorAlpha(mesh->getMesh(0), 128);

Posted: Wed Oct 20, 2004 7:30 am
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?

Posted: Wed Oct 20, 2004 7:43 am
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??

Posted: Wed Oct 20, 2004 12:27 pm
by LEFRANCAIS
i always have semitransparent mesh and my mesh is never white.
How do you make this??

Posted: Wed Oct 20, 2004 12:38 pm
by puh
LEFRANCAIS: Try EMT_TRANSPARENT_REFLECTION_2_LAYER

Posted: Wed Oct 20, 2004 12:56 pm
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.

???

Posted: Wed Oct 20, 2004 12:57 pm
by LEFRANCAIS
thx for reply,
i try with EMT_TRANSPARENT_REFLECTION_2_LAYER but no change.
my model is always 50% transparent.

Posted: Wed Oct 20, 2004 2:17 pm
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...

Posted: Thu Oct 21, 2004 6:01 am
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

Posted: Thu Oct 21, 2004 6:13 am
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.

Posted: Thu Oct 21, 2004 11:37 am
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?

Posted: Thu Oct 21, 2004 12:53 pm
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.

Posted: Fri Oct 22, 2004 8:03 am
by LEFRANCAIS
Somebody know's another way to modify transparency value? :(
thx for your help