precision highp float; varying vec2 uv; uniform sampler2D image, glyphs, toneMap; uniform vec2 resolution, sourceSize, pointer, focus, parallax, glyphCell, chromaDrift; uniform float time, exposure, raster, rasterSeed, ascii, pointerEnergy, breathing, moonSway, stationSymbol, chroma; const vec3 ACCENT = vec3(.78, .624, .937); const float ACCENT_STRENGTH = .12; float b2(vec2 p) { p = floor(mod(p, 2.)); return mod(2. * p.x + 3. * p.y, 4.); } float b8(vec2 p) { return (b2(p) * 16. + b2(p / 2.) * 4. + b2(p / 4.) + .5) / 64.; } float hash(vec2 p) { return fract(sin(dot(p, vec2(12.9898, 78.233))) * 437.5453); } float luminance(vec2 p) { float light = texture2D(image, p).r; if (stationSymbol < .5) return light; // The ⎔ is attached to the same source-space wire as the moon ornament. vec2 relative = abs(p * vec2(1672., 941.) - vec2(998., 941. - 420.)); float hexagon = max(relative.y, dot(relative, vec2(.8660254, .5))); float face = 1. - smoothstep(20., 21., hexagon); float outline = 1. - smoothstep(1.3, 2.2, abs(hexagon - 18.)); return mix(light, mix(.035, .9, outline), face); } vec2 pendulum(vec2 p) { if (moonSway < .5) return p; // Source-space pivot: the hanging wire above the station's moon ornament. // A feathered local rotation leaves the architecture outside it stationary. vec2 originalSize = vec2(1672., 941.); vec2 relative = p * originalSize - vec2(998., originalSize.y - 180.); float mask = (1. - smoothstep(44., 68., abs(relative.x))) * smoothstep(0., 24., -relative.y) * (1. - smoothstep(272., 296., -relative.y)); float angle = sin(time * 1.08) * .024 + sin(time * .63 + 1.2) * .006; float c = cos(angle), s = sin(angle); vec2 rotated = vec2(c * relative.x - s * relative.y, s * relative.x + c * relative.y); return p + (rotated - relative) * mask / originalSize; } void main() { vec2 pixel = floor(uv * resolution); float aspect = resolution.x / resolution.y; float sourceAspect = sourceSize.x / sourceSize.y; vec2 crop = vec2(min(1., aspect / sourceAspect), min(1., sourceAspect / aspect)) * .9; vec2 sourceUv = uv * crop + focus * (1. - crop) + parallax / resolution * crop; vec2 sampleUv = pendulum(sourceUv); float tone = texture2D(toneMap, sourceUv).r; float breath = sin(time * .55 + tone * 2.8 + uv.y * 2.) * breathing; float lightness = smoothstep(.08, .85, tone); // Lighter material moves farther and out of phase with the shadows beneath it. vec2 flow = vec2(sin(uv.y * 6. + time * .19), cos(uv.x * 5. - time * .23)); sampleUv += flow * breath * (.2 + lightness * lightness * 2.8) / resolution * crop; float pulse = 0., influence = 0.; if (pointerEnergy > .005) { float distance = length((uv - pointer) * resolution); influence = pow(max(0., 1. - distance / 84.), 2.) * pointerEnergy; pulse = sin(distance * .09 - time * 3.) * influence; sampleUv.x += pulse * .006; } float offset = 0.; if (raster > 0.) { float row = floor(pixel.y / 5.); float slipped = step(.82, hash(vec2(row, rasterSeed))); offset = slipped * floor(sin(row * 7. + rasterSeed) * 7. * raster) / resolution.x; sampleUv.x += offset; } float illumination = exposure + breath * lightness * .016 + pulse * .2 + influence * .1; float light = luminance(sampleUv) + illumination; if (offset != 0.) light = mix(light, luminance(sampleUv + vec2(offset, 0.)), .22 * raster); float threshold = .045 + b8(pixel) * .94; float bit = step(threshold, light); float ink = mix(.023, .81, bit); float highlight = bit * smoothstep(.35, .85, tone) * ACCENT_STRENGTH; // Misregister the source by whole display pixels, keeping the Bayer grid fixed. // Uniform areas stay neutral; bright edges split, briefly widening during slips. vec2 registration = vec2(1. + step(.01, raster) + floor(chroma), 0.) + chromaDrift; vec2 separation = floor(registration + .5) / resolution * crop; float red = mix(.023, .81, step(threshold, luminance(sampleUv - separation) + illumination)); float blue = mix(.023, .81, step(threshold, luminance(sampleUv + separation) + illumination)); float fringeStrength = .22 + min(length(chromaDrift) * .045, .1) + raster * .2 + chroma * .08; vec3 fringe = (vec3(red, mix(ink, blue, .45), blue) - ink) * fringeStrength; if (ascii > .001) { vec2 charCell = floor(pixel / glyphCell); vec2 charUv = (charCell + .5) * glyphCell / resolution; vec2 glyphSource = charUv * crop + focus * (1. - crop) + parallax / resolution * crop; float value = clamp(luminance(pendulum(glyphSource)) + exposure + .03, 0., .999); float glyph = floor(value * 10.); vec2 glyphPixel = mod(pixel, glyphCell) + .5; vec2 glyphUv = vec2((glyph + glyphPixel.x / glyphCell.x) / 10., glyphPixel.y / glyphCell.y); float letter = texture2D(glyphs, glyphUv).a; float asciiInk = .014 + letter * mix(.22, .48, value); float front = ascii * 1.5 - .25; float mask = 1. - smoothstep(front - .09, front + .09, uv.y + (hash(charCell) - .5) * .2); ink = mix(ink, asciiInk, mask); fringe *= 1. - mask; highlight *= 1. - mask; } float scan = mod(pixel.y, 2.) < 1. ? .93 : 1.; gl_FragColor = vec4((mix(vec3(ink), ACCENT, highlight) + fringe) * scan, 1.); }