Skip to content

Instantly share code, notes, and snippets.

@partybusiness
Created May 31, 2025 15:36
Show Gist options
  • Save partybusiness/bab0ef0c42410b3528ec23ab00e59de9 to your computer and use it in GitHub Desktop.
Save partybusiness/bab0ef0c42410b3528ec23ab00e59de9 to your computer and use it in GitHub Desktop.
pixel line shader test
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