3 – Number of Processed Fragments

Another use of the atomic counters, similar to the previous one, is the counting of the number of fragments processed by the fragment/pixel shader stage. Let’s consider the following low resolution torus rendered with back face culling disabled:

There are 196028 processed pixels. Now if we enable the back face culling:

The number of processed pixels is now 98023. Half of the fragments have been discarded. This simple example shows how atomic counters can help us to optimize the rendering pipeline in any shader stage.

Here is a fragment shader that allows to count the number of processed fragments: