Skip to content

Commit

Permalink
fix box test heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
douira committed Jan 14, 2024
1 parent f10dfba commit fd42f5f
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.joml.Vector3dc;
import org.joml.Vector3f;
import org.joml.Vector3fc;

import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
Expand All @@ -19,13 +17,15 @@
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.AnyOrderData;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.BSPDynamicData;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.CombinedCameraPos;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.DynamicData;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.NoData;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.PresentTranslucentData;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.StaticNormalRelativeData;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.StaticTopoAcyclicData;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.TopoSortDynamicData;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.data.TranslucentData;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.trigger.GeometryPlanes;
import me.jellysquid.mods.sodium.client.render.chunk.translucent_sorting.trigger.SortTriggering;
import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder;
import me.jellysquid.mods.sodium.client.util.NativeBuffer;
import net.caffeinemc.mods.sodium.api.util.NormI8;
Expand Down Expand Up @@ -70,7 +70,10 @@ public class TranslucentGeometryCollector {
private int alignedFacingBitmap = 0;

// AABB of the geometry
private float[] extents = new float[ModelQuadFacing.DIRECTIONS];
private float[] extents = new float[] {
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY
};

// true if one of the extents has more than one plane
private boolean alignedExtentsMultiple = false;
Expand Down Expand Up @@ -192,8 +195,6 @@ public void appendQuad(int packedNormal, ChunkVertexEncoder.Vertex[] vertices, M
if (quadList == null) {
quadList = new ReferenceArrayList<>();
this.quadLists[direction] = quadList;
} else if (facing.isAligned()) {
this.alignedExtentsMultiple = true;
}

if (facing.isAligned()) {
Expand All @@ -213,7 +214,15 @@ public void appendQuad(int packedNormal, ChunkVertexEncoder.Vertex[] vertices, M

var extreme = this.alignedExtremes[direction];
var distance = quad.getDotProduct();
if (facing.getSign() > 1) {

// check if this is a new dot product for this distance
var existingExtreme = this.alignedExtremes[direction];
if (!this.alignedExtentsMultiple && !Float.isInfinite(existingExtreme) && existingExtreme != distance) {
this.alignedExtentsMultiple = true;
}

// update the aligned extremes (which are the direction dependent dot products)
if (facing.getSign() > 0) {
this.alignedExtremes[direction] = Math.max(extreme, distance);
} else {
this.alignedExtremes[direction] = Math.min(extreme, distance);
Expand Down

0 comments on commit fd42f5f

Please sign in to comment.