Smarter translucency sorting #42
No files matched your search
+27
-7
@@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
|||||||
import it.unimi.dsi.fastutil.floats.FloatArrays;
|
import it.unimi.dsi.fastutil.floats.FloatArrays;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrays;
|
import it.unimi.dsi.fastutil.ints.IntArrays;
|
||||||
|
import org.embeddedt.embeddium.impl.util.sorting.MergeSort;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -68,10 +69,15 @@ public final class PartitionTree implements SortState.Resortable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Node partition(QuadSet quads, int[] group, int parentAxis, FloatArrayList[] collectedCuts) {
|
private static Node partition(QuadSet quads, int[] group, int parentAxis, FloatArrayList[] collectedCuts) {
|
||||||
if (group.length <= 1 || isAllCoplanar(quads, group)) {
|
if (group.length <= 1) {
|
||||||
return new Leaf(group);
|
return new Leaf(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int[] parallel = parallelOrder(quads, group);
|
||||||
|
if (parallel != null) {
|
||||||
|
return new Leaf(parallel);
|
||||||
|
}
|
||||||
|
|
||||||
int axis = -1;
|
int axis = -1;
|
||||||
float[] planes = FloatArrays.EMPTY_ARRAY;
|
float[] planes = FloatArrays.EMPTY_ARRAY;
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
@@ -174,13 +180,27 @@ public final class PartitionTree implements SortState.Resortable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isAllCoplanar(QuadSet quads, int[] group) {
|
private static int @Nullable [] parallelOrder(QuadSet quads, int[] group) {
|
||||||
for (int i = 1; i < group.length; i++) {
|
int reference = group[0];
|
||||||
if (!quads.isCoplanar(group[0], group[i])) {
|
float nx = quads.normalX(reference), ny = quads.normalY(reference), nz = quads.normalZ(reference);
|
||||||
return false;
|
float[] centers = quads.centers();
|
||||||
}
|
int far = TranslucentSorter.FAKE_STATIC_CAMERA_OFFSET;
|
||||||
|
float camX = centers[reference * 3] + nx * far, camY = centers[reference * 3 + 1] + ny * far, camZ = centers[reference * 3 + 2] + nz * far;
|
||||||
|
|
||||||
|
float[] keys = new float[group.length];
|
||||||
|
for (int i = 0; i < group.length; i++) {
|
||||||
|
int quad = group[i];
|
||||||
|
float dot = quads.normalDot(quad, reference);
|
||||||
|
if (Math.abs(dot) < 1 - QuadSet.EPSILON) return null;
|
||||||
|
|
||||||
|
int c = quad * 3;
|
||||||
|
keys[i] = (nx * (centers[c] - camX) + ny * (centers[c + 1] - camY) + nz * (centers[c + 2] - camZ)) * (dot < 0 ? 1 : -1);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
int[] byKey = MergeSort.mergeSort(keys);
|
||||||
|
int[] order = new int[group.length];
|
||||||
|
for (int i = 0; i < order.length; i++) order[i] = group[byKey[i]];
|
||||||
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float[] cutsOn(QuadSet quads, int[] group, int axis) {
|
private static float[] cutsOn(QuadSet quads, int[] group, int axis) {
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ public final class TranslucentSorter {
|
|||||||
* How far along the shared normal the imaginary camera used by {@link #sortNormalRelative} sits. Any value
|
* How far along the shared normal the imaginary camera used by {@link #sortNormalRelative} sits. Any value
|
||||||
* comfortably beyond the section is equivalent, since only the ordering of the projections matters.
|
* comfortably beyond the section is equivalent, since only the ordering of the projections matters.
|
||||||
*/
|
*/
|
||||||
private static final int FAKE_STATIC_CAMERA_OFFSET = 1000;
|
static final int FAKE_STATIC_CAMERA_OFFSET = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How closely two normals must agree to be treated as parallel. Only +/-1 truly imply a shared normal, but
|
* How closely two normals must agree to be treated as parallel. Only +/-1 truly imply a shared normal, but
|
||||||
|
|||||||
Reference in new issue
Block a user