diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java b/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java index b27ddad9e..76892647e 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java @@ -442,6 +442,7 @@ public enum Mixins implements IMixins { , "celeritas.terrain.MixinWorld_AwaitingDescriptor" , "celeritas.terrain.MixinRenderRegion" , "celeritas.terrain.MixinChunkRenderList" + , "celeritas.terrain.MixinChunkMeshBufferBuilder" , "celeritas.terrain.MixinVisibleChunkCollector" , "celeritas.terrain.MixinRenderListManager" , "celeritas.terrain.MixinSectionRenderDataStorage" diff --git a/src/main/java/com/gtnewhorizons/angelica/rendering/celeritas/AngelicaChunkBuildContext.java b/src/main/java/com/gtnewhorizons/angelica/rendering/celeritas/AngelicaChunkBuildContext.java index 9b26e27fc..ff94bbbd4 100644 --- a/src/main/java/com/gtnewhorizons/angelica/rendering/celeritas/AngelicaChunkBuildContext.java +++ b/src/main/java/com/gtnewhorizons/angelica/rendering/celeritas/AngelicaChunkBuildContext.java @@ -76,8 +76,10 @@ public class AngelicaChunkBuildContext extends ChunkBuildContext { super(renderPassConfiguration); this.textureAtlas = (TextureMapExtension) Minecraft.getMinecraft().getTextureMapBlocks(); this.worldSlice = new WorldSlice(world); - this.smoothLightPipeline = new SmoothLightPipeline(lightDataCache, VanillaDiffuseProvider.INSTANCE, false); - this.flatLightPipeline = new FlatLightPipeline(lightDataCache, VanillaDiffuseProvider.INSTANCE, false); + // Shade by the quad normal so sloped quads blend the face shades instead of snapping to the dominant axis; + // axis-aligned quads come out the same either way + this.smoothLightPipeline = new SmoothLightPipeline(lightDataCache, VanillaDiffuseProvider.INSTANCE, true); + this.flatLightPipeline = new FlatLightPipeline(lightDataCache, VanillaDiffuseProvider.INSTANCE, true); this.quadView = new VertexArrayQuadView(vertices); this.hasColoredLight = quadLightData instanceof ExtQuadLightData; } diff --git a/src/main/java/com/gtnewhorizons/angelica/rendering/celeritas/VertexArrayQuadView.java b/src/main/java/com/gtnewhorizons/angelica/rendering/celeritas/VertexArrayQuadView.java index a0dd28b3d..f525235f2 100644 --- a/src/main/java/com/gtnewhorizons/angelica/rendering/celeritas/VertexArrayQuadView.java +++ b/src/main/java/com/gtnewhorizons/angelica/rendering/celeritas/VertexArrayQuadView.java @@ -109,6 +109,18 @@ public class VertexArrayQuadView implements ModelQuadView { return trueNormal; } + /** + * Directional shading follows the geometry, never the tessellator normal. In 1.7.10 chunk rendering a normal set + * through setNormal has no visible effect (the face shade is baked by RenderBlocks), so no block relies on it for + * shading. It does stay set until the next startDrawing though, so a normal from inventory-style code early in a + * block would otherwise shade every later face of that block, e.g. a renderStandardBlock cube with all sides lit + * like the top. + */ + @Override + public int getModFaceNormal() { + return trueNormal; + } + /** * Gets the cull face of a quad. This is distinct from the light face, as it will not be set for non-axis-aligned * and non-block-grid-aligned quads (i.e. quads on the surface of the 1x1x1 cube). diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/celeritas/terrain/MixinChunkMeshBufferBuilder.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/celeritas/terrain/MixinChunkMeshBufferBuilder.java new file mode 100644 index 000000000..f39cd5311 --- /dev/null +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/celeritas/terrain/MixinChunkMeshBufferBuilder.java @@ -0,0 +1,45 @@ +package com.gtnewhorizons.angelica.mixins.early.celeritas.terrain; + +import org.embeddedt.embeddium.impl.render.chunk.vertex.builder.ChunkMeshBufferBuilder; +import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * The bilinear AO correction assumes the four vertices are the corners of a parallelogram, in order: it derives the + * twist from c1 + c3 - c0 - c2 and the shader weights it by each fragment's position in that parallelogram. A triangle + * sent through the tessellator as a quad with a repeated vertex has no such parallelogram, so the computed twist is just + * the difference between two of its corners, and the correction lands along an edge the neighbouring triangle does not + * correct. That shows up as a visible brightness step along every such edge. + */ +@Mixin(value = ChunkMeshBufferBuilder.class, remap = false) +public abstract class MixinChunkMeshBufferBuilder { + + @Inject(method = "postprocessVertices", at = @At("HEAD"), cancellable = true) + private static void angelica$skipCorrectionForTriangles(ChunkVertexEncoder.Vertex[] vertices, CallbackInfo ci) { + if (vertices.length != 4 || !angelica$hasRepeatedVertex(vertices)) { + return; + } + for (ChunkVertexEncoder.Vertex vertex : vertices) { + vertex.rdhFactor = 0; + } + ci.cancel(); + } + + @Unique + private static boolean angelica$hasRepeatedVertex(ChunkVertexEncoder.Vertex[] vertices) { + for (int i = 0; i < 4; i++) { + for (int j = i + 1; j < 4; j++) { + final ChunkVertexEncoder.Vertex a = vertices[i]; + final ChunkVertexEncoder.Vertex b = vertices[j]; + if (a.x == b.x && a.y == b.y && a.z == b.z) { + return true; + } + } + } + return false; + } +} diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/rendering/MixinTessellator.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/rendering/MixinTessellator.java index a603a2f58..476bb8c33 100644 --- a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/rendering/MixinTessellator.java +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/rendering/MixinTessellator.java @@ -67,6 +67,14 @@ public class MixinTessellator implements StateAwareTessellator, BiomeBlendTessel @Inject(method = "addVertex", at = @At("RETURN")) private void addElementState(CallbackInfo ci) { if (!celeritasMeshing) return; + + // Vanilla only writes the normal slot after setNormal, leaving whatever an earlier vertex put there otherwise. + // Zero means "no normal" to the light pipeline, which then falls back to the computed face normal. + final Tessellator self = (Tessellator) (Object) this; + if (!self.hasNormals) { + self.rawBuffer[self.rawBufferIndex - 2] = 0; + } + int state = 0; if (appliedAo) state |= StateAwareTessellator.RENDERED_WITH_VANILLA_AO;