Files
LNXSDK/leenkx/Shaders/blur_adaptive_pass/blur_adaptive_pass.frag.glsl

61 lines
1.4 KiB
Plaintext
Raw Normal View History

2025-01-22 16:18:30 +01:00
// Exclusive to SSR for now
#version 450
#include "compiled.inc"
#include "std/gbuffer.glsl"
uniform sampler2D tex;
uniform sampler2D gbuffer0; // Roughness
2026-08-07 02:04:01 -07:00
uniform sampler2D gbufferD; // Depth
2025-01-22 16:18:30 +01:00
uniform vec2 dirInv;
in vec2 texCoord;
out vec4 fragColor;
void main() {
float roughness = textureLod(gbuffer0, texCoord, 0.0).b;
2026-08-07 02:04:01 -07:00
if (roughness >= 0.8) {
2025-01-22 16:18:30 +01:00
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
return;
}
2026-08-07 02:04:01 -07:00
if (roughness < 0.01) {
fragColor.rgb = textureLod(tex, texCoord, 0.0).rgb;
return;
}
float blurRadius = 1.0 + roughness * 4.0;
vec3 center = textureLod(tex, texCoord, 0.0).rgb;
float centerDepth = textureLod(gbufferD, texCoord, 0.0).r;
float w0 = 1.0 / (1.0 + roughness * 2.0);
float w1 = 1.0 / (1.0 + roughness);
float w2 = 1.0 / (1.0 + roughness * 0.5);
float totalW = w0;
fragColor.rgb = center * w0;
vec2 offsets[4];
offsets[0] = dirInv * blurRadius * 2.5;
offsets[1] = dirInv * blurRadius * 1.5;
offsets[2] = -dirInv * blurRadius * 1.5;
offsets[3] = -dirInv * blurRadius * 2.5;
float weights[4];
weights[0] = w2;
weights[1] = w1;
weights[2] = w1;
weights[3] = w2;
for (int i = 0; i < 4; i++) {
vec2 sampleTC = texCoord + offsets[i];
float sampleDepth = textureLod(gbufferD, sampleTC, 0.0).r;
float depthWeight = exp(-abs(centerDepth - sampleDepth) * 100.0);
float w = weights[i] * depthWeight;
fragColor.rgb += textureLod(tex, sampleTC, 0.0).rgb * w;
totalW += w;
}
fragColor.rgb /= vec3(totalW);
2025-01-22 16:18:30 +01:00
}