From 1bedff2affac95e715adac0fea590eb53b780c94 Mon Sep 17 00:00:00 2001 From: Anemunt <69436164+darkresident55@users.noreply.github.com> Date: Sat, 27 Dec 2025 21:46:33 -0500 Subject: [PATCH] fixed light flickering when rotating an object. --- Resources/Shaders/postfx_bright_frag.glsl | 6 +++-- Resources/Shaders/postfx_frag.glsl | 30 ++++++++++------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Resources/Shaders/postfx_bright_frag.glsl b/Resources/Shaders/postfx_bright_frag.glsl index 0e2369c..8482a18 100644 --- a/Resources/Shaders/postfx_bright_frag.glsl +++ b/Resources/Shaders/postfx_bright_frag.glsl @@ -9,7 +9,9 @@ uniform float threshold = 1.0; void main() { vec3 c = texture(sceneTex, TexCoord).rgb; float luma = dot(c, vec3(0.2125, 0.7154, 0.0721)); - float bright = max(luma - threshold, 0.0); - vec3 masked = c * step(0.0, bright); + float knee = 0.25; + float w = clamp((luma - threshold) / max(knee, 1e-4), 0.0, 1.0); + w = w * w * (3.0 - 2.0 * w); + vec3 masked = c * w; FragColor = vec4(masked, 1.0); } diff --git a/Resources/Shaders/postfx_frag.glsl b/Resources/Shaders/postfx_frag.glsl index d2047ba..be3dc6e 100644 --- a/Resources/Shaders/postfx_frag.glsl +++ b/Resources/Shaders/postfx_frag.glsl @@ -42,17 +42,8 @@ vec3 applyColorAdjust(vec3 color) { return color; } -vec3 sampleCombined(vec2 uv) { - vec3 c = texture(sceneTex, uv).rgb; - if (enableBloom) { - vec3 glow = texture(bloomTex, uv).rgb * bloomIntensity; - c += glow; - } - return c; -} - -vec3 sampleAdjusted(vec2 uv) { - return applyColorAdjust(sampleCombined(uv)); +vec3 sampleBase(vec2 uv) { + return applyColorAdjust(texture(sceneTex, uv).rgb); } float luminance(vec3 c) { @@ -66,24 +57,24 @@ float computeVignette(vec2 uv) { } vec3 applyChromatic(vec2 uv) { - vec3 base = sampleAdjusted(uv); + vec3 base = sampleBase(uv); vec2 dir = uv - vec2(0.5); float dist = max(length(dir), 0.0001); vec2 offset = normalize(dir) * chromaticAmount * (1.0 + dist * 2.0); - vec3 rSample = sampleAdjusted(uv + offset); - vec3 bSample = sampleAdjusted(uv - offset); + vec3 rSample = sampleBase(uv + offset); + vec3 bSample = sampleBase(uv - offset); vec3 ca = vec3(rSample.r, base.g, bSample.b); return mix(base, ca, 0.85); } float computeAOFactor(vec2 uv) { - vec3 centerColor = sampleAdjusted(uv); + vec3 centerColor = sampleBase(uv); float centerLum = luminance(centerColor); float occlusion = 0.0; vec2 directions[4] = vec2[](vec2(1.0, 0.0), vec2(-1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, -1.0)); for (int i = 0; i < 4; ++i) { vec2 sampleUv = uv + directions[i] * aoRadius; - vec3 sampleColor = sampleAdjusted(sampleUv); + vec3 sampleColor = sampleBase(sampleUv); float sampleLum = luminance(sampleColor); occlusion += max(0.0, centerLum - sampleLum); } @@ -92,7 +83,7 @@ float computeAOFactor(vec2 uv) { } void main() { - vec3 color = sampleAdjusted(TexCoord); + vec3 color = sampleBase(TexCoord); if (enableChromatic) { color = applyChromatic(TexCoord); @@ -132,5 +123,10 @@ void main() { } } + if (enableBloom) { + vec3 glow = texture(bloomTex, TexCoord).rgb * bloomIntensity; + color += glow; + } + FragColor = vec4(color, 1.0); }