Skip to content

Commit 4f5836e

Browse files
PepperCode1modmuss50
authored andcommitted
Modernize Indigo (#2110)
* Modernize Indigo - Restructure ItemRenderContext to be more efficient and consistent with block rendering - Remove unnecessary code including CompatibilityHelper - Add Unique annotations to fields added by Indigo - Fix typos - Organize imports * Remove unused import * Fix bugs - Fix enchantment glint not rendering on item models - Fix QuadView#copyTo not copying enough data - Make ItemRenderContext vertex consumer calculation mirror vanilla and be more efficient * Clear the target quad's material * Tweaks - Retain material during copyTo instead of clearing it - Standardize mixins * Direct return - Return from ItemRenderContext#quadVertexConsumer instead of assigning value to variable
1 parent c65ffd6 commit 4f5836e

16 files changed

+291
-289
lines changed

fabric-renderer-indigo/src/main/java/net/fabricmc/fabric/impl/client/indigo/renderer/mesh/QuadViewImpl.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333

3434
import com.google.common.base.Preconditions;
3535

36-
import net.minecraft.util.math.Vec3f;
3736
import net.minecraft.util.math.Direction;
37+
import net.minecraft.util.math.Vec3f;
3838

39+
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
3940
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
4041
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView;
4142
import net.fabricmc.fabric.impl.client.indigo.renderer.RenderMaterialImpl;
@@ -163,7 +164,9 @@ public void copyTo(MutableQuadView target) {
163164

164165
final MutableQuadViewImpl quad = (MutableQuadViewImpl) target;
165166
// copy everything except the material
166-
System.arraycopy(data, baseIndex + 1, quad.data, quad.baseIndex + 1, EncodingFormat.TOTAL_STRIDE - 1);
167+
RenderMaterial material = quad.material();
168+
System.arraycopy(data, baseIndex, quad.data, quad.baseIndex, EncodingFormat.TOTAL_STRIDE);
169+
quad.material(material);
167170
quad.faceNormal.set(faceNormal.getX(), faceNormal.getY(), faceNormal.getZ());
168171
quad.nominalFace = this.nominalFace;
169172
quad.isGeometryInvalid = false;

fabric-renderer-indigo/src/main/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/AbstractMeshConsumer.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import net.fabricmc.fabric.impl.client.indigo.renderer.mesh.MutableQuadViewImpl;
3535

3636
/**
37-
* Consumer for pre-baked meshes. Works by copying the mesh data to a
37+
* Consumer for pre-baked meshes. Works by copying the mesh data to an
3838
* "editor" quad held in the instance, where all transformations are applied before buffering.
3939
*/
4040
public abstract class AbstractMeshConsumer extends AbstractQuadRenderer implements Consumer<Mesh> {
@@ -46,7 +46,7 @@ protected AbstractMeshConsumer(BlockRenderInfo blockInfo, Function<RenderLayer,
4646
* Where we handle all pre-buffer coloring, lighting, transformation, etc.
4747
* Reused for all mesh quads. Fixed baking array sized to hold largest possible mesh quad.
4848
*/
49-
private class Maker extends MutableQuadViewImpl implements QuadEmitter {
49+
private class Maker extends MutableQuadViewImpl {
5050
{
5151
data = new int[EncodingFormat.TOTAL_STRIDE];
5252
material(IndigoRenderer.MATERIAL_STANDARD);
@@ -84,44 +84,44 @@ public QuadEmitter getEmitter() {
8484
return editorQuad;
8585
}
8686

87-
private void renderQuad(MutableQuadViewImpl q) {
88-
if (!transform.transform(editorQuad)) {
87+
private void renderQuad(MutableQuadViewImpl quad) {
88+
if (!transform.transform(quad)) {
8989
return;
9090
}
9191

92-
if (!blockInfo.shouldDrawFace(q.cullFace())) {
92+
if (!blockInfo.shouldDrawFace(quad.cullFace())) {
9393
return;
9494
}
9595

96-
final RenderMaterialImpl.Value mat = q.material();
96+
final RenderMaterialImpl.Value mat = quad.material();
9797

9898
if (!mat.disableAo(0) && MinecraftClient.isAmbientOcclusionEnabled()) {
9999
// needs to happen before offsets are applied
100-
aoCalc.compute(q, false);
100+
aoCalc.compute(quad, false);
101101
}
102102

103-
tesselateQuad(q, mat, 0);
103+
tessellateQuad(quad, mat, 0);
104104
}
105105

106106
/**
107107
* Determines color index and render layer, then routes to appropriate
108-
* tesselate routine based on material properties.
108+
* tessellate routine based on material properties.
109109
*/
110-
private void tesselateQuad(MutableQuadViewImpl quad, RenderMaterialImpl.Value mat, int textureIndex) {
110+
private void tessellateQuad(MutableQuadViewImpl quad, RenderMaterialImpl.Value mat, int textureIndex) {
111111
final int colorIndex = mat.disableColorIndex(textureIndex) ? -1 : quad.colorIndex();
112112
final RenderLayer renderLayer = blockInfo.effectiveRenderLayer(mat.blendMode(textureIndex));
113113

114114
if (blockInfo.defaultAo && !mat.disableAo(textureIndex)) {
115115
if (mat.emissive(textureIndex)) {
116-
tesselateSmoothEmissive(quad, renderLayer, colorIndex);
116+
tessellateSmoothEmissive(quad, renderLayer, colorIndex);
117117
} else {
118-
tesselateSmooth(quad, renderLayer, colorIndex);
118+
tessellateSmooth(quad, renderLayer, colorIndex);
119119
}
120120
} else {
121121
if (mat.emissive(textureIndex)) {
122-
tesselateFlatEmissive(quad, renderLayer, colorIndex);
122+
tessellateFlatEmissive(quad, renderLayer, colorIndex);
123123
} else {
124-
tesselateFlat(quad, renderLayer, colorIndex);
124+
tessellateFlat(quad, renderLayer, colorIndex);
125125
}
126126
}
127127
}

fabric-renderer-indigo/src/main/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/AbstractQuadRenderer.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222

2323
import net.minecraft.block.Block;
2424
import net.minecraft.block.BlockState;
25+
import net.minecraft.client.render.LightmapTextureManager;
2526
import net.minecraft.client.render.RenderLayer;
2627
import net.minecraft.client.render.VertexConsumer;
2728
import net.minecraft.client.render.WorldRenderer;
28-
import net.minecraft.util.math.Vec3f;
2929
import net.minecraft.util.math.BlockPos;
3030
import net.minecraft.util.math.Direction;
3131
import net.minecraft.util.math.Matrix3f;
3232
import net.minecraft.util.math.Matrix4f;
33+
import net.minecraft.util.math.Vec3f;
3334

3435
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext.QuadTransform;
3536
import net.fabricmc.fabric.impl.client.indigo.renderer.aocalc.AoCalculator;
@@ -42,8 +43,6 @@
4243
* Has most of the actual buffer-time lighting and coloring logic.
4344
*/
4445
public abstract class AbstractQuadRenderer {
45-
static final int FULL_BRIGHTNESS = 0xF000F0;
46-
4746
protected final Function<RenderLayer, VertexConsumer> bufferFunc;
4847
protected final BlockRenderInfo blockInfo;
4948
protected final AoCalculator aoCalc;
@@ -115,7 +114,7 @@ public static void bufferQuad(VertexConsumer buff, MutableQuadViewImpl quad, Mat
115114
// routines below have a bit of copy-paste code reuse to avoid conditional execution inside a hot loop
116115

117116
/** for non-emissive mesh quads and all fallback quads with smooth lighting. */
118-
protected void tesselateSmooth(MutableQuadViewImpl q, RenderLayer renderLayer, int blockColorIndex) {
117+
protected void tessellateSmooth(MutableQuadViewImpl q, RenderLayer renderLayer, int blockColorIndex) {
119118
colorizeQuad(q, blockColorIndex);
120119

121120
for (int i = 0; i < 4; i++) {
@@ -127,19 +126,19 @@ protected void tesselateSmooth(MutableQuadViewImpl q, RenderLayer renderLayer, i
127126
}
128127

129128
/** for emissive mesh quads with smooth lighting. */
130-
protected void tesselateSmoothEmissive(MutableQuadViewImpl q, RenderLayer renderLayer, int blockColorIndex) {
129+
protected void tessellateSmoothEmissive(MutableQuadViewImpl q, RenderLayer renderLayer, int blockColorIndex) {
131130
colorizeQuad(q, blockColorIndex);
132131

133132
for (int i = 0; i < 4; i++) {
134133
q.spriteColor(i, 0, ColorHelper.multiplyRGB(q.spriteColor(i, 0), aoCalc.ao[i]));
135-
q.lightmap(i, FULL_BRIGHTNESS);
134+
q.lightmap(i, LightmapTextureManager.MAX_LIGHT_COORDINATE);
136135
}
137136

138137
bufferQuad(q, renderLayer);
139138
}
140139

141140
/** for non-emissive mesh quads and all fallback quads with flat lighting. */
142-
protected void tesselateFlat(MutableQuadViewImpl quad, RenderLayer renderLayer, int blockColorIndex) {
141+
protected void tessellateFlat(MutableQuadViewImpl quad, RenderLayer renderLayer, int blockColorIndex) {
143142
colorizeQuad(quad, blockColorIndex);
144143
shadeFlatQuad(quad);
145144

@@ -153,12 +152,12 @@ protected void tesselateFlat(MutableQuadViewImpl quad, RenderLayer renderLayer,
153152
}
154153

155154
/** for emissive mesh quads with flat lighting. */
156-
protected void tesselateFlatEmissive(MutableQuadViewImpl quad, RenderLayer renderLayer, int blockColorIndex) {
155+
protected void tessellateFlatEmissive(MutableQuadViewImpl quad, RenderLayer renderLayer, int blockColorIndex) {
157156
colorizeQuad(quad, blockColorIndex);
158157
shadeFlatQuad(quad);
159158

160159
for (int i = 0; i < 4; i++) {
161-
quad.lightmap(i, FULL_BRIGHTNESS);
160+
quad.lightmap(i, LightmapTextureManager.MAX_LIGHT_COORDINATE);
162161
}
163162

164163
bufferQuad(quad, renderLayer);

fabric-renderer-indigo/src/main/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/AbstractRenderContext.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@
1818

1919
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
2020

21-
import net.minecraft.util.math.Matrix4f;
2221
import net.minecraft.util.math.Matrix3f;
22+
import net.minecraft.util.math.Matrix4f;
2323

2424
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
2525
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
2626

2727
abstract class AbstractRenderContext implements RenderContext {
28-
private final ObjectArrayList<QuadTransform> transformStack = new ObjectArrayList<>();
2928
private static final QuadTransform NO_TRANSFORM = (q) -> true;
30-
protected Matrix4f matrix;
31-
protected Matrix3f normalMatrix;
32-
protected int overlay;
3329

30+
private QuadTransform activeTransform = NO_TRANSFORM;
31+
private final ObjectArrayList<QuadTransform> transformStack = new ObjectArrayList<>();
3432
private final QuadTransform stackTransform = (q) -> {
3533
int i = transformStack.size() - 1;
3634

@@ -43,7 +41,9 @@ abstract class AbstractRenderContext implements RenderContext {
4341
return true;
4442
};
4543

46-
private QuadTransform activeTransform = NO_TRANSFORM;
44+
protected Matrix4f matrix;
45+
protected Matrix3f normalMatrix;
46+
protected int overlay;
4747

4848
protected final boolean transform(MutableQuadView q) {
4949
return activeTransform.transform(q);

fabric-renderer-indigo/src/main/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/BlockRenderContext.java

+27-32
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
package net.fabricmc.fabric.impl.client.indigo.renderer.render;
1818

1919
import java.util.function.Consumer;
20-
import java.util.function.Function;
2120
import java.util.function.Supplier;
2221

2322
import net.minecraft.block.BlockState;
23+
import net.minecraft.client.render.LightmapTextureManager;
2424
import net.minecraft.client.render.RenderLayer;
2525
import net.minecraft.client.render.VertexConsumer;
2626
import net.minecraft.client.render.WorldRenderer;
@@ -35,20 +35,19 @@
3535
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
3636
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
3737
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
38-
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
3938
import net.fabricmc.fabric.impl.client.indigo.renderer.aocalc.AoCalculator;
4039
import net.fabricmc.fabric.impl.client.indigo.renderer.aocalc.AoLuminanceFix;
4140

4241
/**
4342
* Context for non-terrain block rendering.
4443
*/
45-
public class BlockRenderContext extends AbstractRenderContext implements RenderContext {
44+
public class BlockRenderContext extends AbstractRenderContext {
4645
private final BlockRenderInfo blockInfo = new BlockRenderInfo();
4746
private final AoCalculator aoCalc = new AoCalculator(blockInfo, this::brightness, this::aoLevel);
48-
private final MeshConsumer meshConsumer = new MeshConsumer(blockInfo, this::outputBuffer, aoCalc, this::transform);
47+
4948
private VertexConsumer bufferBuilder;
5049
private boolean didOutput = false;
51-
// These are kept as fields to avoid avoid the heap allocation for a supplier.
50+
// These are kept as fields to avoid the heap allocation for a supplier.
5251
// BlockModelRenderer allows the caller to supply both the random object and seed.
5352
private AbstractRandom random;
5453
private long seed;
@@ -57,16 +56,28 @@ public class BlockRenderContext extends AbstractRenderContext implements RenderC
5756
return random;
5857
};
5958

60-
/**
61-
* Reuse the fallback consumer from the render context used during chunk rebuild to make it properly
62-
* apply the current transforms to vanilla models.
63-
*/
64-
private final TerrainFallbackConsumer fallbackConsumer = new TerrainFallbackConsumer(blockInfo, this::outputBuffer, aoCalc, this::transform) {
59+
private final AbstractMeshConsumer meshConsumer = new AbstractMeshConsumer(blockInfo, this::outputBuffer, aoCalc, this::transform) {
60+
@Override
61+
protected Matrix4f matrix() {
62+
return matrix;
63+
}
64+
65+
@Override
66+
protected Matrix3f normalMatrix() {
67+
return normalMatrix;
68+
}
69+
6570
@Override
6671
protected int overlay() {
6772
return overlay;
6873
}
74+
};
6975

76+
/**
77+
* Reuse the fallback consumer from the render context used during chunk rebuild to make it properly
78+
* apply the current transforms to vanilla models.
79+
*/
80+
private final TerrainFallbackConsumer fallbackConsumer = new TerrainFallbackConsumer(blockInfo, this::outputBuffer, aoCalc, this::transform) {
7081
@Override
7182
protected Matrix4f matrix() {
7283
return matrix;
@@ -76,11 +87,16 @@ protected Matrix4f matrix() {
7687
protected Matrix3f normalMatrix() {
7788
return normalMatrix;
7889
}
90+
91+
@Override
92+
protected int overlay() {
93+
return overlay;
94+
}
7995
};
8096

8197
private int brightness(BlockPos pos) {
8298
if (blockInfo.blockView == null) {
83-
return 15 << 20 | 15 << 4;
99+
return LightmapTextureManager.MAX_LIGHT_COORDINATE;
84100
}
85101

86102
return WorldRenderer.getLightmapCoordinates(blockInfo.blockView, blockInfo.blockView.getBlockState(pos), pos);
@@ -119,27 +135,6 @@ public boolean render(BlockRenderView blockView, BakedModel model, BlockState st
119135
return didOutput;
120136
}
121137

122-
private class MeshConsumer extends AbstractMeshConsumer {
123-
MeshConsumer(BlockRenderInfo blockInfo, Function<RenderLayer, VertexConsumer> bufferFunc, AoCalculator aoCalc, QuadTransform transform) {
124-
super(blockInfo, bufferFunc, aoCalc, transform);
125-
}
126-
127-
@Override
128-
protected Matrix4f matrix() {
129-
return matrix;
130-
}
131-
132-
@Override
133-
protected Matrix3f normalMatrix() {
134-
return normalMatrix;
135-
}
136-
137-
@Override
138-
protected int overlay() {
139-
return overlay;
140-
}
141-
}
142-
143138
@Override
144139
public Consumer<Mesh> meshConsumer() {
145140
return meshConsumer;

fabric-renderer-indigo/src/main/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/ChunkRenderInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import net.minecraft.client.render.RenderLayer;
2626
import net.minecraft.client.render.WorldRenderer;
2727
import net.minecraft.client.render.chunk.BlockBufferBuilderStorage;
28-
import net.minecraft.client.render.chunk.ChunkBuilder.ChunkData;
2928
import net.minecraft.client.render.chunk.ChunkBuilder.BuiltChunk;
29+
import net.minecraft.client.render.chunk.ChunkBuilder.ChunkData;
3030
import net.minecraft.client.render.chunk.ChunkRendererRegion;
3131
import net.minecraft.util.math.BlockPos;
3232
import net.minecraft.world.BlockRenderView;

fabric-renderer-indigo/src/main/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/CompatibilityHelper.java

-44
This file was deleted.

0 commit comments

Comments
 (0)