Skip to content

Instantly share code, notes, and snippets.

@partybusiness
Created August 5, 2024 00:37
Show Gist options
  • Save partybusiness/af726bf20d0b2aa5b3f302483c284f6e to your computer and use it in GitHub Desktop.
Save partybusiness/af726bf20d0b2aa5b3f302483c284f6e to your computer and use it in GitHub Desktop.
Godot shader that distorts a texture as though it's viewed through a slightly bulbous CRT
shader_type canvas_item;
render_mode blend_mix;
uniform float bulge = 0.1;
uniform float scale = 1.0;
//used to set curvature of screen crop
uniform float n = 5.0;
void fragment() {
vec2 cuv = UV-0.5;
//screen bulge
float xbulge = bulge * abs(cuv.x) * 2.0;
float ybulge = bulge * abs(cuv.y) * 2.0;
float uvX = (cuv.x) * (scale-sin(UV.y*PI)*xbulge) + 0.5;
float uvY = (cuv.y) * (scale-sin(UV.x*PI)*ybulge) + 0.5;
//crop
float angle = atan(cuv.y, cuv.x);
float superellipse_radius = pow( pow(abs(cos(angle)),n) + pow(abs(sin(angle)),n),-1.0/n);
float superellipse_crop = superellipse_radius < length(cuv)*2.0?0.0:1.0;
COLOR = min(texture(TEXTURE, vec2(uvX,uvY)),superellipse_crop);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment