Minimal CRT Shader

Lightweight single-pass CRT Shader with adjustable scanlines and flicker.

Usage:

This is a canvas item shader, which means you have to add a Color Rect -> Create new Shader Material -> Paste Shader.

Support me:  https://www.paypal.me/vinrato

 

Shader code
shader_type canvas_item;
uniform sampler2D ST : hint_screen_texture, filter_linear_mipmap_anisotropic;
uniform vec4 scanline_color : source_color = vec4(0, 0, 0, 1);
uniform vec4 flicker_color : source_color = vec4(0, 0, 0, 1);
uniform float scanlines_count = 10.0;
uniform float scanlines_intensity = 0.05;
uniform float flicker_speed = 30.0;
uniform float flicker_intensity : hint_range(0.0, 1.0, 0.001) = 0.025;
uniform float color_offset = 1.5;
uniform float blur = 0.15;

void fragment() {
	vec2 pixel_size = 1.0 / vec2(textureSize(ST, 0));
	float offset = color_offset * pixel_size.x;
	
	// chromatic aberration
	float channel_r = textureLod(ST, SCREEN_UV + vec2(offset, 0.0), blur).r;
	float channel_g = textureLod(ST, SCREEN_UV, blur).g;
	float channel_b = textureLod(ST, SCREEN_UV + vec2(-offset, 0.0), blur).b;
	vec4 aberrate = vec4(channel_r, channel_g, channel_b, 1.0);
	
	// scanline flicker
	float mix_value = sin((UV.y - (TIME * flicker_speed)) * 10.0) * flicker_intensity;
	vec4 flicker = mix(aberrate, flicker_color, mix_value);

	// scanlines
	float scanlines = sin(FRAGCOORD.y * scanlines_count) * scanlines_intensity;
	vec4 final = mix(flicker, scanline_color, scanlines);
	
	COLOR = final;
}
Live Preview
Tags
CRT, flicker, retro, vintage
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from blitpxl

Related shaders

guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
DonProtz
DonProtz
8 months ago

NICE

works like a charm, thx for sharing

Francesc
3 months ago

Works well in Godot 4.5 using a ColorRect. Good job!

Veedub
Veedub
8 days ago

Works for my background texture, set as a child of the ColorRect which contains the shader. Other items, all CharacterBody2Ds, are not affeced by the shader (they are children of the ColorRect too)
Am I missing something?