Hey everyone, lately, I've been asked to dive back into the world of retro aesthetics, and one thing that always stands out is the look of old CRT (Cathode Ray Tube) monitors. That characteristic scanline flicker, the subtle noise, and the slight color fringing – it's all part of a nostalgic visual language. I wanted to bring that look into Baselight (last time I did this it was for Mistika. https://www.johndaro.com/blog/2020/10/28/vhs-shader), so I built a custom Matchbox shader that accurately simulates these CRT artifacts. This post breaks down the process, from finding inspiration to creating a user-friendly tool.
The Inspiration: Shadertoy
My journey started on Shadertoy, a fantastic resource for exploring and learning about GLSL shaders. I found a great CRT effect shader (https://www.shadertoy.com/view/Ms3XWH) that captured the essence of the look I was after. It used clever techniques to generate scanlines, add noise, and even simulate chromatic aberration (that slight color separation you see at the edges of objects on old TVs).
However, Shadertoy shaders are self-contained and designed for a specific environment. To make this useful in Baselight I needed to adapt it for the Matchbox framework.
From Shadertoy to GLSL Standard
The first step was to "translate" the Shadertoy-specific code into standard GLSL. This involved a few key changes:
mainImage
to main
: Shadertoy uses a function signature mainImage(out vec4 fragColor, in vec2 fragCoord)
. Standard GLSL, and Matchbox, use void main(void)
. We also replace fragCoord
with the built-in gl_FragCoord
and output the color to gl_FragColor
.
Uniform Inputs: Shadertoy provides inputs like iResolution
(screen resolution) and iChannel0
(the input texture) automatically. In Matchbox, we need to explicitly declare these as uniform
variables: adsk_result_w
, adsk_result_h
, and src
, respectively. We also added iTime
as a uniform to control animation.
Texture Sampling: Shadertoy's texture
function becomes the standard texture2D
in GLSL.
Here's a snippet illustrating the change:
Shadertoy: