Add Order Independent Transparency example (#755)

* Add Order Independent Transparency example

* Update README.md

* Add copyright at Order Independent Transparency example

* Disable the validation by default
This commit is contained in:
daemyung jang 2020-08-21 16:27:06 +09:00 committed by GitHub
parent d6b61a0952
commit 82747df540
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 822 additions and 0 deletions

View file

@ -0,0 +1,56 @@
#version 450
#define MAX_FRAGMENT_COUNT 128
struct Node
{
vec4 color;
float depth;
uint next;
};
layout (location = 0) out vec4 outFragColor;
layout (set = 0, binding = 0, r32ui) uniform uimage2D headIndexImage;
layout (set = 0, binding = 1) buffer LinkedListSBO
{
Node nodes[];
};
void main()
{
Node fragments[MAX_FRAGMENT_COUNT];
int count = 0;
uint nodeIdx = imageLoad(headIndexImage, ivec2(gl_FragCoord.xy)).r;
while (nodeIdx != 0xffffffff && count < MAX_FRAGMENT_COUNT)
{
fragments[count] = nodes[nodeIdx];
nodeIdx = fragments[count].next;
++count;
}
// Do the insertion sort
for (uint i = 1; i < count; ++i)
{
Node insert = fragments[i];
uint j = i;
while (j > 0 && insert.depth > fragments[j - 1].depth)
{
fragments[j] = fragments[j-1];
--j;
}
fragments[j] = insert;
}
// Do blending
vec4 color = vec4(0.025, 0.025, 0.025, 1.0f);
for (int i = 0; i < count; ++i)
{
color = mix(color, fragments[i].color, fragments[i].color.a);
}
outFragColor = color;
}

Binary file not shown.

View file

@ -0,0 +1,7 @@
#version 450
void main()
{
vec2 uv = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
gl_Position = vec4(uv * 2.0f + -1.0f, 0.0f, 1.0f);
}

Binary file not shown.

View file

@ -0,0 +1,49 @@
#version 450
#define MAX_FRAGMENT_COUNT 75
layout (early_fragment_tests) in;
struct Node
{
vec4 color;
float depth;
uint next;
};
layout (set = 0, binding = 1) uniform ObjectUBO
{
mat4 model;
vec4 color;
} objectUBO;
layout (set = 0, binding = 2) buffer GeometrySBO
{
uint count;
uint maxNodeCount;
};
layout (set = 0, binding = 3, r32ui) uniform uimage2D headIndexImage;
layout (set = 0, binding = 4) buffer LinkedListSBO
{
Node nodes[];
};
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
nodes[nodeIdx].color = objectUBO.color;
nodes[nodeIdx].depth = gl_FragCoord.z;
nodes[nodeIdx].next = prevHeadIdx;
}
}

Binary file not shown.

View file

@ -0,0 +1,21 @@
#version 450
layout (location = 0) in vec3 inPos;
layout (set = 0, binding = 0) uniform RenderPassUBO
{
mat4 projection;
mat4 view;
} renderPassUBO;
layout (set = 0, binding = 1) uniform ObjectUBO
{
mat4 model;
vec4 color;
} objectUBO;
void main()
{
mat4 PVM = renderPassUBO.projection * renderPassUBO.view * objectUBO.model;
gl_Position = PVM * vec4(inPos, 1.0);
}

Binary file not shown.