summaryrefslogtreecommitdiff
path: root/src/render/shaders
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2023-09-30 01:35:05 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2023-09-30 01:35:05 +0100
commit495d4f2d11f250d8a5ddde840cd0d38861f84623 (patch)
tree20bff2dbc50dd11deae58bbaba4b2b517aed4ded /src/render/shaders
parent7b002d609bd8ff7d56bee4e0988c930eef4ea252 (diff)
shaders: improve border rounding
Diffstat (limited to 'src/render/shaders')
-rw-r--r--src/render/shaders/Border.hpp35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/render/shaders/Border.hpp b/src/render/shaders/Border.hpp
index 4e2d485d..30227804 100644
--- a/src/render/shaders/Border.hpp
+++ b/src/render/shaders/Border.hpp
@@ -63,33 +63,22 @@ void main() {
pixCoord -= topLeft + fullSize * 0.5;
pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0;
pixCoord -= fullSize * 0.5 - radius;
+ pixCoord += vec2(1.0, 1.0) / fullSize; // center the pix dont make it top-left
if (min(pixCoord.x, pixCoord.y) > 0.0 && radius > 0.0) {
float dist = length(pixCoord);
-
- if (dist > radius + 1.0 || dist < radius - thick - 1.0)
- discard;
-
- if (primitiveMultisample == 1 && (dist > radius - 1.0 || dist < radius - thick + 1.0)) {
- float distances = 0.0;
- float len = length(pixCoord + vec2(0.25, 0.25));
- distances += float(len < radius && len > radius - thick);
- len = length(pixCoord + vec2(0.75, 0.25));
- distances += float(len < radius && len > radius - thick);
- len = length(pixCoord + vec2(0.25, 0.75));
- distances += float(len < radius && len > radius - thick);
- len = length(pixCoord + vec2(0.75, 0.75));
- distances += float(len < radius && len > radius - thick);
-
- if (distances == 0.0)
- discard;
-
- distances /= 4.0;
-
- additionalAlpha *= distances;
- } else if (dist > radius || dist < radius - thick)
- discard;
+ float h = (thick / 2.0);
+
+ if (dist < radius - h) {
+ // lower
+ float normalized = clamp(smoothstep(0.0, 1.0, dist - radius + thick + 0.5), 0.0, 1.0);
+ additionalAlpha *= normalized;
+ } else {
+ // higher
+ float normalized = 1.0 - clamp(smoothstep(0.0, 1.0, dist - radius + 0.5), 0.0, 1.0);
+ additionalAlpha *= normalized;
+ }
done = true;
}