32 lines
867 B
GLSL
32 lines
867 B
GLSL
#include "/Lib/Settings.glsl"
|
|
#include "/Lib/Utilities.glsl"
|
|
// MinecraftPT — Diffuse Variance Estimation
|
|
// Computes luminance moments to drive temporal accumulation and firefly rejection.
|
|
|
|
#ifndef DIFFUSE_VARIANCE_ESTIMATION_GLSL
|
|
#define DIFFUSE_VARIANCE_ESTIMATION_GLSL
|
|
|
|
#include "/Lib/Utilities.glsl"
|
|
|
|
vec2 DiffuseEstimateVariance(vec3 color, vec2 texelCoord){
|
|
float lum = luminance(color);
|
|
float lum2 = lum * lum;
|
|
|
|
// Local variance from neighbors (5-tap)
|
|
float variance = 0.0;
|
|
for (int i = -1; i <= 1; i++){
|
|
for (int j = -1; j <= 1; j++){
|
|
if (i == 0 && j == 0) continue;
|
|
vec3 c = texelFetch(colortex7, ivec2(texelCoord) + ivec2(i, j), 0).rgb;
|
|
float l = luminance(c);
|
|
variance += (l - lum) * (l - lum);
|
|
}}
|
|
variance /= 8.0;
|
|
|
|
// Clamp fireflies
|
|
float firefly = step(1.0, lum / max(variance * 4.0, 0.001));
|
|
|
|
return vec2(lum, firefly);
|
|
}
|
|
|
|
#endif |