mirror of
https://github.com/Motschen/Blur.git
synced 2025-12-15 19:25:09 +01:00
fix: improve gradient handling
This commit is contained in:
@@ -23,20 +23,19 @@ public class Blur {
|
|||||||
|
|
||||||
public static boolean doFade = false;
|
public static boolean doFade = false;
|
||||||
|
|
||||||
static float lastDelta;
|
public static void onRender() {
|
||||||
public static void onRender(DrawContext context, int width, int height, MinecraftClient client, float delta) {
|
|
||||||
if (!BlurInfo.doTest && BlurInfo.screenChanged) { // After the tests for blur and background color have been completed
|
if (!BlurInfo.doTest && BlurInfo.screenChanged) { // After the tests for blur and background color have been completed
|
||||||
Blur.onScreenChange();
|
Blur.onScreenChange();
|
||||||
BlurInfo.screenChanged = false;
|
BlurInfo.screenChanged = false;
|
||||||
}
|
}
|
||||||
|
BlurInfo.doTest = false; // Set the test state to completed, as tests will happen in the same tick.
|
||||||
|
}
|
||||||
|
public static void renderFadeout(DrawContext context, int width, int height, MinecraftClient client) {
|
||||||
if (BlurInfo.start >= 0 && !BlurInfo.screenHasBlur && BlurInfo.prevScreenHasBlur) { // Fade out in non-blurred screens
|
if (BlurInfo.start >= 0 && !BlurInfo.screenHasBlur && BlurInfo.prevScreenHasBlur) { // Fade out in non-blurred screens
|
||||||
client.gameRenderer.renderBlur();
|
client.gameRenderer.renderBlur();
|
||||||
|
|
||||||
if (BlurInfo.prevScreenHasBackground && BlurConfig.useGradient && lastDelta != delta) Blur.renderRotatedGradient(context, width, height);
|
if (BlurInfo.prevScreenHasBackground && BlurConfig.useGradient) Blur.renderRotatedGradient(context, width, height);
|
||||||
lastDelta = delta;
|
|
||||||
}
|
}
|
||||||
BlurInfo.doTest = false; // Set the test state to completed, as tests will happen in the same tick.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onScreenChange() {
|
public static void onScreenChange() {
|
||||||
@@ -79,7 +78,10 @@ public class Blur {
|
|||||||
int b = (col.getRGB() >> 8) & 0xFF;
|
int b = (col.getRGB() >> 8) & 0xFF;
|
||||||
int g = col.getRGB() & 0xFF;
|
int g = col.getRGB() & 0xFF;
|
||||||
float prog = progress;
|
float prog = progress;
|
||||||
a *= prog; r *= prog; g *= prog; b *= prog;
|
a = (int) (prog * a);
|
||||||
|
r = (int) (prog * r);
|
||||||
|
g = (int) (prog * g);
|
||||||
|
b = (int) (prog * b);
|
||||||
return a << 24 | r << 16 | b << 8 | g;
|
return a << 24 | r << 16 | b << 8 | g;
|
||||||
}
|
}
|
||||||
public static int getRotation() {
|
public static int getRotation() {
|
||||||
@@ -90,11 +92,12 @@ public class Blur {
|
|||||||
float diagonal = Math.sqrt((float) width*width + height*height);
|
float diagonal = Math.sqrt((float) width*width + height*height);
|
||||||
int smallestDimension = Math.min(width, height);
|
int smallestDimension = Math.min(width, height);
|
||||||
|
|
||||||
|
context.getMatrices().push();
|
||||||
Matrix4f posMatrix = context.getMatrices().peek().getPositionMatrix();
|
Matrix4f posMatrix = context.getMatrices().peek().getPositionMatrix();
|
||||||
posMatrix.rotationZ(Math.toRadians(getRotation()));
|
posMatrix.rotationZ(Math.toRadians(getRotation()));
|
||||||
posMatrix.setTranslation(width / 2f, height / 2f, 0); // Make the gradient's center the pivot point
|
posMatrix.setTranslation(width / 2f, height / 2f, -1); // Make the gradient's center the pivot point
|
||||||
posMatrix.scale(diagonal / smallestDimension); // Scales the gradient to the maximum diagonal value needed
|
posMatrix.scale(diagonal / smallestDimension); // Scales the gradient to the maximum diagonal value needed
|
||||||
context.fillGradient(-width / 2, -height / 2, width / 2, height / 2, Blur.getBackgroundColor(false), Blur.getBackgroundColor(true)); // Actually draw the gradient
|
context.fillGradient(-width / 2, -height / 2, width / 2, height / 2, Blur.getBackgroundColor(false), Blur.getBackgroundColor(true)); // Actually draw the gradient
|
||||||
posMatrix.rotationZ(0);
|
context.getMatrices().pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,6 @@ public class MixinHandledScreen extends Screen {
|
|||||||
}
|
}
|
||||||
@Inject(at = @At("HEAD"), method = "render")
|
@Inject(at = @At("HEAD"), method = "render")
|
||||||
public void blur$processScreenChange(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
public void blur$processScreenChange(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||||
if (PlatformFunctions.getPlatformName().equals("neoforge")) Blur.onRender(context, width, height, this.client, delta);
|
if (PlatformFunctions.getPlatformName().equals("neoforge")) Blur.onRender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,10 @@ public abstract class MixinScreen {
|
|||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "render")
|
@Inject(at = @At("HEAD"), method = "render")
|
||||||
public void blur$processScreenChange(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
public void blur$processScreenChange(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||||
Blur.onRender(context, width, height, this.client, delta);
|
Blur.onRender();
|
||||||
|
Blur.renderFadeout(context, width, height, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "applyBlur", cancellable = true)
|
@Inject(at = @At("HEAD"), method = "applyBlur", cancellable = true)
|
||||||
public void blur$getBlurEnabled(CallbackInfo ci) {
|
public void blur$getBlurEnabled(CallbackInfo ci) {
|
||||||
if (BlurConfig.forceDisabledScreens.contains(this.getClass().getCanonicalName())) {
|
if (BlurConfig.forceDisabledScreens.contains(this.getClass().getCanonicalName())) {
|
||||||
|
|||||||
Reference in New Issue
Block a user