[SOLVED] Node opacity and texture with alpha channel

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
MTLZ
Posts: 11
Joined: Wed Apr 25, 2012 1:39 pm
Location: Paris, France
Contact:

[SOLVED] Node opacity and texture with alpha channel

Post by MTLZ »

Hello everyone.

I made my own GUI interface using screen-aligned quads and I use 24-bit png textures in their materials.
Is there a way to both use those textures with alpha channel and set the node opacity?
Until now, I was using a "diffuse" fragment shader which get the opacity value from a shader constant callback class and apply it. But if I can have opacity without a shader, that would be even better.

Code: Select all

//! 2D Hud element constructor
CHud2DElement::CHud2DElement(f32 x, f32 y, f32 w, f32 h) : CHud()
{
  // [...]
  Material.DiffuseColor.setAlpha(Opacity);
 
  // Apply diffuse shader (based on video::EMT_TRANSPARENT_ALPHA_CHANNEL)
  Material.MaterialType = (video::E_MATERIAL_TYPE)nEngine::CGame::Shaders.Diffuse;
 
  // [...]
}
Thanks
Last edited by MTLZ on Wed Apr 25, 2012 7:29 pm, edited 1 time in total.
MTLZ
== Invisible Spirit - http://www.is06.com ==
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Node opacity and texture with alpha channel

Post by hybrid »

Yes, the material one_texture_blend supports just one texture, but both transparency modes at once.
MTLZ
Posts: 11
Joined: Wed Apr 25, 2012 1:39 pm
Location: Paris, France
Contact:

Re: Node opacity and texture with alpha channel

Post by MTLZ »

Great! Thank you :D

I had to search a little bit for this material type and found that I can set up the blending mode.

Here is my code :

Code: Select all

// Setting material parameters
Material.MaterialType = video::EMT_ONETEXTURE_BLEND;
Material.MaterialTypeParam = video::pack_texureBlendFunc(
  video::EBF_SRC_ALPHA,
  video::EBF_ONE_MINUS_SRC_ALPHA,
  video::EMFN_MODULATE_1X,
  video::EAS_TEXTURE | video::EAS_VERTEX_COLOR
);
 
// Vertex color alpha value
Vertices[0].Color.setAlpha(Opacity);
Vertices[1].Color.setAlpha(Opacity);
Vertices[2].Color.setAlpha(Opacity);
Vertices[3].Color.setAlpha(Opacity);
MTLZ
== Invisible Spirit - http://www.is06.com ==
Post Reply