Hi!
I've searched a lot in topics, but couldn't find an answer to my problem yet.
I load *.obj files with *.mtl materials, I use this format because it supports normal and tangent vectors for lights. One of my models has two materials and two textures in it: one for the body and one for a half-transparent glass. They can be seen on the right position with the right texture, but my problem is half-transparent glass is not transparent at all. I tried to set transparency inside the *.tga texture itself, I also tried to set transparency in model vectors, but none of them work. I use the latest Irrlicht release with no external loaders.
Do you know a solution for this without writing my own *.obj loader?
OBJ file textures
Re: OBJ file textures
You need to set the material of that meshbuffer to transparent inside your program. It can't be detected in a mesh loader, as all textures have alpha after loading.
edit: Unless the mesh format includes a specifier for it to be transparent, which OBJ doesn't.
edit: Unless the mesh format includes a specifier for it to be transparent, which OBJ doesn't.
Re: OBJ file textures
There are map_d or map_opacity (handled the same) which create a EMT_TRANSPARENT_ADD_COLOR material type. Thought not sure if that is sufficient for glass as you probably would want EMT_TRANSPARENT_ALPHA_CHANNEL which .obj files don't set directly (meaning you have to do it in code as hendu proposed). But if your glass texture is not using that yet try to set that in the mtl file.
Otherwise you might be able to use vertex transparency (EMT_TRANSPARENT_VERTEX_ALPHA). That one is set either with a d parameter < 1 (that is the usual one) or with Tf red green blue together below 1 (only seeing that in code, never tried that one myself). Note that you can only set either EMT_TRANSPARENT_ADD_COLOR or EMT_TRANSPARENT_VERTEX_ALPHA in obj files directly, not both as those exclude each other.
Otherwise you might be able to use vertex transparency (EMT_TRANSPARENT_VERTEX_ALPHA). That one is set either with a d parameter < 1 (that is the usual one) or with Tf red green blue together below 1 (only seeing that in code, never tried that one myself). Note that you can only set either EMT_TRANSPARENT_ADD_COLOR or EMT_TRANSPARENT_VERTEX_ALPHA in obj files directly, not both as those exclude each other.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: OBJ file textures
You have two problems. The first is that the map_d texture overwrites the diffuse texture in the loader. I complained about this and it is in the bugs section. The second is that TRANSPARENT_ADD_COLOR is a really bad choice.
However, there is some ambiguity regarding map_d. It probably is meant to blend using alpha, as in hair. You need TRANSPARENT_ALPHA_CHANNEL for this. But if you think about creating shapes in this way, you really need TRANSPARENT_ALPHA_CHANNEL_REF. I'm assuming you want the first. Open COBJMeshFileLoader.cpp and look for the word "type". Replace the section of code related to "type == 2" with the following. Now, in your shader, set the alpha from tex1 and it will cause tex0 to be blended.
However, there is some ambiguity regarding map_d. It probably is meant to blend using alpha, as in hair. You need TRANSPARENT_ALPHA_CHANNEL for this. But if you think about creating shapes in this way, you really need TRANSPARENT_ALPHA_CHANNEL_REF. I'm assuming you want the first. Open COBJMeshFileLoader.cpp and look for the word "type". Replace the section of code related to "type == 2" with the following. Now, in your shader, set the alpha from tex1 and it will cause tex0 to be blended.
Code: Select all
else if (type==2)
{
currMaterial->Meshbuffer->Material.setTexture(1, texture);
currMaterial->Meshbuffer->Material.MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL;
}
Last edited by mongoose7 on Fri Oct 17, 2014 2:01 pm, edited 1 time in total.
Re: OBJ file textures
Texture overwriting diffuse texture should not be a problem in this case as a Window should have only the transparent texture and not 2 textures on the same meshbuffer. That's also why TRANSPARENT_ALPHA_CHANNEL_REF would be the wrong material for it - that only makes sense when you have 2 textures on the same meshbuffer.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: OBJ file textures
I think you don't understand. For hair, the hair colour texture is the diffuse. The map_d texture is a transparency map. As I said in my first complaint, you don't want to texture the hair with the transparency map.
Re: OBJ file textures
Well, but we're not talking about hair but Windows here. I just explain how it work with the current format and loader. As you have noticed there is no correct support for alpha-texture maps on top of other textures so far. But for Windows (or glass) this will still work.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: OBJ file textures
Well, imagine sunglasses. With the current implementation, the glasses get *more* transparent the darker they are!
Anyway, the OP would probably get more mileage by setting "d" to 0.7. This will set the material type to TRANSPARENT_VERTEX_ALPHA and set the alpha channel in Material.DiffuseColor.
Anyway, the OP would probably get more mileage by setting "d" to 0.7. This will set the material type to TRANSPARENT_VERTEX_ALPHA and set the alpha channel in Material.DiffuseColor.