diff --git a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java index bd4bc232f5..6a2224c38c 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java @@ -114,6 +114,9 @@ public class MixinLevelRenderer { private void iris$endLevelRender(PoseStack poseStack, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo callback) { HandRenderer.INSTANCE.renderTranslucent(poseStack, tickDelta, camera, gameRenderer, pipeline); Minecraft.getInstance().getProfiler().popPush("iris_final"); + CapturedRenderingState.INSTANCE.velocityInfoEdit = new PoseStack(); + CapturedRenderingState.INSTANCE.velocityInfoEdit.mulPose(Axis.XP.rotationDegrees(camera.getXRot())); + CapturedRenderingState.INSTANCE.velocityInfoEdit.mulPose(Axis.YP.rotationDegrees(camera.getYRot() + 180.0F)); pipeline.finalizeLevelRendering(); pipeline = null; } diff --git a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinBlockEntityRenderDispatcher.java b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinBlockEntityRenderDispatcher.java index 7603b60044..451314aeb4 100644 --- a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinBlockEntityRenderDispatcher.java +++ b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinBlockEntityRenderDispatcher.java @@ -57,7 +57,7 @@ public class MixinBlockEntityRenderDispatcher { int intId = blockStateIds.getOrDefault(state, -1); CapturedRenderingState.INSTANCE.setCurrentBlockEntity(intId); - CapturedRenderingState.INSTANCE.setUniqueEntityId(blockEntity.getBlockPos().getX() + blockEntity.getBlockPos().getY()); + CapturedRenderingState.INSTANCE.setUniqueEntityId(blockEntity.getBlockPos().getX() + blockEntity.getBlockPos().getY() + blockEntity.getType().hashCode()); return type -> bufferSource.getBuffer(OuterWrappedRenderType.wrapExactlyOnce("iris:is_block_entity", type, BlockEntityRenderStateShard.INSTANCE)); diff --git a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinEntityRenderDispatcher.java b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinEntityRenderDispatcher.java index 2efc7bc3b3..d82621fdce 100644 --- a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinEntityRenderDispatcher.java +++ b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinEntityRenderDispatcher.java @@ -14,12 +14,15 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderStateShard; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.monster.ZombieVillager; +import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; @@ -31,11 +34,27 @@ * rendered. */ @Mixin(EntityRenderDispatcher.class) -public class MixinEntityRenderDispatcher { +public abstract class MixinEntityRenderDispatcher { + @Shadow + public abstract EntityRenderer getRenderer(T pEntityRenderDispatcher0); + // Inject after MatrixStack#push since at this point we know that most cancellation checks have already passed. @ModifyVariable(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V", shift = At.Shift.AFTER), allow = 1, require = 1) - private MultiBufferSource iris$beginEntityRender(MultiBufferSource bufferSource, Entity entity) { + private MultiBufferSource iris$beginEntityRender(MultiBufferSource bufferSource, Entity entity, + double pDouble1, + double pDouble2, + double pDouble3, + float pFloat4, + float pFloat5) { + + Vec3 lvVec314 = this.getRenderer(entity).getRenderOffset(entity, pFloat5); + double lvDouble15 = pDouble1 + lvVec314.x(); + double lvDouble17 = pDouble2 + lvVec314.y(); + double lvDouble19 = pDouble3 + lvVec314.z(); + CapturedRenderingState.INSTANCE.velocityInfoEdit.pushPose(); + CapturedRenderingState.INSTANCE.velocityInfoEdit.translate(lvDouble15, lvDouble17, lvDouble19); + if (!(bufferSource instanceof Groupable)) { // Fully batched entity rendering is not being used, do not use this wrapper!!! return bufferSource; @@ -43,6 +62,7 @@ public class MixinEntityRenderDispatcher { Object2IntFunction entityIds = BlockRenderingSettings.INSTANCE.getEntityIds(); + if (entityIds == null) { return bufferSource; } @@ -71,5 +91,6 @@ public class MixinEntityRenderDispatcher { CallbackInfo ci) { CapturedRenderingState.INSTANCE.setCurrentEntity(0); CapturedRenderingState.INSTANCE.setUniqueEntityId(0); + CapturedRenderingState.INSTANCE.velocityInfoEdit.popPose(); } } diff --git a/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinEntityRenderer.java b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinEntityRenderer.java new file mode 100644 index 0000000000..f40cef3e15 --- /dev/null +++ b/src/main/java/net/coderbot/iris/mixin/entity_render_context/MixinEntityRenderer.java @@ -0,0 +1,29 @@ +package net.coderbot.iris.mixin.entity_render_context; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.coderbot.iris.uniforms.CapturedRenderingState; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.Entity; +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; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(EntityRenderer.class) +public class MixinEntityRenderer { + @Shadow + @Final + protected EntityRenderDispatcher entityRenderDispatcher; + + @Inject(method = "renderNameTag", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getNameTagOffsetY()F")) + private void iris$editVelocityInfo(Entity pEntityRenderer0, Component pComponent1, PoseStack pPoseStack2, MultiBufferSource pMultiBufferSource3, int pInt4, CallbackInfo ci) { + CapturedRenderingState.INSTANCE.velocityInfoEdit.translate(0.0F, pEntityRenderer0.getNameTagOffsetY(), 0.0F); + CapturedRenderingState.INSTANCE.velocityInfoEdit.mulPose(this.entityRenderDispatcher.cameraOrientation()); + CapturedRenderingState.INSTANCE.velocityInfoEdit.scale(-0.025F, -0.025F, 0.025F); + } +} diff --git a/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java b/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java index dd3e537ec5..1ecbaacc9f 100644 --- a/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java +++ b/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java @@ -1,5 +1,6 @@ package net.coderbot.iris.uniforms; +import com.mojang.blaze3d.vertex.PoseStack; import net.coderbot.iris.gl.state.ValueUpdateNotifier; import net.minecraft.client.Minecraft; import org.joml.Matrix4f; @@ -12,6 +13,7 @@ public class CapturedRenderingState { private Matrix4f gbufferModelView; private Matrix4f gbufferProjection; + public PoseStack velocityInfoEdit= new PoseStack(); private Vector3d fogColor; private float fogDensity; private float darknessLightFactor; diff --git a/src/main/resources/mixins.iris.json b/src/main/resources/mixins.iris.json index 8168c58a96..31a635fddb 100644 --- a/src/main/resources/mixins.iris.json +++ b/src/main/resources/mixins.iris.json @@ -55,6 +55,7 @@ "MixinVertexBuffer", "entity_render_context.MixinBlockEntityRenderDispatcher", "entity_render_context.MixinEntityRenderDispatcher", + "entity_render_context.MixinEntityRenderer", "entity_render_context.MixinHumanoidArmorLayer", "entity_render_context.MixinItemRenderer", "fabulous.MixinDisableFabulousGraphics", diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/entities/IrisModelCuboid.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/entities/IrisModelCuboid.java index a1bdc6e878..1fb8220e3f 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/entities/IrisModelCuboid.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/entities/IrisModelCuboid.java @@ -5,6 +5,7 @@ import net.coderbot.iris.Iris; import net.coderbot.iris.shadows.ShadowRenderingState; import net.coderbot.iris.uniforms.CapturedRenderingState; +import net.coderbot.iris.uniforms.SystemTimeUniforms; import net.jodah.expiringmap.ExpiringMap; import net.minecraft.core.Direction; import org.joml.*; @@ -109,11 +110,12 @@ public void updateVertices(Matrix4f mat) { src.mulPosition(mat, dst); - if (!ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { + if (!ShadowRenderingState.areShadowsCurrentlyBeingRendered() && history.lastFrame != SystemTimeUniforms.COUNTER.getAsInt()) { previous[i].set(history.storedPositions[i]); history.storedPositions[i].set(dst); } } + history.lastFrame = SystemTimeUniforms.COUNTER.getAsInt(); } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/entities/VertexHistory.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/entities/VertexHistory.java index a7d1d4661c..027d9610f3 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/entities/VertexHistory.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/entities/VertexHistory.java @@ -4,6 +4,7 @@ public class VertexHistory { public Vector3f[] storedPositions; + public int lastFrame; public VertexHistory(int id, int size) { storedPositions = new Vector3f[size]; diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexExt.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexExt.java index 3a98da0dee..931e8f6351 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexExt.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexExt.java @@ -39,7 +39,7 @@ public final class GlyphVertexExt { private static Vector3f lastNormal = new Vector3f(); - public static void write(long ptr, float x, float y, float z, int color, float u, float v, int light) { + public static void write(long ptr, float x, float y, float z, float prevX, float prevY, float prevZ, int color, float u, float v, int light) { long i = ptr; vertexCount++; @@ -63,6 +63,10 @@ public static void write(long ptr, float x, float y, float z, int color, float u MemoryUtil.memPutShort(ptr + 38, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity()); MemoryUtil.memPutShort(ptr + 40, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem()); + MemoryUtil.memPutFloat(ptr + 52, x - prevX); + MemoryUtil.memPutFloat(ptr + 56, y - prevY); + MemoryUtil.memPutFloat(ptr + 60, z - prevZ); + if (vertexCount == 4) { endQuad(ptr); } @@ -131,7 +135,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m float yt = (matPosition.m01() * x) + (matPosition.m11() * y) + (matPosition.m21() * z) + matPosition.m31(); float zt = (matPosition.m02() * x) + (matPosition.m12() * y) + (matPosition.m22() * z) + matPosition.m32(); - write(ptr, xt, yt, zt, color, quad.getTexU(i), quad.getTexV(i), light); + write(ptr, xt, yt, zt, 0, 0, 0, color, quad.getTexU(i), quad.getTexV(i), light); ptr += STRIDE; } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/font/MixinGlyphRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/font/MixinGlyphRenderer.java index eb36d14635..c547b5eac8 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/font/MixinGlyphRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/font/MixinGlyphRenderer.java @@ -5,6 +5,7 @@ import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.caffeinemc.mods.sodium.api.vertex.format.common.GlyphVertex; import net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp.GlyphVertexExt; +import net.coderbot.iris.uniforms.CapturedRenderingState; import net.coderbot.iris.vertices.ImmediateState; import net.irisshaders.iris.api.v0.IrisApi; import net.minecraft.client.gui.font.glyphs.BakedGlyph; @@ -100,9 +101,13 @@ private static void write(boolean ext, long buffer, float x2 = Math.fma(matrix.m00(), x, Math.fma(matrix.m10(), y, Math.fma(matrix.m20(), z, matrix.m30()))); float y2 = Math.fma(matrix.m01(), x, Math.fma(matrix.m11(), y, Math.fma(matrix.m21(), z, matrix.m31()))); float z2 = Math.fma(matrix.m02(), x, Math.fma(matrix.m12(), y, Math.fma(matrix.m22(), z, matrix.m32()))); + Matrix4f mat2 = CapturedRenderingState.INSTANCE.velocityInfoEdit.last().pose(); + float x3 = Math.fma(mat2.m00(), x, Math.fma(mat2.m10(), y, Math.fma(mat2.m20(), z, mat2.m30()))); + float y3 = Math.fma(mat2.m01(), x, Math.fma(mat2.m11(), y, Math.fma(mat2.m21(), z, mat2.m31()))); + float z3 = Math.fma(mat2.m02(), x, Math.fma(mat2.m12(), y, Math.fma(mat2.m22(), z, mat2.m32()))); if (ext) { - GlyphVertexExt.write(buffer, x2, y2, z2, color, u, v, light); + GlyphVertexExt.write(buffer, x2, y2, z2, x3, y3, z3, color, u, v, light); } else { GlyphVertex.put(buffer, x2, y2, z2, color, u, v, light); } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/item/MixinItemRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/item/MixinItemRenderer.java index ed88917010..d95202d4a4 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/item/MixinItemRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/item/MixinItemRenderer.java @@ -17,6 +17,7 @@ import net.coderbot.iris.compat.sodium.impl.entities.VertexHistory; import net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp.EntityVertex; import net.coderbot.iris.shadows.ShadowRenderingState; +import net.coderbot.iris.uniforms.SystemTimeUniforms; import net.coderbot.iris.vertices.ImmediateState; import net.coderbot.iris.vertices.NormalHelper; import net.irisshaders.iris.api.v0.IrisApi; @@ -92,8 +93,9 @@ private static void writeQuadVerticesIris(VertexBufferWriter writer, PoseStack.P EntityVertex.writeUnknownTangentWithVelocity(ptr, xt, yt, zt, lastPos.storedPositions[i].x, lastPos.storedPositions[i].y, lastPos.storedPositions[i].z, color, quad.getTexU(i), quad.getTexV(i), midU, midV, light, overlay, normal); ptr += EntityVertex.STRIDE; - if (!ShadowRenderingState.areShadowsCurrentlyBeingRendered()) lastPos.storedPositions[i].set(xt, yt, zt); + if (!ShadowRenderingState.areShadowsCurrentlyBeingRendered() && lastPos.lastFrame != SystemTimeUniforms.COUNTER.getAsInt()) lastPos.storedPositions[i].set(xt, yt, zt); } + lastPos.lastFrame = SystemTimeUniforms.COUNTER.getAsInt(); writer.push(stack, buffer, 4, EntityVertex.FORMAT); }