Building a Retro CRT Effect: From Shadertoy to Baselight Matchbox Shader

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:

  1. 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.

  2. 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.

  3. Texture Sampling: Shadertoy's texture function becomes the standard texture2D in GLSL.

Here's a snippet illustrating the change:

Shadertoy:

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord.xy / iResolution.xy;
    // ...
    vec4 tex = texture(iChannel0, uv);
    fragColor = tex;
}

Standard GLSL (for Matchbox):

uniform float adsk_result_w;
uniform float adsk_result_h;
uniform sampler2D src;

void main (void)
{
    vec2 uv = gl_FragCoord.xy / vec2(adsk_result_w, adsk_result_h);
    // ...
    vec4 tex = texture2D(src, uv);
    gl_FragColor = tex;
}

Making it Controllable: Matchbox XML

The real power of Matchbox comes from its ability to expose shader parameters as user-adjustable controls. This is done through an XML file that describes the interface. I wanted to give users control over the key aspects of the CRT effect:

  • Scanline Width: How thick the scanlines appear.

  • Noise Quality: The granularity of the vertical noise (lower values create more distinct lines).

  • Noise Intensity: The amount of horizontal jitter.

  • Scanline Offset: The intensity of the vertical scanline displacement.

  • Chromatic Aberration: The strength of the color fringing.

  • Time: The speed of the animation.

To achieve this, I did the following:

  1. GLSL Changes: In the GLSL code, I replaced the const float variables that controlled these parameters with uniform float variables. This is crucial – it tells Matchbox that these values can be changed externally.

// Before (hardcoded):
const float range = 0.05;

// After (Matchbox controllable):
uniform float scanlineRange;

XML Creation: I created an XML file (with the same name as the GLSL file) that defines the controls. Each control is specified using a <Uniform> tag. The most important attribute is Name, which must match the corresponding uniform variable name in the GLSL code.

<Uniform Max="0.1" Min="0.0" Default="0.05" Inc="0.001" ... Name="scanlineRange">
</Uniform>

The XML also includes attributes like DisplayName (the label in the Baselight UI), Min, Max, Default, Tooltip, and layout information (Row, Col, Page). These define how the control appears and behaves in Baselight.

Putting it All Together

The final step was to place both the .glsl and .xml files in the usr/fl/shaders directory. Baselight automatically recognizes the shader and makes it available in the Matchbox node. Pro tip, my shaders directory is a link to a network location. This way all the Baselights can share the same shaders and it makes updating easier.

Now, when I add a Matchbox node and select the CRT effect, I get a set of sliders and controls that let me tweak the look in real-time. I can easily adjust the scanline thickness, add more or less noise, and dial in the perfect amount of retro goodness.

Download the Files

You can download the complete GLSL and XML files for this Matchbox shader here:


Conclusion

This project was a great upgrade to my GLSL knowledge, demonstrating how to take a cool shader effect from a platform like Shadertoy and adapt it into a practical, user-friendly tool for Baselight. The combination of GLSL's power, speed, and Matchbox's flexibility opens up a world of possibilities for creating custom effects that can be used through out the entire post pipeline. It might be old tech but still very useful today. I hope this breakdown inspires you to experiment with your own implementation. Let me know what you think, and feel free to share your own shader creations!

How to - Add a LUT in Avid Media Composer

There are several ways to load LUTs into Avid Media Composer:

1. Through Source Settings:

  • Right-click on a clip in your bin or timeline.  

  • Select "Source Settings."  

  • Under the "Color Encoding" tab, go to "Color Adapter Type."  

  • Click on the dropdown menu and choose "User Installed LUTs." You can add LUTs you have already loaded to the source clip and hit “Apply”

  • To load a LUT click Color Management Settings and then click “Select LUT file”

  • Browse your LUT file's location (.cube or .lut format) and select it.

  • Click "Open" to load the LUT.

2. Through Color Management Settings:

Color Management Settings
  • Go to "Settings" in the menu bar.

  • Select "Color Management."  

  • Under the "Project" or "Shared" tab (depending on where you want the LUT to be available), click "Select LUT File."  

  • Browse for your LUT file and select it.  

  • Click "Open" to load the LUT.  

3. Using the "Color LUT" Effect:

  • Go to the "Effects" tab in the Effect Palette.

  • Under "Image" effects, find and drag the "Color LUT" effect onto your clip in the timeline.  

  • In the Effect Editor, click on the dropdown menu next to "LUT File" and choose your loaded LUT.

Avid LUT Effect on Filler track

Additional Tips:

  • LUTs should be in either .cube or .lut format to be compatible with Avid.

  • Make sure to place the LUT files in a location you can easily access and remember.

  • You can organize your LUTs by creating subfolders within the Avid LUTs directory.

  • Shared LUTs are available to all projects, while project-specific LUTs are only accessible within the current project.

For more detailed instructions and visual guides, you can refer to these resources:

I hope this helps! Let me know if you have any other questions.

Cheers to "The Sea Beast" Best Animated Feature Film Nomination!

Sending a big cheers and congratulations to Netflix and The Sea Beast crew for their nomination today. The film is a beautiful culmination of an elite group of artists' fantastic work. I am super grateful and proud to have been a part of the team.

Cheers to "The Sea Beast" Best Animated Feature Film Oscar Nomination!

Flippers crossed for a win on the day!

Best Animated Feature Film Nominations

  • “Guillermo del Toro’s Pinocchio,” Guillermo del Toro, Mark Gustafson, Gary Ungar and Alex Bulkley

  • “Marcel the Shell With Shoes On,” Dean Fleischer Camp, Elisabeth Holm, Andrew Goldman, Caroline Kaplan and Paul Mezey

  • “Puss in Boots: The Last Wish,” Joel Crawford and Mark Swift

  • “The Sea Beast,” Chris Williams and Jed Schlanger

  • “Turning Red,” Domee Shi and Lindsey Collins

DC League of Super Pets

Super excited for everyone to check out the latest from Warner Animation. DC League of Super Pets is a super fun romp expertly animated by the talented team at Animal Logic.

Toshi the Wonder Dog!

Anybody that has ever had a pet is going to love this movie.

Post services provided by Warner PPCS include an ACES HDR picture finish and sound. Truly a post-production one-stop-shop.

The project was supervised by Randy Bol. The great thing about working with Randy is we have a level of trust that has been built over many other projects collaborating together. There is definitely a shorthand when both of us are in the suite. One of the best post sups you’ll work with plus just a good dude too.

Color was supervised by co-director Sam Levine. This guy was cracking me up every session. Not only was he hilarious, but damn, what an eagle eye. I was sort of bummed when our time together ended.

A big thanks to Paul Lavoie and Leo Ferrini too for keeping the ship afloat. I would be drowning in a pile of pixels without these guys.

Now go see DC League of Super Pets only in theaters… Preferably a Dolby Cinema one.

SCOOB! and Best Friends Animal Society

It's not a mystery, everyone needs a best friend! I couldn’t imagine life without my little man Toshi! Watch Shaggy meet his new friend, rescued dog Scooby Doo, in this new PSA from @BestFriendsAnimalSociety.  And you can enjoy Exclusive Early Access to the new animated movie @SCCOB with Home Premiere! Available to own May 15th.

@scoob #SCOOB @bestfriendsanimalsociety #SaveThemAll #fosteringsaveslives #thelabellefoundation

00100lrPORTRAIT_00100_BURST20200508074700600_COVER.jpg

My Dog Toshi

A Huge thank you to TheLabelleFoundation for bringing us together!