mcstairs/stairs.gdshader
2025-04-18 01:41:24 -07:00

57 lines
1.4 KiB
Plaintext

shader_type canvas_item;
uniform int step_count = 168;
uniform int inner = 101;
uniform int pixel_size = 121;
uniform int highlight = 0;
uniform float grid_thickness = 0.125;
uniform float offset = 0.0;
float mask(float inner_radius, float outer_radius, vec2 p) {
if (inner_radius < length(p) && length(p) < outer_radius) {
return 1.0;
} else {
return 0.0;
}
}
float f(vec2 uv, vec2 p) {
float angle = atan(p.y, p.x) / PI / 2.0 + 0.5 + offset/float(step_count);
float color = round(angle * float(step_count)) / float(step_count);
return color;
}
float grid_mask(vec2 uv) {
float x = mod(uv.x*float(pixel_size), 1.0);
float y = mod(uv.y*float(pixel_size), 1.0);
return step(grid_thickness, x)* step(grid_thickness, y);
}
void fragment() {
vec2 p = UV - vec2(0.5, 0.5);
p = round(p * float(pixel_size)) / float(pixel_size);
float color = f(UV, p);
//color *= edge_mask(UV, vec2(0.002, 0.002));
vec3 chroma = vec3(color, color, color);
int i = int(color * float(step_count));
if (i == highlight) {
chroma = vec3(0.0, 1.0, 0.0);
} else if (i % 2 == 0) {
chroma = vec3(0.3, 0.3, 0.3);
} else if (i % 2 == 1) {
chroma = vec3(0.6, 0.6, 0.6);
}
chroma *= grid_mask(UV);
chroma *= mask(float(inner) / float(pixel_size * 2), 0.5, p);
COLOR = vec4(chroma, 1.0);
}
//void light() {
// // Called for every pixel for every light affecting the CanvasItem.
// // Uncomment to replace the default light processing function with this one.
//}