Skip to content

Instantly share code, notes, and snippets.

@jimmyjonezz
Last active January 23, 2020 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmyjonezz/c6ced75ace4c986eb24465fc8225d564 to your computer and use it in GitHub Desktop.
Save jimmyjonezz/c6ced75ace4c986eb24465fc8225d564 to your computer and use it in GitHub Desktop.
crt_filter
shader_type canvas_item;
float Less(float x, float value) {
return 1.0 - step(value, x);
}
// Will return a value of 1 if the 'x' is >= 'lower' && < 'upper'
float Between(float x, float lower, float upper) {
return step(lower, x) * (1.0 - step(upper, x));
}
// Will return a value of 1 if 'x' is >= value
float GEqual(float x, float value) {
return step(value, x);
}
void fragment() {
float brightness = 1.25;
vec2 uv = FRAGCOORD.xy / SCREEN_PIXEL_SIZE.xy;
uv.y = -uv.y;
//uv = uv * 0.05;
vec2 uvStep;
uvStep.x = uv.x / (1.0 / SCREEN_PIXEL_SIZE.x);
uvStep.x = mod(uvStep.x, 3.0);
uvStep.y = uv.y / (1.0 / SCREEN_PIXEL_SIZE.y);
uvStep.y = mod(uvStep.y, 3.0);
vec4 newColour = texture(SCREEN_TEXTURE, SCREEN_UV);
newColour.r = newColour.r * step(1.0, (Less(uvStep.x, 1.0) + Less(uvStep.y, 1.0)));
newColour.g = newColour.g * step(1.0, (Between(uvStep.x, 1.0, 2.0) + Between(uvStep.y, 1.0, 2.0)));
newColour.b = newColour.b * step(1.0, (GEqual(uvStep.x, 2.0) + GEqual(uvStep.y, 2.0)));
COLOR = newColour * brightness;
}
@jimmyjonezz
Copy link
Author

#ifdef X_ONLY
newColour.r = newColour.r * Less(uvStep.x, 1.0);
newColour.g = newColour.g * Between(uvStep.x, 1.0, 2.0);
newColour.b = newColour.b * GEqual(uvStep.x, 2.0);
#endif

#ifdef Y_ONLY
newColour.r = newColour.r * Less(uvStep.y, 1.0);
newColour.g = newColour.g * Between(uvStep.y, 1.0, 2.0);
newColour.b = newColour.b * GEqual(uvStep.y, 2.0);
#endif

#ifdef X_AND_Y
newColour.r = newColour.r * step(1.0, (Less(uvStep.x, 1.0) + Less(uvStep.y, 1.0)));
newColour.g = newColour.g * step(1.0, (Between(uvStep.x, 1.0, 2.0) + Between(uvStep.y, 1.0, 2.0)));
newColour.b = newColour.b * step(1.0, (GEqual(uvStep.x, 2.0) + GEqual(uvStep.y, 2.0)));
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment