Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Sep 27, 2024
1 parent 3fc94e8 commit eb43f82
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,77 @@
package net.irisshaders.iris.mixin;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.debug.ChunkBorderRenderer;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;

@Mixin(ChunkBorderRenderer.class)
public class MixinChunkBorderRenderer {
@WrapWithCondition(
private VertexConsumer fakeConsumer = new VertexConsumer() {
@Override
public VertexConsumer addVertex(float x, float y, float z) {
return this;
}

@Override
public VertexConsumer setColor(int red, int green, int blue, int alpha) {
return this;
}

@Override
public VertexConsumer setUv(float u, float v) {
return this;
}

@Override
public VertexConsumer setUv1(int u, int v) {
return this;
}

@Override
public VertexConsumer setUv2(int u, int v) {
return this;
}

@Override
public VertexConsumer setNormal(float normalX, float normalY, float normalZ) {
return this;
}
};

@Redirect(
method = "render",
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/VertexConsumer;endVertex()V"),
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/VertexConsumer;addVertex(Lorg/joml/Matrix4f;FFF)Lcom/mojang/blaze3d/vertex/VertexConsumer;"),
slice = @Slice(
from = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack$Pose;pose()Lorg/joml/Matrix4f;"),
to = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/debug/ChunkBorderRenderer;CELL_BORDER:I", ordinal = 0)
)
)
private boolean isCameraChunk(VertexConsumer instance, @Local(ordinal = 0) int k, @Local(ordinal = 1) int l) {
return !((k == 0 || k == 16) && (l == 0 || l == 16));
private VertexConsumer isCameraChunk(VertexConsumer instance, Matrix4f pose, float x, float y, float z, @Local(ordinal = 0) int k, @Local(ordinal = 1) int l) {
if (!((k == 0 || k == 16) && (l == 0 || l == 16))) {
return instance.addVertex(pose, x,y ,z);
} else {
return fakeConsumer;
}
}

@WrapWithCondition(
@Redirect(
method = "render",
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/VertexConsumer;endVertex()V"),
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/VertexConsumer;addVertex(Lorg/joml/Matrix4f;FFF)Lcom/mojang/blaze3d/vertex/VertexConsumer;"),
slice = @Slice(
from = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;getMinBuildHeight()I", ordinal = 1),
to = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource;getBuffer(Lnet/minecraft/client/renderer/RenderType;)Lcom/mojang/blaze3d/vertex/VertexConsumer;", ordinal = 1)
)
)
private boolean isSubChunkBorder(VertexConsumer instance, @Local(ordinal = 0) int k) {
return k % 16 != 0;
private VertexConsumer isSubChunkBorder(VertexConsumer instance, Matrix4f pose, float x, float y, float z, @Local(ordinal = 0) int k) {
if (k % 16 != 0) {
return instance.addVertex(pose, x,y ,z);
} else {
return fakeConsumer;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static ChunkVertexType createFormat(boolean blockId, boolean normal, bool
}

if (midBlock) {
key |= 16;
key |= 8;
}

if (classMap.containsKey(key)) {
Expand Down Expand Up @@ -89,7 +89,7 @@ public static ChunkVertexType createFormat(boolean blockId, boolean normal, bool
VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.MID_BLOCK, 14, midBlockOffset);
}

//System.out.println("Created a new format with " + offset + " stride: " + Integer.toBinaryString(key));
System.out.println("Created a new format with " + offset + " stride: " + Integer.toBinaryString(key));


return classMap.computeIfAbsent(key, k -> new XHFPModelVertexType(VERTEX_FORMAT.build(), blockIdOffset, normalOffset, midUvOffset, midBlockOffset));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public class XHFPTerrainVertex implements ChunkVertexEncoder, VertexEncoderInter
private static final int TEXTURE_MAX_VALUE = 1 << 15;
private static final float MODEL_ORIGIN = 8.0f;
private static final float MODEL_RANGE = 32.0f;
private static final int DEFAULT_NORMAL;

static {
Vector2f normE = new Vector2f(), tangE = new Vector2f();
NormalHelper.octahedronEncode(normE, 0, 1, 0);
NormalHelper.tangentEncode(tangE, new Vector4f(0, 1, 0, 1));
DEFAULT_NORMAL = NormI8.pack(normE.x, normE.y, tangE.x, tangE.y);
}

private final Vector3f normal = new Vector3f(0.0f, 1.0f, 0.0f);
private final Vector4f tangent = new Vector4f(0.0f, 1.0f, 0.0f, 1.0f);
private final int blockIdOffset;
Expand Down Expand Up @@ -111,19 +120,21 @@ public long write(long ptr,
texCentroidV *= 0.25f;
int midUV = XHFPModelVertexType.encodeOld(texCentroidU, texCentroidV);

NormalHelper.computeFaceNormalManual(normal,
vertices[0].x, vertices[0].y, vertices[0].z,
vertices[1].x, vertices[1].y, vertices[1].z,
vertices[2].x, vertices[2].y, vertices[2].z,
vertices[3].x, vertices[3].y, vertices[3].z);

int tangent = computeTangentForQuad(normal, vertices);

NormalHelper.octahedronEncode(normEncoded, normal.x, normal.y, normal.z);
NormalHelper.tangentEncode(tangEncoded, this.tangent);

int finalNorm = NormI8.pack(normEncoded.x, normEncoded.y, tangEncoded.x, tangEncoded.y);

int finalNorm;
if (normalOffset != 0) {
NormalHelper.computeFaceNormalManual(normal,
vertices[0].x, vertices[0].y, vertices[0].z,
vertices[1].x, vertices[1].y, vertices[1].z,
vertices[2].x, vertices[2].y, vertices[2].z,
vertices[3].x, vertices[3].y, vertices[3].z);

int tangent = computeTangentForQuad(normal, vertices);
NormalHelper.octahedronEncode(normEncoded, normal.x, normal.y, normal.z);
NormalHelper.tangentEncode(tangEncoded, this.tangent);
finalNorm = NormI8.pack(normEncoded.x, normEncoded.y, tangEncoded.x, tangEncoded.y);
} else {
finalNorm = DEFAULT_NORMAL;
}

for (int i = 0; i < 4; i++) {
var vertex = vertices[i];
Expand Down

0 comments on commit eb43f82

Please sign in to comment.