Skip to content

Commit 70cd468

Browse files
committed
improve blur, fix bugs
1 parent 655df9b commit 70cd468

6 files changed

Lines changed: 53 additions & 16 deletions

File tree

src/main/java/eu/shoroa/contrib/render/ShBlur.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ private int nvgImageFromHandle(int texture, int width, int height, int flags) {
9292
}
9393

9494
public void render() {
95+
if (!InternalSettingsMod.getInstance().getBlurSetting().isToggled()) return;
9596
if (nvgImage == -1) {
9697
nvgImage = nvgImageFromHandle(
9798
framebuffer3.framebufferTexture, mc.displayWidth, mc.displayHeight, NanoVG.NVG_IMAGE_FLIPY
9899
);
99100
}
100-
101101
ScaledResolution sr = new ScaledResolution(mc);
102102
if (System.currentTimeMillis() - lastUpdate > 15) {
103103
lastUpdate = System.currentTimeMillis();
@@ -113,6 +113,7 @@ public void render() {
113113
1f / mc.getFramebuffer().framebufferHeight
114114
));
115115
shader.uniform(Uniform.makeFloatBuffer("kernels", weightBuffer));
116+
shader.uniform(Uniform.makeInt("ignoreAlpha", 1));
116117
shader.rect(0f, 0f, sr.getScaledWidth(), sr.getScaledHeight());
117118

118119
framebuffer1.bindFramebuffer(true);
@@ -154,6 +155,7 @@ private float gauss(float x, float sigma) {
154155
}
155156

156157
public void drawBlur(float x, float y, float w, float h, float radius) {
158+
if (!InternalSettingsMod.getInstance().getBlurSetting().isToggled()) return;
157159
long ctx = Glide.getInstance().getNanoVGManager().getContext();
158160
ScaledResolution sr = new ScaledResolution(mc);
159161

@@ -178,6 +180,7 @@ public void drawBlur(float x, float y, float w, float h, float radius) {
178180
}
179181

180182
public void drawBlur(Runnable r) {
183+
if (!InternalSettingsMod.getInstance().getBlurSetting().isToggled()) return;
181184
long ctx = Glide.getInstance().getNanoVGManager().getContext();
182185
ScaledResolution sr = new ScaledResolution(mc);
183186
NVGPaint paint = NVGPaint.calloc();

src/main/java/me/eldodebug/soar/gui/GuiEditHUD.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.ArrayList;
66
import java.util.Collections;
77

8+
import eu.shoroa.contrib.render.ShBlur;
9+
import me.eldodebug.soar.management.mods.impl.InternalSettingsMod;
810
import org.lwjgl.input.Keyboard;
911
import org.lwjgl.input.Mouse;
1012

@@ -24,6 +26,7 @@
2426
import me.eldodebug.soar.utils.render.BlurUtils;
2527
import net.minecraft.client.gui.GuiScreen;
2628
import net.minecraft.client.gui.ScaledResolution;
29+
import org.lwjgl.nanovg.NanoVG;
2730

2831
public class GuiEditHUD extends GuiScreen {
2932

@@ -47,7 +50,7 @@ public void initGui() {
4750
m.getAnimation().setValue(0.0F);
4851
}
4952

50-
introAnimation = new EaseBackIn(320, 1.0F, 2.0F);
53+
introAnimation = new EaseBackIn(500, 1.0F, 0F);
5154
introAnimation.setDirection(Direction.FORWARDS);
5255
}
5356

@@ -67,16 +70,26 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
6770
if(introAnimation.isDone(Direction.BACKWARDS)) {
6871
mc.displayGuiScreen(null);
6972
}
70-
71-
BlurUtils.drawBlurScreen((float) (Math.min(introAnimation.getValue(), 1) * 20) + 1F);
73+
if (!InternalSettingsMod.getInstance().getBlurSetting().isToggled()) {
74+
BlurUtils.drawBlurScreen((float) (Math.min(introAnimation.getValue(), 1) * 20) + 1F);
75+
}
7276

7377
nvg.setupAndDraw(() -> {
74-
78+
79+
nvg.save();
80+
NanoVG.nvgGlobalAlpha(nvg.getContext(), (float) introAnimation.getValue());
81+
if (InternalSettingsMod.getInstance().getBlurSetting().isToggled()) {
82+
ShBlur.getInstance().drawBlur(() -> nvg.drawRect(0,0, sr.getScaledWidth(), sr.getScaledHeight(), Color.WHITE));
83+
}
84+
nvg.restore();
85+
nvg.drawRect(0,0, sr.getScaledWidth(), sr.getScaledHeight(), new Color(0,0,0, (int) (introAnimation.getValue() * 100)));
7586
int halfScreenWidth = sr.getScaledWidth() / 2;
7687
int halfScreenHeight = sr.getScaledHeight() / 2;
77-
88+
89+
// guide lines
7890
nvg.drawRect(0, halfScreenHeight, sr.getScaledWidth(), 0.5F, palette.getBackgroundColor(ColorType.DARK));
7991
nvg.drawRect(halfScreenWidth, 0, 0.5F, sr.getScaledHeight(), palette.getBackgroundColor(ColorType.DARK));
92+
// todo add more splashers
8093
nvg.drawCenteredText("You can resize elements by scrolling over them. Use shift for more control.", sr.getScaledWidth() / 2F, sr.getScaledHeight() - 15, new Color(255,255,255, 200), 8F, Fonts.REGULAR);
8194

8295
for(HUDMod m : mods) {

src/main/java/me/eldodebug/soar/gui/modmenu/GuiModMenu.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.File;
55
import java.io.IOException;
66
import java.util.ArrayList;
7+
import java.util.Objects;
78

89
import eu.shoroa.contrib.render.ShBlur;
910
import me.eldodebug.soar.gui.modmenu.category.impl.*;
@@ -186,7 +187,7 @@ private void drawNanoVG(int mouseX, int mouseY, float partialTicks) {
186187
searchBox.draw(mouseX, mouseY, partialTicks);
187188
}
188189
int yOff = (currentCategory.isShowTitle()) ? 31 : 0;
189-
if(currentCategory.getNameKey() == TranslateText.COSMETICS.getKey()){
190+
if(Objects.equals(currentCategory.getNameKey(), TranslateText.COSMETICS.getKey())){
190191
float folderButtonX = x + width - 198;
191192
float folderButtonY = y + 6.5F;
192193
nvg.drawRoundedRect(folderButtonX, folderButtonY, 18,18, 6, palette.getBackgroundColor(ColorType.DARK));
@@ -241,7 +242,7 @@ public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
241242
currentCategory.mouseClicked(mouseX, mouseY, mouseButton);
242243
searchBox.mouseClicked(mouseX, mouseY, mouseButton);
243244

244-
if(currentCategory.getNameKey() == TranslateText.COSMETICS.getKey()){
245+
if(Objects.equals(currentCategory.getNameKey(), TranslateText.COSMETICS.getKey())){
245246
float folderButtonX = x + width - 198;
246247
float folderButtonY = y + 6.5F;
247248
if (MouseUtils.isInside(mouseX, mouseY, folderButtonX, folderButtonY, 18, 18)){

src/main/java/me/eldodebug/soar/gui/modmenu/category/impl/game/impl/BirdScene.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.eldodebug.soar.gui.modmenu.category.impl.game.impl;
22

3+
import eu.shoroa.contrib.render.ShBlur;
34
import me.eldodebug.soar.Glide;
45
import me.eldodebug.soar.gui.modmenu.category.impl.GamesCategory;
56
import me.eldodebug.soar.gui.modmenu.category.impl.game.GameScene;
@@ -8,6 +9,7 @@
89
import me.eldodebug.soar.management.color.palette.ColorPalette;
910
import me.eldodebug.soar.management.color.palette.ColorType;
1011
import me.eldodebug.soar.management.language.TranslateText;
12+
import me.eldodebug.soar.management.mods.impl.InternalSettingsMod;
1113
import me.eldodebug.soar.management.nanovg.NanoVGManager;
1214
import me.eldodebug.soar.management.nanovg.font.Fonts;
1315
import me.eldodebug.soar.management.nanovg.font.LegacyIcon;
@@ -62,7 +64,13 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
6264

6365
nvg.save();
6466
nvg.scissor(x, y, width, height);
65-
nvg.drawRect(x, y, width, height, palette.getBackgroundColor(ColorType.DARK));
67+
if (InternalSettingsMod.getInstance().getBlurSetting().isToggled()) {
68+
ShBlur.getInstance().drawBlur(() -> nvg.drawRect(x, y, width, height, palette.getBackgroundColor(ColorType.DARK)));
69+
Color colsidebar = palette.getBackgroundColor(ColorType.DARK);
70+
nvg.drawRect(x, y, width, height, new Color(colsidebar.getRed(), colsidebar.getGreen(), colsidebar.getBlue(), 210));
71+
} else {
72+
nvg.drawRect(x, y, width, height, palette.getBackgroundColor(ColorType.DARK));
73+
}
6674
if(gameStarted){
6775
nvg.drawText(score + "", x + 10, y + 10, currentColor.getColor1(), 8, Fonts.MEDIUM);
6876
drawPlayer(nvg, currentColor);

src/main/java/me/eldodebug/soar/management/mods/impl/InternalSettingsMod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class InternalSettingsMod extends Mod {
2828

2929
private final BooleanSetting blurSetting = new BooleanSetting(TranslateText.UI_BLUR, this, true);
3030

31-
private final BooleanSetting mcFontSetting = new BooleanSetting(TranslateText.MC_FONT, this, true);
31+
private final BooleanSetting mcFontSetting = new BooleanSetting(TranslateText.MC_FONT, this, false);
3232

3333
private final NumberSetting volumeSetting = new NumberSetting(TranslateText.VOLUME, this, 0.8, 0, 1, false);
3434

src/main/resources/assets/minecraft/soar/shaders/blur.frag

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@ uniform sampler2D texture;
44
uniform vec2 texelSize, direction;
55
uniform int radius = 25;
66
uniform float kernels[128];
7-
7+
uniform bool ignoreAlpha = false;
88
varying vec4 texCoord;
99

1010
void main() {
11-
vec3 color = texture2D(texture, texCoord.xy).rgb * kernels[0];
12-
for(int i = 1; i <= radius; i++) {
13-
color += texture2D(texture, texCoord.xy + i * texelSize * direction).rgb * kernels[i];
14-
color += texture2D(texture, texCoord.xy - i * texelSize * direction).rgb * kernels[i];
11+
vec4 color = vec4(0.0);
12+
float weightSum = kernels[0];
13+
14+
color += texture2D(texture, texCoord.xy) * kernels[0];
15+
for (int i = 1; i <= radius; i++) {
16+
vec2 offset = i * texelSize * direction;
17+
vec2 coordPlus = clamp(texCoord.xy + offset, vec2(0.0), vec2(1.0));
18+
vec2 coordMinus = clamp(texCoord.xy - offset, vec2(0.0), vec2(1.0));
19+
float weight = kernels[i];
20+
21+
color += texture2D(texture, coordPlus) * weight;
22+
color += texture2D(texture, coordMinus) * weight;
23+
weightSum += 2.0 * weight;
1524
}
16-
gl_FragColor = vec4(color, 1.0);
25+
color /= weightSum;
26+
27+
if (ignoreAlpha) color.a = 1.0;
28+
gl_FragColor = color;
1729
}

0 commit comments

Comments
 (0)