Skip to content

Commit

Permalink
feat: smol updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna0x01 committed Jan 31, 2025
1 parent 6aa4d21 commit a39c22d
Show file tree
Hide file tree
Showing 45 changed files with 460 additions and 468 deletions.
3 changes: 2 additions & 1 deletion common/src/main/resources/sodium-common.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ accessible method net/minecraft/client/render/GameRenderer getFov (FZ)F
accessible method net/minecraft/client/render/GameRenderer bobViewWhenHurt (F)V
accessible method net/minecraft/client/render/GameRenderer bobView (F)V
accessible field net/minecraft/client/render/GameRenderer viewDistance F
accessible field net/minecraft/client/render/model/TexturedBakedQuad sprite Lnet/minecraft/client/texture/Sprite;
accessible field net/minecraft/client/render/model/TexturedBakedQuad sprite Lnet/minecraft/client/texture/Sprite;
accessible class net/minecraft/client/render/WorldRenderer$ChunkInfo
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@

@Mixin(GameRenderer.class)
public interface GameRendererAccessor {
@Invoker
void invokeBobViewWhenHurt(float tickDelta);

@Invoker
void invokeBobView(float tickDelta);

@Accessor
int getFrameCount();

@Accessor
void setFrameCount(int frameCount);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@

@Mixin(WorldRenderer.class)
public interface LevelRendererAccessor {
@Accessor("entityRenderDispatcher")
@Accessor("entityRenderDispatcher")
EntityRenderDispatcher getEntityRenderDispatcher();

@Invoker("renderLayer")
@Invoker("renderLayer")
int invokeRenderLayer(RenderLayer renderLayer, double tickDelta, int anaglyphFilter, Entity entity);

@Invoker("setupTerrain")
void invokeSetupRender(Entity entity, double tickDelta, CameraView cameraView, int frame, boolean spectator);
@Invoker("setupTerrain")
void invokeSetupRender(Entity entity, double tickDelta, CameraView cameraView, int frame, boolean spectator);

@Accessor("world")
@Accessor("world")
ClientWorld getLevel();

@Accessor("ticks")
int getFrameId();
@Accessor("ticks")
int getFrameId();

@Accessor("ticks")
void setFrameId(int frame);
}
@Accessor("ticks")
void setFrameId(int frame);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@Mixin(GameRenderer.class)
public interface LightTextureAccessor {
@Accessor("lightmapTexture")
@Accessor("lightmapTexture")
NativeImageBackedTexture getLightTexture();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.coderbot.iris.Iris;
import net.minecraft.util.crash.CrashReport;
import net.minecraft.util.crash.CrashReportSection;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -15,13 +16,14 @@
@Mixin(CrashReport.class)
public abstract class MixinCrashReport {
@Shadow
public abstract CrashReportSection getSystemDetailsSection();
@Final
private CrashReportSection systemDetailsSection;

@Inject(at = @At("RETURN"), method = "fillSystemDetails")
private void fillSystemDetails(CallbackInfo info) {
if (Iris.getCurrentPackName() == null) return; // this also gets called at startup for some reason

getSystemDetailsSection().add("Loaded Shaderpack", () -> {
this.systemDetailsSection.add("Loaded Shaderpack", () -> {
StringBuilder sb = new StringBuilder(Iris.getCurrentPackName() + (Iris.isFallback() ? " (fallback)" : ""));
Iris.getCurrentPack().ifPresent(pack -> {
sb.append("\n\t\t");
Expand All @@ -30,7 +32,7 @@ private void fillSystemDetails(CallbackInfo info) {
return sb.toString();
});

getSystemDetailsSection().add("NEC status", () -> {
this.systemDetailsSection.add("NEC status", () -> {
if (Iris.hasNotEnoughCrashes()) {
return "Has NEC: INVALID";
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.coderbot.iris.mixin;

import com.mojang.realmsclient.gui.ChatFormatting;
import net.coderbot.iris.Iris;
import net.minecraft.client.gui.hud.DebugHud;
import net.minecraft.util.Formatting;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -65,6 +65,11 @@ public abstract class MixinDebugScreenOverlay {
private void iris$appendShadowDebugText(CallbackInfoReturnable<List<String>> cir) {
List<String> messages = cir.getReturnValue();

if (!Iris.isSodiumInstalled() && Iris.getCurrentPack().isPresent()) {
messages.add(1, ChatFormatting.YELLOW + "[" + Iris.MODNAME + "] Sodium isn't installed; you will have poor performance.");
messages.add(2, ChatFormatting.YELLOW + "[" + Iris.MODNAME + "] Install Sodium if you want to run benchmarks or get higher FPS!");
}

Iris.getPipelineManager().getPipeline().ifPresent(pipeline -> pipeline.addDebugText(messages));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
package net.coderbot.iris.mixin;

import com.mojang.blaze3d.vertex.PoseStack;
import net.coderbot.iris.Iris;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(EntityRenderer.class)
@Mixin(EntityRenderDispatcher.class)
public class MixinEntityRenderDispatcher {
@Inject(method = "renderShadow", at = @At("HEAD"), cancellable = true)
private void iris$maybeSuppressEntityShadow(Entity entity, double x, double y, double z, float f, float tickDelta, CallbackInfo ci) {
iris$maybeSuppressShadow(ci);
}

@Unique
private static void iris$maybeSuppressShadow(CallbackInfo ci) {
@Inject(method = "shouldRenderShadows", at = @At("RETURN"), cancellable = true)
private void iris$shouldRenderShadows(CallbackInfoReturnable<Boolean> cir) {
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();

if (pipeline != null && pipeline.shouldDisableVanillaEntityShadows()) {
ci.cancel();
cir.setReturnValue(false);
}
}
}
198 changes: 92 additions & 106 deletions common/src/shaders/java/net/coderbot/iris/mixin/MixinGameRenderer.java
Original file line number Diff line number Diff line change
@@ -1,141 +1,127 @@
package net.coderbot.iris.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import com.mojang.blaze3d.platform.GLX;
import com.mojang.blaze3d.vertex.PoseStack;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.program.Program;
import net.coderbot.iris.pipeline.HandRenderer;
import net.coderbot.iris.pipeline.WorldRenderingPhase;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.uniforms.CapturedRenderingState;
import net.coderbot.iris.uniforms.SystemTimeUniforms;
import net.coderbot.iris.vendored.joml.Matrix4f;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.resource.ResourceManager;
import net.coderbot.iris.vendored.joml.Matrix4f;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GameRenderer.class)
public class MixinGameRenderer {
@Shadow
private MinecraftClient client;
@Shadow
public float fogRed;
@Shadow
public float fogBlue;
@Shadow
public float fogGreen;
@Unique
private WorldRenderingPipeline pipeline;

@Inject(method = "<init>", at = @At("TAIL"))
@Inject(method = "<init>", at = @At("TAIL"))
private void iris$logSystem(MinecraftClient minecraftClient, ResourceManager resourceManager, CallbackInfo ci) {
Iris.logger.info("Hardware information:");
Iris.logger.info("CPU: " + GLX.getProcessor());
Iris.logger.info("GPU: " + GL11.glGetString(7937) + " (Supports OpenGL " + GL11.glGetString(7938) + ")");
Iris.logger.info("GPU: " + GL11.glGetString(GL11.GL_RENDERER) + " (Supports OpenGL " + GL11.glGetString(GL11.GL_VERSION) + ")");
Iris.logger.info("OS: " + System.getProperty("os.name") + " (" + System.getProperty("os.version") + ")");
}

@Redirect(method = "renderHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderArmHoldingItem(F)V"))
private void disableVanillaHandRendering(HeldItemRenderer instance, float tickDelta) {
if (Iris.getCurrentPack().isPresent()) {
return;
}

instance.renderArmHoldingItem(tickDelta);
}

@Unique
private WorldRenderingPipeline pipeline;


// Begin shader rendering after buffers have been cleared.
// At this point we've ensured that Minecraft's main framebuffer is cleared.
// This is important or else very odd issues will happen with shaders that have a final pass that doesn't write to
// all pixels.
@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;clear(I)V", shift = At.Shift.AFTER))
private void iris$beginLevelRender(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
if (Iris.isSodiumInvalid()) {
throw new IllegalStateException("An invalid version of Sodium is installed, and the warning screen somehow" +
" didn't work. This is a bug! Please report it to the Iris developers.");
}

CapturedRenderingState.INSTANCE.setGbufferModelView(new Matrix4f(Camera.MODEL_MATRIX));
CapturedRenderingState.INSTANCE.setGbufferProjection(new Matrix4f(Camera.PROJECTION_MATRIX));
CapturedRenderingState.INSTANCE.setTickDelta(tickDelta);
SystemTimeUniforms.COUNTER.beginFrame();
SystemTimeUniforms.TIMER.beginFrame(limitTime);

Program.unbind();

pipeline = Iris.getPipelineManager().preparePipeline(Iris.getCurrentDimension());

pipeline.beginLevelRendering();
}

// Inject a bit early so that we can end our rendering before mods like VoxelMap (which inject at RETURN)
// render their waypoint beams.
@Inject(method = "renderWorld(IFJ)V", at = @At(value = "RETURN", shift = At.Shift.BEFORE))
private void iris$endLevelRender(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
HandRenderer.INSTANCE.renderTranslucent(tickDelta, (GameRenderer) (Object) this, pipeline);
MinecraftClient.getInstance().profiler.swap("iris_final");
pipeline.finalizeLevelRendering();
pipeline = null;
Program.unbind();
}

// Setup shadow terrain & render shadows before the main terrain setup. We need to do things in this order to
// avoid breaking other mods such as Light Overlay: https://github.com/IrisShaders/Iris/issues/1356
@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;setupCamera(FI)V"))
private void iris$renderTerrainShadows(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
pipeline.renderShadows((LevelRendererAccessor) MinecraftClient.getInstance().worldRenderer);
}

@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;renderSky(FI)V"))
private void iris$beginSky(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
// Use CUSTOM_SKY until levelFogColor is called as a heuristic to catch FabricSkyboxes.
pipeline.setPhase(WorldRenderingPhase.CUSTOM_SKY);
}

@Redirect(method = "renderWorld(IFJ)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/option/GameOptions;viewDistance:I"))
private int iris$alwaysRenderSky(GameOptions instance) {
return Math.max(instance.viewDistance, 4);
}


@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;renderWeather(F)V"))
private void iris$beginWeather(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
Iris.getPipelineManager().getPipelineNullable().setPhase(WorldRenderingPhase.RAIN_SNOW);
}

@ModifyArg(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;depthMask(Z)V", ordinal = 0))
private boolean iris$writeRainAndSnowToDepthBuffer(boolean depthMaskEnabled) {
if (Iris.getPipelineManager().getPipelineNullable().shouldWriteRainAndSnowToDepthBuffer()) {
return true;
}

return depthMaskEnabled;
}

// Begin shader rendering after buffers have been cleared.
// At this point we've ensured that Minecraft's main framebuffer is cleared.
// This is important or else very odd issues will happen with shaders that have a final pass that doesn't write to
// all pixels.
@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/CameraView;setPos(DDD)V", shift = At.Shift.AFTER))
private void iris$beginLevelRender(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
if (Iris.isSodiumInvalid()) {
throw new IllegalStateException("An invalid version of Sodium is installed, and the warning screen somehow" +
" didn't work. This is a bug! Please report it to the Iris developers.");
}

CapturedRenderingState.INSTANCE.setGbufferModelView(new Matrix4f(Camera.MODEL_MATRIX));
CapturedRenderingState.INSTANCE.setGbufferProjection(new Matrix4f(Camera.PROJECTION_MATRIX));
CapturedRenderingState.INSTANCE.setTickDelta(tickDelta);
CapturedRenderingState.INSTANCE.setFogColor(this.fogRed, this.fogGreen, this.fogBlue);
SystemTimeUniforms.COUNTER.beginFrame();
SystemTimeUniforms.TIMER.beginFrame(limitTime);

Program.unbind();

pipeline = Iris.getPipelineManager().preparePipeline(Iris.getCurrentDimension());

pipeline.beginLevelRendering();
}


@Inject(method = "renderWorld(IFJ)V", at = @At(value = "RETURN"))
private void iris$endLevelRender(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
// TODO: Iris
HandRenderer.INSTANCE.renderTranslucent(tickDelta, this.client.gameRenderer, pipeline);
MinecraftClient.getInstance().profiler.swap("iris_final");
pipeline.finalizeLevelRendering();
Program.unbind();
}

@WrapOperation(method = "renderHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderArmHoldingItem(F)V"))
private void iris$disableVanillaRenderHand(HeldItemRenderer instance, float tickDelta, Operation<Void> original) {
if (Iris.getCurrentPack().isEmpty()) {
original.call(instance, tickDelta);
}
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;setupTerrain(Lnet/minecraft/entity/Entity;DLnet/minecraft/client/render/CameraView;IZ)V", shift = At.Shift.AFTER), method = "renderWorld(IFJ)V")
private void iris$beginEntities(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
pipeline.renderShadows((LevelRendererAccessor) this.client.worldRenderer);
}


@Redirect(method = "renderWorld(IFJ)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/option/GameOptions;viewDistance:I"))
private int iris$alwaysRenderSky(GameOptions instance) {
return Math.max(instance.viewDistance, 4);
}

@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;renderSky(FI)V"))
private void iris$beginSky(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
// Use CUSTOM_SKY until levelFogColor is called as a heuristic to catch FabricSkyboxes.
pipeline.setPhase(WorldRenderingPhase.CUSTOM_SKY);
}


@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;renderSky(FI)V", shift = At.Shift.AFTER))
private void iris$endSky(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
pipeline.setPhase(WorldRenderingPhase.NONE);
}

@WrapOperation(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;renderClouds(Lnet/minecraft/client/render/WorldRenderer;FI)V"))
private void iris$clouds(GameRenderer instance, WorldRenderer worldRenderer, float tickDelta, int anaglyphFilter, Operation<Void> original) {
pipeline.setPhase(WorldRenderingPhase.CLOUDS);
original.call(instance, worldRenderer, tickDelta, anaglyphFilter);
pipeline.setPhase(WorldRenderingPhase.NONE);
}


@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;renderWeather(F)V"))
private void iris$beginWeatherAndwriteRainAndSnowToDepthBuffer(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
pipeline.setPhase(WorldRenderingPhase.RAIN_SNOW);
if (pipeline.shouldWriteRainAndSnowToDepthBuffer()) {
GL11.glDepthMask(true);
}
}

@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;renderWeather(F)V", shift = At.Shift.AFTER))
private void iris$endWeather(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
pipeline.setPhase(WorldRenderingPhase.NONE);
}
@Inject(method = "renderWorld(IFJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;renderWeather(F)V", shift = At.Shift.AFTER))
private void iris$endWeather(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
Iris.getPipelineManager().getPipelineNullable().setPhase(WorldRenderingPhase.NONE);
}

@Inject(method = "renderWorld(IFJ)V", at = @At(value = "CONSTANT", args = "stringValue=translucent"))
private void iris$beginTranslucents(int anaglyphFilter, float tickDelta, long limitTime, CallbackInfo ci) {
Iris.getPipelineManager().getPipelineNullable().beginHand();
HandRenderer.INSTANCE.renderSolid(tickDelta, (GameRenderer) (Object) this, pipeline);
MinecraftClient.getInstance().profiler.swap("iris_pre_translucent");
Iris.getPipelineManager().getPipelineNullable().beginTranslucents();
}
}
Loading

0 comments on commit a39c22d

Please sign in to comment.