My algorithm doesn’t care what goes into those outputs when I don’t write to them, but to make you happy (and show what my problem actually seems to be) I’ve adjusted my main function to the following:
void main()
{
vec4 output;
output = colour_ambient_frag;
// handle depth peeling
float depth_0 = texture(Depth0, gl_FragCoord.xy / textureSize(Depth0, 0));
float depth_1 = texture(Depth1, gl_FragCoord.xy / textureSize(Depth1, 0));
float depth_2 = texture(Depth2, gl_FragCoord.xy / textureSize(Depth2, 0));
float depth_3 = texture(Depth3, gl_FragCoord.xy / textureSize(Depth3, 0));
gl_FragDepth = 1;
layer0 = vec4(0,0,0,0);
layer1 = vec4(0,0,0,0);
layer2 = vec4(0,0,0,0);
layer3 = vec4(0,0,0,0);
if (tol(gl_FragCoord.z,depth_0))
{
layer0 = output;
gl_FragDepth = gl_FragCoord.z;
}
if (tol(gl_FragCoord.z,depth_1))
{
layer1 = output;
gl_FragDepth = gl_FragCoord.z;
}
if (tol(gl_FragCoord.z,depth_2))
{
layer2 = output;
gl_FragDepth = gl_FragCoord.z;
}
if (tol(gl_FragCoord.z,depth_3))
{
layer3 = output;
gl_FragDepth = gl_FragCoord.z;
}
}
My issue is that layers 1-3 are coming out pure black, but if I comment out the if statement for layer0, then layer1 coumes out how I would expect, same for layer2 if I comment out the if blocks for layers 0 and 1. So the following code gives me the correct output for layer1:
void main()
{
vec4 output;
output = colour_ambient_frag;
// handle depth peeling
float depth_0 = texture(Depth0, gl_FragCoord.xy / textureSize(Depth0, 0));
float depth_1 = texture(Depth1, gl_FragCoord.xy / textureSize(Depth1, 0));
float depth_2 = texture(Depth2, gl_FragCoord.xy / textureSize(Depth2, 0));
float depth_3 = texture(Depth3, gl_FragCoord.xy / textureSize(Depth3, 0));
gl_FragDepth = 1;
layer0 = vec4(0,0,0,0);
layer1 = vec4(0,0,0,0);
layer2 = vec4(0,0,0,0);
layer3 = vec4(0,0,0,0);
/*if (tol(gl_FragCoord.z,depth_0))
{
layer0 = output;
gl_FragDepth = gl_FragCoord.z;
}*/
if (tol(gl_FragCoord.z,depth_1))
{
layer1 = output;
gl_FragDepth = gl_FragCoord.z;
}
if (tol(gl_FragCoord.z,depth_2))
{
layer2 = output;
gl_FragDepth = gl_FragCoord.z;
}
if (tol(gl_FragCoord.z,depth_3))
{
layer3 = output;
gl_FragDepth = gl_FragCoord.z;
}
}
What am I missing?