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

Gsplat rendering fix #6590

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/scene/gsplat/gsplat-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ class GSplatData {
data.f_dc_0[i] = (c.x - 0.5) / SH_C0;
data.f_dc_1[i] = (c.y - 0.5) / SH_C0;
data.f_dc_2[i] = (c.z - 0.5) / SH_C0;
data.opacity[i] = -Math.log(1 / c.w - 1);
// convert opacity to log sigmoid taking into account infinities at 0 and 1
data.opacity[i] = (c.w <= 0) ? -40 : (c.w >= 1) ? 40 : -Math.log(1 / c.w - 1);
slimbuck marked this conversation as resolved.
Show resolved Hide resolved
}

return new GSplatData([{
Expand Down
4 changes: 1 addition & 3 deletions src/scene/gsplat/gsplat.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ class GSplat {
result.setParameter('transformA', this.transformATexture);
result.setParameter('transformB', this.transformBTexture);
result.setParameter('transformC', this.transformCTexture);

const { width, height } = this.colorTexture;
result.setParameter('tex_params', new Float32Array([width, height, 1 / width, 1 / height]));
result.setParameter('tex_params', new Float32Array([this.colorTexture.width, this.numSplats]));
return result;
}

Expand Down
8 changes: 5 additions & 3 deletions src/scene/gsplat/shader-generator-gsplat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const splatCoreVS = /* glsl */ `
varying vec4 color;
varying float id;

uniform vec4 tex_params;
// width, numSplats
uniform vec2 tex_params;
uniform sampler2D splatColor;

uniform highp usampler2D splatOrder;
Expand All @@ -33,13 +34,14 @@ const splatCoreVS = /* glsl */ `
attribute vec3 vertex_position;
attribute uint vertex_id_attrib;

uint orderId;
uint splatId;
ivec2 splatUV;
void evalSplatUV() {
int bufferSizeX = int(tex_params.x);

// 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) % bufferSizeX,
int(orderId) / bufferSizeX
Expand Down Expand Up @@ -82,7 +84,7 @@ const splatCoreVS = /* glsl */ `
vec4 splat_proj = matrix_projection * splat_cam;

// cull behind camera
if (splat_proj.z < -splat_proj.w) {
if (splat_proj.z < -splat_proj.w || orderId >= uint(tex_params.y)) {
return vec4(0.0, 0.0, 2.0, 1.0);
}

Expand Down