From 42a1c727a676007c4c3b2fb7aea7500cbc97285e Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Sun, 6 Aug 2023 19:48:44 +0600 Subject: [PATCH] New Blur --- .../client/gui/minecraft/GuiIngameMenu.java | 10 +-- .../client/gui/util/BlurUtil.java | 79 +++++++++++++++++++ .../client/mixin/ducks/MinecraftExt.java | 1 + .../client/mixin/mixins/MinecraftMixin.java | 8 ++ .../client/mixin/mixins/ShaderGroupMixin.java | 9 +++ .../client/mods/util/IMixinShaderGroup.java | 5 +- .../client/utils/MenuBlurUtils.java | 19 ++--- 7 files changed, 114 insertions(+), 17 deletions(-) create mode 100644 src/main/java/net/silentclient/client/gui/util/BlurUtil.java diff --git a/src/main/java/net/silentclient/client/gui/minecraft/GuiIngameMenu.java b/src/main/java/net/silentclient/client/gui/minecraft/GuiIngameMenu.java index 67f2a2a..067d0e7 100644 --- a/src/main/java/net/silentclient/client/gui/minecraft/GuiIngameMenu.java +++ b/src/main/java/net/silentclient/client/gui/minecraft/GuiIngameMenu.java @@ -1,6 +1,5 @@ package net.silentclient.client.gui.minecraft; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; import net.minecraft.client.gui.achievement.GuiAchievements; import net.minecraft.client.gui.achievement.GuiStats; @@ -21,7 +20,6 @@ import net.silentclient.client.gui.hud.Watermark; import net.silentclient.client.gui.lite.clickgui.ClickGUI; import net.silentclient.client.gui.modmenu.ModMenu; import net.silentclient.client.mods.ModCategory; -import net.silentclient.client.mods.settings.GeneralMod; import net.silentclient.client.utils.MenuBlurUtils; import java.io.IOException; @@ -34,7 +32,7 @@ public class GuiIngameMenu extends GuiScreen */ public void initGui() { - MenuBlurUtils.loadBlur(); +// MenuBlurUtils.loadBlur(); this.buttonList.clear(); int i = -16; this.buttonList.add(new Button(1, this.width / 2 - 100, this.height / 4 + 120 + i, "Save and Quit to Title", true)); @@ -167,9 +165,9 @@ public class GuiIngameMenu extends GuiScreen @Override public void onGuiClosed() { - if(Client.getInstance().getSettingsManager().getSettingByClass(GeneralMod.class, "Menu Background Blur").getValBoolean()) { - Minecraft.getMinecraft().entityRenderer.loadEntityShader(null); - } +// if(Client.getInstance().getSettingsManager().getSettingByClass(GeneralMod.class, "Menu Background Blur").getValBoolean()) { +// Minecraft.getMinecraft().entityRenderer.loadEntityShader(null); +// } super.onGuiClosed(); } } diff --git a/src/main/java/net/silentclient/client/gui/util/BlurUtil.java b/src/main/java/net/silentclient/client/gui/util/BlurUtil.java new file mode 100644 index 0000000..36c7f01 --- /dev/null +++ b/src/main/java/net/silentclient/client/gui/util/BlurUtil.java @@ -0,0 +1,79 @@ +package net.silentclient.client.gui.util; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.shader.Framebuffer; +import net.minecraft.client.shader.ShaderGroup; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Timer; +import net.silentclient.client.mixin.ducks.MinecraftExt; +import net.silentclient.client.mods.util.IMixinShaderGroup; +import org.lwjgl.opengl.GL11; + +public class BlurUtil { + private static int lastScale; + + private static int lastScaleWidth; + + private static int lastScaleHeight; + + private static Framebuffer buffer; + + private static ShaderGroup blurShader; + + + private static final ResourceLocation shader = new ResourceLocation("shaders/post/menu_blur.json"); + + public static void initFboAndShader() { + Minecraft mc = Minecraft.getMinecraft(); + try { + blurShader = new ShaderGroup(mc.getTextureManager(), mc.getResourceManager(), mc.getFramebuffer(), shader); + blurShader.createBindFramebuffers(mc.displayWidth, mc.displayHeight); + buffer = (Framebuffer) ((IMixinShaderGroup) blurShader).getMainFramebuffer(); + } catch (Exception e) { + e.printStackTrace(); + } + } + public static void crop(float x, float y, float x2, float y2) { + Minecraft mc = Minecraft.getMinecraft(); + ScaledResolution scaledResolution = new ScaledResolution(mc); + int factor = scaledResolution.getScaleFactor(); + GL11.glScissor((int)(x * factor), (int)((scaledResolution.getScaledHeight() - y2) * factor), (int)((x2 - x) * factor), (int)((y2 - y) * factor)); + } + + public static void blur(float x, float y, float x2, float y2, ScaledResolution sr){ + Minecraft mc = Minecraft.getMinecraft(); + + int factor = sr.getScaleFactor(); + int factor2 = sr.getScaledWidth(); + int factor3 = sr.getScaledHeight(); + if (lastScale != factor || lastScaleWidth != factor2 || lastScaleHeight != factor3 || buffer == null || blurShader == null) + initFboAndShader(); + lastScale = factor; + lastScaleWidth = factor2; + lastScaleHeight = factor3; + GL11.glEnable(3089); + crop(x, y, x2, y2); + buffer.framebufferHeight = mc.displayHeight; + buffer.framebufferWidth = mc.displayWidth; + GlStateManager.resetColor(); + blurShader.loadShaderGroup(((Timer) ((MinecraftExt) mc).getTimer()).renderPartialTicks); + buffer.bindFramebuffer(true); + mc.getFramebuffer().bindFramebuffer(true); + GL11.glDisable(3089); + } + + public static void blur(float x, float y, float x2, float y2) { + Minecraft mc = Minecraft.getMinecraft(); + GlStateManager.disableAlpha(); + blur(x, y, x2, y2, new ScaledResolution(mc)); + GlStateManager.enableAlpha(); + } + public static void blur2(float x, float y, float x2, float y2, float h, float w) { + Minecraft mc = Minecraft.getMinecraft(); + GlStateManager.disableAlpha(); + blur(x, y, x2 + w, y2 + h, new ScaledResolution(mc)); + GlStateManager.enableAlpha(); + } +} \ No newline at end of file diff --git a/src/main/java/net/silentclient/client/mixin/ducks/MinecraftExt.java b/src/main/java/net/silentclient/client/mixin/ducks/MinecraftExt.java index e5948d9..79fb7c8 100644 --- a/src/main/java/net/silentclient/client/mixin/ducks/MinecraftExt.java +++ b/src/main/java/net/silentclient/client/mixin/ducks/MinecraftExt.java @@ -2,4 +2,5 @@ package net.silentclient.client.mixin.ducks; public interface MinecraftExt { void setSession(Object session); + Object getTimer(); } diff --git a/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java index 2f97dfe..4891ef2 100644 --- a/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java +++ b/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java @@ -16,6 +16,7 @@ import net.minecraft.item.ItemBlock; import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Session; +import net.minecraft.util.Timer; import net.minecraft.world.WorldSettings; import net.silentclient.client.Client; import net.silentclient.client.event.impl.*; @@ -128,6 +129,8 @@ public abstract class MinecraftMixin implements MinecraftExt { @Mutable @Shadow @Final private Session session; + @Shadow private Timer timer; + @Inject(method = "displayGuiScreen", at = @At("RETURN"), cancellable = true) public void displayGuiScreenInject(GuiScreen guiScreenIn, CallbackInfo ci) { if(Client.backgroundPanorama == null) { @@ -317,4 +320,9 @@ public abstract class MinecraftMixin implements MinecraftExt { return this.theWorld == null && this.currentScreen != null ? 30 : this.gameSettings.limitFramerate; } + + @Override + public Object getTimer() { + return this.timer; + } } diff --git a/src/main/java/net/silentclient/client/mixin/mixins/ShaderGroupMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/ShaderGroupMixin.java index b999e53..f237052 100644 --- a/src/main/java/net/silentclient/client/mixin/mixins/ShaderGroupMixin.java +++ b/src/main/java/net/silentclient/client/mixin/mixins/ShaderGroupMixin.java @@ -1,16 +1,25 @@ package net.silentclient.client.mixin.mixins; +import net.minecraft.client.shader.Framebuffer; import net.minecraft.client.shader.Shader; import net.minecraft.client.shader.ShaderGroup; import net.silentclient.client.mods.util.IMixinShaderGroup; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.gen.Accessor; import java.util.List; @Mixin(ShaderGroup.class) public abstract class ShaderGroupMixin implements IMixinShaderGroup { + @Shadow private Framebuffer mainFramebuffer; + @Override @Accessor public abstract List getListShaders(); + + @Override + public Object getMainFramebuffer() { + return this.mainFramebuffer; + } } diff --git a/src/main/java/net/silentclient/client/mods/util/IMixinShaderGroup.java b/src/main/java/net/silentclient/client/mods/util/IMixinShaderGroup.java index cb78c22..b96326b 100644 --- a/src/main/java/net/silentclient/client/mods/util/IMixinShaderGroup.java +++ b/src/main/java/net/silentclient/client/mods/util/IMixinShaderGroup.java @@ -1,9 +1,10 @@ package net.silentclient.client.mods.util; -import java.util.List; - import net.minecraft.client.shader.Shader; +import java.util.List; + public interface IMixinShaderGroup { List getListShaders(); + Object getMainFramebuffer(); } diff --git a/src/main/java/net/silentclient/client/utils/MenuBlurUtils.java b/src/main/java/net/silentclient/client/utils/MenuBlurUtils.java index e7acd94..a9c1121 100644 --- a/src/main/java/net/silentclient/client/utils/MenuBlurUtils.java +++ b/src/main/java/net/silentclient/client/utils/MenuBlurUtils.java @@ -1,11 +1,9 @@ package net.silentclient.client.utils; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.silentclient.client.Client; -import net.silentclient.client.cosmetics.StaticResourceLocation; +import net.silentclient.client.gui.util.BlurUtil; import net.silentclient.client.mixin.accessors.GuiAccessor; -import net.silentclient.client.mixin.ducks.EntityRendererExt; import net.silentclient.client.mods.settings.GeneralMod; import java.awt.*; @@ -16,12 +14,15 @@ public class MenuBlurUtils { } public static void loadBlur(boolean force) { - if(Client.getInstance().getSettingsManager().getSettingByClass(GeneralMod.class, "Menu Background Blur").getValBoolean() || force) { - ((EntityRendererExt) Minecraft.getMinecraft().entityRenderer).silent$loadShader(new StaticResourceLocation("shaders/post/menu_blur.json")); - } +// if(Client.getInstance().getSettingsManager().getSettingByClass(GeneralMod.class, "Menu Background Blur").getValBoolean() || force) { +// ((EntityRendererExt) Minecraft.getMinecraft().entityRenderer).silent$loadShader(new StaticResourceLocation("shaders/post/menu_blur.json")); +// } } public static void renderBackground(GuiScreen instance) { + if(Client.getInstance().getSettingsManager().getSettingByClass(GeneralMod.class, "Menu Background Blur").getValBoolean()) { + BlurUtil.blur2(0, 0, 1920, 1080, 0, 0); + } if(Client.getInstance().getSettingsManager().getSettingByClass(GeneralMod.class, "Menu Background Blur").getValBoolean() && !Client.getInstance().getGlobalSettings().isLite()) { ((GuiAccessor) instance).silent$drawGradientRect(0, 0, instance.width, instance.height, new Color(0, 0, 0, 0).getRGB(), new Color(0, 0, 0, 0).getRGB()); } else { @@ -34,8 +35,8 @@ public class MenuBlurUtils { } public static void unloadBlur(boolean force) { - if(Client.getInstance().getSettingsManager().getSettingByClass(GeneralMod.class, "Menu Background Blur").getValBoolean() || force) { - Minecraft.getMinecraft().entityRenderer.loadEntityShader(null); - } +// if(Client.getInstance().getSettingsManager().getSettingByClass(GeneralMod.class, "Menu Background Blur").getValBoolean() || force) { +// Minecraft.getMinecraft().entityRenderer.loadEntityShader(null); +// } } }