From 6e15590e98ca643d06eacc84adf161bcef705c0b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 19 Oct 2023 14:04:50 +0100 Subject: shaders: support changing the outer radius of borders independently --- src/render/shaders/Border.hpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/render/shaders') diff --git a/src/render/shaders/Border.hpp b/src/render/shaders/Border.hpp index f7b9d94d..79493da9 100644 --- a/src/render/shaders/Border.hpp +++ b/src/render/shaders/Border.hpp @@ -12,6 +12,7 @@ uniform vec2 topLeft; uniform vec2 fullSize; uniform vec2 fullSizeUntransformed; uniform float radius; +uniform float radiusOuter; uniform float thick; uniform vec4 gradient[10]; @@ -51,6 +52,7 @@ vec4 getColorForCoord(vec2 normalizedCoord) { void main() { highp vec2 pixCoord = vec2(gl_FragCoord); + highp vec2 pixCoordOuter = pixCoord; highp vec2 originalPixCoord = v_texcoord; originalPixCoord *= fullSizeUntransformed; float additionalAlpha = 1.0; @@ -61,25 +63,33 @@ void main() { pixCoord -= topLeft + fullSize * 0.5; pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0; + pixCoordOuter = pixCoord; pixCoord -= fullSize * 0.5 - radius; - pixCoord += vec2(1.0, 1.0) / fullSize; // center the pix dont make it top-left + pixCoordOuter -= fullSize * 0.5 - radiusOuter; - if (min(pixCoord.x, pixCoord.y) > 0.0 && radius > 0.0) { + // center the pixes dont make it top-left + pixCoord += vec2(1.0, 1.0) / fullSize; + pixCoordOuter += vec2(1.0, 1.0) / fullSize; + if (min(pixCoord.x, pixCoord.y) > 0.0 && radius > 0.0) { 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); additionalAlpha *= normalized; - } else { + done = true; + } else if (min(pixCoordOuter.x, pixCoordOuter.y) > 0.0) { // higher - float normalized = 1.0 - smoothstep(0.0, 1.0, dist - radius + 0.5); + float normalized = 1.0 - smoothstep(0.0, 1.0, distOuter - radiusOuter + 0.5); additionalAlpha *= normalized; + done = true; + } else if (distOuter < radiusOuter - h) { + additionalAlpha = 1.0; + done = true; } - - done = true; } // now check for other shit -- cgit v1.2.3