From 9a4f55c4e90ea5e83b6a0829f1b095e3a5ea7273 Mon Sep 17 00:00:00 2001 From: dima_dencep Date: Thu, 14 Dec 2023 16:19:48 +0700 Subject: [PATCH] Revert "Apply Embeddium's patches for packed quad data to overwritten" This reverts commit f2831265687f5e20a5bb1a2d42c2305f7cd950cc. --- .../entity_xhfp/EntityVertex.java | 56 ++++++------------- .../entity/MixinModelVertex.java | 7 +-- 2 files changed, 17 insertions(+), 46 deletions(-) diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertex.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertex.java index b1d133b6b7..99dc7ed331 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertex.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertex.java @@ -2,9 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView; -import me.jellysquid.mods.sodium.client.util.ModelQuadUtil; import net.caffeinemc.mods.sodium.api.math.MatrixHelper; -import net.caffeinemc.mods.sodium.api.util.ColorARGB; import net.caffeinemc.mods.sodium.api.util.NormI8; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription; @@ -88,22 +86,6 @@ public static void write2(long ptr, } - // TODO: Publicize this method in Embeddium so it doesn't need to be copied - private static int multARGBInts(int colorA, int colorB) { - // Most common case: Either quad coloring or tint-based coloring, but not both - if (colorA == -1) { - return colorB; - } else if (colorB == -1) { - return colorA; - } - // General case (rare): Both colorings, actually perform the multiplication - int a = (int)((ColorARGB.unpackAlpha(colorA)/255.0f) * (ColorARGB.unpackAlpha(colorB)/255.0f) * 255.0f); - int b = (int)((ColorARGB.unpackBlue(colorA)/255.0f) * (ColorARGB.unpackBlue(colorB)/255.0f) * 255.0f); - int g = (int)((ColorARGB.unpackGreen(colorA)/255.0f) * (ColorARGB.unpackGreen(colorB)/255.0f) * 255.0f); - int r = (int)((ColorARGB.unpackRed(colorA)/255.0f) * (ColorARGB.unpackRed(colorB)/255.0f) * 255.0f); - return ColorARGB.pack(r, g, b, a); - } - public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose matrices, ModelQuadView quad, int light, int overlay, int color) { Matrix3f matNormal = matrices.normal(); Matrix4f matPosition = matrices.pose(); @@ -112,11 +94,25 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m long buffer = stack.nmalloc(4 * STRIDE); long ptr = buffer; - float nxt = 0, nyt = 0, nzt = 0; + // The packed normal vector + var n = quad.getNormal(); + + // The normal vector + float nx = NormI8.unpackX(n); + float ny = NormI8.unpackY(n); + float nz = NormI8.unpackZ(n); float midU = ((quad.getTexU(0) + quad.getTexU(1) + quad.getTexU(2) + quad.getTexU(3)) * 0.25f); float midV = ((quad.getTexV(0) + quad.getTexV(1) + quad.getTexV(2) + quad.getTexV(3)) * 0.25f); + // The transformed normal vector + float nxt = MatrixHelper.transformNormalX(matNormal, nx, ny, nz); + float nyt = MatrixHelper.transformNormalY(matNormal, nx, ny, nz); + float nzt = MatrixHelper.transformNormalZ(matNormal, nx, ny, nz); + + // The packed transformed normal vector + var nt = NormI8.pack(nxt, nyt, nzt); + for (int i = 0; i < 4; i++) { // The position vector float x = quad.getX(i); @@ -128,27 +124,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m float yt = MatrixHelper.transformPositionY(matPosition, x, y, z); float zt = MatrixHelper.transformPositionZ(matPosition, x, y, z); - // The packed normal vector - var n = quad.getForgeNormal(i); - - if((n & 0xFFFFFF) == 0) { - n = quad.getNormal(); - } - - // The normal vector - float nx = NormI8.unpackX(n); - float ny = NormI8.unpackY(n); - float nz = NormI8.unpackZ(n); - - // The transformed normal vector - nxt = MatrixHelper.transformNormalX(matNormal, nx, ny, nz); - nyt = MatrixHelper.transformNormalY(matNormal, nx, ny, nz); - nzt = MatrixHelper.transformNormalZ(matNormal, nx, ny, nz); - - // The packed transformed normal vector - var nt = NormI8.pack(nxt, nyt, nzt); - - write2(ptr, xt, yt, zt, multARGBInts(quad.getColor(i), color), quad.getTexU(i), quad.getTexV(i), midU, midV, ModelQuadUtil.mergeBakedLight(quad.getLight(i), light), overlay, nt); + write2(ptr, xt, yt, zt, color, quad.getTexU(i), quad.getTexV(i), midU, midV, light, overlay, nt); ptr += STRIDE; } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinModelVertex.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinModelVertex.java index d0c0837695..2d01da3279 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinModelVertex.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinModelVertex.java @@ -3,7 +3,6 @@ import com.mojang.blaze3d.vertex.PoseStack; import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView; import me.jellysquid.mods.sodium.client.render.immediate.model.BakedModelEncoder; -import me.jellysquid.mods.sodium.client.util.ModelQuadUtil; import net.caffeinemc.mods.sodium.api.math.MatrixHelper; import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.caffeinemc.mods.sodium.api.util.ColorU8; @@ -25,10 +24,6 @@ @Mixin(BakedModelEncoder.class) public class MixinModelVertex { - @Shadow private static int mergeNormalAndMult(int packed, int calc, Matrix3f matNormal) { - throw new AssertionError(); - } - @Inject(method = "writeQuadVertices(Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;Lcom/mojang/blaze3d/vertex/PoseStack$Pose;Lme/jellysquid/mods/sodium/client/model/quad/ModelQuadView;III)V", at = @At("HEAD"), cancellable = true, remap = false) private static void redirect2(VertexBufferWriter writer, PoseStack.Pose matrices, ModelQuadView quad, int color, int light, int overlay, CallbackInfo ci) { if (shouldBeExtended()) { @@ -79,7 +74,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m } color = ColorABGR.pack(fR, fG, fB, 1.0F); - ModelVertex.write(ptr, xt, yt, zt, color, quad.getTexU(i), quad.getTexV(i), overlay, ModelQuadUtil.mergeBakedLight(quad.getLight(i), light[i]), mergeNormalAndMult(quad.getForgeNormal(i), normal, matNormal)); + ModelVertex.write(ptr, xt, yt, zt, color, quad.getTexU(i), quad.getTexV(i), overlay, light[i], normal); ptr += 36L; }