|
| 1 | +float polygon(vec2 uv, float width, int sides) { |
| 2 | + uv = uv * 2.0 - 1.0; |
| 3 | + float angle = atan(uv.x, uv.y); |
| 4 | + float radius = 6.28318530718 / float(sides); |
| 5 | + float dist = cos(floor(0.5 + angle / radius) * radius - angle) * length(uv); |
| 6 | + return step(width, dist); |
| 7 | +} |
| 8 | + |
| 9 | +float circle(vec2 uv, float radius, float feather) { |
| 10 | + return smoothstep(radius, radius + feather, dot(position, position) * 4.0); |
| 11 | +} |
| 12 | + |
| 13 | +float square(vec2 uv, float width) { |
| 14 | + uv = uv * 2.0 - 1.0; |
| 15 | + vec2 abs_uv = abs(uv.xy); |
| 16 | + return step(width, max(abs_uv.x, abs_uv.y)); |
| 17 | +} |
| 18 | + |
| 19 | +float square_stroke(vec2 uv, float width, float stroke_width) { |
| 20 | + uv = uv * 2.0 - 1.0; |
| 21 | + vec2 abs_uv = abs(uv.xy); |
| 22 | + float dist = max(abs_uv.x, abs_uv.y); |
| 23 | + return 1.0 - (step(width, dist) - step(width + stroke_width, dist)); |
| 24 | +} |
| 25 | + |
| 26 | +float square_rounded(vec2 uv, float width, float radius) { |
| 27 | + uv = uv * 2.0 - 1.0; |
| 28 | + radius *= width; |
| 29 | + vec2 abs_uv = abs(uv.xy) - radius; |
| 30 | + vec2 dist = vec2(max(abs_uv.xy, 0.0)); |
| 31 | + return step(width - radius, length(dist)); |
| 32 | +} |
| 33 | + |
| 34 | +float swirl(vec2 uv, float size, int arms) { |
| 35 | + float angle = atan(-uv.y + 0.5, uv.x - 0.5); |
| 36 | + float len = length(uv - vec2(0.5, 0.5)); |
| 37 | + return sin(len * size + angle * float(arms)); |
| 38 | +} |
| 39 | + |
| 40 | +float line(vec2 uv, vec2 p1, vec2 p2, float width) { |
| 41 | + float dist = distance(p1, p2); |
| 42 | + float dist_uv = distance(p1, uv); |
| 43 | + return 1.0 - floor(1.0 - (0.001 * width) + distance (mix(p1, p2, clamp(dist_uv / dist, 0.0, 1.0)), uv)); |
| 44 | +} |
| 45 | + |
| 46 | +float border(vec2 uv, float border_width) { |
| 47 | + vec2 bottom_left = step(vec2(border_width), uv); |
| 48 | + vec2 top_right = step(vec2(border_width), 1.0 - uv); |
| 49 | + return bottom_left.x * bottom_left.y * top_right.x * top_right.y; |
| 50 | +} |
| 51 | + |
0 commit comments