2025-06-01 16:44:31 +02:00
|
|
|
#version 450
|
|
|
|
|
|
2025-06-10 23:02:44 +02:00
|
|
|
layout(set = 3, binding = 0) uniform Viewport {
|
|
|
|
|
ivec2 view;
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-15 18:54:35 +02:00
|
|
|
layout(location = 0) in vec4 in_color;
|
|
|
|
|
layout(location = 1) in vec4 in_quad_size; // x,y, w,h
|
|
|
|
|
layout(location = 2) in float in_radius;
|
2025-07-07 13:53:12 +02:00
|
|
|
layout(location = 3) in float thickness;
|
2025-06-10 12:54:03 +02:00
|
|
|
|
2025-06-01 16:44:31 +02:00
|
|
|
layout(location = 0) out vec4 fragColor;
|
|
|
|
|
|
2025-06-10 12:54:03 +02:00
|
|
|
// SDF for a rounded rectangle given the centerpoint, half size and radius, all in pixels
|
2025-06-15 18:54:35 +02:00
|
|
|
float sdf_rr(vec2 p, vec2 half_size, float radius) {
|
2025-06-10 12:54:03 +02:00
|
|
|
vec2 q = abs(p) - half_size + radius;
|
|
|
|
|
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-07 14:38:46 +02:00
|
|
|
const float smoothness = 0.9;
|
2025-07-07 13:53:12 +02:00
|
|
|
|
2025-06-01 16:44:31 +02:00
|
|
|
void main()
|
|
|
|
|
{
|
2025-06-15 18:54:35 +02:00
|
|
|
vec2 centerpoint = in_quad_size.xy + in_quad_size.zw * 0.5;
|
|
|
|
|
vec2 half_size = in_quad_size.zw * 0.5;
|
2025-07-07 13:53:12 +02:00
|
|
|
float distance = -sdf_rr(vec2(gl_FragCoord) - centerpoint, half_size, in_radius);
|
|
|
|
|
|
2025-07-07 14:38:46 +02:00
|
|
|
float alpha_out = smoothstep(0.0-smoothness, 0.0, distance);
|
|
|
|
|
float alpha_in = 1.0 - smoothstep(thickness-smoothness, thickness, distance);
|
2025-06-10 12:54:03 +02:00
|
|
|
|
2025-07-07 13:53:12 +02:00
|
|
|
fragColor = vec4(in_color.rgb, in_color.a * alpha_out * alpha_in);
|
2025-06-01 16:44:31 +02:00
|
|
|
}
|