forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

rounding_alpha.frag27 lines, 1.0 KiBHistoryRawDownload
1float niri_rounding_alpha(vec2 coords, vec2 size, vec4 corner_radius) {
2 vec2 center;
3 float radius;
4
5 if (coords.x < corner_radius.x && coords.y < corner_radius.x) {
6 radius = corner_radius.x;
7 center = vec2(radius, radius);
8 } else if (size.x - corner_radius.y < coords.x && coords.y < corner_radius.y) {
9 radius = corner_radius.y;
10 center = vec2(size.x - radius, radius);
11 } else if (size.x - corner_radius.z < coords.x && size.y - corner_radius.z < coords.y) {
12 radius = corner_radius.z;
13 center = vec2(size.x - radius, size.y - radius);
14 } else if (coords.x < corner_radius.w && size.y - corner_radius.w < coords.y) {
15 radius = corner_radius.w;
16 center = vec2(radius, size.y - radius);
17 } else {
18 return 1.0;
19 }
20
21 float dist = distance(coords, center);
22
23 // Manual smoothstep() between radius - half_px and radius + half_px
24 // to avoid a division in clamp().
25 float t = clamp((dist - radius) * niri_scale + 0.5, 0.0, 1.0);
26 return 1.0 - t * t * (3.0 - 2.0 * t);
27}