Skip to content

Commit

Permalink
Uniforms audit
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 committed Dec 10, 2023
1 parent 1e32eb0 commit b69966d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/net/coderbot/iris/uniforms/SystemTimeUniforms.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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")
Expand All @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ 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);
}

/**
* @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);
}
}
21 changes: 3 additions & 18 deletions src/main/java/net/coderbot/iris/uniforms/WorldTimeUniforms.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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() {
Expand Down

0 comments on commit b69966d

Please sign in to comment.