declare const _default: "\n varying uv0: vec2f;\n var smaaEdgesTexture: texture_2d;\n var smaaEdgesTextureSampler: sampler;\n var smaaAreaTexture: texture_2d;\n var smaaAreaTextureSampler: sampler;\n var smaaSearchTexture: texture_2d;\n var smaaSearchTextureSampler: sampler;\n\n // 1 / width, 1 / height, width, height of the scene\n uniform smaaMetrics: vec4f;\n\n // threshold, maximum search steps, maximum diagonal search steps, corner rounding\n uniform smaaParams: vec4f;\n\n const SMAA_AREATEX_MAX_DISTANCE: f32 = 16.0;\n const SMAA_AREATEX_MAX_DISTANCE_DIAG: f32 = 20.0;\n\n // the size of a texel of the area texture - the 160 x 80 subtexture SMAA 1x reads\n const SMAA_AREATEX_PIXEL_SIZE: vec2f = vec2f(1.0 / 160.0, 1.0 / 80.0);\n const SMAA_SEARCHTEX_SIZE: vec2f = vec2f(66.0, 33.0);\n const SMAA_SEARCHTEX_PACKED_SIZE: vec2f = vec2f(64.0, 16.0);\n\n fn sampleEdges(uv: vec2f) -> vec2f {\n return textureSampleLevel(smaaEdgesTexture, smaaEdgesTextureSampler, uv, 0.0).rg;\n }\n\n fn sampleEdgesOffset(uv: vec2f, offset: vec2f) -> vec2f {\n return sampleEdges(uv + offset * uniform.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 fn decodeDiagBilinearAccess2(e: vec2f) -> vec2f {\n return round(vec2f(e.r * abs(5.0 * e.r - 5.0 * 0.75), e.g));\n }\n\n fn decodeDiagBilinearAccess4(e: vec4f) -> vec4f {\n return round(vec4f(e.r * abs(5.0 * e.r - 5.0 * 0.75), e.g, e.b * abs(5.0 * e.b - 5.0 * 0.75), e.a));\n }\n\n // a diagonal search: the distance and whether the end was found, and the last edges fetched\n struct DiagSearch {\n result: vec2f,\n e: vec2f\n }\n\n // searches along a diagonal for the end of a line\n fn searchDiag1(texcoord: vec2f, dir: vec2f) -> DiagSearch {\n var coord = vec4f(texcoord, -1.0, 1.0);\n let t = vec3f(uniform.smaaMetrics.xy, 1.0);\n let maxSteps = uniform.smaaParams.z - 1.0;\n var e = vec2f(0.0);\n while (coord.z < maxSteps && coord.w > 0.9) {\n coord = vec4f(t * vec3f(dir, 1.0) + coord.xyz, coord.w);\n e = sampleEdges(coord.xy);\n coord.w = dot(e, vec2f(0.5));\n }\n return DiagSearch(coord.zw, e);\n }\n\n fn searchDiag2(texcoord: vec2f, dir: vec2f) -> DiagSearch {\n var coord = vec4f(texcoord, -1.0, 1.0);\n coord.x += 0.25 * uniform.smaaMetrics.x;\n let t = vec3f(uniform.smaaMetrics.xy, 1.0);\n let maxSteps = uniform.smaaParams.z - 1.0;\n var e = vec2f(0.0);\n while (coord.z < maxSteps && coord.w > 0.9) {\n coord = vec4f(t * vec3f(dir, 1.0) + coord.xyz, coord.w);\n\n // fetches both edges at once using bilinear filtering\n e = decodeDiagBilinearAccess2(sampleEdges(coord.xy));\n coord.w = dot(e, vec2f(0.5));\n }\n return DiagSearch(coord.zw, e);\n }\n\n // the area below a diagonal line, from the second half of the area texture\n fn areaDiag(dist: vec2f, e: vec2f) -> vec2f {\n var texcoord = vec2f(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 textureSampleLevel(smaaAreaTexture, smaaAreaTextureSampler, texcoord, 0.0).rg;\n }\n\n // the blending weights for the diagonal lines through the pixel\n fn calculateDiagWeights(texcoord: vec2f, e: vec2f) -> vec2f {\n var weights = vec2f(0.0);\n let metrics = uniform.smaaMetrics;\n\n // the line ends\n var d = vec4f(0.0);\n if (e.r > 0.0) {\n let search = searchDiag1(texcoord, vec2f(-1.0, 1.0));\n d.x = search.result.x + select(0.0, 1.0, search.e.y > 0.9);\n d.z = search.result.y;\n }\n let search1 = searchDiag1(texcoord, vec2f(1.0, -1.0));\n d.y = search1.result.x;\n d.w = search1.result.y;\n\n if (d.x + d.y > 2.0) {\n\n // the crossing edges\n let coords = vec4f(-d.x + 0.25, d.x, d.y, -d.y - 0.25) * metrics.xyxy + texcoord.xyxy;\n let decoded = decodeDiagBilinearAccess4(vec4f(sampleEdgesOffset(coords.xy, vec2f(-1.0, 0.0)), sampleEdgesOffset(coords.zw, vec2f(1.0, 0.0))));\n let c = decoded.yxwz;\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 var cc = vec2f(2.0) * c.xz + c.yw;\n cc = mix(cc, vec2f(0.0), step(vec2f(0.9), d.zw));\n\n weights += areaDiag(d.xy, cc);\n }\n\n // the other diagonal\n let search2 = searchDiag2(texcoord, vec2f(-1.0, -1.0));\n d.x = search2.result.x;\n d.z = search2.result.y;\n if (sampleEdgesOffset(texcoord, vec2f(1.0, 0.0)).r > 0.0) {\n let search3 = searchDiag2(texcoord, vec2f(1.0, 1.0));\n d.y = search3.result.x + select(0.0, 1.0, search3.e.y > 0.9);\n d.w = search3.result.y;\n } else {\n d.y = 0.0;\n d.w = 0.0;\n }\n\n if (d.x + d.y > 2.0) {\n let coords = vec4f(-d.x, -d.x, d.y, d.y) * metrics.xyxy + texcoord.xyxy;\n let right = sampleEdgesOffset(coords.zw, vec2f(1.0, 0.0));\n let c = vec4f(\n sampleEdgesOffset(coords.xy, vec2f(-1.0, 0.0)).g,\n sampleEdgesOffset(coords.xy, vec2f(0.0, -1.0)).r,\n right.g,\n right.r\n );\n var cc = vec2f(2.0) * c.xz + c.yw;\n cc = mix(cc, vec2f(0.0), step(vec2f(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 fn searchLength(e: vec2f, offset: f32) -> f32 {\n\n // the texture is flipped vertically, with the left and the right cases taking half of it\n // horizontally each\n var scale = SMAA_SEARCHTEX_SIZE * vec2f(0.5, -1.0);\n var bias = SMAA_SEARCHTEX_SIZE * vec2f(offset, 1.0);\n\n // scale and bias to access the texel centers, in the cropped texture\n scale += vec2f(-1.0, 1.0);\n bias += vec2f(0.5, -0.5);\n scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;\n bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;\n\n return textureSampleLevel(smaaSearchTexture, smaaSearchTextureSampler, 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 fn searchXLeft(start: vec2f, end: f32) -> f32 {\n var texcoord = start;\n var e = vec2f(0.0, 1.0);\n while (texcoord.x > end && e.g > 0.8281 && e.r == 0.0) {\n e = sampleEdges(texcoord);\n texcoord = -vec2f(2.0, 0.0) * uniform.smaaMetrics.xy + texcoord;\n }\n let offset = -(255.0 / 127.0) * searchLength(e, 0.0) + 3.25;\n return uniform.smaaMetrics.x * offset + texcoord.x;\n }\n\n fn searchXRight(start: vec2f, end: f32) -> f32 {\n var texcoord = start;\n var e = vec2f(0.0, 1.0);\n while (texcoord.x < end && e.g > 0.8281 && e.r == 0.0) {\n e = sampleEdges(texcoord);\n texcoord = vec2f(2.0, 0.0) * uniform.smaaMetrics.xy + texcoord;\n }\n let offset = -(255.0 / 127.0) * searchLength(e, 0.5) + 3.25;\n return -uniform.smaaMetrics.x * offset + texcoord.x;\n }\n\n fn searchYUp(start: vec2f, end: f32) -> f32 {\n var texcoord = start;\n var e = vec2f(1.0, 0.0);\n while (texcoord.y > end && e.r > 0.8281 && e.g == 0.0) {\n e = sampleEdges(texcoord);\n texcoord = -vec2f(0.0, 2.0) * uniform.smaaMetrics.xy + texcoord;\n }\n let offset = -(255.0 / 127.0) * searchLength(e.gr, 0.0) + 3.25;\n return uniform.smaaMetrics.y * offset + texcoord.y;\n }\n\n fn searchYDown(start: vec2f, end: f32) -> f32 {\n var texcoord = start;\n var e = vec2f(1.0, 0.0);\n while (texcoord.y < end && e.r > 0.8281 && e.g == 0.0) {\n e = sampleEdges(texcoord);\n texcoord = vec2f(0.0, 2.0) * uniform.smaaMetrics.xy + texcoord;\n }\n let offset = -(255.0 / 127.0) * searchLength(e.gr, 0.5) + 3.25;\n return -uniform.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 fn area(dist: vec2f, e1: f32, e2: f32) -> vec2f {\n var texcoord = vec2f(SMAA_AREATEX_MAX_DISTANCE) * round(4.0 * vec2f(e1, e2)) + dist;\n texcoord = SMAA_AREATEX_PIXEL_SIZE * texcoord + 0.5 * SMAA_AREATEX_PIXEL_SIZE;\n return textureSampleLevel(smaaAreaTexture, smaaAreaTextureSampler, 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 fn detectHorizontalCornerPattern(weights: vec2f, texcoord: vec4f, d: vec2f) -> vec2f {\n let leftRight = step(d.xy, d.yx);\n var rounding = (1.0 - uniform.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 var factor = vec2f(1.0);\n factor.x -= rounding.x * sampleEdgesOffset(texcoord.xy, vec2f(0.0, 1.0)).r;\n factor.x -= rounding.y * sampleEdgesOffset(texcoord.zw, vec2f(1.0, 1.0)).r;\n factor.y -= rounding.x * sampleEdgesOffset(texcoord.xy, vec2f(0.0, -2.0)).r;\n factor.y -= rounding.y * sampleEdgesOffset(texcoord.zw, vec2f(1.0, -2.0)).r;\n return weights * clamp(factor, vec2f(0.0), vec2f(1.0));\n }\n\n fn detectVerticalCornerPattern(weights: vec2f, texcoord: vec4f, d: vec2f) -> vec2f {\n let leftRight = step(d.xy, d.yx);\n var rounding = (1.0 - uniform.smaaParams.w) * leftRight;\n rounding /= leftRight.x + leftRight.y;\n\n var factor = vec2f(1.0);\n factor.x -= rounding.x * sampleEdgesOffset(texcoord.xy, vec2f(1.0, 0.0)).g;\n factor.x -= rounding.y * sampleEdgesOffset(texcoord.zw, vec2f(1.0, 1.0)).g;\n factor.y -= rounding.x * sampleEdgesOffset(texcoord.xy, vec2f(-2.0, 0.0)).g;\n factor.y -= rounding.y * sampleEdgesOffset(texcoord.zw, vec2f(-2.0, 1.0)).g;\n return weights * clamp(factor, vec2f(0.0), vec2f(1.0));\n }\n\n @fragment\n fn fragmentMain(input: FragmentInput) -> FragmentOutput {\n var output: FragmentOutput;\n let texcoord = uv0;\n let metrics = uniform.smaaMetrics;\n let pixcoord = texcoord * metrics.zw;\n\n // the offsets of the searches, and the ends of their loops\n let offset0 = metrics.xyxy * vec4f(-0.25, -0.125, 1.25, -0.125) + texcoord.xyxy;\n let offset1 = metrics.xyxy * vec4f(-0.125, -0.25, -0.125, 1.25) + texcoord.xyxy;\n let offset2 = metrics.xxyy * (vec4f(-2.0, 2.0, -2.0, 2.0) * uniform.smaaParams.y) + vec4f(offset0.xz, offset1.yw);\n\n var weights = vec4f(0.0);\n var 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 (uniform.smaaParams.z > 0.0) {\n let diag = calculateDiagWeights(texcoord, e);\n weights = vec4f(diag, weights.zw);\n }\n\n // no diagonal line through the pixel, so a horizontal one\n if (weights.r == -weights.g) {\n let left = searchXLeft(offset0.xy, offset2.x);\n let y = offset1.y;\n\n // the crossing edges at the ends, fetched with bilinear filtering to read both of\n // a pair at once\n let e1 = textureSampleLevel(smaaEdgesTexture, smaaEdgesTextureSampler, vec2f(left, y), 0.0).r;\n let right = searchXRight(offset0.zw, offset2.y);\n\n // the distances in pixels, their square roots giving the area texture its range\n let d = abs(round(metrics.zz * vec2f(left, right) - pixcoord.xx));\n let sqrtD = sqrt(d);\n let e2 = sampleEdgesOffset(vec2f(right, y), vec2f(1.0, 0.0)).r;\n let horizontal = detectHorizontalCornerPattern(area(sqrtD, e1, e2), vec4f(left, texcoord.y, right, texcoord.y), d);\n weights = vec4f(horizontal, weights.zw);\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 let up = searchYUp(offset1.xy, offset2.z);\n let x = offset0.x;\n\n let e1 = textureSampleLevel(smaaEdgesTexture, smaaEdgesTextureSampler, vec2f(x, up), 0.0).g;\n let down = searchYDown(offset1.zw, offset2.w);\n\n let d = abs(round(metrics.ww * vec2f(up, down) - pixcoord.yy));\n let sqrtD = sqrt(d);\n let e2 = sampleEdgesOffset(vec2f(x, down), vec2f(0.0, 1.0)).g;\n let vertical = detectVerticalCornerPattern(area(sqrtD, e1, e2), vec4f(texcoord.x, up, texcoord.x, down), d);\n weights = vec4f(weights.xy, vertical);\n }\n\n output.color = weights;\n return output;\n }\n"; export default _default;