Skip to content

Commit

Permalink
Workaround incorrect quad ordering caused by material downgrading
Browse files Browse the repository at this point in the history
This fixes observers appearing red on XyCraft.
  • Loading branch information
IMS212 committed Jan 24, 2025
1 parent 1b54906 commit 2fe7c8b
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;

import java.util.Iterator;

public class BlockRenderer extends AbstractBlockRenderContext {
private final ColorProviderRegistry colorProviderRegistry;
private final int[] vertexColors = new int[4];
Expand All @@ -55,6 +57,7 @@ public class BlockRenderer extends AbstractBlockRenderContext {
@Nullable
private ColorProvider<BlockState> colorProvider;
private TranslucentGeometryCollector collector;
private boolean allowDowngrade;

public BlockRenderer(ColorProviderRegistry colorRegistry, LightPipelineProvider lighters) {
this.colorProviderRegistry = colorRegistry;
Expand Down Expand Up @@ -99,9 +102,20 @@ public void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockP
modelData = PlatformModelAccess.getInstance().getModelData(slice, model, state, pos, slice.getPlatformModelData(pos));

Iterable<RenderType> renderTypes = PlatformModelAccess.getInstance().getModelRenderTypes(level, model, state, pos, random, modelData);
this.allowDowngrade = true;

Iterator<RenderType> it = renderTypes.iterator();
var defaultType = ItemBlockRenderTypes.getChunkRenderType(state);

while (it.hasNext()) {
this.type = it.next();

// TODO: This can be removed once we have a better solution for https://github.com/CaffeineMC/sodium/issues/2868
// If the model contains any materials that are not the default, we can't allow the block to be downgraded. This avoids a potentially incorrect render order if there are overlapping quads.
if (it.hasNext() || this.type != defaultType) {
this.allowDowngrade = false;
}

for (RenderType type : renderTypes) {
this.type = type;
((FabricBakedModel) model).emitBlockQuads(getEmitter(), this.level, state, pos, this.randomSupplier, this::isFaceCulled);
}

Expand Down Expand Up @@ -229,7 +243,7 @@ private boolean validateQuadUVs(TextureAtlasSprite atlasSprite) {
}

private @Nullable TerrainRenderPass attemptPassDowngrade(TextureAtlasSprite sprite, TerrainRenderPass pass) {
if (Workarounds.isWorkaroundEnabled(Workarounds.Reference.INTEL_DEPTH_BUFFER_COMPARISON_UNRELIABLE)) {
if (!allowDowngrade || Workarounds.isWorkaroundEnabled(Workarounds.Reference.INTEL_DEPTH_BUFFER_COMPARISON_UNRELIABLE)) {
return null;
}

Expand Down

0 comments on commit 2fe7c8b

Please sign in to comment.