diff options
| author | xDarksome <dev@darkso.me> | 2022-07-02 19:43:52 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-02 19:43:52 +0300 |
| commit | 185c4d6ea13ad5f4483aa2e389e43bd09106002f (patch) | |
| tree | a7bc4a9510c39e367317b5ce64d2ee0e0a72d4f0 /src/render/shaders | |
| parent | fc4b10d13c14c4eb08febb0637f27177cb6a1940 (diff) | |
| parent | b7b3344188e3ebd2baed14bc288ee42a1ae8d6f2 (diff) | |
Merge branch 'hyprwm:main' into main
Diffstat (limited to 'src/render/shaders')
| -rw-r--r-- | src/render/shaders/Border.hpp | 91 | ||||
| -rw-r--r-- | src/render/shaders/Shadow.hpp | 3 |
2 files changed, 92 insertions, 2 deletions
diff --git a/src/render/shaders/Border.hpp b/src/render/shaders/Border.hpp new file mode 100644 index 00000000..69f1ad5b --- /dev/null +++ b/src/render/shaders/Border.hpp @@ -0,0 +1,91 @@ +#pragma once + +#include <string> + +// makes a stencil without corners +inline const std::string FRAGBORDER1 = R"#( +precision mediump float; +varying vec4 v_color; +varying vec2 v_texcoord; + +uniform vec2 topLeft; +uniform vec2 bottomRight; +uniform vec2 fullSize; +uniform float radius; +uniform float thick; +uniform int primitiveMultisample; + +float getOpacityForPixAndCorner(vec2 pix, vec2 corner) { + + if (primitiveMultisample == 0) { + float dis = distance(pix + vec2(0.5, 0.5), corner); + return dis < radius && dis > radius - thick ? 1.0 : 0.0; + } + + float distance1 = distance(pix + vec2(0.25, 0.25), corner); + float distance2 = distance(pix + vec2(0.75, 0.25), corner); + float distance3 = distance(pix + vec2(0.25, 0.75), corner); + float distance4 = distance(pix + vec2(0.75, 0.75), corner); + + float v1 = distance1 < radius && distance1 > radius - thick ? 1.0 : 0.0; + float v2 = distance2 < radius && distance2 > radius - thick ? 1.0 : 0.0; + float v3 = distance3 < radius && distance3 > radius - thick ? 1.0 : 0.0; + float v4 = distance4 < radius && distance4 > radius - thick ? 1.0 : 0.0; + + return (v1 + v2 + v3 + v4) / 4.0; +} + +void main() { + + vec2 pixCoord = fullSize * v_texcoord; + + vec4 pixColor = v_color; + + bool done = false; + + // check for edges + if (pixCoord[0] < topLeft[0]) { + if (pixCoord[1] < topLeft[1]) { + // top left + pixColor[3] = pixColor[3] * getOpacityForPixAndCorner(pixCoord, topLeft + vec2(1,1)); + done = true; + } else if (pixCoord[1] > bottomRight[1]) { + // bottom left + pixColor[3] = pixColor[3] * getOpacityForPixAndCorner(pixCoord, vec2(topLeft[0] + 1.0, bottomRight[1])); + done = true; + } + } else if (pixCoord[0] > bottomRight[0]) { + if (pixCoord[1] < topLeft[1]) { + // top right + pixColor[3] = pixColor[3] * getOpacityForPixAndCorner(pixCoord, vec2(bottomRight[0], topLeft[1] + 1.0)); + done = true; + } else if (pixCoord[1] > bottomRight[1]) { + // bottom right + pixColor[3] = pixColor[3] * getOpacityForPixAndCorner(pixCoord, bottomRight); + done = true; + } + } + + // now check for other shit + if (!done) { + // distance to all straight bb borders + float distanceT = pixCoord[1]; + float distanceB = fullSize[1] - pixCoord[1]; + float distanceL = pixCoord[0]; + float distanceR = fullSize[0] - pixCoord[0]; + + // get the smallest + float smallest = min(min(distanceT, distanceB), min(distanceL, distanceR)); + + if (smallest > thick) { + discard; return; + } + } + + if (pixColor[3] == 0.0) { + discard; return; + } + + gl_FragColor = pixColor; +} +)#";
\ No newline at end of file diff --git a/src/render/shaders/Shadow.hpp b/src/render/shaders/Shadow.hpp index f54124fa..dca194c0 100644 --- a/src/render/shaders/Shadow.hpp +++ b/src/render/shaders/Shadow.hpp @@ -13,7 +13,6 @@ uniform vec2 fullSize; uniform float radius; uniform float range; uniform float shadowPower; -uniform int ignoreWindow; float pixAlphaRoundedDistance(float distanceToCorner) { if (distanceToCorner > radius) { @@ -75,7 +74,7 @@ void main() { } } - if (pixColor[3] == 0.0 || (ignoreWindow == 1 && pixColor[3] == originalAlpha)) { + if (pixColor[3] == 0.0) { discard; return; } |
