From 3f9c62bf3cf48233eb448e1b14540121a7592e4e Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:10:14 -0700 Subject: [PATCH] Fix Indigo item rendering ignores item color alpha and does not apply special glint transform (#3854) * Fix #3853 * Revert parity change This disparity exists on purpose to make the behavior of BlendMode.TRANSLUCENT more consistent --- .../renderer/render/ItemRenderContext.java | 30 ++++++++++++++++++- .../indigo/renderer/ItemRendererAccessor.java | 30 +++++++++++++++++++ .../fabric-renderer-indigo.mixins.json | 5 ++-- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/mixin/client/indigo/renderer/ItemRendererAccessor.java diff --git a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/ItemRenderContext.java b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/ItemRenderContext.java index b6b4e2bf4..4289162d7 100644 --- a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/ItemRenderContext.java +++ b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/ItemRenderContext.java @@ -18,6 +18,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.MatrixUtil; import java.util.function.Supplier; import org.jetbrains.annotations.Nullable; @@ -45,6 +46,7 @@ import net.fabricmc.fabric.impl.client.indigo.renderer.mesh.EncodingFormat; import net.fabricmc.fabric.impl.client.indigo.renderer.mesh.MutableQuadViewImpl; import net.fabricmc.fabric.impl.renderer.VanillaModelEncoder; +import net.fabricmc.fabric.mixin.client.indigo.renderer.ItemRendererAccessor; /** * The render context used for item rendering. @@ -83,7 +85,9 @@ public void emitDirectly() { private boolean isDefaultTranslucent; private boolean isTranslucentDirect; private boolean isDefaultGlint; + private boolean isGlintDynamicDisplay; + private PoseStack.Pose dynamicDisplayGlintEntry; private VertexConsumer translucentVertexConsumer; private VertexConsumer cutoutVertexConsumer; private VertexConsumer translucentGlintVertexConsumer; @@ -132,6 +136,7 @@ public void renderModel(ItemStack itemStack, ItemDisplayContext transformMode, b this.matrixStack = null; this.vertexConsumerProvider = null; + dynamicDisplayGlintEntry = null; translucentVertexConsumer = null; cutoutVertexConsumer = null; translucentGlintVertexConsumer = null; @@ -158,6 +163,7 @@ private void computeOutputInfo() { } isDefaultGlint = itemStack.hasFoil(); + isGlintDynamicDisplay = ItemRendererAccessor.fabric_callUsesDynamicDisplay(itemStack); } private void renderQuad(MutableQuadViewImpl quad) { @@ -177,7 +183,7 @@ private void renderQuad(MutableQuadViewImpl quad) { private void colorizeQuad(MutableQuadViewImpl quad, int colorIndex) { if (colorIndex != -1) { - final int itemColor = 0xFF000000 | colorMap.getColor(itemStack, colorIndex); + final int itemColor = colorMap.getColor(itemStack, colorIndex); for (int i = 0; i < 4; i++) { quad.color(i, ColorHelper.multiplyColor(itemColor, quad.color(i))); @@ -252,6 +258,10 @@ private VertexConsumer getVertexConsumer(BlendMode blendMode, TriState glintMode } private VertexConsumer createTranslucentVertexConsumer(boolean glint) { + if (glint && isGlintDynamicDisplay) { + return createDynamicDisplayGlintVertexConsumer(Minecraft.useShaderTransparency() && !isTranslucentDirect ? Sheets.translucentItemSheet() : Sheets.translucentCullBlockSheet()); + } + if (isTranslucentDirect) { return ItemRenderer.getFoilBufferDirect(vertexConsumerProvider, Sheets.translucentCullBlockSheet(), true, glint); } else if (Minecraft.useShaderTransparency()) { @@ -262,9 +272,27 @@ private VertexConsumer createTranslucentVertexConsumer(boolean glint) { } private VertexConsumer createCutoutVertexConsumer(boolean glint) { + if (glint && isGlintDynamicDisplay) { + return createDynamicDisplayGlintVertexConsumer(Sheets.cutoutBlockSheet()); + } + return ItemRenderer.getFoilBufferDirect(vertexConsumerProvider, Sheets.cutoutBlockSheet(), true, glint); } + private VertexConsumer createDynamicDisplayGlintVertexConsumer(RenderType layer) { + if (dynamicDisplayGlintEntry == null) { + dynamicDisplayGlintEntry = matrixStack.last().copy(); + + if (transformMode == ItemDisplayContext.GUI) { + MatrixUtil.mulComponentWise(dynamicDisplayGlintEntry.pose(), 0.5F); + } else if (transformMode.firstPerson()) { + MatrixUtil.mulComponentWise(dynamicDisplayGlintEntry.pose(), 0.75F); + } + } + + return ItemRenderer.getCompassFoilBuffer(vertexConsumerProvider, layer, dynamicDisplayGlintEntry); + } + private class BakedModelConsumerImpl implements BakedModelConsumer { @Override public void accept(BakedModel model) { diff --git a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/mixin/client/indigo/renderer/ItemRendererAccessor.java b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/mixin/client/indigo/renderer/ItemRendererAccessor.java new file mode 100644 index 000000000..efa7fd115 --- /dev/null +++ b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/mixin/client/indigo/renderer/ItemRendererAccessor.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.client.indigo.renderer; + +import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.world.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(ItemRenderer.class) +public interface ItemRendererAccessor { + @Invoker("usesDynamicDisplay") + static boolean fabric_callUsesDynamicDisplay(ItemStack stack) { + throw new AssertionError(); + } +} diff --git a/fabric-renderer-indigo/src/client/resources/fabric-renderer-indigo.mixins.json b/fabric-renderer-indigo/src/client/resources/fabric-renderer-indigo.mixins.json index 92b91c4d8..f7adfac5a 100644 --- a/fabric-renderer-indigo/src/client/resources/fabric-renderer-indigo.mixins.json +++ b/fabric-renderer-indigo/src/client/resources/fabric-renderer-indigo.mixins.json @@ -8,9 +8,10 @@ "client": [ "BakedModelMixin", "BlockModelRendererMixin", - "SectionBuilderMixin", "ChunkRendererRegionMixin", - "ItemRendererMixin" + "ItemRendererAccessor", + "ItemRendererMixin", + "SectionBuilderMixin" ], "injectors": { "defaultRequire": 1