Skip to content

Commit

Permalink
Add texture flipping support for negative Y faces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ICaxapI committed Aug 4, 2024
1 parent 01dcf1b commit 57cdda8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/main/java/gregapi/data/CS.java
Original file line number Diff line number Diff line change
Expand Up @@ -2326,4 +2326,11 @@ public static class SFX {

, RES_PATH_IC2 = MD.IC2.mID.toLowerCase() + ":"
;

public static final HashSet<String> SHOULD_FLIP_NEG_Y_TEXTURES = new HashSet<>();

static {
SHOULD_FLIP_NEG_Y_TEXTURES.add("machines");
SHOULD_FLIP_NEG_Y_TEXTURES.add("overlays");
}
}
27 changes: 15 additions & 12 deletions src/main/java/gregapi/render/ITexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package gregapi.render;

import static gregapi.data.CS.*;
import static gregapi.util.UT.shouldFlipNegYTextures;

import org.lwjgl.opengl.GL11;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/gregapi/util/UT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 57cdda8

Please sign in to comment.