Skip to content

Commit

Permalink
Fix Indigo item rendering ignores item color alpha and does not apply…
Browse files Browse the repository at this point in the history
… special glint transform (#3854)

* Fix #3853

* Revert parity change

This disparity exists on purpose to make the behavior of BlendMode.TRANSLUCENT more consistent
  • Loading branch information
PepperCode1 authored and Su5eD committed Jul 4, 2024
1 parent 9315b2b commit 3f9c62b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -158,6 +163,7 @@ private void computeOutputInfo() {
}

isDefaultGlint = itemStack.hasFoil();
isGlintDynamicDisplay = ItemRendererAccessor.fabric_callUsesDynamicDisplay(itemStack);
}

private void renderQuad(MutableQuadViewImpl quad) {
Expand All @@ -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)));
Expand Down Expand Up @@ -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()) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"client": [
"BakedModelMixin",
"BlockModelRendererMixin",
"SectionBuilderMixin",
"ChunkRendererRegionMixin",
"ItemRendererMixin"
"ItemRendererAccessor",
"ItemRendererMixin",
"SectionBuilderMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 3f9c62b

Please sign in to comment.