DoorNroll/assets/shaders/postprocess.fs

78 lines
2.5 KiB
GLSL

#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform float u_time;
uniform float u_glitchIntensity;
uniform vec2 u_resolution;
uniform int u_preset;
// Output fragment color
out vec4 finalColor;
void main()
{
vec2 uv = fragTexCoord;
// 1. Digital Glitch / Tactical Chromatic Aberration
float glitch = (u_preset >= 2) ? clamp(u_glitchIntensity, 0.0, 1.0) : 0.0;
if (glitch > 0.001)
{
// Horizontal line slice displacement
float slice = step(0.68, sin(uv.y * 42.0 + u_time * 30.0));
float sliceOffset = (slice * 2.0 - 1.0) * 0.015 * glitch;
uv.x += sliceOffset;
// Chromatic RGB separation
float split = 0.010 * glitch;
float r = texture(texture0, vec2(uv.x + split, uv.y)).r;
float g = texture(texture0, uv).g;
float b = texture(texture0, vec2(uv.x - split, uv.y)).b;
finalColor = vec4(r, g, b, 1.0);
}
else
{
finalColor = texture(texture0, uv);
}
// 2. Tactical Color Grading (High Contrast Monochrome + Vivid Crimson Accent)
// Desaturate non-red tones toward tactical gunmetal/monochrome
float luma = dot(finalColor.rgb, vec3(0.299, 0.587, 0.114));
// Check if the color is an intentional tactical accent (Crimson, Cobalt EMP, Amber, Acid, Violet)
float maxC = max(finalColor.r, max(finalColor.g, finalColor.b));
float minC = min(finalColor.r, min(finalColor.g, finalColor.b));
float sat = (maxC > 0.05) ? ((maxC - minC) / maxC) : 0.0;
bool isTacticalAccent = (sat > 0.36) || (finalColor.r > 0.35 && finalColor.r > finalColor.g * 1.3);
if (!isTacticalAccent)
{
// Pull low-saturation environmental surfaces toward high-contrast monochrome steel
vec3 mono = vec3(luma);
finalColor.rgb = mix(finalColor.rgb, mono, 0.80);
}
// Enhance contrast (crush deep blacks, crispen bright highlights)
finalColor.rgb = (finalColor.rgb - 0.5) * 1.18 + 0.5;
finalColor.rgb = clamp(finalColor.rgb, 0.0, 1.0);
// 3. Cinematic Corner Vignette (Tactical Helmet Visor Shadow)
float d = distance(uv, vec2(0.5, 0.5));
float vignette = smoothstep(0.78, 0.32, d);
finalColor.rgb *= mix(0.40, 1.0, vignette);
// 4. Subtle Tactical CRT Scanlines (Ultra mode only)
if (u_preset >= 2)
{
float scanline = sin(uv.y * u_resolution.y * 1.5) * 0.025;
finalColor.rgb -= scanline;
}
finalColor.a = 1.0;
}