diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresModelRenderer.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresModelRenderer.java index a8106c6c..522e7c6b 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresModelRenderer.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresModelRenderer.java @@ -78,7 +78,7 @@ public class HiresModelRenderer { minY = Math.max(min.getY(), chunk.getMinY(x, z)); maxY = Math.min(max.getY(), chunk.getMaxY(x, z)); - for (y = minY; y <= maxY; y++) { + for (y = maxY; y >= minY; y--) { block.set(x, y, z); if (!block.isInsideRenderBounds()) continue; @@ -87,17 +87,7 @@ public class HiresModelRenderer { modelFactory.render(block, blockModel, blockColor); //update topBlockLight - if ( - y >= renderSettings.getRemoveCavesBelowY() || - (renderSettings.isCaveDetectionUsesBlockLight() ? block.getBlockLightLevel() : block.getSunLightLevel()) > 0 - ) { - if (blockColor.a > 0) { - topBlockLight = Math.floor(topBlockLight * (1 - blockColor.a)); - } - topBlockLight = Math.max(topBlockLight, block.getBlockLightLevel()); - } else { - topBlockLight = 0; - } + topBlockLight = Math.max(topBlockLight, block.getBlockLightLevel() * (1 - columnColor.a)); // skip empty blocks if (blockModel.getSize() <= 0) continue; @@ -107,9 +97,11 @@ public class HiresModelRenderer { //update color and height (only if not 100% translucent) if (blockColor.a > 0) { - maxHeight = y; - columnColor.overlay(blockColor.premultiplied()); + if (maxHeight < y) maxHeight = y; + columnColor.underlay(blockColor.premultiplied()); } + + //if (blockColor.a > 0.999 && block.getProperties().isCulling()) break; } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/ResourceModelBuilder.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/ResourceModelBuilder.java index fe57b72d..686eb6ca 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/ResourceModelBuilder.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/ResourceModelBuilder.java @@ -193,7 +193,17 @@ public class ResourceModelBuilder { (renderSettings.isCaveDetectionUsesBlockLight() ? Math.max(blockLight, sunLight) : sunLight) == 0 ) return; + // calculate faceRotationVector + faceRotationVector.set( + faceDirVector.getX(), + faceDirVector.getY(), + faceDirVector.getZ() + ); + faceRotationVector.rotateAndScale(element.getRotation().getMatrix()); + makeRotationRelative(faceRotationVector); + // face culling + //if (faceRotationVector.y < 0.01) return; if (face.getCullface() != null) { ExtendedBlock b = getRotationRelativeBlock(face.getCullface()); BlockProperties p = b.getProperties(); @@ -315,14 +325,6 @@ public class ResourceModelBuilder { tileModel.setAOs(face2, ao0, ao2, ao3); //if is top face set model-color - faceRotationVector.set( - faceDirVector.getX(), - faceDirVector.getY(), - faceDirVector.getZ() - ); - faceRotationVector.rotateAndScale(element.getRotation().getMatrix()); - makeRotationRelative(faceRotationVector); - float a = faceRotationVector.y; if (a > 0.01 && texturePath != null) { Texture texture = texturePath.getResource(resourcePack::getTexture); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java index 211fb45f..ef8f5ee3 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java @@ -125,6 +125,20 @@ public class Color { return this; } + public Color underlay(Color color) { + if (color.a < 1f && !color.premultiplied) throw new IllegalArgumentException("Can only underlay premultiplied colors with alpha!"); + + premultiplied(); + + float p = 1 - a; + this.a = p * color.a + this.a; + this.r = p * color.r + this.r; + this.g = p * color.g + this.g; + this.b = p * color.b + this.b; + + return this; + } + public Color flatten() { if (this.a == 1f) return this;