From cba23271513a6809f24760a4b93687d8148f813f Mon Sep 17 00:00:00 2001 From: Vixid <52578495+VixidDev@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:44:13 +0000 Subject: Adds a chroma shader to be used on non-textured GUI elements. #960 --- .../resources/assets/skyhanni/shaders/chroma.fsh | 43 ---------------------- .../resources/assets/skyhanni/shaders/chroma.vsh | 15 -------- .../assets/skyhanni/shaders/standard_chroma.fsh | 37 +++++++++++++++++++ .../assets/skyhanni/shaders/standard_chroma.vsh | 13 +++++++ .../assets/skyhanni/shaders/textured_chroma.fsh | 43 ++++++++++++++++++++++ .../assets/skyhanni/shaders/textured_chroma.vsh | 15 ++++++++ 6 files changed, 108 insertions(+), 58 deletions(-) delete mode 100644 src/main/resources/assets/skyhanni/shaders/chroma.fsh delete mode 100644 src/main/resources/assets/skyhanni/shaders/chroma.vsh create mode 100644 src/main/resources/assets/skyhanni/shaders/standard_chroma.fsh create mode 100644 src/main/resources/assets/skyhanni/shaders/standard_chroma.vsh create mode 100644 src/main/resources/assets/skyhanni/shaders/textured_chroma.fsh create mode 100644 src/main/resources/assets/skyhanni/shaders/textured_chroma.vsh (limited to 'src/main/resources') diff --git a/src/main/resources/assets/skyhanni/shaders/chroma.fsh b/src/main/resources/assets/skyhanni/shaders/chroma.fsh deleted file mode 100644 index 7b48a62f9..000000000 --- a/src/main/resources/assets/skyhanni/shaders/chroma.fsh +++ /dev/null @@ -1,43 +0,0 @@ -// Chroma Fragment Shader -// Modified from SkyblockAddons -// Credit: https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/resources/assets/skyblockaddons/shaders/program/chroma_screen_textured.fsh - -#version 120 - -uniform float chromaSize; -uniform float timeOffset; -uniform float saturation; -uniform bool forwardDirection; - -uniform sampler2D outTexture; - -varying vec2 outTextureCoords; -varying vec4 outColor; - -float rgb2b(vec3 rgb) { - return max(max(rgb.r, rgb.g), rgb.b); -} - -vec3 hsb2rgb_smooth(vec3 c) { - vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0); - rgb = rgb * rgb * (3.0 - 2.0 * rgb); // Cubic smoothing - return c.z * mix(vec3(1.0), rgb, c.y); -} - -void main() { - vec4 originalColor = texture2D(outTexture, outTextureCoords) * outColor; - - // Determine the direction chroma moves - float fragCoord; - if (forwardDirection) { - fragCoord = gl_FragCoord.x - gl_FragCoord.y; - } else { - fragCoord = gl_FragCoord.x + gl_FragCoord.y; - } - - // The hue takes in account the position, chroma settings, and time - float hue = mod(((fragCoord) / chromaSize) - timeOffset, 1.0); - - // Set the color to use the new hue & original saturation/value/alpha values - gl_FragColor = vec4(hsb2rgb_smooth(vec3(hue, saturation, rgb2b(originalColor.rgb))), originalColor.a); -} \ No newline at end of file diff --git a/src/main/resources/assets/skyhanni/shaders/chroma.vsh b/src/main/resources/assets/skyhanni/shaders/chroma.vsh deleted file mode 100644 index 5f5030d07..000000000 --- a/src/main/resources/assets/skyhanni/shaders/chroma.vsh +++ /dev/null @@ -1,15 +0,0 @@ -// Chroma Vertex Shader -// Credit: https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/resources/assets/skyblockaddons/shaders/program/chroma_screen_textured.vsh - -#version 120 - -varying vec2 outTextureCoords; -varying vec4 outColor; - -void main() { - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - - // Pass the color & texture coords to the fragment shader - outColor = gl_Color; - outTextureCoords = gl_MultiTexCoord0.st; -} diff --git a/src/main/resources/assets/skyhanni/shaders/standard_chroma.fsh b/src/main/resources/assets/skyhanni/shaders/standard_chroma.fsh new file mode 100644 index 000000000..8e10708bb --- /dev/null +++ b/src/main/resources/assets/skyhanni/shaders/standard_chroma.fsh @@ -0,0 +1,37 @@ +// Chroma Fragment Shader +// (Same as textured_chroma.fsh but isn't restricted to textured elements) + +#version 130 + +uniform float chromaSize; +uniform float timeOffset; +uniform float saturation; +uniform bool forwardDirection; + +in vec4 originalColor; + +float rgb2b(vec3 rgb) { + return max(max(rgb.r, rgb.g), rgb.b); +} + +vec3 hsb2rgb_smooth(vec3 c) { + vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0); + rgb = rgb * rgb * (3.0 - 2.0 * rgb); // Cubic smoothing + return c.z * mix(vec3(1.0), rgb, c.y); +} + +void main() { + // Determine the direction chroma moves + float fragCoord; + if (forwardDirection) { + fragCoord = gl_FragCoord.x - gl_FragCoord.y; + } else { + fragCoord = gl_FragCoord.x + gl_FragCoord.y; + } + + // The hue takes in account the position, chroma settings, and time + float hue = mod(((fragCoord) / chromaSize) - timeOffset, 1.0); + + // Set the color to use the new hue & original saturation/value/alpha values + gl_FragColor = vec4(hsb2rgb_smooth(vec3(hue, saturation, rgb2b(originalColor.rgb))), originalColor.a); +} \ No newline at end of file diff --git a/src/main/resources/assets/skyhanni/shaders/standard_chroma.vsh b/src/main/resources/assets/skyhanni/shaders/standard_chroma.vsh new file mode 100644 index 000000000..4895d119e --- /dev/null +++ b/src/main/resources/assets/skyhanni/shaders/standard_chroma.vsh @@ -0,0 +1,13 @@ +// Chroma Vertex Shader +// (Same as textured_chroma.vsh but isn't restricted to only texture elements) + +#version 130 + +out vec4 originalColor; + +void main() { + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + + // Pass original color to fragment + originalColor = gl_Color; +} \ No newline at end of file diff --git a/src/main/resources/assets/skyhanni/shaders/textured_chroma.fsh b/src/main/resources/assets/skyhanni/shaders/textured_chroma.fsh new file mode 100644 index 000000000..2f3d76af7 --- /dev/null +++ b/src/main/resources/assets/skyhanni/shaders/textured_chroma.fsh @@ -0,0 +1,43 @@ +// Textured Chroma Fragment Shader +// Modified from SkyblockAddons +// Credit: https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/resources/assets/skyblockaddons/shaders/program/chroma_screen_textured.fsh + +#version 130 + +uniform float chromaSize; +uniform float timeOffset; +uniform float saturation; +uniform bool forwardDirection; + +uniform sampler2D outTexture; + +in vec2 outTextureCoords; +in vec4 outColor; + +float rgb2b(vec3 rgb) { + return max(max(rgb.r, rgb.g), rgb.b); +} + +vec3 hsb2rgb_smooth(vec3 c) { + vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0); + rgb = rgb * rgb * (3.0 - 2.0 * rgb); // Cubic smoothing + return c.z * mix(vec3(1.0), rgb, c.y); +} + +void main() { + vec4 originalColor = texture2D(outTexture, outTextureCoords) * outColor; + + // Determine the direction chroma moves + float fragCoord; + if (forwardDirection) { + fragCoord = gl_FragCoord.x - gl_FragCoord.y; + } else { + fragCoord = gl_FragCoord.x + gl_FragCoord.y; + } + + // The hue takes in account the position, chroma settings, and time + float hue = mod(((fragCoord) / chromaSize) - timeOffset, 1.0); + + // Set the color to use the new hue & original saturation/value/alpha values + gl_FragColor = vec4(hsb2rgb_smooth(vec3(hue, saturation, rgb2b(originalColor.rgb))), originalColor.a); +} \ No newline at end of file diff --git a/src/main/resources/assets/skyhanni/shaders/textured_chroma.vsh b/src/main/resources/assets/skyhanni/shaders/textured_chroma.vsh new file mode 100644 index 000000000..87ca9fece --- /dev/null +++ b/src/main/resources/assets/skyhanni/shaders/textured_chroma.vsh @@ -0,0 +1,15 @@ +// Textured Chroma Vertex Shader +// Credit: https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/resources/assets/skyblockaddons/shaders/program/chroma_screen_textured.vsh + +#version 130 + +out vec2 outTextureCoords; +out vec4 outColor; + +void main() { + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + + // Pass the color & texture coords to the fragment shader + outColor = gl_Color; + outTextureCoords = gl_MultiTexCoord0.st; +} -- cgit