2022-06-26 19:39:56 +02:00
|
|
|
#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 fullSize;
|
2022-11-26 21:36:05 +01:00
|
|
|
uniform vec2 fullSizeUntransformed;
|
2022-06-26 19:39:56 +02:00
|
|
|
uniform float radius;
|
|
|
|
uniform float thick;
|
|
|
|
|
2022-11-26 18:56:43 +01:00
|
|
|
uniform vec4 gradient[10];
|
|
|
|
uniform int gradientLength;
|
|
|
|
uniform float angle;
|
2022-11-26 19:09:57 +01:00
|
|
|
uniform float alpha;
|
2022-11-26 18:56:43 +01:00
|
|
|
|
|
|
|
vec4 getColorForCoord(vec2 normalizedCoord) {
|
|
|
|
if (gradientLength < 2)
|
|
|
|
return gradient[0];
|
|
|
|
|
2022-11-26 20:37:20 +01:00
|
|
|
float finalAng = 0.0;
|
|
|
|
|
|
|
|
if (angle > 4.71 /* 270 deg */) {
|
|
|
|
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
|
|
|
finalAng = 6.28 - angle;
|
|
|
|
} else if (angle > 3.14 /* 180 deg */) {
|
|
|
|
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
|
|
|
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
|
|
|
finalAng = angle - 3.14;
|
|
|
|
} else if (angle > 1.57 /* 90 deg */) {
|
|
|
|
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
|
|
|
finalAng = 3.14 - angle;
|
|
|
|
} else {
|
|
|
|
finalAng = angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
float sine = sin(finalAng);
|
|
|
|
|
2022-11-26 18:56:43 +01:00
|
|
|
float progress = (normalizedCoord[1] * sine + normalizedCoord[0] * (1.0 - sine)) * float(gradientLength - 1);
|
|
|
|
int bottom = int(floor(progress));
|
|
|
|
int top = bottom + 1;
|
|
|
|
|
|
|
|
return gradient[top] * (progress - float(bottom)) + gradient[bottom] * (float(top) - progress);
|
|
|
|
}
|
|
|
|
|
2022-11-21 19:09:47 +01:00
|
|
|
void main() {
|
2022-06-26 19:39:56 +02:00
|
|
|
|
2022-11-21 19:09:47 +01:00
|
|
|
highp vec2 pixCoord = vec2(gl_FragCoord);
|
2022-11-27 00:55:41 +01:00
|
|
|
highp vec2 originalPixCoord = v_texcoord;
|
|
|
|
originalPixCoord *= fullSizeUntransformed;
|
2023-08-06 20:46:00 +02:00
|
|
|
float additionalAlpha = 1.0;
|
2022-06-26 19:39:56 +02:00
|
|
|
|
2022-11-27 01:29:51 +01:00
|
|
|
vec4 pixColor = vec4(1.0, 1.0, 1.0, 1.0);
|
2022-06-26 19:39:56 +02:00
|
|
|
|
2022-11-21 19:09:47 +01:00
|
|
|
bool done = false;
|
2022-06-26 19:39:56 +02:00
|
|
|
|
2022-11-21 19:09:47 +01:00
|
|
|
pixCoord -= topLeft + fullSize * 0.5;
|
|
|
|
pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0;
|
|
|
|
pixCoord -= fullSize * 0.5 - radius;
|
2023-09-30 02:35:05 +02:00
|
|
|
pixCoord += vec2(1.0, 1.0) / fullSize; // center the pix dont make it top-left
|
2022-06-26 19:39:56 +02:00
|
|
|
|
2022-11-26 18:56:43 +01:00
|
|
|
if (min(pixCoord.x, pixCoord.y) > 0.0 && radius > 0.0) {
|
2022-06-26 19:39:56 +02:00
|
|
|
|
2022-11-21 19:09:47 +01:00
|
|
|
float dist = length(pixCoord);
|
2023-09-30 02:35:05 +02:00
|
|
|
float h = (thick / 2.0);
|
|
|
|
|
|
|
|
if (dist < radius - h) {
|
|
|
|
// lower
|
2023-09-30 14:12:48 +02:00
|
|
|
float normalized = smoothstep(0.0, 1.0, dist - radius + thick + 0.5);
|
2023-09-30 02:35:05 +02:00
|
|
|
additionalAlpha *= normalized;
|
|
|
|
} else {
|
|
|
|
// higher
|
2023-09-30 14:12:48 +02:00
|
|
|
float normalized = 1.0 - smoothstep(0.0, 1.0, dist - radius + 0.5);
|
2023-09-30 02:35:05 +02:00
|
|
|
additionalAlpha *= normalized;
|
|
|
|
}
|
2022-11-21 19:09:47 +01:00
|
|
|
|
|
|
|
done = true;
|
2022-06-26 19:39:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// now check for other shit
|
|
|
|
if (!done) {
|
|
|
|
// distance to all straight bb borders
|
2022-11-21 19:09:47 +01:00
|
|
|
float distanceT = originalPixCoord[1];
|
2022-11-26 21:36:05 +01:00
|
|
|
float distanceB = fullSizeUntransformed[1] - originalPixCoord[1];
|
2022-11-21 19:09:47 +01:00
|
|
|
float distanceL = originalPixCoord[0];
|
2022-11-26 21:36:05 +01:00
|
|
|
float distanceR = fullSizeUntransformed[0] - originalPixCoord[0];
|
2022-06-26 19:39:56 +02:00
|
|
|
|
|
|
|
// get the smallest
|
|
|
|
float smallest = min(min(distanceT, distanceB), min(distanceL, distanceR));
|
|
|
|
|
2022-11-21 19:09:47 +01:00
|
|
|
if (smallest > thick)
|
|
|
|
discard;
|
2022-06-26 19:39:56 +02:00
|
|
|
}
|
|
|
|
|
2023-08-18 22:07:28 +02:00
|
|
|
if (additionalAlpha == 0.0)
|
2022-11-21 19:09:47 +01:00
|
|
|
discard;
|
2022-06-26 19:39:56 +02:00
|
|
|
|
2022-11-29 12:12:29 +01:00
|
|
|
pixColor = getColorForCoord(v_texcoord);
|
2023-08-18 22:07:28 +02:00
|
|
|
pixColor.rgb *= pixColor[3];
|
2022-11-27 01:29:51 +01:00
|
|
|
|
2023-08-18 22:07:28 +02:00
|
|
|
pixColor *= alpha * additionalAlpha;
|
|
|
|
|
|
|
|
gl_FragColor = pixColor;
|
2022-06-26 19:39:56 +02:00
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
)#";
|