From b69966d46b364a243171e3eee8a424ff2646d7f6 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sun, 10 Dec 2023 11:31:34 -0800 Subject: [PATCH] Uniforms audit --- .../early/sodium/MixinRenderGlobal.java | 2 +- .../iris/uniforms/CommonUniforms.java | 12 +++-------- .../uniforms/HardcodedCustomUniforms.java | 12 +++++------ .../iris/uniforms/IrisExclusiveUniforms.java | 12 ++++++----- .../iris/uniforms/MatrixUniforms.java | 2 -- .../iris/uniforms/SystemTimeUniforms.java | 21 +++++++------------ .../iris/uniforms/ViewportUniforms.java | 9 +++----- .../iris/uniforms/WorldTimeUniforms.java | 21 +++---------------- 8 files changed, 30 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinRenderGlobal.java b/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinRenderGlobal.java index 037b5b46a..94e55ede4 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinRenderGlobal.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinRenderGlobal.java @@ -192,7 +192,7 @@ public int sortAndRender(EntityLivingBase entity, int pass, double partialTicks) } private boolean isSpectatorMode() { - PlayerControllerMP controller = Minecraft.getMinecraft().playerController; + final PlayerControllerMP controller = Minecraft.getMinecraft().playerController; if(controller == null) return false; return controller.currentGameType.getID() == 3; diff --git a/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java b/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java index 327f8da6c..6175c005a 100644 --- a/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java @@ -141,13 +141,7 @@ private static boolean isInvisible() { } private static boolean isBurning() { - // todo: thePlayer.fire > 0 && !thePlayer.fireResistance - return false; - // if (client.thePlayer != null) { - // return client.thePlayer.isOnFire(); - // } else { - // return false; - // } + return client.thePlayer != null && client.thePlayer.fire > 0 && !client.thePlayer.isImmuneToFire(); } private static boolean isSneaking() { @@ -167,7 +161,7 @@ private static Vector3d getSkyColor() { } static float getBlindness() { - EntityLivingBase cameraEntity = client.renderViewEntity; + final EntityLivingBase cameraEntity = client.renderViewEntity; if (cameraEntity instanceof EntityLiving livingEntity && livingEntity.isPotionActive(Potion.blindness)) { final PotionEffect blindness = livingEntity.getActivePotionEffect(Potion.blindness); @@ -207,7 +201,7 @@ private static Vector2i getEyeBrightness() { if (client.renderViewEntity == null || client.theWorld == null) { return ZERO_VECTOR_2i; } - + // This is what ShadersMod did in 1.7.10 final int eyeBrightness = client.renderViewEntity.getBrightnessForRender(CapturedRenderingState.INSTANCE.getTickDelta()); return new Vector2i((eyeBrightness & 0xffff), (eyeBrightness >> 16)); diff --git a/src/main/java/net/coderbot/iris/uniforms/HardcodedCustomUniforms.java b/src/main/java/net/coderbot/iris/uniforms/HardcodedCustomUniforms.java index a4caf3e23..24994aeaf 100644 --- a/src/main/java/net/coderbot/iris/uniforms/HardcodedCustomUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/HardcodedCustomUniforms.java @@ -145,10 +145,10 @@ private static SmoothedFloat getStarter(CameraUniforms.CameraPositionTracker tra } private static float getMoving(CameraUniforms.CameraPositionTracker tracker) { - float difX = (float) (tracker.getCurrentCameraPosition().x - tracker.getPreviousCameraPosition().x); - float difY = (float) (tracker.getCurrentCameraPosition().y - tracker.getPreviousCameraPosition().y); - float difZ = (float) (tracker.getCurrentCameraPosition().z - tracker.getPreviousCameraPosition().z); - float difSum = Math.abs(difX) + Math.abs(difY) + Math.abs(difZ); + final float difX = (float) (tracker.getCurrentCameraPosition().x - tracker.getPreviousCameraPosition().x); + final float difY = (float) (tracker.getCurrentCameraPosition().y - tracker.getPreviousCameraPosition().y); + final float difZ = (float) (tracker.getCurrentCameraPosition().z - tracker.getPreviousCameraPosition().z); + final float difSum = Math.abs(difX) + Math.abs(difY) + Math.abs(difZ); return (difSum > 0.0F && difSum < 1.0F) ? 1 : 0; } @@ -157,12 +157,10 @@ private static float getTimeAngle() { } private static int getWorldDayTime() { - long timeOfDay = Minecraft.getMinecraft().theWorld.getWorldTime(); + return (int) (Minecraft.getMinecraft().theWorld.getWorldTime() % 24000L); // Level level = Minecraft.getMinecraft().theWorld; // long timeOfDay = level.getDayTime(); // long dayTime = ((DimensionTypeAccessor) level.dimensionType()).getFixedTime().orElse(timeOfDay % 24000L); - - return (int) timeOfDay; } private static float getTimeBrightness() { diff --git a/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java b/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java index 64f971e53..ff4ef3e20 100644 --- a/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java @@ -3,6 +3,7 @@ import net.coderbot.iris.gl.uniform.UniformHolder; import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.entity.EntityLivingBase; import org.joml.Math; @@ -91,21 +92,22 @@ private static boolean isFirstPersonCamera() { } private static boolean isSpectator() { -// return Minecraft.getMinecraft().gameMode.getPlayerMode() == GameType.SPECTATOR; - // TODO: AF? EFR? - return false; + final PlayerControllerMP controller = Minecraft.getMinecraft().playerController; + if(controller == null) + return false; + return controller.currentGameType.getID() == 3; } private static Vector3d getEyePosition() { // Objects.requireNonNull(Minecraft.getMinecraft().getCameraEntity()); // return new Vector3d(Minecraft.getMinecraft().getCameraEntity().getX(), Minecraft.getMinecraft().getCameraEntity().getEyeY(), Minecraft.getMinecraft().getCameraEntity().getZ()); - EntityLivingBase eye = Minecraft.getMinecraft().renderViewEntity; + final EntityLivingBase eye = Minecraft.getMinecraft().renderViewEntity; return new Vector3d(eye.posX, eye.posY, eye.posZ); } public static class WorldInfoUniforms { public static void addWorldInfoUniforms(UniformHolder uniforms) { - WorldClient level = Minecraft.getMinecraft().theWorld; + final WorldClient level = Minecraft.getMinecraft().theWorld; uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "bedrockLevel", () -> 0); uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "cloudHeight", () -> { if (level != null && level.provider != null) { diff --git a/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java b/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java index 89e2e11c9..34862d742 100644 --- a/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java @@ -6,9 +6,7 @@ import net.coderbot.iris.shaderpack.PackDirectives; import net.coderbot.iris.shadow.ShadowMatrices; import org.joml.Matrix4f; -import org.lwjgl.BufferUtils; -import java.nio.FloatBuffer; import java.util.function.Supplier; import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME; diff --git a/src/main/java/net/coderbot/iris/uniforms/SystemTimeUniforms.java b/src/main/java/net/coderbot/iris/uniforms/SystemTimeUniforms.java index c2c9fdc66..4bf8ce6d1 100644 --- a/src/main/java/net/coderbot/iris/uniforms/SystemTimeUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/SystemTimeUniforms.java @@ -1,5 +1,6 @@ package net.coderbot.iris.uniforms; +import lombok.Getter; import net.coderbot.iris.gl.uniform.UniformHolder; import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; @@ -66,8 +67,10 @@ public void reset() { * of the first frame to the start of the current frame. Updated at the start of each frame. */ public static final class Timer { - private float frameTimeCounter; - private float lastFrameTime; + @Getter + private float frameTimeCounter; + @Getter + private float lastFrameTime; // Disabling this because OptionalLong provides a nice wrapper around (boolean valid, long value) @SuppressWarnings("OptionalUsedAsFieldOrParameterType") @@ -80,9 +83,9 @@ public Timer() { public void beginFrame(long frameStartTime) { // Track how much time passed since the last time we began rendering a frame. // If this is the first frame, then use a value of 0. - long diffNs = frameStartTime - lastStartTime.orElse(frameStartTime); + final long diffNs = frameStartTime - lastStartTime.orElse(frameStartTime); // Convert to milliseconds - long diffMs = (diffNs / 1000) / 1000; + final long diffMs = (diffNs / 1000) / 1000; // Convert to seconds with a resolution of 1 millisecond, and store as the time taken for the last frame to complete. lastFrameTime = diffMs / 1000.0F; @@ -100,15 +103,7 @@ public void beginFrame(long frameStartTime) { lastStartTime = OptionalLong.of(frameStartTime); } - public float getFrameTimeCounter() { - return frameTimeCounter; - } - - public float getLastFrameTime() { - return lastFrameTime; - } - - public void reset() { + public void reset() { frameTimeCounter = 0.0F; lastFrameTime = 0.0F; lastStartTime = OptionalLong.empty(); diff --git a/src/main/java/net/coderbot/iris/uniforms/ViewportUniforms.java b/src/main/java/net/coderbot/iris/uniforms/ViewportUniforms.java index c70c1c201..199a1b0af 100644 --- a/src/main/java/net/coderbot/iris/uniforms/ViewportUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/ViewportUniforms.java @@ -24,10 +24,8 @@ public static void addViewportUniforms(UniformHolder uniforms) { // TODO: What about the custom scale.composite3 property? // NB: It is not safe to cache the render target due to mods like Resolution Control modifying the render target field. uniforms -// .uniform1f(PER_FRAME, "viewHeight", () -> Minecraft.getMinecraft().getMainRenderTarget().height) - .uniform1f(PER_FRAME, "viewHeight", () -> Minecraft.getMinecraft().displayHeight) -// .uniform1f(PER_FRAME, "viewWidth", () -> Minecraft.getMinecraft().getMainRenderTarget().width) - .uniform1f(PER_FRAME, "viewWidth", () -> Minecraft.getMinecraft().displayWidth) + .uniform1f(PER_FRAME, "viewHeight", () -> Minecraft.getMinecraft().getFramebuffer().framebufferHeight) + .uniform1f(PER_FRAME, "viewWidth", () -> Minecraft.getMinecraft().getFramebuffer().framebufferWidth) .uniform1f(PER_FRAME, "aspectRatio", ViewportUniforms::getAspectRatio); } @@ -35,7 +33,6 @@ public static void addViewportUniforms(UniformHolder uniforms) { * @return the current viewport aspect ratio, calculated from the current Minecraft window size */ private static float getAspectRatio() { -// return ((float) Minecraft.getMinecraft().getMainRenderTarget().width) / ((float) Minecraft.getMinecraft().getMainRenderTarget().height); - return ((float) Minecraft.getMinecraft().displayWidth) / ((float) Minecraft.getMinecraft().displayHeight); + return ((float) Minecraft.getMinecraft().getFramebuffer().framebufferWidth) / ((float) Minecraft.getMinecraft().getFramebuffer().framebufferHeight); } } diff --git a/src/main/java/net/coderbot/iris/uniforms/WorldTimeUniforms.java b/src/main/java/net/coderbot/iris/uniforms/WorldTimeUniforms.java index dca8f8330..170dc9477 100644 --- a/src/main/java/net/coderbot/iris/uniforms/WorldTimeUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/WorldTimeUniforms.java @@ -1,8 +1,6 @@ package net.coderbot.iris.uniforms; -import net.coderbot.iris.Iris; import net.coderbot.iris.gl.uniform.UniformHolder; -import net.coderbot.iris.shaderpack.DimensionId; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.WorldClient; @@ -27,26 +25,13 @@ public static void addWorldTimeUniforms(UniformHolder uniforms) { } static int getWorldDayTime() { - long timeOfDay = getWorld().getWorldTime(); + return (int) (getWorld().getWorldTime() % 24000L); - if (Iris.getCurrentDimension() == DimensionId.END || Iris.getCurrentDimension() == DimensionId.NETHER) { - // If the dimension is the nether or the end, don't override the fixed time. - // This was an oversight in versions before and including 1.2.5 causing inconsistencies, such as Complementary's ender beams not moving. - return (int) (timeOfDay % 24000L); - } - - long dayTime = Minecraft.getMinecraft().theWorld.getWorldTime(); -// long dayTime = ((DimensionTypeAccessor) getWorld().dimensionType()).getFixedTime() -// .orElse(timeOfDay % 24000L); - - return (int) dayTime; + // long dayTime = ((DimensionTypeAccessor) getWorld().dimensionType()).getFixedTime().orElse(timeOfDay % 24000L); } private static int getWorldDay() { - long timeOfDay = getWorld().getWorldTime(); - long day = timeOfDay / 24000L; - - return (int) day; + return (int) (getWorld().getWorldTime() / 24000L); } private static WorldClient getWorld() {