Hello,
I am using ext_image_load_store extension for the conventional rendering and need to implement the z-buffer algorithm.
I am using coherent textures as they should by specification guarantee consistent reads/writes from different shader threads.
//<vertex>
varying out float fDepth;
void main()
{
gl_Position = ftransform();
//pow function just for the sake of visibility
fDepth = 100.0 * pow(gl_Position.z / gl_Position.w, 10.0);
}
//</vertex>
//<fragment>
#version 400
#extension GL_NV_gpu_shader5 : enable
#extension GL_EXT_shader_image_load_store : enable
#extension GL_EXT_bindable_uniform : enable
#extension GL_NV_shader_buffer_load : enable
#extension GL_NV_shader_buffer_store : enable
coherent uniform layout(size4x32) image2D finalResult;
in vec3 vecNormal;
in float fDepth;
void main()
{
vec3 vecColor = vec3(0.0, 1.0, 0.0);
//if pixel succeeds depth test, replace value in the buffer
if (fDepth < imageLoad(finalResult, ivec2(gl_FragCoord.xy)).x)
{
imageStore(finalResult, ivec2(gl_FragCoord.xy), vec4(fDepth, 0.0, 0.0, 1.0));
}
}
//</fragment>
Here is the result, showing some artifacts, typical for read/write conflict:
What am I doing wrong?