Here's my fragment shader:
#version 420 core
#extension GL_ARB_explicit_uniform_location : enable
#extension GL_ARB_shader_storage_buffer_object : require
layout(early_fragment_tests) in;
layout(binding = 4, offset = 0) uniform atomic_uint num_fragments;
// ...
void main(void)
{
atomicCounterIncrement(num_fragments);
frag_color = vec4(1.0, 0.0, 0.0, 0.0);
atomicAdd(...);
}
My triangles completely cover the screen. The expected behavior is for num_fragments
to be equal to the number of pixels (640*480 = 307200), which it is for a single layer of triangles. However, when I add a triangle behind the existing triangles, num_fragments becomes a higher value, like the fragment shader is being executed for the occluded triangle.
Why is this? I though that the early_fragment_tests directive would prevent this behavior. This isn't just an optimization, because there are atomic stores in the shader that should only be run for un-occluded pixels.