feat: corner radius for CosmicMapped
This commit is contained in:
parent
228af1037a
commit
3465ce7602
7 changed files with 49 additions and 23 deletions
|
|
@ -9,24 +9,29 @@ varying vec2 v_coords;
|
|||
uniform vec3 color;
|
||||
uniform float radius;
|
||||
|
||||
float rounded_box(vec2 center, vec2 size, float radius) {
|
||||
return length(max(abs(center) - size + radius, 0.0)) - radius;
|
||||
float rounded_box(in vec2 p, in vec2 b, in vec4 r)
|
||||
{
|
||||
r.xy = (p.x > 0.0) ? r.xy : r.zw;
|
||||
r.x = (p.y > 0.0) ? r.x : r.y;
|
||||
vec2 q = abs(p) - b + r.x;
|
||||
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 center = size / 2.0;
|
||||
vec2 location = v_coords * size;
|
||||
vec4 mix_color;
|
||||
vec4 corners = vec4(radius);
|
||||
|
||||
float distance = rounded_box(location - center, size / 2.0, radius);
|
||||
float distance = rounded_box(location - center, size / 2.0, corners);
|
||||
float smoothedAlpha = 1.0 - smoothstep(0.0, 1.0, distance);
|
||||
|
||||
|
||||
mix_color = mix(vec4(0.0, 0.0, 0.0, 0.0), vec4(color, alpha), smoothedAlpha);
|
||||
|
||||
#if defined(DEBUG_FLAGS)
|
||||
|
||||
#if defined(DEBUG_FLAGS)
|
||||
if (tint == 1.0)
|
||||
mix_color = vec4(0.0, 0.3, 0.0, 0.2) + mix_color * 0.8;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_FragColor = mix_color;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue