Skip to content

Commit

Permalink
Name tags?
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Aug 30, 2023
1 parent a6c4089 commit b88c342
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,18 +34,35 @@
* rendered.
*/
@Mixin(EntityRenderDispatcher.class)
public class MixinEntityRenderDispatcher {
public abstract class MixinEntityRenderDispatcher {
@Shadow
public abstract <T extends Entity> EntityRenderer<? super T> 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;
}

Object2IntFunction<NamespacedId> entityIds = BlockRenderingSettings.INSTANCE.getEntityIds();


if (entityIds == null) {
return bufferSource;
}
Expand Down Expand Up @@ -71,5 +91,6 @@ public class MixinEntityRenderDispatcher {
CallbackInfo ci) {
CapturedRenderingState.INSTANCE.setCurrentEntity(0);
CapturedRenderingState.INSTANCE.setUniqueEntityId(0);
CapturedRenderingState.INSTANCE.velocityInfoEdit.popPose();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.iris.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public class VertexHistory {
public Vector3f[] storedPositions;
public int lastFrame;

public VertexHistory(int id, int size) {
storedPositions = new Vector3f[size];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

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

0 comments on commit b88c342

Please sign in to comment.