mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-12-12 13:42:41 +00:00
966ef949c5
I had debated putting the blending in the compose subpass or a separate pass but went with the separate pass originally, but it turns out that removing the separate pass gains 1-3% (5-15/545 fps in a timedemo of demo1).
34 lines
800 B
Text
34 lines
800 B
Text
#include "oit.h"
|
|
|
|
vec4
|
|
BlendFrags (vec4 color)
|
|
{
|
|
#define MAX_FRAGMENTS 64
|
|
FragData frags[MAX_FRAGMENTS];
|
|
int numFrags = 0;
|
|
ivec2 coord = ivec2(gl_FragCoord.xy);
|
|
int index = imageLoad (heads, coord).r;
|
|
|
|
//FIXME use a heap and prioritize closer fragments
|
|
while (index != -1 && numFrags < MAX_FRAGMENTS) {
|
|
frags[numFrags] = fragments[index];
|
|
numFrags++;
|
|
index = fragments[index].next;
|
|
}
|
|
//insertion sort
|
|
for (int i = 1; i < numFrags; i++) {
|
|
FragData toInsert = frags[i];
|
|
int j = i;
|
|
while (j > 0 && toInsert.depth > frags[j - 1].depth) {
|
|
frags[j] = frags[j - 1];
|
|
j--;
|
|
}
|
|
frags[j] = toInsert;
|
|
}
|
|
|
|
for (int i = 0; i < numFrags; i++) {
|
|
color = mix (color, frags[i].color,
|
|
clamp (frags[i].color.a, 0.0f, 1.0f));
|
|
}
|
|
return color;
|
|
}
|