From ad520353d766e4448508e338bdc80d7e5ee4b547 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Mon, 9 Dec 2024 11:48:10 +0000 Subject: [PATCH] Small gsplat shader update (#7186) --- examples/src/examples/loaders/gsplat-many.shader.vert | 8 ++++++-- src/scene/gsplat/gsplat-material.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/src/examples/loaders/gsplat-many.shader.vert b/examples/src/examples/loaders/gsplat-many.shader.vert index 1eaa5209ced..3c0b34a1f07 100644 --- a/examples/src/examples/loaders/gsplat-many.shader.vert +++ b/examples/src/examples/loaders/gsplat-many.shader.vert @@ -35,14 +35,18 @@ void main(void) // handle transforms mat4 model_view = matrix_view * matrix_model; vec4 splat_cam = model_view * vec4(center, 1.0); - vec4 splat_proj = matrix_projection * splat_cam; // cull behind camera - if (splat_proj.z < -splat_proj.w) { + if (splat_cam.z > 0.0) { gl_Position = discardVec; return; } + vec4 splat_proj = matrix_projection * splat_cam; + + // ensure gaussians are not clipped by camera near and far + splat_proj.z = clamp(splat_proj.z, -abs(splat_proj.w), abs(splat_proj.w)); + // get covariance vec3 covA, covB; getCovariance(covA, covB); diff --git a/src/scene/gsplat/gsplat-material.js b/src/scene/gsplat/gsplat-material.js index bb436bc359b..2b44f5386b4 100644 --- a/src/scene/gsplat/gsplat-material.js +++ b/src/scene/gsplat/gsplat-material.js @@ -29,14 +29,18 @@ const splatMainVS = /* glsl */ ` // handle transforms mat4 model_view = matrix_view * matrix_model; vec4 splat_cam = model_view * vec4(center, 1.0); - vec4 splat_proj = matrix_projection * splat_cam; // cull behind camera - if (splat_proj.z < -splat_proj.w) { + if (splat_cam.z > 0.0) { gl_Position = discardVec; return; } + vec4 splat_proj = matrix_projection * splat_cam; + + // ensure gaussians are not clipped by camera near and far + splat_proj.z = clamp(splat_proj.z, -abs(splat_proj.w), abs(splat_proj.w)); + // get covariance vec3 covA, covB; getCovariance(covA, covB);