Created
May 31, 2025 15:36
-
-
Save partybusiness/bab0ef0c42410b3528ec23ab00e59de9 to your computer and use it in GitHub Desktop.
pixel line shader test
This file contains hidden or 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; | |
// pixelated shader for use with Line2D | |
// will still have incorrect behaviour at tips and corners where there can be diagonal cut-offs that don't align with pixel_size | |
uniform int pixel_size = 4; | |
void fragment() { | |
vec2 rounded_pixel = floor(FRAGCOORD.xy / float(pixel_size)) * float(pixel_size); // | |
vec2 pixel_diff = FRAGCOORD.xy - rounded_pixel; | |
vec2 offset_scale = vec2(dFdx(UV.y),dFdy(UV.y)); | |
vec2 adjustment = pixel_diff * offset_scale; | |
COLOR.rgb = vec3(0.0); | |
float test_value = ( 1.0 - abs(UV.y - adjustment.x - adjustment.y - 0.5) * 2.0); | |
COLOR.a = step(0.5, test_value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment