ShaderMaterial with gl_FragColor.a = 0.0 will not effect when the material.alpha equals 1.0

In my project,my shaderMaterial will mix a customize image.And it’s alpha maybe 0.0,0.5 or others.
When the image has some pixels alpha is 0.0,i want it show vec4(x, x, x, 0.0).
But now i can’t do it,because the material needAlphaBlending code like this:


How should I understand this? Is this a bug or should I not be doing this like PG?

PG:
material alpha = 1.0

material alpha < 1.0

Are you saying the needAlphaBlending implementation has changed and now it is not applying alpha blending for ShaderMaterial?

ShaderMaterial accepts needAlphaBlending as option to override the default logic in Material class.

So you can add this option when creating ShaderMaterial instead of setting alpha to 0.99:

In shader material the needalphablending function is overriden with Babylon.js/shaderMaterial.ts at master · sebavan/Babylon.js · GitHub

so alpha < 1 should work and have the precedence here.

Your pg actually works

But you do not see anything cause your glFragColor is fully transparent so not the one from the material… you should either pass it in as part of the output color. (Here is a hardcoded pg just proving out the issue https://playground.babylonjs.com/#1OH09K#1570)

1 Like