zworld/assets/shaders/lib/ui.glsl

24 lines
548 B
Plaintext
Raw Normal View History

2024-01-14 22:56:06 +08:00
struct Quad {
vec2 min; // top left
vec2 max; // bottom right
vec2 uv_min; // top left uv
vec2 uv_max; // bottom right uv
vec4 color[4];
float zindex;
float corner_radius;
float edge_softness;
float border;
uint texture;
};
UNIFORM(0, config, {
vec2 resolution;
float zmax;
})
STORAGE_BUFFER(1, Quad, quads)
float RoundedRectSDF(vec2 sample_pos, vec2 rect_center, vec2 rect_half_size, float r) {
vec2 d2 = (abs(rect_center - sample_pos) - rect_half_size + vec2(r, r));
return min(max(d2.x, d2.y), 0.0) + length(max(d2, 0.0)) - r;
}