Defining BlendFactor results to no rendering.

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
Andrey01
Posts: 57
Joined: Mon Jul 27, 2020 9:08 pm

Defining BlendFactor results to no rendering.

Post by Andrey01 »

Sorry for very frequent asking here, but it really doesn't work for an obscure reason although it really should do. I bound an own shader to my material which belongs to a mesh scene node and enabled the blend operation EBO_ADD since this material is intended to be transparent (that shader calculates pbr lighting, shadows and then output to gl_FragColor the final color RGB and alpha component is just taken from its color texture), then I defined the blend factors:

Code: Select all

n_mat_copy.BlendOperation = video::EBO_ADD;
n_mat_copy.BlendFactor = video::pack_textureBlendFunc(video::EBF_SRC_ALPHA, video::EBF_ONE_MINUS_SRC_ALPHA,
video::EMFN_MODULATE_1X, video::EAS_TEXTURE | video::EAS_VERTEX_COLOR);
The fragment shader:

Code: Select all

uniform sampler2D mBaseTex;

//<some uniforms>

vec4 baseColor = texture2D(mBaseTex, gl_TexCoord[0].st);

//<lighting and shadows calculations>

gl_FragColor = vec4(color, baseColor.a);
However, this just renders nothing. The last two parameters (in pack_textureBlendFunc), especially penultimate, are not entirely clear for me what they do, they are bad documented. I can say all my shaders work fine, at least output correct colors, but when I set those blend factors like how above, it stops rendering. If I omit this property (what is identical to setting it as "0.0f"), it renders, however the z-fighting problem is caused and isTransparent() returns false.
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Defining BlendFactor results to no rendering.

Post by CuteAlien »

Don't worry about asking. You also help the next person running in the same problem and I also often learn stuff while trying to find answers.

SMaterial is has so many cases that not everything is documented. I also often struggle with understanding the combination of flags. On top of that it was written back in times of fixed function pipelines and then just slightly modified to get it somewhat working with shaders.

I might read again tomorrow (just hanging on PC right now because I can't sleep...), but I think EBO_ADD is fine. Not sure right now about BlendFactor, I haven't used that one in a long time and can't find any example code right now. Usually I just make sure when creating a shader that it has a transparent base material like EMT_TRANSPARENT_ALPHA_CHANNEL which sets up transparency flags correctly. Only disadvantage of that is that I can't switch the base-material once the shader is created, while that is possible with BlendFactor (and maybe that one offers more options, but I never used those).
If you want to use it, it doesn't look too wrong at first view to me - but maybe get rid of the EAS_VERTEX_COLOR and start with texture only. Could be your vertices are all black and then everything will be black like that.
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
Andrey01
Posts: 57
Joined: Mon Jul 27, 2020 9:08 pm

Re: Defining BlendFactor results to no rendering.

Post by Andrey01 »

Thanks! Setting EMT_TRANSPARENT_ALPHA_CHANNEL for the base shader material is the only thing that solved the problem.
Post Reply