Commit 712e58da authored by Christopher Tenter's avatar Christopher Tenter

fix artifacts at pixels where too many layers overlap (OITLinkedList)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free-Staging@20191 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8081530b
......@@ -18,7 +18,7 @@ layout(binding = 1, rgba32ui) uniform uimageBuffer g_ABuffer;
uniform uvec2 g_ScreenSize;
struct FragListEntry
struct FragListEntry
{
uint color;
float depth;
......@@ -29,75 +29,80 @@ void main()
{
uvec2 absFragCoord = uvec2(gl_FragCoord.xy); // * g_ScreenSize);
uint uiPixelID = absFragCoord.x + g_ScreenSize.x * absFragCoord.y;
// sorted list of the current pixel list
FragListEntry list[MAXLISTSIZE];
// get offset to head of the list
uint uiOffset = imageLoad(g_StartOffsetBuffer, int(uiPixelID)).r;
uint startOffset = uiOffset;
// keep track of list size
int listSize = 0;
vec4 dbgColor = vec4(1,1,1,1);
vec4 dbgColor = vec4(1, 1, 1, 1);
// read linked list from ABuffer, starting at offset of list head
while (uiOffset != 0xffffffff && listSize < MAXLISTSIZE)
while (uiOffset != 0xffffffff)
{
uvec4 fragEntry = imageLoad(g_ABuffer, int(uiOffset));
// fragEntry : (color, depth, next, coverage)
uvec4 fragEntry = imageLoad(g_ABuffer, int(uiOffset));
// fragEntry : (color, depth, next, coverage)
#ifdef OITLL_MSAA
// check if sample is covered by rasterized triangle
if ((fragEntry.w & (1 << gl_SampleID)) != 0)
// check if sample is covered by rasterized triangle
if ((fragEntry.w & (1 << gl_SampleID)) != 0)
#endif
{
list[listSize].color = fragEntry.x;
list[listSize].depth = uintBitsToFloat(fragEntry.y);
// insertion sort
int j = listSize;
int prev = max(j-1, 0);
// insertion sort: front to back
while( (j > 0) && (list[prev].depth > list[j].depth) )
{
// swap
FragListEntry tmp = list[j];
list[j] = list[prev];
list[prev] = tmp;
--j;
prev = max(j-1, 0);
}
listSize = min(listSize+1, MAXLISTSIZE);
}
// goto next entry
uiOffset = fragEntry.z;
{
float fragDepth = uintBitsToFloat(fragEntry.y);
if (listSize < MAXLISTSIZE || list[listSize - 1].depth > fragDepth)
{
int insertPos = min(listSize, MAXLISTSIZE - 1);
list[insertPos].color = fragEntry.x;
list[insertPos].depth = fragDepth;
// insertion sort
int j = insertPos;
int prev = max(j - 1, 0);
// insertion sort: front to back
while ((j > 0) && (list[prev].depth > list[j].depth))
{
// swap
FragListEntry tmp = list[j];
list[j] = list[prev];
list[prev] = tmp;
--j;
prev = max(j - 1, 0);
}
listSize = min(listSize + 1, MAXLISTSIZE);
}
}
// goto next entry
uiOffset = fragEntry.z;
}
vec4 color = vec4(0,0,0,1);
vec4 color = vec4(0, 0, 0, 1);
// blend back to front
for (int i = listSize-1; i >= 0; --i)
for (int i = listSize - 1; i >= 0; --i)
{
vec4 fragColor = unpackUnorm4x8(list[i].color);
color.xyz = mix(color.xyz, fragColor.xyz, fragColor.w);
color.xyz = mix(color.xyz, fragColor.xyz, fragColor.w);
}
outColor = color; // * gl_NumSamples;
// weird bug, for some reason color != (0,0,0,1) for unshaded pixels
if (startOffset == 0xffffffff)
outColor = vec4(0,0,0,1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment