Smarter translucency sorting #42
+22
-8
@@ -21,13 +21,19 @@ public final class PartitionTree implements SortState.Resortable {
|
||||
this.cutPlanes = cutPlanes;
|
||||
}
|
||||
|
||||
static final int STATIC_LEAF_QUADS = 256;
|
||||
|
||||
// null when some slab has no free cut
|
||||
public static @Nullable PartitionTree build(QuadSet quads) {
|
||||
return build(quads, STATIC_LEAF_QUADS);
|
||||
}
|
||||
|
||||
static @Nullable PartitionTree build(QuadSet quads, int staticLeafQuads) {
|
||||
int[] all = new int[quads.count()];
|
||||
for (int i = 0; i < all.length; i++) all[i] = i;
|
||||
|
||||
FloatArrayList[] cuts = { new FloatArrayList(), new FloatArrayList(), new FloatArrayList() };
|
||||
Node root = partition(quads, all, 2, cuts);
|
||||
Node root = partition(quads, all, 2, cuts, staticLeafQuads);
|
||||
if (root == null) return null;
|
||||
|
||||
float[][] cutPlanes = new float[3][];
|
||||
@@ -68,7 +74,7 @@ public final class PartitionTree implements SortState.Resortable {
|
||||
return FloatArrays.copy(array, 0, n);
|
||||
}
|
||||
|
||||
private static Node partition(QuadSet quads, int[] group, int parentAxis, FloatArrayList[] collectedCuts) {
|
||||
private static Node partition(QuadSet quads, int[] group, int parentAxis, FloatArrayList[] collectedCuts, int staticLeafQuads) {
|
||||
if (group.length <= 1) {
|
||||
return new Leaf(group);
|
||||
}
|
||||
@@ -78,6 +84,14 @@ public final class PartitionTree implements SortState.Resortable {
|
||||
return new Leaf(parallel);
|
||||
}
|
||||
|
||||
boolean triedStatic = group.length <= staticLeafQuads;
|
||||
if (triedStatic) {
|
||||
int[] topological = TranslucentSorter.topologicalOrder(quads, group);
|
||||
if (topological != null) {
|
||||
return new Leaf(topological);
|
||||
}
|
||||
}
|
||||
|
||||
int axis = -1;
|
||||
float[] planes = FloatArrays.EMPTY_ARRAY;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -87,11 +101,11 @@ public final class PartitionTree implements SortState.Resortable {
|
||||
}
|
||||
if (planes.length == 0) {
|
||||
// no free cut does not imply a cycle: a camera-independent order may still exist
|
||||
int[] topological = group.length <= TranslucentSorter.MAX_TOPO_QUADS ? TranslucentSorter.topologicalOrder(quads, group) : null;
|
||||
int[] topological = !triedStatic && group.length <= TranslucentSorter.MAX_TOPO_QUADS ? TranslucentSorter.topologicalOrder(quads, group) : null;
|
||||
if (topological != null) {
|
||||
return new Leaf(topological);
|
||||
}
|
||||
return partitionIntersectors(quads, group, collectedCuts);
|
||||
return partitionIntersectors(quads, group, collectedCuts, staticLeafQuads);
|
||||
}
|
||||
|
||||
Buckets buckets = bucket(quads, group, axis, planes);
|
||||
@@ -114,7 +128,7 @@ public final class PartitionTree implements SortState.Resortable {
|
||||
slabs[i] = EMPTY;
|
||||
continue;
|
||||
}
|
||||
Node child = partition(quads, slabGroup, axis, collectedCuts);
|
||||
Node child = partition(quads, slabGroup, axis, collectedCuts, staticLeafQuads);
|
||||
if (child == null) return null;
|
||||
slabs[i] = child;
|
||||
}
|
||||
@@ -178,7 +192,7 @@ public final class PartitionTree implements SortState.Resortable {
|
||||
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 staticLeafQuads) {
|
||||
int n = group.length;
|
||||
if (n > TranslucentSorter.MAX_TOPO_QUADS) return null;
|
||||
|
||||
@@ -213,8 +227,8 @@ public final class PartitionTree implements SortState.Resortable {
|
||||
for (int i = 0, f = 0, r = 0; i < n; i++) {
|
||||
if (primary[i]) first[f++] = group[i]; else rest[r++] = group[i];
|
||||
}
|
||||
Node a = partition(quads, first, 2, collectedCuts);
|
||||
Node b = a == null ? null : partition(quads, rest, 2, collectedCuts);
|
||||
Node a = partition(quads, first, 2, collectedCuts, staticLeafQuads);
|
||||
Node b = a == null ? null : partition(quads, rest, 2, collectedCuts, staticLeafQuads);
|
||||
return b == null ? null : new Fixed(a, b);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user