#version 310 es layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in; precision mediump float; precision mediump image2D; layout(std430) buffer; struct vertex { vec2 pos; vec4 cubic; vec2 uv; vec4 color; vec4 clip; int zIndex; }; layout(binding = 0) restrict readonly buffer vertexBufferSSBO { vertex elements[]; } vertexBuffer ; layout(binding = 1) restrict readonly buffer indexBufferSSBO { uint elements[]; } indexBuffer ; layout(binding = 2) restrict readonly buffer tileCounterBufferSSBO { uint elements[]; } tileCounterBuffer ; layout(binding = 3) restrict readonly buffer tileArrayBufferSSBO { uint elements[]; } tileArrayBuffer ; layout(location = 0) uniform uint indexCount; layout(location = 1) uniform uvec2 tileCount; layout(location = 2) uniform uint tileSize; layout(location = 3) uniform uint tileArraySize; layout(rgba8, binding = 0) uniform restrict writeonly image2D outTexture; void main() {} #if 0 bool is_top_left(ivec2 a, ivec2 b) { return( (a.y == b.y && b.x < a.x) ||(b.y < a.y)); } int orient2d(ivec2 a, ivec2 b, ivec2 p) { return((b.x-a.x)*(p.y-a.y) - (b.y-a.y)*(p.x-a.x)); } void main() { ivec2 pixelCoord = ivec2(gl_WorkGroupID.xy*uvec2(16, 16) + gl_LocalInvocationID.xy); imageStore(outTexture, pixelCoord, vec4(1, 0, 1, 1)); return; uvec2 tileCoord = uvec2(pixelCoord) / tileSize; uint tileIndex = tileCoord.y * tileCount.x + tileCoord.x; uint tileCounter = tileCounterBuffer.elements[tileIndex]; const float subPixelFactor = 16.; ivec2 centerPoint = ivec2(round((vec2(pixelCoord) + vec2(0.5, 0.5)) * subPixelFactor)); /* const int sampleCount = 8; ivec2 samplePoints[sampleCount] = ivec2[sampleCount](centerPoint + ivec2(1, 3), centerPoint + ivec2(-1, -3), centerPoint + ivec2(5, -1), centerPoint + ivec2(-3, 5), centerPoint + ivec2(-5, -5), centerPoint + ivec2(-7, 1), centerPoint + ivec2(3, -7), centerPoint + ivec2(7, 7)); */ const int sampleCount = 4; ivec2 samplePoints[sampleCount] = ivec2[sampleCount](centerPoint + ivec2(-2, 6), centerPoint + ivec2(6, 2), centerPoint + ivec2(-6, -2), centerPoint + ivec2(2, -6)); //DEBUG //* { vec4 fragColor = vec4(0); /* if( pixelCoord.x % 16 == 0 ||pixelCoord.y % 16 == 0) { fragColor = vec4(0, 0, 0, 1); } else if(tileCounterBuffer.elements[tileIndex] == 0xffffu) { fragColor = vec4(1, 0, 1, 1); } else if(tileCounter != 0u) { fragColor = vec4(0, 1, 0, 1); } else { fragColor = vec4(1, 0, 0, 1); } */ imageStore(outTexture, pixelCoord, fragColor); return; } //*/ //---- vec4 sampleColor[sampleCount]; vec4 currentColor[sampleCount]; int currentZIndex[sampleCount]; int flipCount[sampleCount]; for(int i=0; i= 0 && (w1+bias1) >= 0 && (w2+bias2) >= 0) { vec4 cubic = (cubic0*float(w0) + cubic1*float(w1) + cubic2*float(w2))/(float(w0)+float(w1)+float(w2)); float eps = 0.0001; if(cubic.w*(cubic.x*cubic.x*cubic.x - cubic.y*cubic.z) <= eps) { if(zIndex == currentZIndex[sampleIndex]) { flipCount[sampleIndex]++; } else { if((flipCount[sampleIndex] & 0x01) != 0) { sampleColor[sampleIndex] = currentColor[sampleIndex]; } currentColor[sampleIndex] = sampleColor[sampleIndex]*(1.-color.a) + color.a*color; currentZIndex[sampleIndex] = zIndex; flipCount[sampleIndex] = 1; } } } } } vec4 pixelColor = vec4(0); for(int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { if((flipCount[sampleIndex] & 0x01) != 0) { sampleColor[sampleIndex] = currentColor[sampleIndex]; } pixelColor += sampleColor[sampleIndex]; } imageStore(outTexture, pixelCoord, pixelColor/float(sampleCount)); } #endif