Search code examples
openglfragment-shaderopengl-4

Does Enabling/Disabling the DEPTH_TEST affect the imageAtomicExchange, imageStore?


I am trying to implement order independence transparency. During collecting the fragments, the following code is going to be run:

uint index = atomicCounterIncrement(list_counter);
uint old_head = imageAtomicExchange(head_pointer_image, ivec2(gl_FragCoord.xy), uint(index));

item.x = old_head;
item.y = packUnorm4x8(frag_color);
item.z = floatBitsToUint(gl_FragCoord.z);
item.w = packUnorm4x8(frag_specularity);

imageStore(list_buffer, int(index), item);

As it is expected, the fragment shader will run on all the fragments which are rendering. Therefore, disabling/enabling the depth test which will happen after running the fragment shader will not affect on the final head_pointer_image and list_buffer.

But by enabling and disabling the depth test, I am getting the following results:

DEPTH_TEST enabledDEPTH_TEST Enabled

DEPTH_TEST disabledDEPTH_TEST Disabled

I was wondering if the depth test is affecting head_pointer_image and list_buffer? or OpenGL inside optimization are doing them in this way?


Solution

  • In OpenGL, the depth test can also be done before the fragment shader execution. This is called "Early Fragment Testing" and can be enabled as an optimization (or can in case of OpenGL > 4.2 be controlled by the ARB_shader_image_load_store extension).

    Early fragment testing can be enabled by the user by specifying

    layout(early_fragment_tests) in;
    

    but I don't think it is possible to disable it somehow. In your case, the best thing to do is to disable depth testing as you already do. For more information have a look here.