Hello everybody,
I am trying to write geometry normals to an image in a fragment shader using imageStore. I have enabled early-z and want each texel of the image to store the normal corresponding to the color stored in the render target’s texel. I thought this would be a trivial task, but the ordering of stores seems to differ from the ordering of the depth test. Look at this result:
[ATTACH=CONFIG]1293[/ATTACH]
This is an image of the resulting normals converted to colors. The steps are made from separate, instanced boxes and you can see the red fragments where different surfaces of the boxes overlap. The red fragments are different for every frame, so it’s flickering. I know this is a synchronization issue, but I don’t know how I can fix it.
I render all boxes with a single glDrawElementsInstanced call, the fragment shader that I used for the image above is
#version 450
#extension GL_ARB_bindless_texture : enable
layout(early_fragment_tests) in;
in vec3 gsViewSpaceNormal;
layout(bindless_image, rgba32f) uniform coherent writeonly image2D mainNormalImage;
void main()
{
memoryBarrier();
imageStore(mainNormalImage, ivec2(gl_FragCoord.xy), vec4(normalize(gsViewSpaceNormal), 0.0));
memoryBarrier();
}
The memoryBarrier calls are only for show, they do not change the result. So I imagine that two fragments of different triangles, F1 and F2, pass the early depth test, first F1, new depth is written, then F2, new depth is written, then F2 stores its normal and then F1 does so afterwards, leaving the wrong normal in the image. How do I prevent that?
Cheers,
nostalgic