Skip to content

Commit

Permalink
feat(legacy): FrostBlur suboption to TargetHUD (CCBlueX#5357)
Browse files Browse the repository at this point in the history
  • Loading branch information
RtxOP authored Jan 18, 2025
1 parent b145e60 commit b0b059b
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRect
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRoundedBorderRect
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawScaledCustomSizeModalRect
import net.ccbluex.liquidbounce.utils.render.animation.AnimationUtil
import net.ccbluex.liquidbounce.utils.render.shader.shaders.RainbowShader
import net.ccbluex.liquidbounce.utils.render.shader.shaders.FrostShader
import net.ccbluex.liquidbounce.utils.render.shader.shaders.RainbowShader
import net.minecraft.client.gui.GuiChat
import net.minecraft.entity.EntityLivingBase
import net.minecraft.util.ResourceLocation
Expand All @@ -46,7 +46,10 @@ class Target : Element() {

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 frostTintColor by color("Frost-TintColor", Color.WHITE.withAlpha(150)) { backgroundMode == "Frost" }
private val frostBlurRadius by float("Frost-BlurRadius", 2F, 0.5F..5F) { 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 @@ -113,7 +116,9 @@ class Target : Element() {
else -> {
ColorUtils.interpolateHealthColor(
target,
255, 255, 0,
255,
255,
0,
if (fadeMode) alphaText else textColor.alpha,
healthFromScoreboard,
absorption
Expand All @@ -128,20 +133,20 @@ class Target : Element() {
if (smoothMode) {
val targetWidth = if (shouldRender) stringWidth else if (delayCounter >= vanishDelay) 0f else width
width = AnimationUtil.base(width.toDouble(), targetWidth.toDouble(), animationSpeed.toDouble())
.toFloat()
.coerceAtLeast(0f)
.toFloat().coerceAtLeast(0f)

val targetHeight = if (shouldRender) 40f else if (delayCounter >= vanishDelay) 0f else height
height = AnimationUtil.base(height.toDouble(), targetHeight.toDouble(), animationSpeed.toDouble())
.toFloat()
.coerceAtLeast(0f)
.toFloat().coerceAtLeast(0f)
} else {
width = stringWidth
height = 40f

val targetText = if (shouldRender) textColor.alpha else if (delayCounter >= vanishDelay) 0f else alphaText
alphaText = AnimationUtil.base(alphaText.toDouble(), targetText.toDouble(), animationSpeed.toDouble())
.toInt()
val targetText =
if (shouldRender) textColor.alpha else if (delayCounter >= vanishDelay) 0f else alphaText
alphaText =
AnimationUtil.base(alphaText.toDouble(), targetText.toDouble(), animationSpeed.toDouble())
.toInt()

val targetBackground = if (shouldRender) {
backgroundColor.alpha
Expand All @@ -150,9 +155,7 @@ class Target : Element() {
} else alphaBackground

alphaBackground = AnimationUtil.base(
alphaBackground.toDouble(),
targetBackground.toDouble(),
animationSpeed.toDouble()
alphaBackground.toDouble(), targetBackground.toDouble(), animationSpeed.toDouble()
).toInt()

val targetBorder = if (shouldRender) {
Expand All @@ -161,8 +164,9 @@ class Target : Element() {
0f
} else alphaBorder

alphaBorder = AnimationUtil.base(alphaBorder.toDouble(), targetBorder.toDouble(), animationSpeed.toDouble())
.toInt()
alphaBorder =
AnimationUtil.base(alphaBorder.toDouble(), targetBorder.toDouble(), animationSpeed.toDouble())
.toInt()
}

val backgroundCustomColor = backgroundColor.withAlpha(
Expand Down Expand Up @@ -190,19 +194,26 @@ class Target : Element() {

when (backgroundMode) {
"Frost" -> {
FrostShader.begin(true, frostIntensity).use {
FrostShader.begin(
enable = true,
intensity = frostIntensity,
tintColor = frostTintColor,
radius = frostBlurRadius,
).use {
drawRoundedBorderRect(
0F, 0F, width, height, borderStrength,
0,
borderCustomColor,
roundedRectRadius
0F, 0F, width, height, borderStrength, 0, borderCustomColor, roundedRectRadius
)
}
}

else -> {
RainbowShader.begin(backgroundMode == "Rainbow", rainbowX, rainbowY, rainbowOffset).use {
drawRoundedBorderRect(
0F, 0F, width, height, borderStrength,
0F,
0F,
width,
height,
borderStrength,
if (backgroundMode == "Rainbow") 0 else backgroundCustomColor,
borderCustomColor,
roundedRectRadius
Expand All @@ -229,8 +240,8 @@ class Target : Element() {
drawRect(3f + healthBarWidth, 34F, 3f + easingHealthWidth, 36F, Color(252, 185, 65).rgb)
}

val shouldRenderBody = (fadeMode && alphaText + alphaBackground + alphaBorder > 100) ||
(smoothMode && width + height > 100)
val shouldRenderBody =
(fadeMode && alphaText + alphaBackground + alphaBorder > 100) || (smoothMode && width + height > 100)

if (shouldRenderBody) {
// Draw title text
Expand All @@ -248,11 +259,7 @@ class Target : Element() {
// Draw info
mc.netHandler?.getPlayerInfo(target.uniqueID)?.let {
bodyFont.drawString(
"Ping: ${it.responseTime.coerceAtLeast(0)}",
36F,
24F,
textCustomColor,
textShadow
"Ping: ${it.responseTime.coerceAtLeast(0)}", 36F, 24F, textCustomColor, textShadow
)

// Draw head
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ package net.ccbluex.liquidbounce.utils.render.shader.shaders

import net.ccbluex.liquidbounce.utils.render.shader.FramebufferShader
import org.lwjgl.opengl.GL20.*
import java.awt.Color
import java.io.Closeable

object FrostShader : FramebufferShader("frost.frag"), Closeable {
var isInUse = false
private set

var intensity = 0.3f
var tintColor = Color.WHITE
var blurRadius = 2f
var frostAlpha = 0.6f

override fun setupUniforms() {
setupUniform("texture")
setupUniform("texelSize")
setupUniform("radius")
setupUniform("alpha")
setupUniform("intensity")
setupUniform("tintColor")
}

override fun updateUniforms() {
Expand All @@ -24,9 +29,14 @@ object FrostShader : FramebufferShader("frost.frag"), Closeable {
1f / mc.displayWidth * renderScale,
1f / mc.displayHeight * renderScale
)
glUniform1f(getUniform("radius"), 2f)
glUniform1f(getUniform("alpha"), 0.6f)
glUniform1f(getUniform("radius"), blurRadius)
glUniform1f(getUniform("alpha"), frostAlpha)
glUniform1f(getUniform("intensity"), intensity)
glUniform3f(getUniform("tintColor"),
tintColor.red / 255f,
tintColor.green / 255f,
tintColor.blue / 255f
)
}

override fun startShader() {
Expand All @@ -44,9 +54,12 @@ object FrostShader : FramebufferShader("frost.frag"), Closeable {
stopShader()
}

fun begin(enable: Boolean, intensity: Float = 0.3f) = apply {
fun begin(enable: Boolean, intensity: Float = 0.3f, tintColor: Color = Color.WHITE, radius: Float = 2f) = apply {
if (!enable) return@apply
this.intensity = intensity
this.tintColor = tintColor
this.blurRadius = radius
this.frostAlpha = tintColor.alpha / 255f
startShader()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,76 @@ uniform vec2 texelSize;
uniform float radius;
uniform float alpha;
uniform float intensity;
uniform vec3 tintColor;

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;
}
// Enhanced Gaussian weights for stronger blur
const float weights[5] = float[5](0.27027, 0.21621, 0.13513, 0.08108, 0.02702);

float hash(vec2 p) {
float h = dot(p, vec2(127.1, 311.7));
return fract(sin(h) * 43758.5453123);
}

float noise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);

float a = hash(i);
float b = hash(i + vec2(1.0, 0.0));
float c = hash(i + vec2(0.0, 1.0));
float d = hash(i + vec2(1.0, 1.0));

return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
}

// Blur
vec4 blur13(sampler2D image, vec2 uv, vec2 direction) {
vec4 color = texture2D(image, uv) * weights[0];
float totalWeight = weights[0];

for(int i = 1; i < 5; i++) {
vec2 offset = direction * texelSize * float(i) * radius * 2.0; // Doubled sampling distance
vec4 sampleA = texture2D(image, uv + offset);
vec4 sampleB = texture2D(image, uv - offset);

float weight = weights[i];
color += sampleA * weight + sampleB * weight;
totalWeight += 2.0 * weight;
}

return color / totalWeight;
}

// Distortion
vec2 distort(vec2 uv) {
float distortionStrength = intensity * 0.05; // Increased distortion
vec2 noise1 = vec2(noise(uv * 8.0), noise(uv * 8.0 + 0.5));
vec2 noise2 = vec2(noise(uv * 15.0 + 1.0), noise(uv * 15.0 + 1.5));

return uv + (noise1 + noise2 - 1.0) * distortionStrength;
}

// Average the sampled colors and add white tint based on intensity
color = color / count;
color = mix(color, vec4(1.0), intensity);
void main() {
vec2 uv = gl_TexCoord[0].xy;

vec2 distortedUV = distort(uv);

// two-pass gaussian blur with distortion
vec4 color = blur13(texture, distortedUV, vec2(1.0, 0.0));
color = blur13(texture, distortedUV, vec2(0.0, 1.0));

float frost = noise(uv * 12.0) * noise(uv * 18.0) * 1.5;
vec4 frostColor = vec4(tintColor * (0.75 + 0.25 * frost), 1.0);

color = mix(color, frostColor, intensity * 0.8);

float highlight = pow(frost, 3.0) * 0.8;
color.rgb += vec3(highlight) * intensity * 1.5;

// Add subtle frost edges
float edge = smoothstep(0.4, 0.6, frost);
color.rgb += tintColor * edge * intensity * 0.4;

gl_FragColor = vec4(color.rgb, color.a * alpha);
}

0 comments on commit b0b059b

Please sign in to comment.