Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: What goes in my shader when doing hardware occlusion query?

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2010
    Location
    us
    Posts
    12

    What goes in my shader when doing hardware occlusion query?

    I've been looking at the example provided at the bottom of this link: http://www.opengl.org/registry/specs...sion_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?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jan 2004
    Location
    .dk
    Posts
    129
    I just want to add that, like shadowmap-rendering, your fragment program can be a complete passthrough (here glsl330):


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


    fragment program:
    Code :
    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.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •