Add minPixelRadius to skip splats below a given pixel radius (#184)

This commit is contained in:
Noeri Huisman
2025-09-29 18:16:38 +02:00
committed by GitHub
parent 6d7d8012a1
commit 15318d7016
4 changed files with 19 additions and 3 deletions
+10
View File
@@ -84,6 +84,11 @@ export type SparkRendererOptions = {
* @default Math.sqrt(8)
*/
maxStdDev?: number;
/**
* Minimum pixel radius for splat rendering.
* @default 0.0
*/
minPixelRadius?: number;
/**
* Maximum pixel radius for splat rendering.
* @default 512.0
@@ -170,6 +175,7 @@ export class SparkRenderer extends THREE.Mesh {
needsUpdate: boolean;
originDistance: number;
maxStdDev: number;
minPixelRadius: number;
maxPixelRadius: number;
minAlpha: number;
enable2DGS: boolean;
@@ -294,6 +300,7 @@ export class SparkRenderer extends THREE.Mesh {
this.needsUpdate = false;
this.originDistance = options.originDistance ?? 1;
this.maxStdDev = options.maxStdDev ?? Math.sqrt(8.0);
this.minPixelRadius = options.minPixelRadius ?? 0.0;
this.maxPixelRadius = options.maxPixelRadius ?? 512.0;
this.minAlpha = options.minAlpha ?? 0.5 * (1.0 / 255.0);
this.enable2DGS = options.enable2DGS ?? false;
@@ -344,6 +351,8 @@ export class SparkRenderer extends THREE.Mesh {
renderToViewPos: { value: new THREE.Vector3() },
// Maximum distance (in stddevs) from Gsplat center to render
maxStdDev: { value: 1.0 },
// Minimum pixel radius for splat rendering
minPixelRadius: { value: 0.0 },
// Maximum pixel radius for splat rendering
maxPixelRadius: { value: 512.0 },
// Minimum alpha value for splat rendering
@@ -528,6 +537,7 @@ export class SparkRenderer extends THREE.Mesh {
this.uniforms.far.value = typedCamera.far;
this.uniforms.encodeLinear.value = viewpoint.encodeLinear;
this.uniforms.maxStdDev.value = this.maxStdDev;
this.uniforms.minPixelRadius.value = this.minPixelRadius;
this.uniforms.maxPixelRadius.value = this.maxPixelRadius;
this.uniforms.minAlpha.value = this.minAlpha;
this.uniforms.stochastic.value = viewpoint.stochastic;
+7 -3
View File
@@ -17,6 +17,7 @@ uniform uint numSplats;
uniform vec4 renderToViewQuat;
uniform vec3 renderToViewPos;
uniform float maxStdDev;
uniform float minPixelRadius;
uniform float maxPixelRadius;
uniform float time;
uniform float deltaTime;
@@ -199,11 +200,14 @@ void main() {
vec2 eigenVec1 = normalize(vec2((abs(b) < 0.001) ? 1.0 : b, eigen1 - a));
vec2 eigenVec2 = vec2(eigenVec1.y, -eigenVec1.x);
float scale1 = position.x * min(maxPixelRadius, maxStdDev * sqrt(eigen1));
float scale2 = position.y * min(maxPixelRadius, maxStdDev * sqrt(eigen2));
float scale1 = min(maxPixelRadius, maxStdDev * sqrt(eigen1));
float scale2 = min(maxPixelRadius, maxStdDev * sqrt(eigen2));
if (scale1 < minPixelRadius && scale2 < minPixelRadius) {
return;
}
// Compute the NDC coordinates for the ellipsoid's diagonal axes.
vec2 pixelOffset = eigenVec1 * scale1 + eigenVec2 * scale2;
vec2 pixelOffset = position.x * eigenVec1 * scale1 + position.y * eigenVec2 * scale2;
vec2 ndcOffset = (2.0 / scaledRenderSize) * pixelOffset;
vec3 ndc = vec3(ndcCenter.xy + ndcOffset, ndcCenter.z);