Skip to content

Commit 4fd0454

Browse files
authored
Replace premultipliedAlpha property with getter/setter (#331)
1 parent 033051e commit 4fd0454

1 file changed

Lines changed: 38 additions & 17 deletions

File tree

src/SparkRenderer.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,35 +227,41 @@ export interface SparkRendererOptions {
227227
* @default 3
228228
*/
229229
numLodFetchers?: number;
230-
/* Full-width angle in degrees of fixed foveation cone along the view direction
230+
/**
231+
* Full-width angle in degrees of fixed foveation cone along the view direction
231232
* with no foveation applied (full resolution, foveate=1.0). Set to 0 to disable.
232233
* @default 90.0
233234
*/
234235
coneFov0?: number;
235-
/* Full-width angle in degrees of fixed foveation cone along the view direction
236+
/**
237+
* Full-width angle in degrees of fixed foveation cone along the view direction
236238
* with reduced resolution specified by `coneFoveate`. Foveation will be applied
237239
* smoothly from 1.0 down to `coneFoveate` as you move outward from
238240
* `coneFov0` to `coneFov`. Set to 0 to disable.
239241
* @default 120.0
240242
*/
241243
coneFov?: number;
242-
/* Foveation scale to apply to LoD splats at the edge of coneFov. Foveation will
244+
/**
245+
* Foveation scale to apply to LoD splats at the edge of coneFov. Foveation will
243246
* be applied smoothly from `coneFoveate` down to `behindFoveate` as you move
244247
* outward from `coneFov` to 180 degrees (behind the viewer).
245248
* @default 0.4
246249
*/
247250
coneFoveate?: number;
248-
/* Foveation scale to apply to LoD splats behind the viewer. Setting this to 0.1
251+
/**
252+
* Foveation scale to apply to LoD splats behind the viewer. Setting this to 0.1
249253
* for example will result in splats 10x larger than inside the viewing frustum.
250254
* @default 0.2
251255
*/
252256
behindFoveate?: number;
253-
/* How many LoD splats to generate for raycasting
257+
/**
258+
* How many LoD splats to generate for raycasting
254259
* @default 10000-25000 iff default canvas target is used
255260
*/
256261
lodRaycast?: number;
257262
lodRaycastIntervalMs?: number;
258-
/* Configures an offline render target for the SparkRenderer (as opposed to
263+
/**
264+
* Configures an offline render target for the SparkRenderer (as opposed to
259265
* rendering to the canvas). This is useful for rendering environment maps,
260266
* additional viewpoints, or video frame rendering.
261267
* @default undefined
@@ -284,30 +290,36 @@ export interface SparkRendererOptions {
284290
*/
285291
superXY?: number;
286292
} & THREE.RenderTargetOptions;
287-
/* Extra uniform values to pass to the shader.
293+
/**
294+
* Extra uniform values to pass to the shader.
288295
* @default undefined = no extra uniforms
289296
*/
290297
extraUniforms?: Record<string, unknown>;
291-
/* Replace the default `splatVertex.glsl` splat shader with a custom one.
298+
/**
299+
* Replace the default `splatVertex.glsl` splat shader with a custom one.
292300
* @default undefined = use the default `splatVertex.glsl` shader
293301
*/
294302
vertexShader?: string;
295-
/* Replace the default `splatFragment.glsl` splat shader with a custom one.
303+
/**
304+
* Replace the default `splatFragment.glsl` splat shader with a custom one.
296305
* @default undefined = use the default `splatFragment.glsl` shader
297306
*/
298307
fragmentShader?: string;
299-
/* Set the splat shader material to be transparent which determines if the
308+
/**
309+
* Set the splat shader material to be transparent which determines if the
300310
* splats are rendered during the first opaque THREE.js render pass or the
301311
* second transparent render pass.
302312
* @default undefined = true
303313
*/
304314
transparent?: boolean;
305-
/* Set the splat shader material to enable depth testing which determines if the
315+
/**
316+
* Set the splat shader material to enable depth testing which determines if the
306317
* splats respect the Z depth buffer and blend with other opaque objects in the scene.
307318
* @default undefined = true
308319
*/
309320
depthTest?: boolean;
310-
/* Set the splat shader material to enable depth writing which determines if the
321+
/**
322+
* Set the splat shader material to enable depth writing which determines if the
311323
* splats write to the Z depth buffer. Note that enabling this may produce
312324
* undesirable results because most of the Gsplat is transparent.
313325
* @default undefined = false
@@ -316,10 +328,9 @@ export interface SparkRendererOptions {
316328
}
317329

318330
export class SparkRenderer extends THREE.Mesh {
319-
renderer: THREE.WebGLRenderer;
320-
premultipliedAlpha: boolean;
321-
material: THREE.ShaderMaterial;
322-
uniforms: ReturnType<typeof SparkRenderer.makeUniforms>;
331+
readonly renderer: THREE.WebGLRenderer;
332+
readonly material: THREE.ShaderMaterial;
333+
readonly uniforms: ReturnType<typeof SparkRenderer.makeUniforms>;
323334

324335
autoUpdate: boolean;
325336
preUpdate: boolean;
@@ -494,7 +505,6 @@ export class SparkRenderer extends THREE.Mesh {
494505
this.renderer = options.renderer;
495506
this.onDirty = options.onDirty;
496507
this.dirty = true;
497-
this.premultipliedAlpha = premultipliedAlpha;
498508
this.autoUpdate = options.autoUpdate ?? true;
499509
this.preUpdate = options.preUpdate ?? true;
500510

@@ -2067,4 +2077,15 @@ export class SparkRenderer extends THREE.Mesh {
20672077
"Only LoD-enabled PackedSplats and ExtSplats are supported",
20682078
);
20692079
}
2080+
2081+
get premultipliedAlpha(): boolean {
2082+
return this.material.premultipliedAlpha;
2083+
}
2084+
2085+
set premultipliedAlpha(value: boolean) {
2086+
if (this.material.premultipliedAlpha !== value) {
2087+
this.material.premultipliedAlpha = value;
2088+
this.material.needsUpdate = true;
2089+
}
2090+
}
20702091
}

0 commit comments

Comments
 (0)