Smarter translucency sorting #42

Merged
embeddedt merged 24 commits from rdh/celeritas:ts into stonecutter 2026-09-16 11:25:42 -04:00
Showing only changes of commit 2a75492cab - Show all commits
@@ -242,12 +242,12 @@ public final class TranslucentSorter {
int[] out = new int[n]; int[] out = new int[n];
int finished = 0; int finished = 0;
for (int root = 0; root < n; root++) { for (int root = n - 1; root >= 0; root--) {
if (state[root] != 0) continue; if (state[root] != 0) continue;
int depth = 0; int depth = 0;
stack[0] = root; stack[0] = root;
next[0] = 0; next[0] = n - 1;
state[root] = 1; state[root] = 1;
while (depth >= 0) { while (depth >= 0) {
@@ -255,12 +255,12 @@ public final class TranslucentSorter {
int candidate = next[depth]; int candidate = next[depth];
// advance to the next quad that must be drawn after the current one // advance to the next quad that must be drawn after the current one
while (candidate < n && (state[candidate] == 2 || candidate == current while (candidate >= 0 && (state[candidate] == 2 || candidate == current
|| !quads.isSeenThrough(group[current], group[candidate]))) { || !quads.isSeenThrough(group[current], group[candidate]))) {
candidate++; candidate--;
} }
if (candidate == n) { if (candidate < 0) {
state[current] = 2; state[current] = 2;
out[n - 1 - finished++] = group[current]; // reverse postorder: predecessors first out[n - 1 - finished++] = group[current]; // reverse postorder: predecessors first
depth--; depth--;
@@ -271,10 +271,10 @@ public final class TranslucentSorter {
return null; // back edge: a cycle return null; // back edge: a cycle
} }
next[depth] = candidate + 1; next[depth] = candidate - 1;
depth++; depth++;
stack[depth] = candidate; stack[depth] = candidate;
next[depth] = 0; next[depth] = n - 1;
state[candidate] = 1; state[candidate] = 1;
} }
} }