#version 410 core
#extension GL_EXT_shader_image_load_store : require
#extension GL_ARB_gpu_shader5 : require // weird, need to include this for coherent keyword...
// input layout definitions
//layout(early_fragment_tests) in;
// input/output definitions
in per_vertex {
vec3 normal;
vec2 texcoord;
} v_in;
// attribute layout definitions
layout(location = 0, index = 0) out vec4 out_color;
// uniform input definitions
layout(size1x32) coherent uniform image2D output_image;
layout(size1x32) coherent uniform uimage2D depth_image;
// implementation
void main()
{
vec4 c = vec4(v_in.normal, 1.0);
ivec2 frag_coord = ivec2(gl_FragCoord.xy);
ivec2 out_coord = frag_coord; // later used for under sampling
uint z = uint((1.0 - gl_FragCoord.z) * float(0xFFFFFFFFu));
if (z > imageAtomicMax(depth_image, out_coord, z)) {
imageStore(output_image, out_coord, c);
//memoryBarrier();
}
discard;
out_color = c;
}