OpenGL 4.2 Atomic Counters: Rasterization Pattern, Helper for Rendering Optimization (Windows, Linux)

Article index:

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:

OpenGL 4.2 atomic counters, number of processed pixels

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

OpenGL 4.2 atomic counters, number of processed pixels

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:

#version 420
out vec4 Out_Color;
layout(binding=0, offset=0) uniform atomic_uint ac_frag;
void main()
  uint counter = atomicCounterIncrement(ac_frag);
  float r = (counter/255) / 255.f;
  Out_Color = vec4(r, 0, 0, 1);

Article index:

Pages: 1 2 3 4

[ Subscribe to Geeks3D latest news by email ]

↑ Grab this Headline Animator