Skip to content

Commit

Permalink
Fix gsplat sorting bug (#6845)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Jul 24, 2024
1 parent 25d05be commit dac6e4a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/scene/gsplat/gsplat-sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ function SortWorker() {
}
}

if (!countBuffer)
if (!countBuffer) {
countBuffer = new Uint32Array(bucketCount);

for (let i = 0; i < bucketCount; i++)
countBuffer[i] = 0;
} else {
countBuffer.fill(0);
}

// generate per vertex distance to camera
const range = maxDist - minDist;
Expand All @@ -121,8 +121,9 @@ function SortWorker() {
}

// Change countBuffer[i] so that it contains actual position of this digit in outputArray
for (let i = 1; i < bucketCount; i++)
for (let i = 1; i < bucketCount; i++) {
countBuffer[i] += countBuffer[i - 1];
}

// Build the output array
for (let i = 0; i < numVertices; i++) {
Expand All @@ -137,6 +138,7 @@ function SortWorker() {
const result = binarySearch(0, numVertices - 1, i => -dist(i));
return Math.min(numVertices, Math.abs(result));
};
const count = dist(numVertices - 1) >= 0 ? findZero() : numVertices;

// apply mapping
if (mapping) {
Expand All @@ -148,7 +150,7 @@ function SortWorker() {
// send results
self.postMessage({
order: order.buffer,
count: dist(numVertices - 1) >= 0 ? findZero() : numVertices
count
}, [order.buffer]);

order = null;
Expand Down

0 comments on commit dac6e4a

Please sign in to comment.