Last active
January 23, 2020 14:28
-
-
Save jimmyjonezz/c6ced75ace4c986eb24465fc8225d564 to your computer and use it in GitHub Desktop.
crt_filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#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