Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GS rendering #6352

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4a02351
move render order to texture
slimbuck Apr 25, 2024
142b50d
remove unneccessary vertex data
slimbuck Apr 25, 2024
ea02fbf
remove dead code
slimbuck Apr 25, 2024
a3aa33b
small
slimbuck Apr 26, 2024
5871e3a
create correct size target
slimbuck Apr 26, 2024
4061ff7
fix for firefox - specify per-splat indices
slimbuck Apr 26, 2024
eff37ce
sort by camera distance
slimbuck Apr 29, 2024
144bacf
preprocess v1v2 texture
slimbuck Apr 30, 2024
f135b23
using instancing
slimbuck May 1, 2024
2daf06b
Merge branch 'main' into gs-sorter-v1v2-instanced
slimbuck May 1, 2024
ebe5f8d
Revert "sort by camera distance"
slimbuck May 1, 2024
514122e
small
slimbuck May 2, 2024
13e8c09
use sort tex
slimbuck May 2, 2024
c9a3806
small
slimbuck May 2, 2024
1ae4465
small
slimbuck May 2, 2024
0bf88db
bug
slimbuck May 4, 2024
a49d351
preprocess in v1v2
slimbuck May 7, 2024
f46cdae
only preprocess after sort
slimbuck May 8, 2024
5b6a725
Merge branch 'main' into gs-sorter-v1v2-instanced-sorttex-preprocess
slimbuck May 8, 2024
9a88801
revert unused changes
slimbuck May 8, 2024
854e7c2
more
slimbuck May 8, 2024
5ff81f7
small
slimbuck May 8, 2024
060c8bc
Merge branch 'main' into gs-sorter-v1v2-instanced-sorttex-preprocess
slimbuck May 8, 2024
38a7e4d
Merge branch 'main' into gs-sorter-v1v2-instanced-sorttex-preprocess
slimbuck May 8, 2024
18ac422
small
slimbuck May 8, 2024
f9efc39
working on android
slimbuck May 9, 2024
61ddce8
small
slimbuck May 9, 2024
8e31df6
reorder splat data at load
slimbuck May 9, 2024
157a96a
use render pass
slimbuck May 9, 2024
1e779f9
simplify pass
slimbuck May 9, 2024
512369e
small
slimbuck May 9, 2024
5f1dce2
fix splat culling
slimbuck May 10, 2024
030ab27
render last instance
slimbuck May 10, 2024
1751dda
Merge branch 'main' into gs-sorter-v1v2-instanced-sorttex-preprocess
slimbuck May 10, 2024
3485f04
lint
slimbuck May 10, 2024
4c4c234
changes based on feedback
slimbuck May 13, 2024
7b90dd5
Merge branch 'main' into gs-sorter-v1v2-instanced-sorttex-preprocess
slimbuck May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/platform/graphics/shader-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,9 @@ class ShaderUtils {

const precision = forcePrecision ? forcePrecision : device.precision;

let code = '';
if (device.isWebGPU) {

code = `precision ${precision} float;\nprecision ${precision} int;\n`;

} else {
let code = `precision ${precision} float;\nprecision ${precision} int;\n`;

code = `precision ${precision} float;\n`;
if (device.isWebGL2) {
code += `precision ${precision} sampler2DShadow;\n`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/graphics/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ class Texture {
* - {@link TEXTURELOCK_READ}
* - {@link TEXTURELOCK_WRITE}
* Defaults to {@link TEXTURELOCK_WRITE}.
* @returns {Uint8Array|Uint16Array|Float32Array} A typed array containing the pixel data of
* @returns {Uint8Array|Uint16Array|Uint32Array|Float32Array} A typed array containing the pixel data of
* the locked mip level.
*/
lock(options = {}) {
Expand Down
81 changes: 81 additions & 0 deletions src/scene/gsplat/gsplat-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class GSplatData {
if (!this.isCompressed && performZScale) {
mat4.setScale(-1, -1, 1);
this.transform(mat4);

// reorder uncompressed splats in morton order for better memory access
// efficiency during rendering
this.reorderData();
}
}

Expand Down Expand Up @@ -408,6 +412,83 @@ class GSplatData {
})
}], false);
}

calcMortonOrder() {
const calcMinMax = (arr) => {
let min = arr[0];
let max = arr[0];
for (let i = 1; i < arr.length; i++) {
if (arr[i] < min) min = arr[i];
if (arr[i] > max) max = arr[i];
}
return { min, max };
};

// https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/
const encodeMorton3 = (x, y, z) => {
const Part1By2 = (x) => {
x &= 0x000003ff;
x = (x ^ (x << 16)) & 0xff0000ff;
x = (x ^ (x << 8)) & 0x0300f00f;
x = (x ^ (x << 4)) & 0x030c30c3;
x = (x ^ (x << 2)) & 0x09249249;
return x;
};

return (Part1By2(z) << 2) + (Part1By2(y) << 1) + Part1By2(x);
};

const x = this.getProp('x');
const y = this.getProp('y');
const z = this.getProp('z');

const { min: minX, max: maxX } = calcMinMax(x);
const { min: minY, max: maxY } = calcMinMax(y);
const { min: minZ, max: maxZ } = calcMinMax(z);

const sizeX = 1024 / (maxX - minX);
const sizeY = 1024 / (maxY - minY);
const sizeZ = 1024 / (maxZ - minZ);

const morton = new Uint32Array(this.numSplats);
for (let i = 0; i < this.numSplats; i++) {
const ix = Math.floor((x[i] - minX) * sizeX);
const iy = Math.floor((y[i] - minY) * sizeY);
const iz = Math.floor((z[i] - minZ) * sizeZ);
morton[i] = encodeMorton3(ix, iy, iz);
}

// generate indices
const indices = new Uint32Array(this.numSplats);
for (let i = 0; i < this.numSplats; i++) {
indices[i] = i;
}
// order splats by morton code
indices.sort((a, b) => morton[a] - morton[b]);

return indices;
}

reorderData() {
// calculate splat morton order
const order = this.calcMortonOrder();

const reorder = (data) => {
const result = new data.constructor(data.length);

for (let i = 0; i < order.length; i++) {
result[i] = data[order[i]];
}

return result;
};

this.elements.forEach((element) => {
element.properties.forEach((property) => {
property.storage = reorder(property.storage);
});
});
}
}

export { GSplatData };