Smarter translucency sorting #42
+58
-17
@@ -89,26 +89,19 @@ public final class PartitionTree implements SortState.Resortable {
|
|||||||
return partitionIntersectors(quads, group, collectedCuts);
|
return partitionIntersectors(quads, group, collectedCuts);
|
||||||
}
|
}
|
||||||
|
|
||||||
int slabCount = planes.length + 1;
|
Buckets buckets = bucket(quads, group, axis, planes);
|
||||||
IntArrayList[] onPlaneLists = new IntArrayList[planes.length];
|
|
||||||
for (int i = 0; i < planes.length; i++) onPlaneLists[i] = new IntArrayList();
|
|
||||||
IntArrayList[] slabLists = new IntArrayList[slabCount];
|
|
||||||
for (int i = 0; i < slabCount; i++) slabLists[i] = new IntArrayList();
|
|
||||||
|
|
||||||
for (int quad : group) {
|
// gaps between quads that are all parallel would only slice one static leaf into pieces, each gap a trigger
|
||||||
float lo = quads.boundsMin(quad, axis), hi = quads.boundsMax(quad, axis);
|
// plane: keep just the cuts carrying quads on the plane (some do, else the group itself was parallel)
|
||||||
|
float[] carrying = planesWithQuads(planes, buckets.onPlane);
|
||||||
// slab = number of planes at or below this quad's lo
|
if (carrying.length > 0 && carrying.length < planes.length && allParallel(quads, buckets.slabs)) {
|
||||||
int slab = 0;
|
planes = carrying;
|
||||||
while (slab < planes.length && planes[slab] <= lo + QuadSet.EPSILON) slab++;
|
buckets = bucket(quads, group, axis, planes);
|
||||||
|
|
||||||
if (hi - lo <= QuadSet.EPSILON && slab > 0 && Math.abs(planes[slab - 1] - lo) <= QuadSet.EPSILON) {
|
|
||||||
onPlaneLists[slab - 1].add(quad);
|
|
||||||
} else {
|
|
||||||
slabLists[slab].add(quad);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IntArrayList[] onPlaneLists = buckets.onPlane, slabLists = buckets.slabs;
|
||||||
|
int slabCount = planes.length + 1;
|
||||||
|
|
||||||
Node[] slabs = new Node[slabCount];
|
Node[] slabs = new Node[slabCount];
|
||||||
for (int i = 0; i < slabCount; i++) {
|
for (int i = 0; i < slabCount; i++) {
|
||||||
int[] slabGroup = slabLists[i].toIntArray();
|
int[] slabGroup = slabLists[i].toIntArray();
|
||||||
@@ -132,6 +125,54 @@ public final class PartitionTree implements SortState.Resortable {
|
|||||||
return new Split(axis, planes, slabs, onPlane);
|
return new Split(axis, planes, slabs, onPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record Buckets(IntArrayList[] onPlane, IntArrayList[] slabs) {}
|
||||||
|
|
||||||
|
/** sorts the group into the quads lying on each plane and those in each slab between the planes */
|
||||||
|
private static Buckets bucket(QuadSet quads, int[] group, int axis, float[] planes) {
|
||||||
|
IntArrayList[] onPlane = new IntArrayList[planes.length];
|
||||||
|
for (int i = 0; i < planes.length; i++) onPlane[i] = new IntArrayList();
|
||||||
|
IntArrayList[] slabs = new IntArrayList[planes.length + 1];
|
||||||
|
for (int i = 0; i <= planes.length; i++) slabs[i] = new IntArrayList();
|
||||||
|
|
||||||
|
for (int quad : group) {
|
||||||
|
float lo = quads.boundsMin(quad, axis), hi = quads.boundsMax(quad, axis);
|
||||||
|
|
||||||
|
// slab = number of planes at or below this quad's lo
|
||||||
|
int slab = 0;
|
||||||
|
while (slab < planes.length && planes[slab] <= lo + QuadSet.EPSILON) slab++;
|
||||||
|
|
||||||
|
if (hi - lo <= QuadSet.EPSILON && slab > 0 && Math.abs(planes[slab - 1] - lo) <= QuadSet.EPSILON) {
|
||||||
|
onPlane[slab - 1].add(quad);
|
||||||
|
} else {
|
||||||
|
slabs[slab].add(quad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Buckets(onPlane, slabs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] planesWithQuads(float[] planes, IntArrayList[] onPlane) {
|
||||||
|
FloatArrayList kept = new FloatArrayList(planes.length);
|
||||||
|
for (int i = 0; i < planes.length; i++) {
|
||||||
|
if (!onPlane[i].isEmpty()) kept.add(planes[i]);
|
||||||
|
}
|
||||||
|
return kept.toFloatArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean allParallel(QuadSet quads, IntArrayList[] slabs) {
|
||||||
|
int reference = -1;
|
||||||
|
for (IntArrayList slab : slabs) {
|
||||||
|
for (int i = 0; i < slab.size(); i++) {
|
||||||
|
int quad = slab.getInt(i);
|
||||||
|
if (reference < 0) {
|
||||||
|
reference = quad;
|
||||||
|
} else if (Math.abs(quads.normalDot(quad, reference)) < 1 - QuadSet.EPSILON) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static @Nullable Node partitionIntersectors(QuadSet quads, int[] group, FloatArrayList[] collectedCuts) {
|
private static @Nullable Node partitionIntersectors(QuadSet quads, int[] group, FloatArrayList[] collectedCuts) {
|
||||||
int n = group.length;
|
int n = group.length;
|
||||||
if (n > TranslucentSorter.MAX_TOPO_QUADS) return null;
|
if (n > TranslucentSorter.MAX_TOPO_QUADS) return null;
|
||||||
|
|||||||
Reference in new issue
Block a user