shaders: improve border rounding

This commit is contained in:
vaxerski 2023-09-30 01:35:05 +01:00
parent 7b002d609b
commit 495d4f2d11

View file

@ -63,33 +63,22 @@ void main() {
pixCoord -= topLeft + fullSize * 0.5; pixCoord -= topLeft + fullSize * 0.5;
pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0; pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0;
pixCoord -= fullSize * 0.5 - radius; 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) { if (min(pixCoord.x, pixCoord.y) > 0.0 && radius > 0.0) {
float dist = length(pixCoord); float dist = length(pixCoord);
float h = (thick / 2.0);
if (dist > radius + 1.0 || dist < radius - thick - 1.0) if (dist < radius - h) {
discard; // lower
float normalized = clamp(smoothstep(0.0, 1.0, dist - radius + thick + 0.5), 0.0, 1.0);
if (primitiveMultisample == 1 && (dist > radius - 1.0 || dist < radius - thick + 1.0)) { additionalAlpha *= normalized;
float distances = 0.0; } else {
float len = length(pixCoord + vec2(0.25, 0.25)); // higher
distances += float(len < radius && len > radius - thick); float normalized = 1.0 - clamp(smoothstep(0.0, 1.0, dist - radius + 0.5), 0.0, 1.0);
len = length(pixCoord + vec2(0.75, 0.25)); additionalAlpha *= normalized;
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;
done = true; done = true;
} }