Lighting and alpha

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
Alpiro
Posts: 7
Joined: Thu Mar 27, 2025 10:37 pm

Lighting and alpha

Post by Alpiro »

Hello,

Is is possible to make a node with an alpha < 255 when the flag EMF_LIGHTING = true ?

I'm using meshManip->setVertexColorAlpha(mesh, alpha), but the node becomes transparent only if I put the flag on false.

Thanks for your help.
CuteAlien
Admin
Posts: 10021
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Lighting and alpha

Post by CuteAlien »

Hm, it should usually depend on setting: material.BlendOperation = video::EBO_ADD;
Maybe material.ColorMaterial also plays a role.

Sadly I haven't put this stuff yet in MaterialViewer example. But on a quick test adding the line above in CMaterialControl::updateMaterial in that example allowed me to have transparency with or without lighting (should probaby also add bit more pattern to the background in that image to make it more visible - but stuff becomes gray).

I ony tested Irrlicht svn trunk version, not sure about 1.8
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
Alpiro
Posts: 7
Joined: Thu Mar 27, 2025 10:37 pm

Re: Lighting and alpha

Post by Alpiro »

Thanks, it works, but this way it actually applies the new alpha to every node using this mesh. I feel like this is a newbie mistake but I can't see how to solve it, in order to have only 1 mesh for which the new alpha applies.
CuteAlien
Admin
Posts: 10021
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Lighting and alpha

Post by CuteAlien »

Yeah, meshes are by default shared per node. And so if you change alpha in a mesh then then all nodes using that mesh change.

If you want to control it per model it works if you have only have colors (no textures) like:
material.ColorMaterial = video::ECM_NONE;
material.BlendOperation = video::EBO_ADD;
And then control it via the alpha of the DiffuseColor.

If you have textures (usual case...) things get more tricky. At that point I generally switch to shaders which are more flexible.
In theory you can also create mesh-copies and use one per node. Often meshes need very little memory (compare to for example textures), so creating copies isn't really that expensive. So you can have one copy per node for example. Or maybe if you have only need 1 transparent node create a mesh-copy for that one.
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
Alpiro
Posts: 7
Joined: Thu Mar 27, 2025 10:37 pm

Re: Lighting and alpha

Post by Alpiro »

Indeed I am using textures there.
According to the documentation it seems impossible to create a mesh copy for an animated mesh, am I right ?
Alpiro
Posts: 7
Joined: Thu Mar 27, 2025 10:37 pm

Re: Lighting and alpha

Post by Alpiro »

I found out I could change the cache, so it seems to solve the problem, for every new node using the same mesh, every time it has a unique cache. I hope it's the correct way to do.
CuteAlien
Admin
Posts: 10021
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Lighting and alpha

Post by CuteAlien »

If it works it's correct ;-) And yeah, that might be the way to copy it, thought means having to load it a few times from disc then. I'd have to look up myself if there's another way for animated meshes (sorry, I don't use those much in my job I tend to work with static models). Probalby depends also a bit on the animation format you are using (skeleton meshes vs the mesh per frame animation formats).
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
Alpiro
Posts: 7
Joined: Thu Mar 27, 2025 10:37 pm

Re: Lighting and alpha

Post by Alpiro »

Great ! Then I will keep doing this.
I am using b3d format, with rigged meshes.
Post Reply