shader_type canvas_item; render_mode unshaded; uniform sampler2D dither_texture; uniform sampler2D selection; uniform vec4 first_color : hint_color = vec4(1.0); uniform vec4 second_color : hint_color = vec4(0.0, 0.0, 0.0, 1.0); uniform vec2 image_size = vec2(64.0); uniform float position : hint_range(-0.5, 0.5) = 0.0; uniform float size : hint_range(0.01, 2.0) = 1.0; uniform float angle : hint_range(0.0, 360.0) = 0.0; uniform int dither_steps : hint_range(2, 257) = 5; uniform int pixel_size : hint_range(2, 16) = 2; void fragment() { vec4 original_color = texture(TEXTURE, UV); vec4 selection_color = texture(selection, UV); float pivot = position / size; vec2 uv = UV - 0.5; float angle_cos = cos(radians(angle)); float angle_sin = sin(radians(angle)); float rotated = uv.x * angle_cos - uv.y * angle_sin; rotated /= abs(angle_cos) + abs(angle_sin); rotated /= size; rotated -= pivot - 0.5; vec4 dither_value = texture(dither_texture, uv * (image_size / float(pixel_size))); float step_v = 1.0 / float(dither_steps); float step_v_m = 1.0 / float(dither_steps - 1); float rotated_stepped = floor(rotated / step_v) * step_v_m; // Similar to GDScript's stepify float dithered = step(rotated_stepped, dither_value.r); vec4 output = first_color * dithered + second_color * (1.0 - dithered); output = mix(original_color, output, output.a); COLOR = mix(original_color, output, selection_color.a); }