Skip to content

Commit

Permalink
feat(legacy): "Frost" Background color mode to TargetHUD (CCBlueX#5343)
Browse files Browse the repository at this point in the history
  • Loading branch information
RtxOP authored Jan 17, 2025
1 parent 5560611 commit fac7760
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawScaledCustomSizeMod
import net.ccbluex.liquidbounce.utils.render.animation.AnimationUtil
import net.ccbluex.liquidbounce.utils.render.animation.AnimationUtil.debugFPS
import net.ccbluex.liquidbounce.utils.render.shader.shaders.RainbowShader
import net.ccbluex.liquidbounce.utils.render.shader.shaders.FrostShader
import net.minecraft.client.gui.GuiChat
import net.minecraft.entity.EntityLivingBase
import net.minecraft.util.ResourceLocation
Expand All @@ -47,8 +48,9 @@ class Target : Element() {

private val borderStrength by float("Border-Strength", 3F, 1F..5F)

private val backgroundMode by choices("Background-ColorMode", arrayOf("Custom", "Rainbow"), "Custom")
private val backgroundMode by choices("Background-ColorMode", arrayOf("Custom", "Rainbow", "Frost"), "Custom")
private val backgroundColor by color("Background-Color", Color.BLACK.withAlpha(150)) { backgroundMode == "Custom" }
private val frostIntensity by float("Frost-Intensity", 0.3F, 0.1F..1F) { backgroundMode == "Frost" }

private val borderMode by choices("Border-ColorMode", arrayOf("Custom", "Rainbow"), "Custom")
private val borderColor by color("Border-Color", Color.BLACK) { borderMode == "Custom" }
Expand Down Expand Up @@ -201,14 +203,27 @@ class Target : Element() {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

if (fadeMode && shouldRender || smoothMode && shouldRender || delayCounter < vanishDelay) {
// Draw rect box
RainbowShader.begin(backgroundMode == "Rainbow", rainbowX, rainbowY, rainbowOffset).use {
drawRoundedBorderRect(
0F, 0F, width, height, borderStrength,
if (backgroundMode == "Rainbow") 0 else backgroundCustomColor,
borderCustomColor,
roundedRectRadius
)
when (backgroundMode) {
"Frost" -> {
FrostShader.begin(true, frostIntensity).use {
drawRoundedBorderRect(
0F, 0F, width, height, borderStrength,
0,
borderCustomColor,
roundedRectRadius
)
}
}
else -> {
RainbowShader.begin(backgroundMode == "Rainbow", rainbowX, rainbowY, rainbowOffset).use {
drawRoundedBorderRect(
0F, 0F, width, height, borderStrength,
if (backgroundMode == "Rainbow") 0 else backgroundCustomColor,
borderCustomColor,
roundedRectRadius
)
}
}
}

// Health bar
Expand Down
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()
}
}
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);
}

0 comments on commit fac7760

Please sign in to comment.