Common and version specific shader packages #10

Merged
embeddedt merged 24 commits from mitchej123/celeritas:common-shaders-and-enhancements into stonecutter 2025-03-31 19:52:28 -04:00
29 changed files with 471 additions and 278 deletions
Showing only changes of commit 403e627f3f - Show all commits

No files matched your search

@@ -79,6 +79,9 @@ public interface GLStateManagerService {
int getBoundTexture(int internalUnit); // Mojang Addition int getBoundTexture(int internalUnit); // Mojang Addition
int getActiveBoundTexture(); // Mojang Addition int getActiveBoundTexture(); // Mojang Addition
int getViewportWidth(); // Mojang Addition
int getViewportHeight(); // Mojang Addition
boolean getDepthStateMask(); boolean getDepthStateMask();
boolean isBlendEnabled(); boolean isBlendEnabled();
BlendMode getBlendMode(); BlendMode getBlendMode();
@@ -48,6 +48,9 @@ public interface RenderSystemService {
float[] getShaderFogColor(); float[] getShaderFogColor();
float getShaderFogStart(); float getShaderFogStart();
float getShaderFogEnd(); float getShaderFogEnd();
int getFogShape();
float getShaderLineWidth();
Matrix4f getProjectionMatrix(); Matrix4f getProjectionMatrix();
void setProjectionMatrixOrth(Matrix4f projectionMatrix); void setProjectionMatrixOrth(Matrix4f projectionMatrix);
@@ -66,6 +66,27 @@ public interface IrisApi {
*/ */
boolean isRenderingShadowPass(); boolean isRenderingShadowPass();
/**
* Gets the shadow distance that should be used for rendering shadows.
* This method is used to override the shadow distance set in the
* Minecraft options screen.
*
* @param base The shadow distance set in the Minecraft options screen.
* @return The shadow distance that should be used for rendering shadows.
* @since API v0.2
*/
int getOverriddenShadowDistance(int base);
/**
* Checks whether the shadow distance slider should be enabled in the
* Minecraft options screen. If this method returns false, the shadow
* distance slider should be disabled.
*
* @return Whether the shadow distance slider should be enabled.
* @since API v0.2
*/
boolean isShadowDistanceSliderEnabled();
/** /**
* Opens the main Iris GUI screen. It's up to Iris to decide * Opens the main Iris GUI screen. It's up to Iris to decide
* what this screen is, but generally this is the shader selection * what this screen is, but generally this is the shader selection
@@ -1,13 +1,14 @@
package net.irisshaders.iris.features; package net.irisshaders.iris.features;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.minecraft.client.resources.language.I18n;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
public enum FeatureFlags { public enum FeatureFlags {
SEPARATE_HARDWARE_SAMPLERS(() -> true, () -> true), SEPARATE_HARDWARE_SAMPLERS(() -> true, () -> true),
HIGHER_SHADOWCOLOR(() -> true, () -> true), HIGHER_SHADOWCOLOR(() -> true, () -> true),
@@ -39,12 +40,12 @@ public enum FeatureFlags {
if (unsupportedIris) { if (unsupportedIris) {
if (unsupportedHardware) { if (unsupportedHardware) {
return I18n.get("iris.unsupported.irisorpc"); return MINECRAFT_SHIM.translate("iris.unsupported.irisorpc");
} }
return I18n.get("iris.unsupported.iris"); return MINECRAFT_SHIM.translate("iris.unsupported.iris");
} else if (unsupportedHardware) { } else if (unsupportedHardware) {
return I18n.get("iris.unsupported.pc"); return MINECRAFT_SHIM.translate("iris.unsupported.pc");
} else { } else {
return null; return null;
} }
@@ -1,6 +1,6 @@
package net.irisshaders.iris.gui.option; package net.irisshaders.iris.gui.option;
import net.irisshaders.iris.Iris; import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.pathways.colorspace.ColorSpace; import net.irisshaders.iris.pathways.colorspace.ColorSpace;
@@ -9,14 +9,10 @@ public class IrisVideoSettings {
public static ColorSpace colorSpace = ColorSpace.SRGB; public static ColorSpace colorSpace = ColorSpace.SRGB;
public static int getOverriddenShadowDistance(int base) { public static int getOverriddenShadowDistance(int base) {
return Iris.getPipelineManager().getPipeline() return IrisApi.getInstance().getOverriddenShadowDistance(base);
.map(pipeline -> pipeline.getForcedShadowRenderDistanceChunksForDisplay().orElse(base))
.orElse(base);
} }
public static boolean isShadowDistanceSliderEnabled() { public static boolean isShadowDistanceSliderEnabled() {
return Iris.getPipelineManager().getPipeline() return IrisApi.getInstance().isShadowDistanceSliderEnabled();
.map(pipeline -> !pipeline.getForcedShadowRenderDistanceChunksForDisplay().isPresent())
.orElse(true);
} }
} }
@@ -1,20 +1,18 @@
package net.irisshaders.iris.uniforms; package net.irisshaders.iris.uniforms;
import net.irisshaders.iris.gl.uniform.UniformHolder; import net.irisshaders.iris.gl.uniform.UniformHolder;
import net.irisshaders.iris.helpers.JomlConversions;
import net.minecraft.client.Minecraft;
import org.joml.Vector3d; import org.joml.Vector3d;
import org.joml.Vector3f; import org.joml.Vector3f;
import org.joml.Vector3i; import org.joml.Vector3i;
import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.ONCE; import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.ONCE;
import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME; import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
/** /**
* @see <a href="https://github.com/IrisShaders/ShaderDoc/blob/master/uniforms.md#camera">Uniforms: Camera</a> * @see <a href="https://github.com/IrisShaders/ShaderDoc/blob/master/uniforms.md#camera">Uniforms: Camera</a>
*/ */
public class CameraUniforms { public class CameraUniforms {
private static final Minecraft client = Minecraft.getInstance();
private CameraUniforms() { private CameraUniforms() {
} }
@@ -35,12 +33,11 @@ public class CameraUniforms {
} }
private static int getRenderDistanceInBlocks() { private static int getRenderDistanceInBlocks() {
// TODO: Should we ask the game renderer for this? return MINECRAFT_SHIM.getRenderDistanceInBlocks();
return client.options.getEffectiveRenderDistance() * 16;
} }
public static Vector3d getUnshiftedCameraPosition() { public static Vector3d getUnshiftedCameraPosition() {
return JomlConversions.fromVec3(client.gameRenderer.getMainCamera().getPosition()); return MINECRAFT_SHIM.getUnshiftedCameraPosition();
} }
public static Vector3f getCameraPositionFract(Vector3d originalPos) { public static Vector3f getCameraPositionFract(Vector3d originalPos) {
@@ -1,9 +1,10 @@
package net.irisshaders.iris.uniforms; package net.irisshaders.iris.uniforms;
import net.minecraft.client.Minecraft;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Vector3d; import org.joml.Vector3d;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
public class CapturedRenderingState { public class CapturedRenderingState {
public static final CapturedRenderingState INSTANCE = new CapturedRenderingState(); public static final CapturedRenderingState INSTANCE = new CapturedRenderingState();
@@ -44,7 +45,7 @@ public class CapturedRenderingState {
} }
public Vector3d getFogColor() { public Vector3d getFogColor() {
if (Minecraft.getInstance().level == null || fogColor == null) { if (!MINECRAFT_SHIM.isLevelLoaded() || fogColor == null) {
return ZERO_VECTOR_3d; return ZERO_VECTOR_3d;
} }
@@ -1,15 +1,11 @@
package net.irisshaders.iris.uniforms; package net.irisshaders.iris.uniforms;
import com.mojang.math.Axis;
import net.irisshaders.iris.gl.uniform.UniformHolder; import net.irisshaders.iris.gl.uniform.UniformHolder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Vector4f; import org.joml.Vector4f;
import java.util.Objects;
import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME; import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
/** /**
* @see <a href="https://github.com/IrisShaders/ShaderDoc/blob/master/uniforms.md#celestial-bodies">Uniforms: Celestial bodies</a> * @see <a href="https://github.com/IrisShaders/ShaderDoc/blob/master/uniforms.md#celestial-bodies">Uniforms: Celestial bodies</a>
@@ -49,7 +45,7 @@ public final class CelestialUniforms {
// Apply the fixed -90.0F degrees rotation to mirror the same transformation in renderSky. // Apply the fixed -90.0F degrees rotation to mirror the same transformation in renderSky.
// But, notably, skip the rotation by the skyAngle. // But, notably, skip the rotation by the skyAngle.
preCelestial.rotate(Axis.YP.rotationDegrees(-90.0F)); MINECRAFT_SHIM.applyRotationYP(preCelestial, -90.0F);
Review

We should probably just make our own helper that generates quaternions for a given axis, rather than trying to reuse MC's.

We should probably just make our own helper that generates quaternions for a given axis, rather than trying to reuse MC's.
// Use this matrix to transform the vector. // Use this matrix to transform the vector.
upVector = preCelestial.transform(upVector); upVector = preCelestial.transform(upVector);
@@ -64,12 +60,8 @@ public final class CelestialUniforms {
return getSunAngle() <= 0.5; return getSunAngle() <= 0.5;
} }
private static ClientLevel getWorld() {
return Objects.requireNonNull(Minecraft.getInstance().level);
}
private static float getSkyAngle() { private static float getSkyAngle() {
return getWorld().getTimeOfDay(CapturedRenderingState.INSTANCE.getTickDelta()); return MINECRAFT_SHIM.getSkyAngle();
} }
public void addCelestialUniforms(UniformHolder uniforms) { public void addCelestialUniforms(UniformHolder uniforms) {
@@ -107,9 +99,9 @@ public final class CelestialUniforms {
// This is the same transformation applied by renderSky, however, it's been moved to here. // This is the same transformation applied by renderSky, however, it's been moved to here.
// This is because we need the result of it before it's actually performed in vanilla. // This is because we need the result of it before it's actually performed in vanilla.
celestial.rotate(Axis.YP.rotationDegrees(-90.0F)); MINECRAFT_SHIM.applyRotationYP(celestial, -90.0F);
celestial.rotate(Axis.ZP.rotationDegrees(sunPathRotation)); MINECRAFT_SHIM.applyRotationZP(celestial, sunPathRotation);
celestial.rotate(Axis.XP.rotationDegrees(getSkyAngle() * 360.0F)); MINECRAFT_SHIM.applyRotationXP(celestial, getSkyAngle() * 360.0F);
celestial.transform(position); celestial.transform(position);
@@ -123,9 +115,9 @@ public final class CelestialUniforms {
// This is the same transformation applied by renderSky, however, it's been moved to here. // This is the same transformation applied by renderSky, however, it's been moved to here.
// This is because we need the result of it before it's actually performed in vanilla. // This is because we need the result of it before it's actually performed in vanilla.
celestial.rotate(Axis.YP.rotationDegrees(-90.0F)); MINECRAFT_SHIM.applyRotationYP(celestial, -90.0F);
celestial.rotate(Axis.ZP.rotationDegrees(sunPathRotation)); MINECRAFT_SHIM.applyRotationZP(celestial, sunPathRotation);
celestial.rotate(Axis.XP.rotationDegrees(getSkyAngle() * 360.0F)); MINECRAFT_SHIM.applyRotationXP(celestial, getSkyAngle() * 360.0F);
position = celestial.transform(position); position = celestial.transform(position);
@@ -3,8 +3,7 @@ package net.irisshaders.iris.uniforms;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM; import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME; import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME;
import com.mojang.blaze3d.shaders.FogShape;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.gl.state.FogMode; import net.irisshaders.iris.gl.state.FogMode;
import net.irisshaders.iris.gl.state.StateUpdateNotifiers; import net.irisshaders.iris.gl.state.StateUpdateNotifiers;
import net.irisshaders.iris.gl.uniform.DynamicUniformHolder; import net.irisshaders.iris.gl.uniform.DynamicUniformHolder;
@@ -34,7 +33,7 @@ public class FogUniforms {
}); });
// To keep a stable interface, 0 is defined as spherical while 1 is defined as cylindrical, even if Mojang's index changes. // To keep a stable interface, 0 is defined as spherical while 1 is defined as cylindrical, even if Mojang's index changes.
uniforms.uniform1i(PER_FRAME, "fogShape", () -> RenderSystem.getShaderFogShape() == FogShape.CYLINDER ? 1 : 0); uniforms.uniform1i(PER_FRAME, "fogShape", RENDER_SYSTEM::getFogShape);
} }
uniforms.uniform1f("fogDensity", () -> { uniforms.uniform1f("fogDensity", () -> {
@@ -0,0 +1,49 @@
package net.irisshaders.iris.uniforms;
import net.irisshaders.iris.gl.uniform.UniformHolder;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.gui.option.IrisVideoSettings;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
public class IrisExclusiveUniforms {
public static void addIrisExclusiveUniforms(UniformHolder uniforms) {
WorldInfoUniforms.addWorldInfoUniforms(uniforms);
uniforms.uniform1i(UniformUpdateFrequency.PER_TICK, "currentColorSpace", () -> IrisVideoSettings.colorSpace.ordinal());
//All Iris-exclusive uniforms (uniforms which do not exist in either OptiFine or ShadersMod) should be registered here.
uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "thunderStrength", MINECRAFT_SHIM::getThunderStrength);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHealth", MINECRAFT_SHIM::getCurrentHealth);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHealth", MINECRAFT_SHIM::getMaxHealth);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHunger", MINECRAFT_SHIM::getCurrentHunger);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHunger", () -> 20);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerArmor", MINECRAFT_SHIM::getCurrentArmor);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerArmor", () -> 50);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerAir", MINECRAFT_SHIM::getCurrentAir);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerAir", MINECRAFT_SHIM::getMaxAir);
uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "firstPersonCamera", MINECRAFT_SHIM::isFirstPersonCamera);
uniforms.uniform1b(UniformUpdateFrequency.PER_TICK, "isSpectator", MINECRAFT_SHIM::isSpectator);
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "eyePosition", MINECRAFT_SHIM::getEyePosition);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "cloudTime", CapturedRenderingState.INSTANCE::getCloudTime);
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "relativeEyePosition", () -> CameraUniforms.getUnshiftedCameraPosition().sub(MINECRAFT_SHIM.getEyePosition()));
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerLookVector", MINECRAFT_SHIM::getPlayerLookVector);
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerBodyVector", MINECRAFT_SHIM::getPlayerBodyVector);
uniforms.uniform4f(UniformUpdateFrequency.PER_TICK, "lightningBoltPosition", MINECRAFT_SHIM::getLightningBoltPosition);
}
public static class WorldInfoUniforms {
public static void addWorldInfoUniforms(UniformHolder uniforms) {
// TODO: Use level.dimensionType() coordinates for 1.18!
uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "bedrockLevel", MINECRAFT_SHIM::getBedrockLevel);
uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "cloudHeight", MINECRAFT_SHIM::getCloudHeight);
uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "heightLimit", MINECRAFT_SHIM::getHeightLimit);
uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "logicalHeightLimit", MINECRAFT_SHIM::getLogicalHeightLimit);
uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "hasCeiling", MINECRAFT_SHIM::hasCeiling);
uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "hasSkylight", MINECRAFT_SHIM::hasSkyLight);
uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "ambientLight", MINECRAFT_SHIM::getAmbientLight);
}
}
}
@@ -3,7 +3,6 @@ package net.irisshaders.iris.uniforms;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM; import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME; import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.gl.state.FogMode; import net.irisshaders.iris.gl.state.FogMode;
import net.irisshaders.iris.gl.uniform.DynamicUniformHolder; import net.irisshaders.iris.gl.uniform.DynamicUniformHolder;
import org.joml.Vector4f; import org.joml.Vector4f;
@@ -23,8 +22,8 @@ public class IrisInternalUniforms {
return new Vector4f(fogColor[0], fogColor[1], fogColor[2], fogColor[3]); return new Vector4f(fogColor[0], fogColor[1], fogColor[2], fogColor[3]);
}); });
uniforms.uniform1f(PER_FRAME, "iris_FogStart", RenderSystem::getShaderFogStart) uniforms.uniform1f(PER_FRAME, "iris_FogStart", RENDER_SYSTEM::getShaderFogStart)
.uniform1f(PER_FRAME, "iris_FogEnd", RenderSystem::getShaderFogEnd); .uniform1f(PER_FRAME, "iris_FogEnd", RENDER_SYSTEM::getShaderFogEnd);
uniforms.uniform1f("iris_FogDensity", () -> { uniforms.uniform1f("iris_FogDensity", () -> {
// ensure that the minimum value is 0.0 // ensure that the minimum value is 0.0
@@ -1,17 +1,18 @@
package net.irisshaders.iris.uniforms; package net.irisshaders.iris.uniforms;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.gl.uniform.DynamicUniformHolder; import net.irisshaders.iris.gl.uniform.DynamicUniformHolder;
import org.joml.Vector2f; import org.joml.Vector2f;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
public class VanillaUniforms { public class VanillaUniforms {
public static void addVanillaUniforms(DynamicUniformHolder uniforms) { public static void addVanillaUniforms(DynamicUniformHolder uniforms) {
Vector2f cachedScreenSize = new Vector2f(); Vector2f cachedScreenSize = new Vector2f();
// listener -> {} dictates we want this to run on every shader update, not just on a new frame. These are dynamic. // listener -> {} dictates we want this to run on every shader update, not just on a new frame. These are dynamic.
uniforms.uniform1f("iris_LineWidth", RenderSystem::getShaderLineWidth, listener -> { uniforms.uniform1f("iris_LineWidth", RENDER_SYSTEM::getShaderLineWidth, listener -> {
}); });
uniforms.uniform2f("iris_ScreenSize", () -> cachedScreenSize.set(GlStateManager.Viewport.width(), GlStateManager.Viewport.height()), listener -> { uniforms.uniform2f("iris_ScreenSize", () -> cachedScreenSize.set(GL_STATE_MANAGER.getViewportWidth(), GL_STATE_MANAGER.getViewportHeight()), listener -> {
}); });
} }
} }
@@ -1,9 +1,9 @@
package net.irisshaders.iris.uniforms; package net.irisshaders.iris.uniforms;
import net.irisshaders.iris.gl.uniform.UniformHolder; import net.irisshaders.iris.gl.uniform.UniformHolder;
import net.minecraft.client.Minecraft;
import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME; import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
/** /**
* Implements uniforms relating the current viewport * Implements uniforms relating the current viewport
@@ -24,8 +24,8 @@ public final class ViewportUniforms {
// TODO: What about the custom scale.composite3 property? // 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. // NB: It is not safe to cache the render target due to mods like Resolution Control modifying the render target field.
uniforms uniforms
.uniform1f(PER_FRAME, "viewHeight", () -> Minecraft.getInstance().getMainRenderTarget().height) .uniform1f(PER_FRAME, "viewHeight", MINECRAFT_SHIM::getMinecraftRenderHeight)
.uniform1f(PER_FRAME, "viewWidth", () -> Minecraft.getInstance().getMainRenderTarget().width) .uniform1f(PER_FRAME, "viewWidth", MINECRAFT_SHIM::getMinecraftRenderWidth)
.uniform1f(PER_FRAME, "aspectRatio", ViewportUniforms::getAspectRatio); .uniform1f(PER_FRAME, "aspectRatio", ViewportUniforms::getAspectRatio);
} }
@@ -33,6 +33,6 @@ public final class ViewportUniforms {
* @return the current viewport aspect ratio, calculated from the current Minecraft window size * @return the current viewport aspect ratio, calculated from the current Minecraft window size
*/ */
private static float getAspectRatio() { private static float getAspectRatio() {
return ((float) Minecraft.getInstance().getMainRenderTarget().width) / ((float) Minecraft.getInstance().getMainRenderTarget().height); return ((float) MINECRAFT_SHIM.getMinecraftRenderWidth()) / ((float) MINECRAFT_SHIM.getMinecraftRenderHeight());
} }
} }
@@ -1,14 +1,9 @@
package net.irisshaders.iris.uniforms; package net.irisshaders.iris.uniforms;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.uniform.UniformHolder; import net.irisshaders.iris.gl.uniform.UniformHolder;
import net.irisshaders.iris.shaderpack.DimensionId;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import java.util.Objects;
import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_TICK; import static net.irisshaders.iris.gl.uniform.UniformUpdateFrequency.PER_TICK;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
public final class WorldTimeUniforms { public final class WorldTimeUniforms {
private WorldTimeUniforms() { private WorldTimeUniforms() {
@@ -23,32 +18,28 @@ public final class WorldTimeUniforms {
uniforms uniforms
.uniform1i(PER_TICK, "worldTime", WorldTimeUniforms::getWorldDayTime) .uniform1i(PER_TICK, "worldTime", WorldTimeUniforms::getWorldDayTime)
.uniform1i(PER_TICK, "worldDay", WorldTimeUniforms::getWorldDay) .uniform1i(PER_TICK, "worldDay", WorldTimeUniforms::getWorldDay)
.uniform1i(PER_TICK, "moonPhase", () -> getWorld().getMoonPhase()); .uniform1i(PER_TICK, "moonPhase", MINECRAFT_SHIM::getMoonPhase);
} }
static int getWorldDayTime() { static int getWorldDayTime() {
long timeOfDay = getWorld().getDayTime(); long timeOfDay = MINECRAFT_SHIM.getDayTime();
if (Iris.getCurrentDimension() == DimensionId.END || Iris.getCurrentDimension() == DimensionId.NETHER) { if (MINECRAFT_SHIM.isCurrentDimensionEnd() || MINECRAFT_SHIM.isCurrentDimensionNether()) {
// If the dimension is the nether or the end, don't override the fixed time. // 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. // 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); return (int) (timeOfDay % 24000L);
} }
long dayTime = getWorld().dimensionType().fixedTime() long dayTime = MINECRAFT_SHIM.getDimensionTime(timeOfDay % 24000L);
.orElse(timeOfDay % 24000L);
return (int) dayTime; return (int) dayTime;
} }
private static int getWorldDay() { private static int getWorldDay() {
long timeOfDay = getWorld().getDayTime(); long timeOfDay = MINECRAFT_SHIM.getDayTime();
long day = timeOfDay / 24000L; long day = timeOfDay / 24000L;
return (int) day; return (int) day;
} }
private static ClientLevel getWorld() {
return Objects.requireNonNull(Minecraft.getInstance().level);
}
} }
@@ -1,5 +1,9 @@
package org.embeddedt.embeddium.compat.mc; package org.embeddedt.embeddium.compat.mc;
import org.joml.Matrix4f;
import org.joml.Vector3d;
import org.joml.Vector4f;
import java.util.ServiceLoader; import java.util.ServiceLoader;
/** /**
@@ -7,6 +11,8 @@ import java.util.ServiceLoader;
*/ */
public interface MinecraftVersionShimService { public interface MinecraftVersionShimService {
MinecraftVersionShimService MINECRAFT_SHIM = ServiceLoader.load(MinecraftVersionShimService.class).findFirst().orElseThrow(); MinecraftVersionShimService MINECRAFT_SHIM = ServiceLoader.load(MinecraftVersionShimService.class).findFirst().orElseThrow();
Vector3d ZERO3D = new Vector3d(0);
Vector4f ZERO4F = new Vector4f(0);
default boolean getSmartCull() { default boolean getSmartCull() {
return false; return false;
@@ -23,4 +29,46 @@ public interface MinecraftVersionShimService {
int getMipmapLevels(); int getMipmapLevels();
boolean isModLoaded(String modId); boolean isModLoaded(String modId);
String translate(String key, Object... args);
boolean isLevelLoaded();
int getRenderDistanceInBlocks();
Vector3d getUnshiftedCameraPosition();
float getSkyAngle();
void applyRotationYP(Matrix4f preCelestial, float degrees);
void applyRotationXP(Matrix4f preCelestial, float degrees);
void applyRotationZP(Matrix4f preCelestial, float degrees);
int getMoonPhase();
long getDayTime();
long getDimensionTime(long orElse);
boolean isCurrentDimensionNether();
boolean isCurrentDimensionEnd();
int getMinecraftRenderHeight();
int getMinecraftRenderWidth();
int getBedrockLevel();
float getCloudHeight();
int getHeightLimit();
int getLogicalHeightLimit();
boolean hasCeiling();
boolean hasSkyLight();
float getAmbientLight();
Vector3d getPlayerLookVector();
Vector3d getPlayerBodyVector();
Vector4f getLightningBoltPosition();
float getThunderStrength();
float getCurrentHealth();
float getCurrentHunger();
float getCurrentAir();
float getCurrentArmor();
float getMaxAir();
float getMaxHealth();
boolean isFirstPersonCamera();
boolean isSpectator();
Vector3d getEyePosition();
} }
@@ -38,6 +38,20 @@ public class IrisApiV0Impl implements IrisApi {
return ShadowRenderingState.areShadowsCurrentlyBeingRendered(); return ShadowRenderingState.areShadowsCurrentlyBeingRendered();
} }
@Override
public int getOverriddenShadowDistance(int base) {
return Iris.getPipelineManager().getPipeline()
.map(pipeline -> pipeline.getForcedShadowRenderDistanceChunksForDisplay().orElse(base))
.orElse(base);
}
@Override
public boolean isShadowDistanceSliderEnabled() {
return Iris.getPipelineManager().getPipeline()
.map(pipeline -> !pipeline.getForcedShadowRenderDistanceChunksForDisplay().isPresent())
.orElse(true);
}
@Override @Override
public Object openMainIrisScreenObj(Object parent) { public Object openMainIrisScreenObj(Object parent) {
return new ShaderPackScreen((Screen) parent); return new ShaderPackScreen((Screen) parent);
@@ -8,7 +8,6 @@ import com.google.gson.stream.JsonReader;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.features.FeatureFlags; import net.irisshaders.iris.features.FeatureFlags;
import net.irisshaders.iris.gl.texture.TextureDefinition; import net.irisshaders.iris.gl.texture.TextureDefinition;
@@ -64,6 +63,8 @@ import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static net.irisshaders.iris.IrisLogging.IRIS_LOGGER;
public class ShaderPack { public class ShaderPack {
private static final Gson GSON = new Gson(); private static final Gson GSON = new Gson();
public final CustomUniforms.Builder customUniforms; public final CustomUniforms.Builder customUniforms;
@@ -151,7 +152,7 @@ public class ShaderPack {
if (!graph.getFailures().isEmpty()) { if (!graph.getFailures().isEmpty()) {
graph.getFailures().forEach((path, error) -> { graph.getFailures().forEach((path, error) -> {
Iris.logger.error("{}", error.toString()); IRIS_LOGGER.error("{}", error.toString());
}); });
throw new IOException("Failed to resolve some #include directives, see previous messages for details"); throw new IOException("Failed to resolve some #include directives, see previous messages for details");
@@ -217,7 +218,7 @@ public class ShaderPack {
List<String> optionalFeatureFlags = shaderProperties.getOptionalFeatureFlags().stream().filter(flag -> !FeatureFlags.isInvalid(flag)).toList(); List<String> optionalFeatureFlags = shaderProperties.getOptionalFeatureFlags().stream().filter(flag -> !FeatureFlags.isInvalid(flag)).toList();
if (!optionalFeatureFlags.isEmpty()) { if (!optionalFeatureFlags.isEmpty()) {
optionalFeatureFlags.forEach(flag -> Iris.logger.warn("Found flag " + flag)); optionalFeatureFlags.forEach(flag -> IRIS_LOGGER.warn("Found flag " + flag));
optionalFeatureFlags.forEach(flag -> newEnvDefines.add(new StringPair("IRIS_FEATURE_" + flag, ""))); optionalFeatureFlags.forEach(flag -> newEnvDefines.add(new StringPair("IRIS_FEATURE_" + flag, "")));
} }
@@ -250,7 +251,7 @@ public class ShaderPack {
this.profileInfo = "Profile: " + profileName + " (+" + userOptionsChanged + " option" + (userOptionsChanged == 1 ? "" : "s") + " changed by user)"; this.profileInfo = "Profile: " + profileName + " (+" + userOptionsChanged + " option" + (userOptionsChanged == 1 ? "" : "s") + " changed by user)";
} }
Iris.logger.info(this.profileInfo); IRIS_LOGGER.info(this.profileInfo);
// Prepare our include processor // Prepare our include processor
IncludeProcessor includeProcessor = new IncludeProcessor(graph); IncludeProcessor includeProcessor = new IncludeProcessor(graph);
@@ -303,7 +304,7 @@ public class ShaderPack {
try { try {
return readTexture(root, new TextureDefinition.PNGDefinition(path)); return readTexture(root, new TextureDefinition.PNGDefinition(path));
} catch (IOException e) { } catch (IOException e) {
Iris.logger.error("Unable to read the custom noise texture at " + path, e); IRIS_LOGGER.error("Unable to read the custom noise texture at " + path, e);
return null; return null;
} }
@@ -315,7 +316,7 @@ public class ShaderPack {
try { try {
innerCustomTextureDataMap.put(samplerName, readTexture(root, path)); innerCustomTextureDataMap.put(samplerName, readTexture(root, path));
} catch (IOException e) { } catch (IOException e) {
Iris.logger.error("Unable to read the custom texture at " + path, e); IRIS_LOGGER.error("Unable to read the custom texture at " + path, e);
} }
}); });
@@ -330,7 +331,7 @@ public class ShaderPack {
try { try {
irisCustomTextureDataMap.put(name, readTexture(root, texture)); irisCustomTextureDataMap.put(name, readTexture(root, texture));
} catch (IOException e) { } catch (IOException e) {
Iris.logger.error("Unable to read the custom texture at " + texture.getName(), e); IRIS_LOGGER.error("Unable to read the custom texture at " + texture.getName(), e);
} }
}); });
} }
@@ -358,7 +359,7 @@ public class ShaderPack {
try { try {
properties.load(propertiesReader); properties.load(propertiesReader);
} catch (IOException e) { } catch (IOException e) {
Iris.logger.error("Error loading " + name + " at " + shaderPath, e); IRIS_LOGGER.error("Error loading " + name + " at " + shaderPath, e);
return Optional.empty(); return Optional.empty();
} }
@@ -416,11 +417,11 @@ public class ShaderPack {
// Property files should be encoded in ISO_8859_1. // Property files should be encoded in ISO_8859_1.
return Files.readString(shaderPath.resolve(name), StandardCharsets.ISO_8859_1); return Files.readString(shaderPath.resolve(name), StandardCharsets.ISO_8859_1);
} catch (NoSuchFileException e) { } catch (NoSuchFileException e) {
Iris.logger.debug("An " + name + " file was not found in the current shaderpack"); IRIS_LOGGER.debug("An " + name + " file was not found in the current shaderpack");
return null; return null;
} catch (IOException e) { } catch (IOException e) {
Iris.logger.error("An IOException occurred reading " + name + " from the current shaderpack", e); IRIS_LOGGER.error("An IOException occurred reading " + name + " from the current shaderpack", e);
return null; return null;
} }
@@ -460,7 +461,7 @@ public class ShaderPack {
String[] parts = path.split(":"); String[] parts = path.split(":");
if (parts.length > 2) { if (parts.length > 2) {
Iris.logger.warn("Resource location " + path + " contained more than two parts?"); IRIS_LOGGER.warn("Resource location " + path + " contained more than two parts?");
} }
if (parts[0].equals("minecraft") && (parts[1].equals("dynamic/lightmap_1") || parts[1].equals("dynamic/light_map_1"))) { if (parts[0].equals("minecraft") && (parts[1].equals("dynamic/lightmap_1") || parts[1].equals("dynamic/light_map_1"))) {
@@ -494,7 +495,7 @@ public class ShaderPack {
} }
} }
} catch (IOException e) { } catch (IOException e) {
Iris.logger.error("Unable to read the custom texture mcmeta at " + mcMetaPath + ", ignoring: " + e); IRIS_LOGGER.error("Unable to read the custom texture mcmeta at " + mcMetaPath + ", ignoring: " + e);
} }
} }
@@ -537,7 +538,7 @@ public class ShaderPack {
if (dimensionIds.contains(name)) { if (dimensionIds.contains(name)) {
return new ProgramSet(AbsolutePackPath.fromAbsolutePath("/" + name), sourceProvider, shaderProperties, this); return new ProgramSet(AbsolutePackPath.fromAbsolutePath("/" + name), sourceProvider, shaderProperties, this);
} else { } else {
Iris.logger.error("Attempted to load dimension folder " + name + " for dimension " + dimension + ", but it does not exist!"); IRIS_LOGGER.error("Attempted to load dimension folder " + name + " for dimension " + dimension + ", but it does not exist!");
return ProgramSetInterface.Empty.INSTANCE; return ProgramSetInterface.Empty.INSTANCE;
} }
} else { } else {
@@ -1,200 +0,0 @@
package net.irisshaders.iris.uniforms;
import net.irisshaders.iris.gl.uniform.UniformHolder;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.gui.option.IrisVideoSettings;
import net.irisshaders.iris.helpers.JomlConversions;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.GameType;
import net.minecraft.world.phys.Vec3;
import org.joml.Math;
import org.joml.Vector3d;
import org.joml.Vector4f;
import java.util.Objects;
import java.util.stream.StreamSupport;
public class IrisExclusiveUniforms {
private static final Vector3d ZERO = new Vector3d(0);
public static void addIrisExclusiveUniforms(UniformHolder uniforms) {
WorldInfoUniforms.addWorldInfoUniforms(uniforms);
uniforms.uniform1i(UniformUpdateFrequency.PER_TICK, "currentColorSpace", () -> IrisVideoSettings.colorSpace.ordinal());
//All Iris-exclusive uniforms (uniforms which do not exist in either OptiFine or ShadersMod) should be registered here.
uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "thunderStrength", IrisExclusiveUniforms::getThunderStrength);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHealth", IrisExclusiveUniforms::getCurrentHealth);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHealth", IrisExclusiveUniforms::getMaxHealth);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerHunger", IrisExclusiveUniforms::getCurrentHunger);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerHunger", () -> 20);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerArmor", IrisExclusiveUniforms::getCurrentArmor);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerArmor", () -> 50);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "currentPlayerAir", IrisExclusiveUniforms::getCurrentAir);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerAir", IrisExclusiveUniforms::getMaxAir);
uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "firstPersonCamera", IrisExclusiveUniforms::isFirstPersonCamera);
uniforms.uniform1b(UniformUpdateFrequency.PER_TICK, "isSpectator", IrisExclusiveUniforms::isSpectator);
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "eyePosition", IrisExclusiveUniforms::getEyePosition);
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "cloudTime", CapturedRenderingState.INSTANCE::getCloudTime);
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "relativeEyePosition", () -> CameraUniforms.getUnshiftedCameraPosition().sub(getEyePosition()));
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerLookVector", () -> {
if (Minecraft.getInstance().cameraEntity instanceof LivingEntity livingEntity) {
return JomlConversions.fromVec3(livingEntity.getViewVector(CapturedRenderingState.INSTANCE.getTickDelta()));
} else {
return ZERO;
}
});
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerBodyVector", () -> JomlConversions.fromVec3(Minecraft.getInstance().getCameraEntity().getForward()));
Vector4f zero = new Vector4f(0, 0, 0, 0);
uniforms.uniform4f(UniformUpdateFrequency.PER_TICK, "lightningBoltPosition", () -> {
if (Minecraft.getInstance().level != null) {
return StreamSupport.stream(Minecraft.getInstance().level.entitiesForRendering().spliterator(), false).filter(bolt -> bolt instanceof LightningBolt).findAny().map(bolt -> {
Vector3d unshiftedCameraPosition = CameraUniforms.getUnshiftedCameraPosition();
//? if >=1.21 {
/*float deltaFrameTime = Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(true);
*///?} else {
float deltaFrameTime = Minecraft.getInstance().getDeltaFrameTime();
//?}
Vec3 vec3 = bolt.getPosition(deltaFrameTime);
return new Vector4f((float) (vec3.x - unshiftedCameraPosition.x), (float) (vec3.y - unshiftedCameraPosition.y), (float) (vec3.z - unshiftedCameraPosition.z), 1);
}).orElse(zero);
} else {
return zero;
}
});
}
private static float getThunderStrength() {
// Note: Ensure this is in the range of 0 to 1 - some custom servers send out of range values.
return Math.clamp(0.0F, 1.0F,
Minecraft.getInstance().level.getThunderLevel(CapturedRenderingState.INSTANCE.getTickDelta()));
}
private static float getCurrentHealth() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getHealth() / Minecraft.getInstance().player.getMaxHealth();
}
private static float getCurrentHunger() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getFoodData().getFoodLevel() / 20f;
}
private static float getCurrentAir() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return (float) Minecraft.getInstance().player.getAirSupply() / (float) Minecraft.getInstance().player.getMaxAirSupply();
}
private static float getCurrentArmor() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getArmorValue() / 50.0f;
}
private static float getMaxAir() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getMaxAirSupply();
}
private static float getMaxHealth() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getMaxHealth();
}
private static boolean isFirstPersonCamera() {
// If camera type is not explicitly third-person, assume it's first-person.
return switch (Minecraft.getInstance().options.getCameraType()) {
case THIRD_PERSON_BACK, THIRD_PERSON_FRONT -> false;
default -> true;
};
}
private static boolean isSpectator() {
return Minecraft.getInstance().gameMode.getPlayerMode() == GameType.SPECTATOR;
}
private static Vector3d getEyePosition() {
Objects.requireNonNull(Minecraft.getInstance().getCameraEntity());
Vec3 pos = Minecraft.getInstance().getCameraEntity().getEyePosition(CapturedRenderingState.INSTANCE.getTickDelta());
return new Vector3d(pos.x, pos.y, pos.z);
}
public static class WorldInfoUniforms {
public static void addWorldInfoUniforms(UniformHolder uniforms) {
ClientLevel level = Minecraft.getInstance().level;
// TODO: Use level.dimensionType() coordinates for 1.18!
uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "bedrockLevel", () -> {
if (level != null) {
return level.dimensionType().minY();
} else {
return 0;
}
});
uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "cloudHeight", () -> {
if (level != null) {
return level.effects().getCloudHeight();
} else {
return 192.0;
}
});
uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "heightLimit", () -> {
if (level != null) {
return level.dimensionType().height();
} else {
return 256;
}
});
uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "logicalHeightLimit", () -> {
if (level != null) {
return level.dimensionType().logicalHeight();
} else {
return 256;
}
});
uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "hasCeiling", () -> {
if (level != null) {
return level.dimensionType().hasCeiling();
} else {
return false;
}
});
uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "hasSkylight", () -> {
if (level != null) {
return level.dimensionType().hasSkyLight();
} else {
return true;
}
});
uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "ambientLight", () -> {
if (level != null) {
return level.dimensionType().ambientLight();
} else {
return 0f;
}
});
}
}
}
@@ -1,8 +1,28 @@
package org.embeddedt.embeddium.impl; package org.embeddedt.embeddium.impl;
import com.mojang.math.Axis;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.helpers.JomlConversions;
import net.irisshaders.iris.shaderpack.DimensionId;
import net.irisshaders.iris.uniforms.CameraUniforms;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.GameType;
import net.minecraft.world.phys.Vec3;
import org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService; import org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import org.embeddedt.embeddium.impl.loader.common.EarlyLoaderServices; import org.embeddedt.embeddium.impl.loader.common.EarlyLoaderServices;
import org.joml.Math;
import org.joml.Matrix4f;
import org.joml.Vector3d;
import org.joml.Vector4f;
import java.util.Objects;
import java.util.stream.StreamSupport;
public class MinecraftModernVersionShimImpl implements MinecraftVersionShimService { public class MinecraftModernVersionShimImpl implements MinecraftVersionShimService {
@Override @Override
@@ -33,4 +53,240 @@ public class MinecraftModernVersionShimImpl implements MinecraftVersionShimServi
public boolean isModLoaded(String modId) { public boolean isModLoaded(String modId) {
return EarlyLoaderServices.INSTANCE.isModLoaded(modId); return EarlyLoaderServices.INSTANCE.isModLoaded(modId);
} }
@Override
public String translate(String key, Object... args) {
return I18n.get(key, args);
}
@Override
public boolean isLevelLoaded() {
return Minecraft.getInstance().level != null;
}
@Override
public int getRenderDistanceInBlocks() {
// TODO: Should we ask the game renderer for this?
return Minecraft.getInstance().options.getEffectiveRenderDistance() * 16;
}
@Override
public Vector3d getUnshiftedCameraPosition() {
return JomlConversions.fromVec3(Minecraft.getInstance().gameRenderer.getMainCamera().getPosition());
}
private ClientLevel getWorld() {
return Objects.requireNonNull(Minecraft.getInstance().level);
}
@Override
public float getSkyAngle() {
return getWorld().getTimeOfDay(CapturedRenderingState.INSTANCE.getTickDelta());
}
@Override
public void applyRotationYP(Matrix4f mat, float degrees) {
mat.rotate(Axis.YP.rotationDegrees(degrees));
}
@Override
public void applyRotationXP(Matrix4f mat, float degrees) {
mat.rotate(Axis.XP.rotationDegrees(degrees));
}
@Override
public void applyRotationZP(Matrix4f mat, float degrees) {
mat.rotate(Axis.ZP.rotationDegrees(degrees));
}
@Override
public int getMoonPhase() {
return getWorld().getMoonPhase();
}
@Override
public long getDayTime() {
return getWorld().getDayTime();
}
@Override
public long getDimensionTime(long orElse) {
return getWorld().dimensionType().fixedTime().orElse(orElse);
}
@Override
public boolean isCurrentDimensionNether() {
return Iris.getCurrentDimension() == DimensionId.NETHER;
}
@Override
public boolean isCurrentDimensionEnd() {
return Iris.getCurrentDimension() == DimensionId.END;
}
@Override
public int getMinecraftRenderHeight() {
return Minecraft.getInstance().getMainRenderTarget().height;
}
@Override
public int getMinecraftRenderWidth() {
return Minecraft.getInstance().getMainRenderTarget().width;
}
@Override
public int getBedrockLevel() {
final ClientLevel level = getWorld();
return level != null ? level.dimensionType().minY() : 0;
}
@Override
public float getCloudHeight() {
final ClientLevel level = getWorld();
return level != null ? level.effects().getCloudHeight() : 192.0f;
}
@Override
public int getHeightLimit() {
final ClientLevel level = getWorld();
return level != null ? level.dimensionType().height() : 256;
}
@Override
public int getLogicalHeightLimit() {
final ClientLevel level = getWorld();
return level != null ? level.dimensionType().logicalHeight() : 256;
}
@Override
public boolean hasCeiling() {
final ClientLevel level = getWorld();
return level != null && level.dimensionType().hasCeiling();
}
@Override
public boolean hasSkyLight() {
final ClientLevel level = getWorld();
return level == null || level.dimensionType().hasSkyLight();
}
@Override
public float getAmbientLight() {
final ClientLevel level = getWorld();
return level != null ? level.dimensionType().ambientLight() : 0f;
}
@Override
public Vector3d getPlayerLookVector() {
if (Minecraft.getInstance().cameraEntity instanceof LivingEntity livingEntity) {
return JomlConversions.fromVec3(livingEntity.getViewVector(CapturedRenderingState.INSTANCE.getTickDelta()));
} else {
return ZERO3D;
}
}
@Override
public Vector3d getPlayerBodyVector() {
return JomlConversions.fromVec3(Minecraft.getInstance().getCameraEntity().getForward());
}
@Override
public Vector4f getLightningBoltPosition() {
if (Minecraft.getInstance().level != null) {
return StreamSupport.stream(Minecraft.getInstance().level.entitiesForRendering().spliterator(), false).filter(bolt -> bolt instanceof LightningBolt).findAny().map(bolt -> {
Vector3d unshiftedCameraPosition = CameraUniforms.getUnshiftedCameraPosition();
//? if >=1.21 {
/*float deltaFrameTime = Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(true);
*///?} else {
float deltaFrameTime = Minecraft.getInstance().getDeltaFrameTime();
//?}
Vec3 vec3 = bolt.getPosition(deltaFrameTime);
return new Vector4f((float) (vec3.x - unshiftedCameraPosition.x), (float) (vec3.y - unshiftedCameraPosition.y), (float) (vec3.z - unshiftedCameraPosition.z), 1);
}).orElse(ZERO4F);
} else {
return ZERO4F;
}
}
@Override
public float getThunderStrength() {
// Note: Ensure this is in the range of 0 to 1 - some custom servers send out of range values.
return Math.clamp(0.0F, 1.0F,
Minecraft.getInstance().level.getThunderLevel(CapturedRenderingState.INSTANCE.getTickDelta()));
}
@Override
public float getCurrentHealth() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getHealth() / Minecraft.getInstance().player.getMaxHealth();
}
@Override
public float getCurrentHunger() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getFoodData().getFoodLevel() / 20f;
}
@Override
public float getCurrentAir() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return (float) Minecraft.getInstance().player.getAirSupply() / (float) Minecraft.getInstance().player.getMaxAirSupply();
}
@Override
public float getCurrentArmor() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getArmorValue() / 50.0f;
}
@Override
public float getMaxAir() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getMaxAirSupply();
}
@Override
public float getMaxHealth() {
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) {
return -1;
}
return Minecraft.getInstance().player.getMaxHealth();
}
@Override
public boolean isFirstPersonCamera() {
// If camera type is not explicitly third-person, assume it's first-person.
return switch (Minecraft.getInstance().options.getCameraType()) {
case THIRD_PERSON_BACK, THIRD_PERSON_FRONT -> false;
default -> true;
};
}
@Override
public boolean isSpectator() {
return Minecraft.getInstance().gameMode.getPlayerMode() == GameType.SPECTATOR;
}
@Override
public Vector3d getEyePosition() {
Objects.requireNonNull(Minecraft.getInstance().getCameraEntity());
Vec3 pos = Minecraft.getInstance().getCameraEntity().getEyePosition(CapturedRenderingState.INSTANCE.getTickDelta());
return new Vector3d(pos.x, pos.y, pos.z);
}
} }
@@ -228,6 +228,16 @@ public class GLStateManagerImpl implements GLStateManagerService {
return GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].binding; return GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].binding;
} }
@Override
public int getViewportWidth() {
return GlStateManager.Viewport.width();
}
@Override
public int getViewportHeight() {
return GlStateManager.Viewport.height();
}
@Override @Override
public void setBoundTexture(int unit, int texture) { public void setBoundTexture(int unit, int texture) {
GlStateManagerAccessor.getTEXTURES()[unit].binding = texture; GlStateManagerAccessor.getTEXTURES()[unit].binding = texture;
@@ -3,6 +3,7 @@ package org.embeddedt.embeddium.impl.gl;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import com.mitchej123.glsm.RenderSystemService; import com.mitchej123.glsm.RenderSystemService;
import com.mojang.blaze3d.shaders.FogShape;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.mixin.GlStateManagerAccessor; import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import org.embeddedt.embeddium.compat.BooleanStateExtended; import org.embeddedt.embeddium.compat.BooleanStateExtended;
@@ -134,6 +135,16 @@ public class RenderSystemImpl implements RenderSystemService {
return RenderSystem.getShaderFogEnd(); return RenderSystem.getShaderFogEnd();
} }
@Override
public int getFogShape() {
return RenderSystem.getShaderFogShape() == FogShape.CYLINDER ? 1 : 0;
}
@Override
public float getShaderLineWidth() {
return RenderSystem.getShaderLineWidth();
}
@Override @Override
public Matrix4f getProjectionMatrix() { public Matrix4f getProjectionMatrix() {
return RenderSystem.getProjectionMatrix(); return RenderSystem.getProjectionMatrix();