Monday 15 March 2010

opengl - Occlusion queries with stencil test only -



opengl - Occlusion queries with stencil test only -

do occlusion queries still work if disable depth testing altogether when obstacle set known priori strictly in-between photographic camera , object tested? effort improve performance, as, logically, don't need complex z-tests if none of occluders behind occludee.

i'm using next commands initialize color/depth/stencil buffers:

sdl_gl_setattribute(sdl_gl_red_size, 0); sdl_gl_setattribute(sdl_gl_green_size, 0); sdl_gl_setattribute(sdl_gl_blue_size, 0); sdl_gl_setattribute(sdl_gl_depth_size, 0); sdl_gl_setattribute(sdl_gl_stencil_size, 1); ... glcolormask(gl_false, gl_false, gl_false, gl_false); gldisable(gl_cull_face); gldisable(gl_depth_test); gldepthmask(gl_false); glenable(gl_stencil_test); glstencilmask(0x00000001); ... glclear(gl_stencil_buffer_bit);

the conclusive document latest opengl spec. opengl 4.5 spec, section "17.3.7 occlusion queries", on page 476 (with emphasis added me):

occlusion queries utilize query objects track number of fragments or samples pass depth test.

when occlusion query active, samples-passed count incremented each fragment passes depth test.

therefore, real question becomes: "pass depth test" mean? pixel pass depth test if there no depth test? , how stencil test come play?

the key stencil test applied before depth test, behavior defined in spec. fragments pass stencil test go through depth test, , hence counted in occlusion query. or in other words, fragments pass both stencil , depth test counted.

one approach work enable depth test, , allow fragments pass depth test. count fragments passed stencil test. settings utilize are:

glenable(gl_depth_test); gldepthfunc(gl_always); glenable(gl_stencil_test); ...

now, work desired without having depth buffer, or depth buffer disabled? first part of answered @ end of section "17.3.6 depth buffer test":

if there no depth buffer, if the depth buffer test passes.

in case, reply yes, can utilize occlusion query without depth buffer, , count fragments pass stencil test.

the sec case covered before in section "17.3.6 depth buffer test":

when disabled, depth comparing , subsequent possible updates depth buffer value bypassed , the fragment passed next operation.

figure 17.1 in spec shows "occlusion query" next operation next "depth buffer test". therefore, fragments passed before tests (including stencil) counted occlusion query if depth test disabled.

and final reply is: yes, can utilize occlusion queries stencil test.

acknowledgement: latest version revised based on feedback @jozxyqk , @user2464424

opengl sdl stencil-buffer occlusion-culling

No comments:

Post a Comment