3DS semi-transparency isn't working

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
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

3DS semi-transparency isn't working

Post by Donald Duck »

I've made a simple mesh in Blender with a semi-transparent green plane, and exported it as 3DS to use with Irrlicht. The Blender file and the 3DS file can be downloaded here: http://www.files.com/shared/59008a3f8f7 ... 20mapp.zip.

The problem is that when I try to use the 3DS in Irrlicht, the transparency isn't rendered correctly. I tried the following code:

Code: Select all

irr::scene::IMeshSceneNode *mesh = sceneManager->addMeshSceneNode(sceneManager->getMesh("untitled.3ds"), 0, -1, irr::core::vector3df(0, 0, 0), irr::core::vector3df(0, 0, 0), irr::core::vector3df(1, 1, 1));
mesh->setMaterialType(irr::video::EMT_TRANSPARENT_EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
The problem is that the transparency is ignored. Here is a screenshot (I've added the earth.x mesh from the Media folder from the Irrlicht library to see if the transparency is rendered correctly):

Image

I also tried irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, irr::video::EMT_TRANSPARENT_REFLECTION_2_LAYER and irr::video::EMT_TRANSPARENT_VERTEX_ALPHA with the same result.

I also tried irr::video::EMT_TRANSPARENT_ADD_COLOR, which is a bit better but still not what I want:

Image

Here is approximately the result that I want (made with Blender):

Image

How can I get the semi-transparency to work correctly in Irrlicht?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: 3DS semi-transparency isn't working

Post by CuteAlien »

Export and load as .obj file - that seems to work. Did a quick check on debug and it used something like:
video::EMT_TRANSPARENT_VERTEX_ALPHA as MaterialType
Material.DiffuseColor.setAlpha set to 127
If you scale it by 100 (on export or after loading) you can check it out in the meshviewer.

edit: It also sets the other color values, check the corresponding .mtl file when exporting as .obj file.
Ka is ambient Kd is diffuse Ks is specular, Ke is emissive and d is the transparency.
But ... the real trick here isn't Material.DiffuseColor.setAlpha - but that the obj loader later on sets the vertex-colors to Material.DiffuseColor.Alpha - so you can get the same result by setting vertex colors directly to 127 (with meshmanipulator).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Re: 3DS semi-transparency isn't working

Post by Donald Duck »

Thanks, it worked. I had a few issues with the ambient lighting in Irrlicht making the OBJ mesh brown instead of green though. I solved that by adding the following code:

Code: Select all

mesh->getMaterial(0).AmbientColor = irr::video::SColor(0, 0, 200, 0);
Post Reply