declare const _default: "\n varying vec2 uv0;\n uniform sampler2D smaaEdgesTexture;\n uniform sampler2D smaaAreaTexture;\n uniform sampler2D smaaSearchTexture;\n\n // 1 / width, 1 / height, width, height of the scene\n uniform vec4 smaaMetrics;\n\n // threshold, maximum search steps, maximum diagonal search steps, corner rounding\n uniform vec4 smaaParams;\n\n #define SMAA_AREATEX_MAX_DISTANCE 16.0\n #define SMAA_AREATEX_MAX_DISTANCE_DIAG 20.0\n\n // the size of a texel of the area texture - the 160 x 80 subtexture SMAA 1x reads\n #define SMAA_AREATEX_PIXEL_SIZE (1.0 / vec2(160.0, 80.0))\n #define SMAA_SEARCHTEX_SIZE vec2(66.0, 33.0)\n #define SMAA_SEARCHTEX_PACKED_SIZE vec2(64.0, 16.0)\n\n vec2 sampleEdges(vec2 uv) {\n return texture2DLod(smaaEdgesTexture, uv, 0.0).rg;\n }\n\n vec2 sampleEdgesOffset(vec2 uv, vec2 offset) {\n return sampleEdges(uv + offset * smaaMetrics.xy);\n }\n\n // ---- diagonal search ----\n\n // The edges are fetched with bilinear filtering at a 0.25 offset, reading two of them at once,\n // which this unpacks\n vec2 decodeDiagBilinearAccess(vec2 e) {\n e.r = e.r * abs(5.0 * e.r - 5.0 * 0.75);\n return round(e);\n }\n\n vec4 decodeDiagBilinearAccess(vec4 e) {\n e.rb = e.rb * abs(5.0 * e.rb - 5.0 * 0.75);\n return round(e);\n }\n\n // searches along a diagonal for the end of a line, returning the distance and whether the end\n // was found\n vec2 searchDiag1(vec2 texcoord, vec2 dir, out vec2 e) {\n vec4 coord = vec4(texcoord, -1.0, 1.0);\n vec3 t = vec3(smaaMetrics.xy, 1.0);\n float maxSteps = smaaParams.z - 1.0;\n e = vec2(0.0);\n while (coord.z < maxSteps && coord.w > 0.9) {\n coord.xyz = t * vec3(dir, 1.0) + coord.xyz;\n e = sampleEdges(coord.xy);\n coord.w = dot(e, vec2(0.5));\n }\n return coord.zw;\n }\n\n vec2 searchDiag2(vec2 texcoord, vec2 dir, out vec2 e) {\n vec4 coord = vec4(texcoord, -1.0, 1.0);\n coord.x += 0.25 * smaaMetrics.x;\n vec3 t = vec3(smaaMetrics.xy, 1.0);\n float maxSteps = smaaParams.z - 1.0;\n e = vec2(0.0);\n while (coord.z < maxSteps && coord.w > 0.9) {\n coord.xyz = t * vec3(dir, 1.0) + coord.xyz;\n\n // fetches both edges at once using bilinear filtering\n e = decodeDiagBilinearAccess(sampleEdges(coord.xy));\n coord.w = dot(e, vec2(0.5));\n }\n return coord.zw;\n }\n\n // the area below a diagonal line, from the second half of the area texture\n vec2 areaDiag(vec2 dist, vec2 e) {\n vec2 texcoord = vec2(SMAA_AREATEX_MAX_DISTANCE_DIAG) * e + dist;\n texcoord = SMAA_AREATEX_PIXEL_SIZE * texcoord + 0.5 * SMAA_AREATEX_PIXEL_SIZE;\n texcoord.x += 0.5;\n return texture2DLod(smaaAreaTexture, texcoord, 0.0).rg;\n }\n\n // the blending weights for the diagonal lines through the pixel\n vec2 calculateDiagWeights(vec2 texcoord, vec2 e) {\n vec2 weights = vec2(0.0);\n\n // the line ends\n vec4 d;\n vec2 end;\n if (e.r > 0.0) {\n d.xz = searchDiag1(texcoord, vec2(-1.0, 1.0), end);\n d.x += float(end.y > 0.9);\n } else {\n d.xz = vec2(0.0);\n }\n d.yw = searchDiag1(texcoord, vec2(1.0, -1.0), end);\n\n if (d.x + d.y > 2.0) {\n\n // the crossing edges\n vec4 coords = vec4(-d.x + 0.25, d.x, d.y, -d.y - 0.25) * smaaMetrics.xyxy + texcoord.xyxy;\n vec4 c;\n c.xy = sampleEdgesOffset(coords.xy, vec2(-1.0, 0.0));\n c.zw = sampleEdgesOffset(coords.zw, vec2(1.0, 0.0));\n c.yxwz = decodeDiagBilinearAccess(c.xyzw);\n\n // merges the crossing edges at each side into a single value, without the crossing\n // edge where the end of the line was not found\n vec2 cc = vec2(2.0) * c.xz + c.yw;\n cc = mix(cc, vec2(0.0), step(vec2(0.9), d.zw));\n\n weights += areaDiag(d.xy, cc);\n }\n\n // the other diagonal\n d.xz = searchDiag2(texcoord, vec2(-1.0, -1.0), end);\n if (sampleEdgesOffset(texcoord, vec2(1.0, 0.0)).r > 0.0) {\n d.yw = searchDiag2(texcoord, vec2(1.0, 1.0), end);\n d.y += float(end.y > 0.9);\n } else {\n d.yw = vec2(0.0);\n }\n\n if (d.x + d.y > 2.0) {\n vec4 coords = vec4(-d.x, -d.x, d.y, d.y) * smaaMetrics.xyxy + texcoord.xyxy;\n vec4 c;\n c.x = sampleEdgesOffset(coords.xy, vec2(-1.0, 0.0)).g;\n c.y = sampleEdgesOffset(coords.xy, vec2(0.0, -1.0)).r;\n c.zw = sampleEdgesOffset(coords.zw, vec2(1.0, 0.0)).gr;\n vec2 cc = vec2(2.0) * c.xz + c.yw;\n cc = mix(cc, vec2(0.0), step(vec2(0.9), d.zw));\n\n weights += areaDiag(d.xy, cc).gr;\n }\n\n return weights;\n }\n\n // ---- horizontal and vertical search ----\n\n // the length of the edge past the last two pixels fetched, which the search texture decodes\n // from their bilinear fetch\n float searchLength(vec2 e, float offset) {\n\n // the texture is flipped vertically, with the left and the right cases taking half of it\n // horizontally each\n vec2 scale = SMAA_SEARCHTEX_SIZE * vec2(0.5, -1.0);\n vec2 bias = SMAA_SEARCHTEX_SIZE * vec2(offset, 1.0);\n\n // scale and bias to access the texel centers, in the cropped texture\n scale += vec2(-1.0, 1.0);\n bias += vec2(0.5, -0.5);\n scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;\n bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;\n\n return texture2DLod(smaaSearchTexture, scale * e + bias, 0.0).r;\n }\n\n // searches for the end of a horizontal or vertical line, two pixels at a time, stopping at a\n // crossing edge\n float searchXLeft(vec2 texcoord, float end) {\n vec2 e = vec2(0.0, 1.0);\n while (texcoord.x > end && e.g > 0.8281 && e.r == 0.0) {\n e = sampleEdges(texcoord);\n texcoord = -vec2(2.0, 0.0) * smaaMetrics.xy + texcoord;\n }\n float offset = -(255.0 / 127.0) * searchLength(e, 0.0) + 3.25;\n return smaaMetrics.x * offset + texcoord.x;\n }\n\n float searchXRight(vec2 texcoord, float end) {\n vec2 e = vec2(0.0, 1.0);\n while (texcoord.x < end && e.g > 0.8281 && e.r == 0.0) {\n e = sampleEdges(texcoord);\n texcoord = vec2(2.0, 0.0) * smaaMetrics.xy + texcoord;\n }\n float offset = -(255.0 / 127.0) * searchLength(e, 0.5) + 3.25;\n return -smaaMetrics.x * offset + texcoord.x;\n }\n\n float searchYUp(vec2 texcoord, float end) {\n vec2 e = vec2(1.0, 0.0);\n while (texcoord.y > end && e.r > 0.8281 && e.g == 0.0) {\n e = sampleEdges(texcoord);\n texcoord = -vec2(0.0, 2.0) * smaaMetrics.xy + texcoord;\n }\n float offset = -(255.0 / 127.0) * searchLength(e.gr, 0.0) + 3.25;\n return smaaMetrics.y * offset + texcoord.y;\n }\n\n float searchYDown(vec2 texcoord, float end) {\n vec2 e = vec2(1.0, 0.0);\n while (texcoord.y < end && e.r > 0.8281 && e.g == 0.0) {\n e = sampleEdges(texcoord);\n texcoord = vec2(0.0, 2.0) * smaaMetrics.xy + texcoord;\n }\n float offset = -(255.0 / 127.0) * searchLength(e.gr, 0.5) + 3.25;\n return -smaaMetrics.y * offset + texcoord.y;\n }\n\n // the area below a horizontal or vertical line, given the distances to its ends and the\n // crossing edges there\n vec2 area(vec2 dist, float e1, float e2) {\n vec2 texcoord = vec2(SMAA_AREATEX_MAX_DISTANCE) * round(4.0 * vec2(e1, e2)) + dist;\n texcoord = SMAA_AREATEX_PIXEL_SIZE * texcoord + 0.5 * SMAA_AREATEX_PIXEL_SIZE;\n return texture2DLod(smaaAreaTexture, texcoord, 0.0).rg;\n }\n\n // ---- corner detection ----\n\n // reduces the blending at sharp corners, keeping them sharp - not at all with a corner rounding\n // of 1, the normalized smaaParams.w\n vec2 detectHorizontalCornerPattern(vec2 weights, vec4 texcoord, vec2 d) {\n vec2 leftRight = step(d.xy, d.yx);\n vec2 rounding = (1.0 - smaaParams.w) * leftRight;\n\n // reduces the blending for the pixels in the center of a line\n rounding /= leftRight.x + leftRight.y;\n\n vec2 factor = vec2(1.0);\n factor.x -= rounding.x * sampleEdgesOffset(texcoord.xy, vec2(0.0, 1.0)).r;\n factor.x -= rounding.y * sampleEdgesOffset(texcoord.zw, vec2(1.0, 1.0)).r;\n factor.y -= rounding.x * sampleEdgesOffset(texcoord.xy, vec2(0.0, -2.0)).r;\n factor.y -= rounding.y * sampleEdgesOffset(texcoord.zw, vec2(1.0, -2.0)).r;\n return weights * clamp(factor, 0.0, 1.0);\n }\n\n vec2 detectVerticalCornerPattern(vec2 weights, vec4 texcoord, vec2 d) {\n vec2 leftRight = step(d.xy, d.yx);\n vec2 rounding = (1.0 - smaaParams.w) * leftRight;\n rounding /= leftRight.x + leftRight.y;\n\n vec2 factor = vec2(1.0);\n factor.x -= rounding.x * sampleEdgesOffset(texcoord.xy, vec2(1.0, 0.0)).g;\n factor.x -= rounding.y * sampleEdgesOffset(texcoord.zw, vec2(1.0, 1.0)).g;\n factor.y -= rounding.x * sampleEdgesOffset(texcoord.xy, vec2(-2.0, 0.0)).g;\n factor.y -= rounding.y * sampleEdgesOffset(texcoord.zw, vec2(-2.0, 1.0)).g;\n return weights * clamp(factor, 0.0, 1.0);\n }\n\n void main(void) {\n vec2 texcoord = uv0;\n vec4 metrics = smaaMetrics;\n vec2 pixcoord = texcoord * metrics.zw;\n\n // the offsets of the searches, and the ends of their loops\n vec4 offset0 = metrics.xyxy * vec4(-0.25, -0.125, 1.25, -0.125) + texcoord.xyxy;\n vec4 offset1 = metrics.xyxy * vec4(-0.125, -0.25, -0.125, 1.25) + texcoord.xyxy;\n vec4 offset2 = metrics.xxyy * (vec4(-2.0, 2.0, -2.0, 2.0) * smaaParams.y) + vec4(offset0.xz, offset1.yw);\n\n vec4 weights = vec4(0.0);\n vec2 e = sampleEdges(texcoord);\n\n // an edge at the top\n if (e.g > 0.0) {\n\n // the diagonals first, unless disabled by no diagonal search steps\n if (smaaParams.z > 0.0) {\n weights.rg = calculateDiagWeights(texcoord, e);\n }\n\n // no diagonal line through the pixel, so a horizontal one\n if (weights.r == -weights.g) {\n vec2 d;\n vec3 coords;\n coords.x = searchXLeft(offset0.xy, offset2.x);\n coords.y = offset1.y;\n d.x = coords.x;\n\n // the crossing edges at the ends, fetched with bilinear filtering to read both of\n // a pair at once\n float e1 = texture2DLod(smaaEdgesTexture, coords.xy, 0.0).r;\n coords.z = searchXRight(offset0.zw, offset2.y);\n d.y = coords.z;\n\n // the distances in pixels, their square roots giving the area texture its range\n d = abs(round(metrics.zz * d - pixcoord.xx));\n vec2 sqrtD = sqrt(d);\n float e2 = sampleEdgesOffset(coords.zy, vec2(1.0, 0.0)).r;\n weights.rg = area(sqrtD, e1, e2);\n\n coords.y = texcoord.y;\n weights.rg = detectHorizontalCornerPattern(weights.rg, coords.xyzy, d);\n } else {\n\n // a diagonal line, which the vertical search would mistake for edges of its own\n e.r = 0.0;\n }\n }\n\n // an edge at the left\n if (e.r > 0.0) {\n vec2 d;\n vec3 coords;\n coords.y = searchYUp(offset1.xy, offset2.z);\n coords.x = offset0.x;\n d.x = coords.y;\n\n float e1 = texture2DLod(smaaEdgesTexture, coords.xy, 0.0).g;\n coords.z = searchYDown(offset1.zw, offset2.w);\n d.y = coords.z;\n\n d = abs(round(metrics.ww * d - pixcoord.yy));\n vec2 sqrtD = sqrt(d);\n float e2 = sampleEdgesOffset(coords.xz, vec2(0.0, 1.0)).g;\n weights.ba = area(sqrtD, e1, e2);\n\n coords.x = texcoord.x;\n weights.ba = detectVerticalCornerPattern(weights.ba, coords.xyxz, d);\n }\n\n gl_FragColor = weights;\n }\n"; export default _default;