0
vec3 crntCol = sharpen();
#else
vec3 crntCol = sample(u_inputRt, in_uv);
#endif
// Remove ghosting by clamping the history color to neighbour's AABB
vec3 near0 = sampleOffset(u_inputRt, in_uv, 1, 0);
vec3 near1 = sampleOffset(u_inputRt, in_uv, 0, 1);
vec3 near2 = sampleOffset(u_inputRt, in_uv, -1, 0);
vec3 near3 = sampleOffset(u_inputRt, in_uv, 0, -1);
#if VARIANCE_CLIPPING
vec3 m1 = crntCol + near0 + near1 + near2 + near3;
vec3 m2 = crntCol * crntCol + near0 * near0 + near1 * near1 + near2 * near2 + near3 * near3;
vec3 mu = m1 / 5.0;
vec3 sigma = sqrt(m2 / 5.0 - mu * mu);
vec3 boxMin = mu - VARIANCE_CLIPPING_GAMMA * sigma;
vec3 boxMax = mu + VARIANCE_CLIPPING_GAMMA * sigma;
#else
vec3 boxMin = min(crntCol, min(near0, min(near1, min(near2, near3))));
vec3 boxMax = max(crntCol, max(near0, max(near1, max(near2, near3))));
#endif
historyCol = clamp(historyCol, boxMin, boxMax);
// Remove jitter (T. Lottes)
#if YCBCR
float lum0 = crntCol.r;
float lum1 = historyCol.r;
float maxLum = boxMax.r;
#elif TONEMAP_FIX
float lum0 = computeLuminance(tonemap(crntCol, u_exposureThreshold0));
float lum1 = computeLuminance(tonemap(historyCol, u_exposureThreshold0));
//float maxLum = computeLuminance(tonemap(boxMax, u_exposureThreshold0));
float maxLum = 1.0;
#else
float lum0 = computeLuminance(crntCol);
float lum1 = computeLuminance(historyCol);
float maxLum = computeLuminance(boxMax);
#endif
float diff = abs(lum0 - lum1) / max(lum0, max(lum1, maxLum + EPSILON));
diff = 1.0 - diff;
diff = diff * diff;
float feedback = mix(0.0, BLEND_FACTOR, diff);
// Write result
#if YCBCR
out_color = yCbCrToRgb(mix(historyCol, crntCol, feedback));
#else
out_color = mix(historyCol, crntCol, feedback);
#endif
}
]]>