(feature) better rounds

This commit is contained in:
kirillsaint 2024-05-31 01:36:28 +06:00
parent 9a81e6f087
commit fc4b24cf19
11 changed files with 279 additions and 24 deletions

View File

@ -83,7 +83,7 @@ public class LiteMainMenu extends SilentScreen
} else {
this.bannerAnimation.setAnimation(0, 30);
}
RenderUtil.drawImage(PromoController.getResponse().getCurrentPanel().getImageLocation(), this.width - 74 + (-this.bannerAnimation.getValue()), this.height - 42 + (-this.bannerAnimation.getValue()), 71, 40, false);
RenderUtil.drawRoundTextured(this.width - 74 + (-this.bannerAnimation.getValue()), this.height - 42 + (-this.bannerAnimation.getValue()), 71, 40, 4, 1, PromoController.getResponse().getCurrentPanel().getImageLocation(), false);
} else {
PromoController.getResponse().getCurrentPanel().loadImage();
}

View File

@ -3,6 +3,7 @@ package net.silentclient.client.gui.util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
@ -13,14 +14,59 @@ import net.silentclient.client.Client;
import net.silentclient.client.cosmetics.StaticResourceLocation;
import net.silentclient.client.mixin.ducks.TextureManagerExt;
import net.silentclient.client.utils.ColorUtils;
import net.silentclient.client.utils.ShaderUtils;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import static org.lwjgl.opengl.GL11.*;
public class RenderUtil {
final static Minecraft mc = Minecraft.getMinecraft();
final static FontRenderer fr = mc.fontRendererObj;
public static ShaderUtils roundedShader = new ShaderUtils("silentclient/shaders/roundedRect.frag");
public static ShaderUtils roundedOutlineShader = new ShaderUtils("silentclient/shaders/roundRectOutline.frag");
private static ShaderUtils roundedTexturedShader = new ShaderUtils("silentclient/shaders/roundRectTextured.frag");
public static void drawRound(float x, float y, float width, float height, float radius, Color color) {
ColorUtils.resetColor();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
roundedShader.init();
setupRoundedRectUniforms(x, y, width, height, radius, roundedShader);
roundedShader.setUniformf("color", color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
ShaderUtils.drawQuads(x - 1, y - 1, width + 2, height + 2);
roundedShader.unload();
GlStateManager.disableBlend();
}
public static void drawRoundTextured(float x, float y, float width, float height, float radius, float alpha, ResourceLocation image, boolean mipmapped) {
if(mipmapped) {
Client.getInstance().getTextureManager().bindTextureMipmapped(image);
} else {
Minecraft.getMinecraft().getTextureManager().bindTexture(image);
}
ColorUtils.resetColor();
roundedTexturedShader.init();
roundedTexturedShader.setUniformi("textureIn", 0);
setupRoundedRectUniforms(x, y, width, height, radius, roundedTexturedShader);
roundedTexturedShader.setUniformf("alpha", alpha);
ShaderUtils.drawQuads(x - 1, y - 1, width + 2, height + 2);
roundedTexturedShader.unload();
GlStateManager.disableBlend();
}
private static void setupRoundedRectUniforms(float x, float y, float width, float height, float radius, ShaderUtils roundedTexturedShader) {
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
roundedTexturedShader.setUniformf("location", x * sr.getScaleFactor(),
(Minecraft.getMinecraft().displayHeight - (height * sr.getScaleFactor())) - (y * sr.getScaleFactor()));
roundedTexturedShader.setUniformf("rectSize", width * sr.getScaleFactor(), height * sr.getScaleFactor());
roundedTexturedShader.setUniformf("radius", radius * sr.getScaleFactor());
}
public static void drawRoundedRect(float x, float y, float x1, float y1, float radius, int color) {
x1 = x + x1;
y1 = y + y1;
@ -65,7 +111,7 @@ public class RenderUtil {
glPopAttrib();
glLineWidth(1);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
}
}
public static void drawRoundedOutline(float x, float y, float x1, float y1, float radius,float lineWidth, int color) {
x1 = x + x1;
y1 = y + y1;
@ -83,13 +129,13 @@ public class RenderUtil {
glBegin(GL_LINE_LOOP);
int i;
for (i = 0; i <= 90; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y + radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y + radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 90; i <= 180; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 0; i <= 90; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius);
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius);
for (i = 90; i <= 180; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y + radius + Math.cos(i * Math.PI / 180.0D) * radius);
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y + radius + Math.cos(i * Math.PI / 180.0D) * radius);
glEnd();
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
@ -100,7 +146,7 @@ public class RenderUtil {
glPopAttrib();
glLineWidth(1);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
}
}
/*
*

View File

@ -35,6 +35,7 @@ public class HudMod extends ModDraggable {
this.addBooleanSetting("Brackets", this, false);
this.addBooleanSetting("Fancy Font", this, false);
this.addBooleanSetting("Rounded Corners", this, false);
this.addSliderSetting("Rounding Strength", this, 3, 1, 6, true);
}
public String getText() {
@ -110,7 +111,7 @@ public class HudMod extends ModDraggable {
preRender();
if(background) {
if(roundedCorners) {
RenderUtil.drawRoundedRect(getX(), getY(), this.getRealWidth(), this.getHeight(), 6, backgroundColor.getRGB());
RenderUtil.drawRound(getX(), getY(), this.getRealWidth(), this.getHeight(), Client.getInstance().getSettingsManager().getSettingByName(this, "Rounding Strength").getValInt(), backgroundColor);
} else {
RenderUtils.drawRect(getX(), getY(), this.getRealWidth(), this.getHeight(), backgroundColor.getRGB());
}

View File

@ -1,7 +1,5 @@
package net.silentclient.client.mods.hud;
import java.awt.Color;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
@ -15,13 +13,16 @@ import net.minecraft.potion.Potion;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.silentclient.client.Client;
import net.silentclient.client.gui.hud.ScreenPosition;
import net.silentclient.client.gui.lite.clickgui.utils.GlUtils;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.hud.ScreenPosition;
import net.silentclient.client.gui.util.RenderUtil;
import net.silentclient.client.mods.CustomFontRenderer;
import net.silentclient.client.mods.ModCategory;
import net.silentclient.client.mods.ModDraggable;
import java.awt.*;
public class BlockInfoMod extends ModDraggable {
private BlockPos pos;
private IBlockState state;
@ -43,6 +44,8 @@ public class BlockInfoMod extends ModDraggable {
this.addColorSetting("Color", this, new Color(255, 255, 255));
this.addBooleanSetting("Font Shadow", this, true);
this.addBooleanSetting("Fancy Font", this, false);
this.addBooleanSetting("Rounded Corners", this, false);
this.addSliderSetting("Rounding Strength", this, 3, 1, 6, true);
}
@Override
@ -70,6 +73,8 @@ public class BlockInfoMod extends ModDraggable {
if(block != null && !block.equals(Blocks.portal) && !block.equals(Blocks.end_portal)) {
String harvest = "";
boolean background = Client.getInstance().getSettingsManager().getSettingByName(this, "Background").getValBoolean();
boolean roundedCorners = Client.getInstance().getSettingsManager().getSettingByName(this, "Rounded Corners").getValBoolean();
Color backgroundColor = Client.getInstance().getSettingsManager().getSettingByName(this, "Background Color").getValColor();
boolean fontShadow = Client.getInstance().getSettingsManager().getSettingByName(this, "Font Shadow").getValBoolean();
Color color = Client.getInstance().getSettingsManager().getSettingByName(this, "Color").getValColor();
@ -82,11 +87,15 @@ public class BlockInfoMod extends ModDraggable {
float infoY = 4.5F;
font.setRenderMode(fancyFont ? CustomFontRenderer.RenderMode.CUSTOM : CustomFontRenderer.RenderMode.DEFAULT);
if(background) {
RenderUtils.drawRect(0, 0, getWidth(), getHeight(), backgroundColor.getRGB());
if(roundedCorners) {
RenderUtil.drawRound(0, 0, getWidth(), getHeight(), Client.getInstance().getSettingsManager().getSettingByName(this, "Rounding Strength").getValInt(), backgroundColor);
} else {
RenderUtils.drawRect(0, 0, getWidth(), getHeight(), backgroundColor.getRGB());
}
}
GlUtils.startScale(0, 0, 5, 50, 1.8F);
RenderHelper.enableGUIStandardItemLighting();
mc.getRenderItem().renderItemAndEffectIntoGUI(new ItemStack(block), 0 + 5, 0 + (50 / 2) - 8);

View File

@ -1,16 +1,17 @@
package net.silentclient.client.mods.hud;
import java.awt.Color;
import net.minecraft.util.BlockPos;
import net.minecraft.world.chunk.Chunk;
import net.silentclient.client.Client;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.hud.ScreenPosition;
import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils;
import net.silentclient.client.gui.util.RenderUtil;
import net.silentclient.client.mods.CustomFontRenderer;
import net.silentclient.client.mods.ModCategory;
import net.silentclient.client.mods.ModDraggable;
import java.awt.*;
public class CoordinatesMod extends ModDraggable {
int maxWidth = 0;
@ -27,6 +28,8 @@ public class CoordinatesMod extends ModDraggable {
this.addBooleanSetting("Font Shadow", this, true);
this.addBooleanSetting("Brackets", this, false);
this.addBooleanSetting("Fancy Font", this, false);
this.addBooleanSetting("Rounded Corners", this, false);
this.addSliderSetting("Rounding Strength", this, 3, 1, 6, true);
this.addBooleanSetting("Show Biome", this, true);
}
@ -48,6 +51,7 @@ public class CoordinatesMod extends ModDraggable {
CustomFontRenderer font = new CustomFontRenderer();
font.setRenderMode(fancyFont ? CustomFontRenderer.RenderMode.CUSTOM : CustomFontRenderer.RenderMode.DEFAULT);
boolean roundedCorners = Client.getInstance().getSettingsManager().getSettingByName(this, "Rounded Corners").getValBoolean();
boolean background = Client.getInstance().getSettingsManager().getSettingByName(this, "Background").getValBoolean();
Color backgroundColor = Client.getInstance().getSettingsManager().getSettingByName(this, "Background Color").getValColor();
boolean fontShadow = Client.getInstance().getSettingsManager().getSettingByName(this, "Font Shadow").getValBoolean();
@ -67,7 +71,11 @@ public class CoordinatesMod extends ModDraggable {
}
if(background) {
RenderUtils.drawRect(0, 0, maxWidth, getHeight(), backgroundColor.getRGB());
if(roundedCorners) {
RenderUtil.drawRound(0, 0, maxWidth, getHeight(), Client.getInstance().getSettingsManager().getSettingByName(this, "Rounding Strength").getValInt(), backgroundColor);
} else {
RenderUtils.drawRect(0, 0, maxWidth, getHeight(), backgroundColor.getRGB());
}
}
font.drawString((!brackets ? "" : "[") + "X: " + (int) (mc.thePlayer.posX) + (!brackets ? "" : "]"), (int) (0 + 4.5F), (int) (0 + 4.5F), color.getRGB(), fontShadow);

View File

@ -38,6 +38,7 @@ public class KeystrokesMod extends ModDraggable {
this.addBooleanSetting("Fancy Font", this, false);
this.addBooleanSetting("Background", this, true);
this.addBooleanSetting("Rounded Corners", this, false);
this.addSliderSetting("Rounding Strength", this, 3, 1, 6, true);
this.addModeSetting("CPS Mode", this, "Small", cpsModes);
this.addColorSetting("Color", this, new Color(255, 255, 255));
this.addColorSetting("Background Color", this, new Color(0, 0, 0), 127);
@ -205,13 +206,13 @@ public class KeystrokesMod extends ModDraggable {
setAnimation(key.blue, key.isDown() ? clickedBackgroundColor.getBlue() : backgroundColor.getBlue(), fadeDelay);
setAnimation(key.alpha, key.isDown() ? clickedBackgroundColor.getAlpha() : backgroundColor.getAlpha(), fadeDelay);
if(roundedCorners) {
RenderUtil.drawRoundedRect(
RenderUtil.drawRound(
key.getX(),
key.getY(),
key.getWidth(),
key.getHeight(),
6,
new Color((int) key.red.getValue(), (int) key.green.getValue(), (int) key.blue.getValue(), (int) key.alpha.getValue()).getRGB()
Client.getInstance().getSettingsManager().getSettingByName(this, "Rounding Strength").getValInt(),
new Color((int) key.red.getValue(), (int) key.green.getValue(), (int) key.blue.getValue(), (int) key.alpha.getValue())
);
} else {
RenderUtils.drawRect(
@ -308,13 +309,13 @@ public class KeystrokesMod extends ModDraggable {
setAnimation(Space.blue, Space.isDown() ? clickedBackgroundColor.getBlue() : backgroundColor.getBlue(), fadeDelay);
setAnimation(Space.alpha, Space.isDown() ? clickedBackgroundColor.getAlpha() : backgroundColor.getAlpha(), fadeDelay);
if(roundedCorners) {
RenderUtil.drawRoundedRect(
RenderUtil.drawRound(
0,
0 + mode.getHeight() + 2,
mode.getWidth(),
10,
6,
new Color((int) Space.red.getValue(), (int) Space.green.getValue(), (int) Space.blue.getValue(), (int) Space.alpha.getValue()).getRGB()
Client.getInstance().getSettingsManager().getSettingByName(this, "Rounding Strength").getValInt(),
new Color((int) Space.red.getValue(), (int) Space.green.getValue(), (int) Space.blue.getValue(), (int) Space.alpha.getValue())
);
} else {
RenderUtils.drawRect(

View File

@ -0,0 +1,123 @@
package net.silentclient.client.utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;
import java.io.IOException;
import java.io.InputStream;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL20.*;
public class ShaderUtils {
private static Minecraft mc = Minecraft.getMinecraft();
private final int programID;
public ShaderUtils(String fragmentShaderLoc, String vertexShaderLoc) {
int program = glCreateProgram();
try {
int fragmentShaderID = createShader(mc.getResourceManager().getResource(new ResourceLocation(fragmentShaderLoc)).getInputStream(), GL_FRAGMENT_SHADER);;
glAttachShader(program, fragmentShaderID);
int vertexShaderID = createShader(mc.getResourceManager().getResource(new ResourceLocation(vertexShaderLoc)).getInputStream(), GL_VERTEX_SHADER);
glAttachShader(program, vertexShaderID);
} catch (IOException e) {
e.printStackTrace();
}
glLinkProgram(program);
int status = glGetProgrami(program, GL_LINK_STATUS);
if (status == 0) {
throw new IllegalStateException("Shader failed to link!");
}
this.programID = program;
}
public ShaderUtils(String fragmentShaderLoc) {
this(fragmentShaderLoc, "silentclient/shaders/vertex.vsh");
}
public void init() {
glUseProgram(programID);
}
public void unload() {
glUseProgram(0);
}
public int getUniform(String name) {
return glGetUniformLocation(programID, name);
}
public void setUniformf(String name, float... args) {
int loc = glGetUniformLocation(programID, name);
switch (args.length) {
case 1:
glUniform1f(loc, args[0]);
break;
case 2:
glUniform2f(loc, args[0], args[1]);
break;
case 3:
glUniform3f(loc, args[0], args[1], args[2]);
break;
case 4:
glUniform4f(loc, args[0], args[1], args[2], args[3]);
break;
}
}
public void setUniformi(String name, int... args) {
int loc = glGetUniformLocation(programID, name);
if (args.length > 1) glUniform2i(loc, args[0], args[1]);
else glUniform1i(loc, args[0]);
}
public static void drawQuads(float x, float y, float width, float height) {
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(x, y);
glTexCoord2f(0, 1);
glVertex2f(x, y + height);
glTexCoord2f(1, 1);
glVertex2f(x + width, y + height);
glTexCoord2f(1, 0);
glVertex2f(x + width, y);
glEnd();
}
public static void drawQuads() {
ScaledResolution sr = new ScaledResolution(mc);
float width = (float) sr.getScaledWidth_double();
float height = (float) sr.getScaledHeight_double();
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex2f(0, 0);
glTexCoord2f(0, 0);
glVertex2f(0, height);
glTexCoord2f(1, 0);
glVertex2f(width, height);
glTexCoord2f(1, 1);
glVertex2f(width, 0);
glEnd();
}
private int createShader(InputStream inputStream, int shaderType) {
int shader = glCreateShader(shaderType);
glShaderSource(shader, FileUtils.readInputStream(inputStream));
glCompileShader(shader);
if (glGetShaderi(shader, GL_COMPILE_STATUS) == 0) {
System.out.println(glGetShaderInfoLog(shader, 4096));
throw new IllegalStateException(String.format("Shader failed to compile!", shaderType));
}
return shader;
}
}

View File

@ -0,0 +1,19 @@
#version 120
uniform vec2 location, rectSize;
uniform vec4 color, outlineColor;
uniform float radius, outlineThickness;
float roundedSDF(vec2 centerPos, vec2 size, float radius) {
return length(max(abs(centerPos) - size + radius, 0.0)) - radius;
}
void main() {
float distance = roundedSDF(gl_FragCoord.xy - location - (rectSize * .5), (rectSize * .5) + (outlineThickness *.5) - 1.0, radius);
float blendAmount = smoothstep(0., 2., abs(distance) - (outlineThickness * .5));
vec4 insideColor = (distance < 0.) ? color : vec4(outlineColor.rgb, 0.0);
gl_FragColor = mix(outlineColor, insideColor, blendAmount);
}

View File

@ -0,0 +1,16 @@
#version 120
uniform vec2 location, rectSize;
uniform sampler2D textureIn;
uniform float radius, alpha;
float roundedBoxSDF(vec2 centerPos, vec2 size, float radius) {
return length(max(abs(centerPos) -size, 0.)) - radius;
}
void main() {
float distance = roundedBoxSDF((rectSize * .5) - (gl_TexCoord[0].st * rectSize), (rectSize * .5) - radius - 1., radius);
float smoothedAlpha = (1.0-smoothstep(0.0, 2.0, distance)) * alpha;
gl_FragColor = vec4(texture2D(textureIn, gl_TexCoord[0].st).rgb, smoothedAlpha);
}

View File

@ -0,0 +1,15 @@
#version 120
uniform vec2 rectSize;
uniform sampler2D textureIn;
uniform float radius, alpha;
float roundedBoxSDF(vec2 centerPos, vec2 size, float radius) {
return length(max(abs(centerPos) -size, 0.)) - radius;
}
void main() {
float distance = roundedBoxSDF((rectSize * .5) - (gl_TexCoord[0].st * rectSize), (rectSize * .5) - radius - 1., radius);
float smoothedAlpha = (1.0-smoothstep(0.0, 2.0, distance)) * alpha;
gl_FragColor = vec4(texture2D(textureIn, gl_TexCoord[0].st).rgb, smoothedAlpha);
}

View File

@ -0,0 +1,17 @@
#version 120
uniform vec2 location, rectSize;
uniform vec4 color;
uniform float radius;
uniform bool blur;
float roundSDF(vec2 p, vec2 b, float r) {
return length(max(abs(p) - b, 0.0)) - r;
}
void main() {
vec2 rectHalf = rectSize * .5;
float smoothedAlpha = (1.0-smoothstep(0.0, 1.0, roundSDF(rectHalf - (gl_TexCoord[0].st * rectSize), rectHalf - radius - 1., radius))) * color.a;
gl_FragColor = vec4(color.rgb, smoothedAlpha);
}