In my scene there are lots of objects that use a transparent shader. I thought it was causing lots of overdraws and general bad performance, so I changed it to use the SCREEN_TEXTURE, not ALPHA. This results in a pretty good transparent effect, at the cost of course that transparent objects occlude themselves, wich I am totally ok with. Here's the code:
//mostly messing with emission + alpha on the original transparent shader
vec3 screen_pixel = textureLod(SCREEN_TEXTURE, SCREEN_UV ,0.0).rgb;
ALBEDO *= screen_pixel; // good enough for albedo
EMISSION = mix(screen_pixel, EMISSION, ALPHA);
ALPHA = 1.0;
The issue I would like to solve now is this: when two of these objects intersect, it looks like they don't check the depth buffer, resulting in one of them being fully drawn in front of the other one (the order changes based on the camera position). I am having trouble understanding why this happens and how to fix it. The end goal would be for the two transparent objects to be able to occlude themselves at a per-pixel level, while still showing the background.