From ccc661225e4458451c4e74799934912bc7e538f0 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 25 Jul 2021 17:58:46 -0500 Subject: [PATCH] Improve the DARKEN_SIDES shading mode --- .../lodTemplates/CubicLodTemplate.java | 46 ++++++++++--------- .../java/com/seibel/lod/util/LodUtil.java | 28 +++++++++++ 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java b/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java index 7217aadb3..0b63ded17 100644 --- a/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java +++ b/src/main/java/com/seibel/lod/builders/lodTemplates/CubicLodTemplate.java @@ -24,6 +24,7 @@ import com.seibel.lod.enums.ShadingMode; import com.seibel.lod.handlers.LodConfig; import com.seibel.lod.objects.LodChunk; import com.seibel.lod.objects.LodDimension; +import com.seibel.lod.util.LodUtil; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.util.math.AxisAlignedBB; @@ -105,17 +106,20 @@ public class CubicLodTemplate extends AbstractLodTemplate private void addBoundingBoxToBuffer(BufferBuilder buffer, AxisAlignedBB bb, Color c) { Color topColor = c; - Color sideColor = c; + Color northSouthColor = c; + Color eastWestColor = c; Color bottomColor = c; // darken the bottom and side colors if requested if (LodConfig.CLIENT.shadingMode.get() == ShadingMode.DARKEN_SIDES) { - int sideDarkenAmount = 50; - int bottomDarkenAmount = sideDarkenAmount + 25; + int northSouthDarkenAmount = 25; + int eastWestDarkenAmount = 50; + int bottomDarkenAmount = 75; - sideColor = new Color(Math.max(0, c.getRed() - sideDarkenAmount), Math.max(0, c.getGreen() - sideDarkenAmount), Math.max(0, c.getBlue() - sideDarkenAmount), Math.max(0, c.getAlpha() - sideDarkenAmount)); - bottomColor = new Color(Math.max(0, c.getRed() - bottomDarkenAmount), Math.max(0, c.getGreen() - bottomDarkenAmount), Math.max(0, c.getBlue() - bottomDarkenAmount), Math.max(0, c.getAlpha() - bottomDarkenAmount)); + northSouthColor = new Color(Math.max(0, c.getRed() - northSouthDarkenAmount), Math.max(0, c.getGreen() - northSouthDarkenAmount), Math.max(0, c.getBlue() - northSouthDarkenAmount), c.getAlpha()); + eastWestColor = new Color(Math.max(0, c.getRed() - eastWestDarkenAmount), Math.max(0, c.getGreen() - eastWestDarkenAmount), Math.max(0, c.getBlue() - eastWestDarkenAmount), c.getAlpha()); + bottomColor = new Color(Math.max(0, c.getRed() - bottomDarkenAmount), Math.max(0, c.getGreen() - bottomDarkenAmount), Math.max(0, c.getBlue() - bottomDarkenAmount), c.getAlpha()); } @@ -131,26 +135,26 @@ public class CubicLodTemplate extends AbstractLodTemplate addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, bottomColor.getRed(), bottomColor.getGreen(), bottomColor.getBlue(), bottomColor.getAlpha()); // south (facing -Z) - addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); // north (facing +Z) - addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, northSouthColor.getRed(), northSouthColor.getGreen(), northSouthColor.getBlue(), northSouthColor.getAlpha()); // west (facing -X) - addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); // east (facing +X) - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); - addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, sideColor.getRed(), sideColor.getGreen(), sideColor.getBlue(), sideColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); + addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, eastWestColor.getRed(), eastWestColor.getGreen(), eastWestColor.getBlue(), eastWestColor.getAlpha()); } diff --git a/src/main/java/com/seibel/lod/util/LodUtil.java b/src/main/java/com/seibel/lod/util/LodUtil.java index b0fcabd7a..fb87b381d 100644 --- a/src/main/java/com/seibel/lod/util/LodUtil.java +++ b/src/main/java/com/seibel/lod/util/LodUtil.java @@ -254,4 +254,32 @@ public class LodUtil { return color.getRGB(); } + + + /** + * Clamps the given value between the min and max values. + * May behave strangely if min > max. + */ + public static int clamp(int min, int value, int max) + { + return Math.min(max, Math.max(value, min)); + } + + /** + * Clamps the given value between the min and max values. + * May behave strangely if min > max. + */ + public static float clamp(float min, float value, float max) + { + return Math.min(max, Math.max(value, min)); + } + + /** + * Clamps the given value between the min and max values. + * May behave strangely if min > max. + */ + public static double clamp(double min, double value, double max) + { + return Math.min(max, Math.max(value, min)); + } }