Skip to content

Commit

Permalink
Use quad's Uv bounds instead of quadbounds for transluceny check
Browse files Browse the repository at this point in the history
  • Loading branch information
1foxy2 committed Feb 24, 2025
1 parent b8cca1a commit ba60a6b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 47 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
import ca.fxco.moreculling.api.data.QuadBounds;
import ca.fxco.moreculling.api.model.BakedOpacity;
import ca.fxco.moreculling.api.sprite.SpriteOpacity;
import ca.fxco.moreculling.platform.Services;
import ca.fxco.moreculling.utils.CullingUtils;
import ca.fxco.moreculling.utils.DirectionBits;
import ca.fxco.moreculling.utils.VertexUtils;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.SimpleBakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -57,8 +52,7 @@ public abstract class SimpleBakedModel_cacheMixin implements BakedOpacity {
BakedQuad initialQuad = layeredQuads.removeFirst();
SpriteOpacity opacity = ((SpriteOpacity) initialQuad.getSprite());
NativeImage image = opacity.moreculling$getUnmipmappedImage();
QuadBounds bounds = VertexUtils.getQuadBounds(initialQuad, direction.getAxis(),
image.getWidth(), image.getHeight());
QuadBounds bounds = VertexUtils.getQuadUvBounds(initialQuad, image.getWidth(), image.getHeight());
if (!opacity.moreculling$hasTranslucency(bounds)) {
if (!layeredQuads.isEmpty()) {
List<NativeImage> overlappingImages = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public static void resetAllCache() {
// Reset all model translucency cache
Map<BlockState, BakedModel> allModels = ((BlockModelShaperAccessor) blockRenderManager.getBlockModelShaper()).getModels();
allModels.forEach((state, model) -> {
if (!state.canOcclude()) {
((BakedOpacity) model).moreculling$resetTranslucencyCache(state);
}
((BakedOpacity) model).moreculling$resetTranslucencyCache(state);
});
//TODO: Reset quad cache
MoreCulling.LOGGER.info(allModels.size() + " cache(s) where cleared!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ca.fxco.moreculling.MoreCulling;
import ca.fxco.moreculling.api.blockstate.MoreStateCulling;
import ca.fxco.moreculling.api.blockstate.StateCullingShapeCache;
import com.mojang.logging.LogUtils;
import it.unimi.dsi.fastutil.objects.Object2ByteLinkedOpenHashMap;
import net.caffeinemc.mods.sodium.client.SodiumClientMod;
import net.minecraft.client.GraphicsStatus;
Expand All @@ -13,6 +14,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
Expand Down
30 changes: 12 additions & 18 deletions common/src/main/java/ca/fxco/moreculling/utils/VertexUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ca.fxco.moreculling.api.data.QuadBounds;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.core.Direction;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import org.joml.Math;
import org.joml.*;

Expand Down Expand Up @@ -36,34 +36,28 @@ private static Vector3f getPos(int[] data, int vertexIndex) {
);
}

private static Vector2f getPos(int[] data, int vertexIndex, Direction.Axis axis) {
private static Vector2f getUv(TextureAtlasSprite sprite, int[] data, int vertexIndex, int imageWidth, int imageHeight) {
final int index = vertexIndex * VERTEX_STRIDE;
if (axis.isVertical()) {
return new Vector2f(
Float.intBitsToFloat(data[index]), // x
Float.intBitsToFloat(data[index + 2]) // z
);
} else {
return new Vector2f(
(float) axis.choose(Float.intBitsToFloat(data[index + 2]), 0, Float.intBitsToFloat(data[index])),
Float.intBitsToFloat(data[index + 1])
);
}
float width = sprite.getU1() - sprite.getU0();
float height = sprite.getV1() - sprite.getV0();
return new Vector2f(
((Float.intBitsToFloat(data[index + 4]) - sprite.getU0()) / width) * imageWidth, // x
((Float.intBitsToFloat(data[index + 5]) - sprite.getV0()) / height) * imageHeight // y
);
}

public static QuadBounds getQuadBounds(BakedQuad quad, Direction.Axis axis,
int resolutionScaleX, int resolutionScaleY) {
public static QuadBounds getQuadUvBounds(BakedQuad quad, int imageWidth, int imageHeight) {
Vector2i minPos = new Vector2i(Integer.MAX_VALUE);
Vector2i maxPos = new Vector2i(-Integer.MAX_VALUE);
int[] vertexData = quad.getVertices();
for (int i = 0; i < 4; i++) {
Vector2f tmpPos = getPos(vertexData, i, axis);
Vector2f tmpPos = getUv(quad.getSprite(), vertexData, i, imageWidth, imageHeight);
Vector2i pos = new Vector2i(Math.round(tmpPos.x), Math.round(tmpPos.y));
minPos.min(pos);
maxPos.max(pos);
}
return new QuadBounds(minPos.x * resolutionScaleX, minPos.y * resolutionScaleY,
maxPos.x * resolutionScaleX, maxPos.y * resolutionScaleY);
return new QuadBounds(minPos.x, minPos.y,
maxPos.x, maxPos.y);
}

public static boolean isAxisAligned(BakedQuad quad) {
Expand Down
1 change: 0 additions & 1 deletion common/src/main/resources/moreculling.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"blocks.cullshape.ChorusFlowerBlock_voxelMixin",
"blocks.DoorBlock_cullAgainstMixin",
"blocks.EndGatewayBlock_cullMixin",
"blocks.EndRodBlock_cullMixin",
"blocks.FletchingTableBlock_devMixin",
"blocks.LadderBlock_cullAgainstMixin",
"blocks.LeavesBlock_typesMixin",
Expand Down

0 comments on commit ba60a6b

Please sign in to comment.