From 0639f2f9630c11deea9d8d6adf62f10f02abf840 Mon Sep 17 00:00:00 2001 From: Andreas Sundquist Date: Fri, 11 Jul 2025 18:59:05 -0700 Subject: [PATCH] Rename SparkRenderer.renderScale to focalAdjustment. Add to constructor options and to docs. (#113) --- docs/docs/spark-renderer.md | 2 ++ examples/editor/index.html | 2 +- src/SparkRenderer.ts | 12 +++++++++--- src/shaders/splatVertex.glsl | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/docs/spark-renderer.md b/docs/docs/spark-renderer.md index 9a86693..29959ad 100644 --- a/docs/docs/spark-renderer.md +++ b/docs/docs/spark-renderer.md @@ -39,6 +39,7 @@ const spark = new SparkRenderer({ apertureAngle?: number; falloff?: number; clipXY?: number; + focalAdjustment?: number; view?: SparkViewpointOptions; }); ``` @@ -63,6 +64,7 @@ const spark = new SparkRenderer({ | **apertureAngle** | Full-width angle of aperture opening from pinhole camera origin in radians (default: `0.0` to disable) | **falloff** | Modulate Gaussian kernel falloff. 0 means "no falloff, flat shading", while 1 is the normal Gaussian kernel. (default: `1.0`) | **clipXY** | X/Y clipping boundary factor for splat centers against view frustum. 1.0 clips any centers that are exactly out of bounds (but the splat's entire projection may still be in bounds), while 1.4 clips centers that are 40% beyond the bounds. (default: `1.4`) +| **focalAdjustment** | Parameter to adjust projected splat scale calculation to match other renderers, similar to the same parameter in the MKellogg 3DGS renderer. Higher values will tend to sharpen the splats. A value 2.0 can be used to match the behavior of the PlayCanvas renderer. (default: `1.0`) | **view** | Configures the `SparkViewpointOptions` for the default `SparkViewpoint` associated with this `SparkRenderer`. Notable option: `sortRadial` (sort by radial distance or Z-depth) ## `newViewpoint(options: SparkViewpointOptions)` diff --git a/examples/editor/index.html b/examples/editor/index.html index bf703f1..f744c1d 100644 --- a/examples/editor/index.html +++ b/examples/editor/index.html @@ -512,7 +512,7 @@ spark.blurAmount = 0.3; }, }, "AA").name("AA preset"); - debugFolder.add(spark, "renderScale", 0.1, 2.0, 0.1).name("Render scale"); + debugFolder.add(spark, "focalAdjustment", 0.1, 2.0, 0.1).name("Tweak focalAdjustment"); const splatsFolder = secondGui.addFolder("Files"); diff --git a/src/SparkRenderer.ts b/src/SparkRenderer.ts index 44d26d3..02ebc94 100644 --- a/src/SparkRenderer.ts +++ b/src/SparkRenderer.ts @@ -126,6 +126,11 @@ export type SparkRendererOptions = { // 1.0 clips any centers that are exactly out of bounds, while 1.4 clips // centers that are 40% beyond the bounds. (default: 1.4) clipXY?: number; + // Parameter to adjust projected splat scale calculation to match other renderers, + // similar to the same parameter in the MKellogg 3DGS renderer. Higher values will + // tend to sharpen the splats. A value 2.0 can be used to match the behavior of + // the PlayCanvas renderer. (default: 1.0) + focalAdjustment?: number; // Configures the SparkViewpointOptions for the default SparkViewpoint // associated with this SparkRenderer. Notable option: sortRadial (sort by // radial distance or Z-depth) @@ -148,7 +153,7 @@ export class SparkRenderer extends THREE.Mesh { apertureAngle: number; falloff: number; clipXY: number; - renderScale = 1.0; + focalAdjustment: number; splatTexture: null | { enable?: boolean; @@ -264,6 +269,7 @@ export class SparkRenderer extends THREE.Mesh { this.apertureAngle = options.apertureAngle ?? 0.0; this.falloff = options.falloff ?? 1.0; this.clipXY = options.clipXY ?? 1.4; + this.focalAdjustment = options.focalAdjustment ?? 1.0; this.active = new SplatAccumulator(); this.accumulatorCount = 1; @@ -321,7 +327,7 @@ export class SparkRenderer extends THREE.Mesh { // Clip Gsplats that are clipXY times beyond the +-1 frustum bounds clipXY: { value: 1.4 }, // Debug renderSize scale factor - renderScale: { value: 1.0 }, + focalAdjustment: { value: 1.0 }, // Enable splat texture rendering splatTexEnable: { value: false }, // Splat texture to render @@ -479,7 +485,7 @@ export class SparkRenderer extends THREE.Mesh { this.uniforms.apertureAngle.value = this.apertureAngle; this.uniforms.falloff.value = this.falloff; this.uniforms.clipXY.value = this.clipXY; - this.uniforms.renderScale.value = this.renderScale; + this.uniforms.focalAdjustment.value = this.focalAdjustment; if (this.splatTexture) { const { enable, texture, multiply, add, near, far, mid } = diff --git a/src/shaders/splatVertex.glsl b/src/shaders/splatVertex.glsl index 2eb0312..aea0475 100644 --- a/src/shaders/splatVertex.glsl +++ b/src/shaders/splatVertex.glsl @@ -25,7 +25,7 @@ uniform float preBlurAmount; uniform float focalDistance; uniform float apertureAngle; uniform float clipXY; -uniform float renderScale; +uniform float focalAdjustment; uniform usampler2DArray packedSplats; @@ -112,7 +112,7 @@ void main() { mat3 cov3D = RS * transpose(RS); // Compute the Jacobian of the splat's projection at its center - vec2 scaledRenderSize = renderSize * renderScale; + vec2 scaledRenderSize = renderSize * focalAdjustment; vec2 focal = 0.5 * scaledRenderSize * vec2(projectionMatrix[0][0], projectionMatrix[1][1]); float invZ = 1.0 / viewCenter.z; vec2 J1 = focal * invZ;