hello, long time no see, I have been getting though somethings but have manage to chug on, anyway I have finally reached a point where my game is ready for another big update, though, I ran into a big problem, it is a problem that was had thought been solved in mid 2023.
the problem was with the alpha blending in glsl, back in 2023 this issue was raised and addressed but in a small controlled environment, I was told to use TransparencyAttrib.M_alpha and it worked back then, however recently I have had the chance use this in real gameplay and it did not go too well.
here is a example of 2 images that shows a pool of “Clear Soda” the Cg shader works 100% which is 1st, then the 2nd shows GLSL m_dual which shows not only that the soda no longer blends hence it is no clear any more, but there was a feature in my game that shows off a draft which should be invisible while standing and it is not.
now, it would appear then m_alpha fixes this, though I notice a couple of issues, namely the draft takes on the texture of whatever it is overlaying and changing the camera view will cut off and stop blending completely.
The solution to the M_dual issue in GLSL is to put an alpha test in your fragment shader. Ideally, you’d put this as early as possible, but the most straightforward solution is just to put this at the end: (replace p3d_FragColor with gl_FragColor or whatever output color variable you are writing to)
if (p3d_FragColor.a < 0.5) {
discard;
}
However, it is generally a bad idea for performance and alpha sorting issues if opaque objects have a transparency mode applied. Try to make sure that all your objects that have no transparency don’t have a transparency mode assigned.
ah, thank you for the reply, does discard have a value to it? what if instead of a “If” statement I were to use step and mix combo to replace the if statement?
if discard had a value this could work sorry I am not keen on the discard feature I read about but was told to avoid it if possible, anyway, I will go ahead and install this in my fragment shader then, many thanks for your help.
No, discard is on or off. It throws away the current fragment entirely, like M_binary alpha does. This is called alpha testing, and it’s the only way to get transparency working without sorting issues. There can be a performance cost in certain situations, sure, but otherwise you have to find another way to fix the sorting issues.
You might need to lower the value from 0.5 to 0.1 or something else low, otherwise semitransparent parts of the mesh may not render properly.
In fact, M_dual is basically a combination of M_binary and M_alpha: the semitransparent parts of the mesh are drawn with regular M_alpha (suffering from sorting issues) but the opaque and totally transparent parts are rendered as with M_binary.
yes, this solves the issue of the topic, by setting it to 0.01 instead 0.5, I did not see any performance suffering, so I guess the if statement can stay, but the sorting issues still occur, but will make another topic about that, anyway, thank you rdb, this is solved.