aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources
diff options
context:
space:
mode:
authorVixid <52578495+VixidDev@users.noreply.github.com>2024-02-19 15:02:49 +0000
committerGitHub <noreply@github.com>2024-02-19 16:02:49 +0100
commit35df2ab2aa2056b61034757fe61554e7075dedd1 (patch)
tree634d4bbd47bb7fc8bc680d884a638d566059300e /src/main/resources
parentb065fc1113977529831be5eab587c1612efdde79 (diff)
downloadskyhanni-35df2ab2aa2056b61034757fe61554e7075dedd1.tar.gz
skyhanni-35df2ab2aa2056b61034757fe61554e7075dedd1.tar.bz2
skyhanni-35df2ab2aa2056b61034757fe61554e7075dedd1.zip
Added support for rendering rounded rectangles. #851
Diffstat (limited to 'src/main/resources')
-rw-r--r--src/main/resources/assets/skyhanni/shaders/rounded_rect.fsh34
-rw-r--r--src/main/resources/assets/skyhanni/shaders/rounded_rect.vsh8
2 files changed, 42 insertions, 0 deletions
diff --git a/src/main/resources/assets/skyhanni/shaders/rounded_rect.fsh b/src/main/resources/assets/skyhanni/shaders/rounded_rect.fsh
new file mode 100644
index 000000000..9f3c31786
--- /dev/null
+++ b/src/main/resources/assets/skyhanni/shaders/rounded_rect.fsh
@@ -0,0 +1,34 @@
+#version 130
+
+uniform float scaleFactor;
+uniform float radius;
+uniform float smoothness;
+uniform vec2 halfSize;
+uniform vec2 centerPos;
+
+in vec4 color;
+
+// From https://www.shadertoy.com/view/WtdSDs
+float roundedRectSDF(vec2 center, vec2 halfSize, float radius) {
+ return length(max(abs(center) - halfSize + radius, 0.0)) - radius;
+}
+
+void main() {
+ float xScale = gl_ModelViewMatrix[0][0];
+ float yScale = gl_ModelViewMatrix[1][1];
+ float xTranslation = gl_ModelViewMatrix[3][0];
+ float yTranslation = gl_ModelViewMatrix[3][1];
+
+ vec2 newHalfSize = vec2(halfSize.x * xScale, halfSize.y * yScale);
+
+ float newCenterPosY = centerPos.y;
+ if (yScale > 1.0) {
+ newCenterPosY = centerPos.y - (halfSize.y * (yScale - 1));
+ }
+
+ vec2 newCenterPos = vec2((centerPos.x * xScale) + (xTranslation * scaleFactor), newCenterPosY - (yTranslation * scaleFactor));
+
+ float distance = roundedRectSDF(gl_FragCoord.xy - newCenterPos, newHalfSize, radius);
+ float smoothed = 1.0 - smoothstep(0.0, smoothness, distance);
+ gl_FragColor = color * vec4(1.0, 1.0, 1.0, smoothed);
+} \ No newline at end of file
diff --git a/src/main/resources/assets/skyhanni/shaders/rounded_rect.vsh b/src/main/resources/assets/skyhanni/shaders/rounded_rect.vsh
new file mode 100644
index 000000000..beadbf5fb
--- /dev/null
+++ b/src/main/resources/assets/skyhanni/shaders/rounded_rect.vsh
@@ -0,0 +1,8 @@
+#version 130
+
+out vec4 color;
+
+void main() {
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+ color = gl_Color;
+} \ No newline at end of file