diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-11-05 16:11:05 +0000 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-11-05 16:11:05 +0000 |
| commit | 0920572e703201368c9fbcc9108ce1888600ffa2 (patch) | |
| tree | 3f11edb6e4c9d7ffcb02bdcc75caac6b63121379 /src/render/shaders/Border.hpp | |
| parent | 55ccb1a8cf2c8541a32890e9b76e7c20fc9227cd (diff) | |
shaders: improve corner AA in borders shader
Diffstat (limited to 'src/render/shaders/Border.hpp')
| -rw-r--r-- | src/render/shaders/Border.hpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/render/shaders/Border.hpp b/src/render/shaders/Border.hpp index a33694a7..1f4a1d97 100644 --- a/src/render/shaders/Border.hpp +++ b/src/render/shaders/Border.hpp @@ -1,6 +1,8 @@ #pragma once #include <string> +#include <format> +#include "SharedValues.hpp" // makes a stencil without corners inline const std::string FRAGBORDER1 = R"#( @@ -72,18 +74,22 @@ void main() { pixCoordOuter += vec2(1.0, 1.0) / fullSize; if (min(pixCoord.x, pixCoord.y) > 0.0 && radius > 0.0) { + // smoothing constant for the edge: more = blurrier, but smoother + const float SMOOTHING_CONSTANT = )#" + + std::format("{:.7f}", SHADER_ROUNDED_SMOOTHING_FACTOR) + R"#(; + float dist = length(pixCoord); float distOuter = length(pixCoordOuter); float h = (thick / 2.0); if (dist < radius - h) { // lower - float normalized = smoothstep(0.0, 1.0, dist - radius + thick + 0.5); + float normalized = smoothstep(0.0, 1.0, (dist - radius + thick + SMOOTHING_CONSTANT) / (SMOOTHING_CONSTANT * 2.0)); additionalAlpha *= normalized; done = true; } else if (min(pixCoordOuter.x, pixCoordOuter.y) > 0.0) { // higher - float normalized = 1.0 - smoothstep(0.0, 1.0, distOuter - radiusOuter + 0.5); + float normalized = 1.0 - smoothstep(0.0, 1.0, (distOuter - radiusOuter + SMOOTHING_CONSTANT) / (SMOOTHING_CONSTANT * 2.0)); additionalAlpha *= normalized; done = true; } else if (distOuter < radiusOuter - h) { |
