From 57cdda8dc513eafabd91e07fb9f0a779f1acff93 Mon Sep 17 00:00:00 2001 From: Alexander Glazkov <78122700@mail.ru> Date: Sun, 4 Aug 2024 10:55:54 +0300 Subject: [PATCH] Add texture flipping support for negative Y faces Introduced a utility method to determine if textures need flipping based on texture groups and block bounds. Updated rendering functions to use this logic, ensuring correct texture orientation for specific cases. Corrected UV coordinates for the negative y face rendering. These changes ensure proper texture alignment for bottom sides when using ambient occlusion (AO) and regular rendering. --- src/main/java/gregapi/data/CS.java | 7 ++++++ src/main/java/gregapi/render/ITexture.java | 27 ++++++++++++---------- src/main/java/gregapi/util/UT.java | 10 ++++++++ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/java/gregapi/data/CS.java b/src/main/java/gregapi/data/CS.java index b71529993..16805293f 100644 --- a/src/main/java/gregapi/data/CS.java +++ b/src/main/java/gregapi/data/CS.java @@ -2326,4 +2326,11 @@ public static class SFX { , RES_PATH_IC2 = MD.IC2.mID.toLowerCase() + ":" ; + + public static final HashSet SHOULD_FLIP_NEG_Y_TEXTURES = new HashSet<>(); + + static { + SHOULD_FLIP_NEG_Y_TEXTURES.add("machines"); + SHOULD_FLIP_NEG_Y_TEXTURES.add("overlays"); + } } diff --git a/src/main/java/gregapi/render/ITexture.java b/src/main/java/gregapi/render/ITexture.java index d07482caa..a75604790 100644 --- a/src/main/java/gregapi/render/ITexture.java +++ b/src/main/java/gregapi/render/ITexture.java @@ -20,6 +20,7 @@ package gregapi.render; import static gregapi.data.CS.*; +import static gregapi.util.UT.shouldFlipNegYTextures; import org.lwjgl.opengl.GL11; @@ -248,11 +249,11 @@ public static boolean doRenderYNeg(IIcon aIcon, RenderBlocks aRenderer, Block aB if (aBlock.getRenderBlockPass() > 0) { double tOldValue = aRenderer.renderMinY; aRenderer.renderMinY -= (aRenderer.renderFromInside?-1:+1)*OFFSET_Y_NEG; - renderFixedNegativeYFacing(aIcon, aRenderer, aBlock, aX, aY, aZ); + renderFixedNegativeYFacing(aIcon, aRenderer, aBlock, aX, aY, aZ, aChangedBlockBounds); aRenderer.renderMinY = tOldValue; OFFSET_Y_NEG += OFFSET_ADD; } else { - renderFixedNegativeYFacing(aIcon, aRenderer, aBlock, aX, aY, aZ); + renderFixedNegativeYFacing(aIcon, aRenderer, aBlock, aX, aY, aZ, aChangedBlockBounds); } return T; } @@ -285,13 +286,15 @@ public static boolean doRenderZNeg(IIcon aIcon, RenderBlocks aRenderer, Block aB return T; } - public static void renderFixedNegativeYFacing(IIcon aIcon, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { + public static void renderFixedNegativeYFacing(IIcon aIcon, RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ, boolean aChangedBlockBounds) { if (aRenderer.hasOverrideBlockTexture()) aIcon = aRenderer.overrideBlockTexture; // double tMaxX1 = aIcon.getInterpolatedU(aRenderer.renderMaxX * 16.0); // double tMinX1 = aIcon.getInterpolatedU(aRenderer.renderMinX * 16.0); // double tMaxZ1 = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0); // double tMinZ1 = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0); - + + boolean shouldFlipTexture = shouldFlipNegYTextures(aIcon.getIconName(), aChangedBlockBounds); + double tMaxX1 = aIcon.getInterpolatedU(aRenderer.renderMaxX * 16.0); double tMinX1 = aIcon.getInterpolatedU(aRenderer.renderMinX * 16.0); double tMaxZ1 = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0); @@ -358,21 +361,21 @@ public static void renderFixedNegativeYFacing(IIcon aIcon, RenderBlocks aRendere if (aRenderer.enableAO) { Tessellator.instance.setColorOpaque_F(aRenderer.colorRedTopLeft, aRenderer.colorGreenTopLeft, aRenderer.colorBlueTopLeft); Tessellator.instance.setBrightness(aRenderer.brightnessTopLeft); - Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMaxZ3, tMinX2, tMinZ2); + Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMaxZ3, tMinX2, shouldFlipTexture ? tMinZ2 : tMaxZ2); Tessellator.instance.setColorOpaque_F(aRenderer.colorRedBottomLeft, aRenderer.colorGreenBottomLeft, aRenderer.colorBlueBottomLeft); Tessellator.instance.setBrightness(aRenderer.brightnessBottomLeft); - Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMinZ3, tMinX1, tMaxZ1); + Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMinZ3, tMinX1, shouldFlipTexture ? tMaxZ1 : tMinZ1); Tessellator.instance.setColorOpaque_F(aRenderer.colorRedBottomRight, aRenderer.colorGreenBottomRight, aRenderer.colorBlueBottomRight); Tessellator.instance.setBrightness(aRenderer.brightnessBottomRight); - Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMinZ3, tMaxX2, tMaxZ2); + Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMinZ3, tMaxX2, shouldFlipTexture ? tMaxZ2 : tMinZ2); Tessellator.instance.setColorOpaque_F(aRenderer.colorRedTopRight, aRenderer.colorGreenTopRight, aRenderer.colorBlueTopRight); Tessellator.instance.setBrightness(aRenderer.brightnessTopRight); - Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMaxZ3, tMaxX1, tMinZ1); + Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMaxZ3, tMaxX1, shouldFlipTexture ? tMinZ1 : tMaxZ1); } else { - Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMaxZ3, tMinX2, tMinZ2); - Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMinZ3, tMinX1, tMaxZ1); - Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMinZ3, tMaxX2, tMaxZ2); - Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMaxZ3, tMaxX1, tMinZ1); + Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMaxZ3, tMinX2, shouldFlipTexture ? tMinZ2 : tMaxZ2); + Tessellator.instance.addVertexWithUV(tMinX3, tMinY3, tMinZ3, tMinX1, shouldFlipTexture ? tMaxZ1 : tMinZ1); + Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMinZ3, tMaxX2, shouldFlipTexture ? tMaxZ2 : tMinZ2); + Tessellator.instance.addVertexWithUV(tMaxX3, tMinY3, tMaxZ3, tMaxX1, shouldFlipTexture ? tMinZ1 : tMaxZ1); } } diff --git a/src/main/java/gregapi/util/UT.java b/src/main/java/gregapi/util/UT.java index df8737dac..4bbb5e579 100644 --- a/src/main/java/gregapi/util/UT.java +++ b/src/main/java/gregapi/util/UT.java @@ -3568,4 +3568,14 @@ public static boolean finish() { return F; } } + + public static boolean shouldFlipNegYTextures(String textureName, boolean aChangedBlockBounds){ + int start = textureName.indexOf(":"); + int stop = textureName.indexOf("/"); + if (start != -1 && stop != -1) { + String textureGroup = textureName.substring(start + 1, stop); + return aChangedBlockBounds && (SHOULD_FLIP_NEG_Y_TEXTURES.contains(textureGroup)); // dirty hack, but works fine + } + return false; + } }