graphics - OpenGL early depth test not working -
here's fragment shader:
#version 420 core #extension gl_arb_explicit_uniform_location : enable #extension gl_arb_shader_storage_buffer_object : require layout(early_fragment_tests) in; layout(binding = 4, offset = 0) uniform atomic_uint num_fragments; // ... void main(void) { atomiccounterincrement(num_fragments); frag_color = vec4(1.0, 0.0, 0.0, 0.0); atomicadd(...); } my triangles cover screen. expected behavior num_fragments equal number of pixels (640*480 = 307200), single layer of triangles. however, when add triangle behind existing triangles, num_fragments becomes higher value, fragment shader being executed occluded triangle.
why this? though early_fragment_tests directive prevent behavior. isn't optimization, because there atomic stores in shader should run un-occluded pixels.
my triangles cover screen. expected behavior num_fragments equal number of pixels (640*480 = 307200), single layer of triangles.
no, not expected behavior.
early depth tests not magic. not in way guarantee random assortment of triangles have 0 overdraw. force fragment tests happen before executing fragment shader. ensure test has passed or failed. , therefore, fragment shader execute fragments have passed.
overdraw has nothing depth tests. overdraw order of triangles you're rendering. if render them sorted front-to-back, 0 overdraw. if render them sorted back-to-front, maximum possible overdraw.
this happens regardless of whether fragment tests happen before fragment shader or not.
this isn't optimization, because there atomic stores in shader should run un-occluded pixels.
the way make depth-only pre-pass. have render scene depth buffer (with no fragment shader). when render scene real, fragments pass depth test ones visible.
Comments
Post a Comment