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; ...@@ -18,7 +18,7 @@ layout(binding = 1, rgba32ui) uniform uimageBuffer g_ABuffer;
uniform uvec2 g_ScreenSize; uniform uvec2 g_ScreenSize;
struct FragListEntry struct FragListEntry
{ {
uint color; uint color;
float depth; float depth;
...@@ -29,75 +29,80 @@ void main() ...@@ -29,75 +29,80 @@ void main()
{ {
uvec2 absFragCoord = uvec2(gl_FragCoord.xy); // * g_ScreenSize); uvec2 absFragCoord = uvec2(gl_FragCoord.xy); // * g_ScreenSize);
uint uiPixelID = absFragCoord.x + g_ScreenSize.x * absFragCoord.y; uint uiPixelID = absFragCoord.x + g_ScreenSize.x * absFragCoord.y;
// sorted list of the current pixel list // sorted list of the current pixel list
FragListEntry list[MAXLISTSIZE]; FragListEntry list[MAXLISTSIZE];
// get offset to head of the list // get offset to head of the list
uint uiOffset = imageLoad(g_StartOffsetBuffer, int(uiPixelID)).r; uint uiOffset = imageLoad(g_StartOffsetBuffer, int(uiPixelID)).r;
uint startOffset = uiOffset; uint startOffset = uiOffset;
// keep track of list size // keep track of list size
int listSize = 0; 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 // 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)); uvec4 fragEntry = imageLoad(g_ABuffer, int(uiOffset));
// fragEntry : (color, depth, next, coverage) // fragEntry : (color, depth, next, coverage)
#ifdef OITLL_MSAA #ifdef OITLL_MSAA
// check if sample is covered by rasterized triangle // check if sample is covered by rasterized triangle
if ((fragEntry.w & (1 << gl_SampleID)) != 0) if ((fragEntry.w & (1 << gl_SampleID)) != 0)
#endif #endif
{ {
list[listSize].color = fragEntry.x; float fragDepth = uintBitsToFloat(fragEntry.y);
list[listSize].depth = uintBitsToFloat(fragEntry.y);
// insertion sort if (listSize < MAXLISTSIZE || list[listSize - 1].depth > fragDepth)
int j = listSize; {
int prev = max(j-1, 0); int insertPos = min(listSize, MAXLISTSIZE - 1);
// insertion sort: front to back list[insertPos].color = fragEntry.x;
while( (j > 0) && (list[prev].depth > list[j].depth) ) list[insertPos].depth = fragDepth;
{
// swap
FragListEntry tmp = list[j]; // insertion sort
list[j] = list[prev]; int j = insertPos;
list[prev] = tmp; int prev = max(j - 1, 0);
--j; // insertion sort: front to back
prev = max(j-1, 0); while ((j > 0) && (list[prev].depth > list[j].depth))
} {
// swap
listSize = min(listSize+1, MAXLISTSIZE); FragListEntry tmp = list[j];
list[j] = list[prev];
} list[prev] = tmp;
// goto next entry --j;
uiOffset = fragEntry.z; 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 // 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); 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; 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