2020-08-21 16:27:06 +09:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
|
|
layout (early_fragment_tests) in;
|
|
|
|
|
|
|
|
|
|
struct Node
|
|
|
|
|
{
|
|
|
|
|
vec4 color;
|
|
|
|
|
float depth;
|
|
|
|
|
uint next;
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-21 17:27:54 +02:00
|
|
|
layout (set = 0, binding = 1) buffer GeometrySBO
|
2020-08-21 16:27:06 +09:00
|
|
|
{
|
|
|
|
|
uint count;
|
|
|
|
|
uint maxNodeCount;
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-28 11:16:35 +01:00
|
|
|
layout (set = 0, binding = 2, r32ui) uniform coherent uimage2D headIndexImage;
|
2020-08-21 16:27:06 +09:00
|
|
|
|
2020-08-21 17:27:54 +02:00
|
|
|
layout (set = 0, binding = 3) buffer LinkedListSBO
|
2020-08-21 16:27:06 +09:00
|
|
|
{
|
|
|
|
|
Node nodes[];
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-21 17:27:54 +02:00
|
|
|
layout(push_constant) uniform PushConsts {
|
|
|
|
|
mat4 model;
|
|
|
|
|
vec4 color;
|
|
|
|
|
} pushConsts;
|
|
|
|
|
|
2020-08-21 16:27:06 +09:00
|
|
|
void main()
|
|
|
|
|
{
|
|
|
|
|
// Increase the node count
|
|
|
|
|
uint nodeIdx = atomicAdd(count, 1);
|
|
|
|
|
|
|
|
|
|
// Check LinkedListSBO is full
|
|
|
|
|
if (nodeIdx < maxNodeCount)
|
|
|
|
|
{
|
|
|
|
|
// Exchange new head index and previous head index
|
|
|
|
|
uint prevHeadIdx = imageAtomicExchange(headIndexImage, ivec2(gl_FragCoord.xy), nodeIdx);
|
|
|
|
|
|
|
|
|
|
// Store node data
|
2020-08-21 17:27:54 +02:00
|
|
|
nodes[nodeIdx].color = pushConsts.color;
|
2020-08-21 16:27:06 +09:00
|
|
|
nodes[nodeIdx].depth = gl_FragCoord.z;
|
|
|
|
|
nodes[nodeIdx].next = prevHeadIdx;
|
|
|
|
|
}
|
|
|
|
|
}
|