View Full Version : What goes in my shader when doing hardware occlusion query?

05-30-2013, 03:52 PM
I've been looking at the example provided at the bottom of this link: http://www.opengl.org/registry/specs/ARB/occlusion_query.txt

I'm doing this on for iPhone using OpenGL ES 2. Do I just create a very simple shader as if I was rendering a colored box?

05-31-2013, 03:55 AM
Hardware occlusion queries provide information in two fashions. For any primitive generated for the vertices submitted during the begin and the end of the query, you can read back

a) how many fragments (GL_ARB_occlusion_query1)
b) if any fragments have been generated - a binary decision so to speak (GL_ARB_occlusion_query2)

Usually you'll disable both color and depth writes so the only thing you need is a very simple vertex shader that transform your bounding geometry correctly. Since occlusion queries operate solely on the depth values of generated samples (or fragments iff multisampling is disabled), and color writes are disables anyway, a fragment shader doesn't make any sense. Depth values are defined for a generated fragment (i.e. not clipped or optimized out in another way) even if there isn't a fragment shader - only the result of fragment shading isn't.

Mikkel Gjoel
05-31-2013, 04:54 AM
I just want to add that, like shadowmap-rendering, your fragment program can be a complete passthrough (here glsl330):

vertex program:

layout(location = 0) in vec3 os_pos;
uniform mat4 mvp;void main() {
gl_Position = mvp * vec4( os_pos.xyz, 1 );

fragment program:

void main() {}

Depending on what use of the OCQ, you may need to handle alphatest/per-pixel-discards as well. In the generic case of just rendering an object-boundingbox, the above should do.

05-31-2013, 05:03 AM
You don't export anything in the fragment shader - I'm pretty sure that means the results are still undefined. So, why add a FS in the first place? Plus, even if you defined something, with color writes disabled, you would have any effect and probably additional and completely useless overhead.