Alternative to NV Occlusion Query - getting the number of fragments which passed the depth test

Posted by Etan on Game Development See other posts from Game Development or by Etan
Published on 2011-11-24T15:46:46Z Indexed on 2011/11/24 18:21 UTC
Read the original article Hit count: 270

Filed under:
|
|
|

In "modern" environments, the "NV Occlusion Query" extension provide a method to get the number of fragments which passed the depth test. However, on the iPad / iPhone using OpenGL ES, the extension is not available.

What is the most performant approach to implement a similar behaviour in the fragment shader?

Some of my ideas:

  • Render the object completely in white, then count all the colors together using a two-pass shader where first a vertical line is rendered and for each fragment the shader computes the sum over the whole row. Then, a single vertex is rendered whose fragment sums all the partial sums of the first pass. Doesn't seem to be very efficient.

  • Render the object completely in white over a black background. Downsample recursively, abusing the hardware linear interpolation between textures until being at a reasonably small resolution. This leads to fragments which have a greyscale level depending on the number of white pixels where in their corresponding region. Is this even accurate enough?

  • ... ?

© Game Development or respective owner

Related posts about opengl

Related posts about graphics