forked from hannibal002/SkyHanni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/at/hannibal2/skyhanni/features/misc/RoundedRectangleShader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package at.hannibal2.skyhanni.features.misc | ||
|
||
import at.hannibal2.skyhanni.utils.shader.Shader | ||
import at.hannibal2.skyhanni.utils.shader.Uniform | ||
import net.minecraft.client.Minecraft | ||
|
||
object RoundedRectangleShader : Shader("rounded_rect", "rounded_rect") { | ||
|
||
val INSTANCE: RoundedRectangleShader | ||
get() = this | ||
|
||
var radius: Float = 0f | ||
var smoothness: Float = 0f | ||
var halfSize: FloatArray = floatArrayOf(0f, 0f) | ||
var centerPos: FloatArray = floatArrayOf(0f, 0f) | ||
set(value) { | ||
field = floatArrayOf(value[0], Minecraft.getMinecraft().displayHeight - value[1]) | ||
} | ||
|
||
override fun registerUniforms() { | ||
registerUniform(Uniform.UniformType.FLOAT, "radius") { radius } | ||
registerUniform(Uniform.UniformType.FLOAT, "smoothness") { smoothness } | ||
registerUniform(Uniform.UniformType.VEC2, "halfSize") { halfSize } | ||
registerUniform(Uniform.UniformType.VEC2, "centerPos") { centerPos } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/resources/assets/skyhanni/shaders/rounded_rect.fsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Based on https://www.shadertoy.com/view/WtdSDs | ||
|
||
#version 130 | ||
|
||
uniform float radius; | ||
uniform float smoothness; | ||
uniform vec2 halfSize; | ||
uniform vec2 centerPos; | ||
|
||
varying vec4 color; | ||
|
||
float roundedRectSDF(vec2 center, vec2 halfSize, float radius) { | ||
return length(max(abs(center) - halfSize + radius, 0.0)) - radius; | ||
} | ||
|
||
void main() { | ||
float distance = roundedRectSDF(gl_FragCoord.xy - centerPos, halfSize, radius); | ||
float smoothed = 1.0 - smoothstep(0.0, smoothness, distance); | ||
gl_FragColor = color * vec4(1.0, 1.0, 1.0, smoothed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#version 130 | ||
|
||
varying vec4 color; | ||
|
||
void main() { | ||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; | ||
color = gl_Color; | ||
} |