From 35df2ab2aa2056b61034757fe61554e7075dedd1 Mon Sep 17 00:00:00 2001 From: Vixid <52578495+VixidDev@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:02:49 +0000 Subject: Added support for rendering rounded rectangles. #851 --- .../assets/skyhanni/shaders/rounded_rect.fsh | 34 ++++++++++++++++++++++ .../assets/skyhanni/shaders/rounded_rect.vsh | 8 +++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/resources/assets/skyhanni/shaders/rounded_rect.fsh create mode 100644 src/main/resources/assets/skyhanni/shaders/rounded_rect.vsh (limited to 'src/main/resources/assets/skyhanni') 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 -- cgit