declare const _default: "\n #include \"sampleCatmullRomPS\"\n #include \"reversibleTonemapPS\"\n #include \"screenDepthPS\"\n\n uniform sampler2D sourceTexture;\n uniform sampler2D historyTexture;\n uniform mat4 matrix_viewProjectionPrevious;\n uniform mat4 matrix_viewProjectionInverse;\n uniform float taaExposure; // the exposure the scene is displayed with\n uniform vec4 jitters; // xy: current frame, zw: previous frame\n uniform vec2 textureSize;\n uniform vec2 historySize;\n\n varying vec2 uv0;\n\n // the most of the current frame taken while the camera moves the surface of a pixel across the\n // screen, and the motion from which it is taken, in pixels of the history\n const float TAA_MOTION_BLEND = 0.5;\n const float TAA_MOTION_PIXELS = 32.0;\n\n vec2 reproject(vec2 uv, float depth) {\n\n // fragment NDC\n depth = depth * 2.0 - 1.0;\n vec4 ndc = vec4(uv * 2.0 - 1.0, depth, 1.0);\n\n // remove jitter from the current frame\n ndc.xy -= jitters.xy;\n\n // Transform NDC to world space of the current frame\n vec4 worldPosition = matrix_viewProjectionInverse * ndc;\n worldPosition /= worldPosition.w;\n\n // world position to screen space of the previous frame\n vec4 screenPrevious = matrix_viewProjectionPrevious * worldPosition;\n\n // remove the jitter of the previous frame, as the history holds the image without it\n return (screenPrevious.xy / screenPrevious.w + jitters.zw) * 0.5 + 0.5;\n }\n\n vec3 colorClampPremul(vec2 uv, vec3 historyPremul) {\n\n vec3 minPremul = vec3(9999.0);\n vec3 maxPremul = vec3(-9999.0);\n\n // 3x3 neighborhood in premultiplied space \u2014 same domain as the temporal mix (see main()).\n for(float x = -1.0; x <= 1.0; ++x) {\n for(float y = -1.0; y <= 1.0; ++y) {\n vec4 s = texture2D(sourceTexture, uv + vec2(x, y) / textureSize);\n vec3 premul = s.rgb * s.a;\n minPremul = min(minPremul, premul);\n maxPremul = max(maxPremul, premul);\n }\n }\n\n return clamp(historyPremul, minPremul, maxPremul);\n }\n\n #ifdef TAA_UPSCALE\n\n // The current frame renders at a lower resolution than the history. Each of its texels holds\n // the image at its center moved by the jitter of the frame, so from frame to frame its sample\n // lands at a different position within the pixels of the history. The current color at this\n // pixel is reconstructed from the texels around it, weighted by how close their samples are\n // to it, and the weight of the nearest decides how much of it the history takes - over the\n // jitter sequence, each pixel of the history accumulates the samples landing on it.\n vec4 upscaleCurrent(vec2 uv, out float weight, out vec3 minPremul, out vec3 maxPremul) {\n\n // this pixel and the jitter, in texels of the current frame\n vec2 position = uv * textureSize;\n vec2 jitter = jitters.xy * 0.5 * textureSize;\n\n // the texel whose sample is nearest to this pixel\n vec2 nearest = floor(position - jitter);\n\n // pixels of the history per texel of the current frame\n float scale = historySize.x / textureSize.x;\n\n vec4 sum = vec4(0.0);\n float sumWeight = 0.0;\n vec4 nearestColor = vec4(0.0);\n weight = 0.0;\n minPremul = vec3(9999.0);\n maxPremul = vec3(-9999.0);\n for (float x = -1.0; x <= 1.0; ++x) {\n for (float y = -1.0; y <= 1.0; ++y) {\n vec2 texel = nearest + vec2(x, y);\n vec4 s = texture2DLod(sourceTexture, (texel + 0.5) / textureSize, 0.0);\n vec3 premul = s.rgb * s.a;\n minPremul = min(minPremul, premul);\n maxPremul = max(maxPremul, premul);\n if (x == 0.0 && y == 0.0) {\n nearestColor = s;\n }\n\n // the distance of its sample to this pixel, in pixels of the history\n vec2 d = (texel + 0.5 + jitter - position) * scale;\n float w = exp(-2.29 * dot(d, d));\n sum += s * w;\n sumWeight += w;\n weight = max(weight, w);\n }\n }\n return sumWeight > 1e-4 ? sum / sumWeight : nearestColor;\n }\n\n #endif\n\n void main()\n {\n // current frame\n #ifdef TAA_UPSCALE\n float currentWeight;\n vec3 minPremul;\n vec3 maxPremul;\n vec4 srcColor = upscaleCurrent(uv0, currentWeight, minPremul, maxPremul);\n #else\n vec4 srcColor = texture2D(sourceTexture, uv0);\n #endif\n\n // current depth is in linear space, convert it to non-linear space\n float linearDepth = getLinearScreenDepth(uv0);\n float depth = delinearizeDepth(linearDepth);\n\n // previous frame\n vec2 historyUv = reproject(uv0, depth);\n\n #ifdef QUALITY_HIGH\n\n vec4 historySample = SampleTextureCatmullRom(TEXTURE_PASS(historyTexture), historyUv, historySize);\n\n #else\n\n vec4 historySample = texture2D(historyTexture, historyUv);\n\n #endif\n\n // Premultiplied (rgb * a) is the coverage-correct space for TAA: straight RGB interpolates\n // uncorrelated color and opacity at edges, which causes colored fringes and alpha-related\n // ghosting when history is blended or clamped against a 3x3 neighborhood. We clamp and mix\n // in premultiplied space, then un-premultiply once using the current frame's alpha only\n // (alpha is not temporally filtered \u2014 output stays tied to this frame's coverage).\n vec3 historyPremul = historySample.rgb * historySample.a;\n vec3 srcPremul = srcColor.rgb * srcColor.a;\n\n #ifdef TAA_UPSCALE\n // clamped to the range of the texels around this pixel, and taking more of the current\n // frame the closer its nearest sample is to this pixel\n vec3 historyPremulClamped = clamp(historyPremul, minPremul, maxPremul);\n float blend = 0.1 * currentWeight;\n #else\n vec3 historyPremulClamped = colorClampPremul(uv0, historyPremul);\n float blend = 0.05;\n #endif\n\n // The further the history of this pixel was reprojected from, the faster the camera moves its\n // surface across the screen: the history has been resampled further, which blurs it, and it is\n // more likely not to hold this surface at all. The current frame is then taken more of, up to\n // TAA_MOTION_BLEND from a motion of TAA_MOTION_PIXELS pixels of the history - while the camera\n // is still, the history accumulates as before.\n float motion = length((uv0 - historyUv) * historySize);\n blend = mix(blend, max(blend, TAA_MOTION_BLEND), clamp(motion / TAA_MOTION_PIXELS, 0.0, 1.0));\n\n float mixFactor = (historyUv.x < 0.0 || historyUv.x > 1.0 || historyUv.y < 0.0 || historyUv.y > 1.0) ?\n 1.0 : blend;\n\n // The history and the current frame are blended compressed by a reversible tone mapping of\n // their exposed values. Blended in linear HDR, the samples of a bright surface partially\n // covering a pixel dominate its average, which the tone mapping then displays nearly as\n // bright as the surface - the edges of bright geometry would stay thick and aliased.\n float e = max(taaExposure, 1e-6);\n vec3 mixedPremul = reversibleTonemapInverse(mix(reversibleTonemap(historyPremulClamped * e), reversibleTonemap(srcPremul * e), mixFactor)) / e;\n float a = srcColor.a;\n // Match UNORM8 alpha quantum: below one step, un-premul is ill-defined / noisy; use current RGB.\n const float UNPREMUL_EPS = 1.0 / 255.0;\n vec3 rgbStraight = (a > UNPREMUL_EPS) ? (mixedPremul / a) : srcColor.rgb;\n gl_FragColor = vec4(rgbStraight, a);\n }\n"; export default _default;