Last active
March 14, 2025 09:27
-
-
Save lukad/d979a36ed9a83020bd6fa3fa0d5d7c89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add this to your ghostty config: | |
// custom-shader = "<path to retro.glsl>" | |
#define DISTORTION 0.1 | |
#define BASE_ABERRATION 0.0015 | |
float rand(vec2 co) | |
{ | |
return fract(sin(dot(co.xy, vec2(12.0909, 78.233))) * 43758.5453); | |
} | |
vec2 radialDistortion(vec2 coord) { | |
vec2 center = coord - 0.5; | |
float aspect = iResolution.x / iResolution.y; | |
center.x *= aspect; | |
float dist = length(center) * length(center) * DISTORTION; | |
center *= (1.0 + dist); | |
center.x /= aspect; | |
return center + 0.5; | |
} | |
float vignette(vec2 coord) { | |
coord = (coord - vec2(0.5)) + vec2(0.5); | |
coord = min(coord, vec2(1.0) - coord) * vec2(1.0, 0.75); | |
vec2 cdist = vec2(0.02); | |
coord = (cdist - min(coord, cdist)); | |
float dist = sqrt(dot(coord, coord)); | |
return clamp((cdist.x - dist) * 200.0, 0.5, 1.0); | |
} | |
void mainImage(out vec4 fragColor, in vec2 fragCoord) { | |
vec2 uv = fragCoord / iResolution.xy; | |
uv = radialDistortion(uv); | |
vec4 color = texture2D(iChannel0, uv); | |
float referenceWidth = 2560.0; | |
float aberrationScale = referenceWidth / iResolution.x; | |
float aberration_factor = 1.0; | |
float chance = rand(vec2(floor(iTime * 0.5), tan(iTime * 0.5))); | |
if (chance > 0.95) { | |
aberration_factor = 1.5 + 3.0 * rand(vec2(iTime, iTime * 0.3)); | |
} | |
float base_aberration = BASE_ABERRATION * aberration_factor; | |
float color_r = texture2D(iChannel0, uv + vec2(base_aberration * aberrationScale, 0.0)).r; | |
float color_b = texture2D(iChannel0, uv + vec2(-base_aberration * aberrationScale, 0.0)).b; | |
color.rgb = vec3(color_r, color.g, color_b); | |
// tint | |
color *= vec4(1.0, 1.1, 1.2, 1.0); | |
// scanlines | |
color.rgb *= 0.8 + 0.2 * sin(5.0 * iTime + uv.y * 900.0); | |
// flicker | |
color.rgb *= 1.0 - 0.05 * rand(vec2(iTime, tan(iTime))); | |
// vignette | |
color.rgb *= vignette(uv); | |
fragColor = color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment