83 lines
2.1 KiB
GLSL
83 lines
2.1 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;
|
|
|
|
// Output fragment color
|
|
out vec4 finalColor;
|
|
|
|
void main()
|
|
{
|
|
vec2 uv = fragTexCoord;
|
|
|
|
// 1. Digital Glitch / Chromatic Aberration
|
|
float glitch = clamp(u_glitchIntensity, 0.0, 1.0);
|
|
if (glitch > 0.001)
|
|
{
|
|
// Horizontal line slice displacement
|
|
float slice = step(0.65, sin(uv.y * 35.0 + u_time * 25.0));
|
|
float sliceOffset = (slice * 2.0 - 1.0) * 0.018 * glitch;
|
|
uv.x += sliceOffset;
|
|
|
|
// Chromatic RGB separation
|
|
float split = 0.012 * 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. Neon Bloom / Emissive Halo
|
|
vec2 texel = 1.0 / u_resolution;
|
|
vec3 bloom = vec3(0.0);
|
|
float bloomWeight = 0.0;
|
|
|
|
// 9-tap bright-pass sample
|
|
vec2 offsets[8] = vec2[](
|
|
vec2(-2.0, 0.0), vec2( 2.0, 0.0),
|
|
vec2( 0.0, -2.0), vec2( 0.0, 2.0),
|
|
vec2(-1.5, -1.5), vec2( 1.5, -1.5),
|
|
vec2(-1.5, 1.5), vec2( 1.5, 1.5)
|
|
);
|
|
|
|
for (int i = 0; i < 8; ++i)
|
|
{
|
|
vec3 col = texture(texture0, uv + offsets[i] * texel * 1.8).rgb;
|
|
float brightness = dot(col, vec3(0.2126, 0.7152, 0.0722));
|
|
if (brightness > 0.55)
|
|
{
|
|
bloom += (col - 0.45) * 1.4;
|
|
bloomWeight += 1.0;
|
|
}
|
|
}
|
|
|
|
if (bloomWeight > 0.0)
|
|
{
|
|
bloom /= 8.0;
|
|
finalColor.rgb += bloom * 0.75;
|
|
}
|
|
|
|
// 3. Vignette (Smooth cinematic edge darkening)
|
|
float d = distance(uv, vec2(0.5, 0.5));
|
|
float vignette = smoothstep(0.82, 0.38, d);
|
|
finalColor.rgb *= mix(0.58, 1.0, vignette);
|
|
|
|
// 4. Subtle Cyber Scanlines
|
|
float scanline = sin(uv.y * u_resolution.y * 1.8) * 0.035;
|
|
finalColor.rgb -= scanline;
|
|
|
|
finalColor.a = 1.0;
|
|
}
|