forked from CCBlueX/LiquidBounce
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(legacy): "Frost" Background color mode to TargetHUD (CCBlueX#5343)
- Loading branch information
Showing
3 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
src/main/java/net/ccbluex/liquidbounce/utils/render/shader/shaders/FrostShader.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,52 @@ | ||
package net.ccbluex.liquidbounce.utils.render.shader.shaders | ||
|
||
import net.ccbluex.liquidbounce.utils.render.shader.FramebufferShader | ||
import org.lwjgl.opengl.GL20.* | ||
import java.io.Closeable | ||
|
||
object FrostShader : FramebufferShader("frost.frag"), Closeable { | ||
var isInUse = false | ||
private set | ||
|
||
var intensity = 0.3f | ||
|
||
override fun setupUniforms() { | ||
setupUniform("texture") | ||
setupUniform("texelSize") | ||
setupUniform("radius") | ||
setupUniform("alpha") | ||
setupUniform("intensity") | ||
} | ||
|
||
override fun updateUniforms() { | ||
glUniform1i(getUniform("texture"), 0) | ||
glUniform2f(getUniform("texelSize"), | ||
1f / mc.displayWidth * renderScale, | ||
1f / mc.displayHeight * renderScale | ||
) | ||
glUniform1f(getUniform("radius"), 2f) | ||
glUniform1f(getUniform("alpha"), 0.6f) | ||
glUniform1f(getUniform("intensity"), intensity) | ||
} | ||
|
||
override fun startShader() { | ||
super.startShader() | ||
isInUse = true | ||
} | ||
|
||
override fun stopShader() { | ||
super.stopShader() | ||
isInUse = false | ||
} | ||
|
||
override fun close() { | ||
if (isInUse) | ||
stopShader() | ||
} | ||
|
||
fun begin(enable: Boolean, intensity: Float = 0.3f) = apply { | ||
if (!enable) return@apply | ||
this.intensity = intensity | ||
startShader() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/resources/assets/minecraft/liquidbounce/shader/fragment/frost.frag
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 @@ | ||
#version 120 | ||
|
||
uniform sampler2D texture; | ||
uniform vec2 texelSize; | ||
uniform float radius; | ||
uniform float alpha; | ||
uniform float intensity; | ||
|
||
void main() { | ||
vec4 color = vec4(0.0); | ||
float count = 0.0; | ||
|
||
// Sample pixels in a radius for the blur effect | ||
for(float x = -radius; x <= radius; x++) { | ||
for(float y = -radius; y <= radius; y++) { | ||
vec2 offset = vec2(x, y) * texelSize; | ||
color += texture2D(texture, gl_TexCoord[0].xy + offset); | ||
count += 1.0; | ||
} | ||
} | ||
|
||
// Average the sampled colors and add white tint based on intensity | ||
color = color / count; | ||
color = mix(color, vec4(1.0), intensity); | ||
gl_FragColor = vec4(color.rgb, color.a * alpha); | ||
} |