Skip to content

Commit

Permalink
Gsplat fixes (#6711)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Jun 17, 2024
1 parent a309116 commit 35904d5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/scene/gsplat/gsplat-compressed-material.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ varying vec4 color;
#endif
uniform vec2 viewport;
uniform vec4 bufferWidths;
uniform vec4 bufferWidths; // packed width, chunked width, numSplats
uniform highp usampler2D splatOrder;
uniform highp usampler2D packedTexture;
uniform highp sampler2D chunkTexture;
uint orderId;
uint splatId;
ivec2 splatUV;
ivec2 chunkUV;
Expand All @@ -46,7 +47,7 @@ void calcUV() {
int chunkWidth = int(bufferWidths.y);
// sample order texture
uint orderId = vertex_id_attrib + uint(vertex_position.z);
orderId = vertex_id_attrib + uint(vertex_position.z);
ivec2 orderUV = ivec2(
int(orderId) % packedWidth,
int(orderId) / packedWidth
Expand Down Expand Up @@ -197,7 +198,7 @@ vec4 evalSplat() {
vec4 centerClip = matrix_projection * centerView;
// cull behind camera
if (centerClip.z < -centerClip.w) {
if (centerClip.z < -centerClip.w || orderId >= uint(bufferWidths.z)) {
return vec4(0.0, 0.0, 2.0, 1.0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/scene/gsplat/gsplat-compressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class GSplatCompressed {
const result = createGSplatCompressedMaterial(options);
result.setParameter('packedTexture', this.packedTexture);
result.setParameter('chunkTexture', this.chunkTexture);
result.setParameter('bufferWidths', new Float32Array([this.packedTexture.width, this.chunkTexture.width / 3, 0, 0]));
result.setParameter('bufferWidths', new Float32Array([this.packedTexture.width, this.chunkTexture.width / 3, this.numSplats, 0]));
return result;
}

Expand Down
4 changes: 3 additions & 1 deletion src/scene/gsplat/gsplat-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ class GSplatInstance {
this.meshInstance = new MeshInstance(this.mesh, this.material);
this.meshInstance.setInstancing(indicesVB, true);
this.meshInstance.gsplatInstance = this;
this.meshInstance.instancingCount = numSplatInstances;

// only start rendering the splat after we've received the splat order data
this.meshInstance.instancingCount = 0;

// clone centers to allow multiple instances of sorter
this.centers = new Float32Array(splat.centers);
Expand Down

0 comments on commit 35904d5

Please sign in to comment.