@viggle/splat-engine-three 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -71,6 +71,7 @@ import {
71
71
  SplatPLYLoader,
72
72
  SplatQuality,
73
73
  SplatRelight,
74
+ SplatSOGLoader,
74
75
  SplatSPZLoader,
75
76
  SpriteLayerRenderer,
76
77
  SunLight,
@@ -140,7 +141,7 @@ import {
140
141
  setShareSplatResources,
141
142
  uninstallFetchInterceptor,
142
143
  validateShaderGLSL
143
- } from "./chunks/chunk-2GKWT24B.js";
144
+ } from "./chunks/chunk-NNGE5LDC.js";
144
145
  export {
145
146
  ALL_BODY_PARTS,
146
147
  Animation,
@@ -215,6 +216,7 @@ export {
215
216
  SplatPLYLoader,
216
217
  SplatQuality,
217
218
  SplatRelight,
219
+ SplatSOGLoader,
218
220
  SplatSPZLoader,
219
221
  SpriteLayerRenderer,
220
222
  SunLight,
@@ -399,7 +399,9 @@ export declare class Character {
399
399
  * animates in lockstep) but on `layerIds`. With the body occluded by real
400
400
  * objects, this copy is what shows through obstacles: give it a see-through
401
401
  * look with its own {@link Splat.setOpacity} or {@link Splat.setColorModifier}
402
- * (the PlayCanvas build's `applyOverlaySplatStyle` is not ported).
402
+ * (the PlayCanvas build's `applyOverlaySplatStyle` is not ported). It
403
+ * writes no depth under {@link SplatQuality.depthWriteAlpha}, so it never
404
+ * hides what it is meant to show through.
403
405
  * Synchronous: reuses the decoded data.
404
406
  */
405
407
  addOverlaySplat(layerIds: number[]): Splat;
@@ -111,8 +111,9 @@ export declare class Environment {
111
111
  /**
112
112
  * Fetch, decode and add an environment splat.
113
113
  *
114
- * Reads uncompressed 3D Gaussian Splatting `.ply`, `.spz` (versions 1 to
115
- * 4), and SOG (a `.sog` bundle or an unbundled `meta.json`). The format is
114
+ * Reads 3D Gaussian Splatting `.ply` (uncompressed, or PlayCanvas's
115
+ * `.compressed.ply`), `.spz` (versions 1 to 4), and SOG (a `.sog` bundle or
116
+ * an unbundled `meta.json`). The format is
116
117
  * told by the file name: pass `filename` when the URL does not end in one.
117
118
  * `.spz` and SOG decode in a worker.
118
119
  *
@@ -19,6 +19,7 @@ export { Mat4, Quat, Vec3 } from './math';
19
19
  export { Environment } from './environment';
20
20
  export type { LoadEnvironmentOptions, LoadLodBundleOptions } from './environment';
21
21
  export { SplatSPZLoader } from './three/spz-loader';
22
+ export { SplatSOGLoader } from './three/sog-loader';
22
23
  export { decodeSplatFile, loadSplatAsset, loadSplatSource, setShareSplatResources } from './loader/shared/asset-loader';
23
24
  export { decodeSpz } from './loader/environment/spz';
24
25
  export { Splat } from './splat/splat';
@@ -0,0 +1,40 @@
1
+ /**
2
+ * PlayCanvas's quantised `.compressed.ply` - the layout SuperSplat and
3
+ * splat-transform write, and the PlayCanvas build reads natively:
4
+ *
5
+ * - `element chunk` - one per 256 splats, float ranges: `min_x/y/z`,
6
+ * `max_x/y/z`, `min_scale_x/y/z`, `max_scale_x/y/z`, and optionally
7
+ * `min_r/g/b`, `max_r/g/b`.
8
+ * - `element vertex` - four `uint`s per splat: `packed_position` (11/10/11
9
+ * unorm, within the chunk's range), `packed_rotation` (2-bit largest
10
+ * component + three 10-bit smallest components), `packed_scale` (11/10/11
11
+ * unorm log-scale, within the chunk's range), `packed_color` (8888 unorm:
12
+ * colour, within the chunk's colour range when it has one, and opacity).
13
+ * - `element sh` (optional) - `uchar f_rest_*`; skipped, as for the float
14
+ * PLY: splats here are lit flat, by their DC colour.
15
+ *
16
+ * Decoded into the same {@link SplatAttributes} the float PLY gives, with the
17
+ * arithmetic of PlayCanvas's `GSplatCompressedData.decompress`, so both builds
18
+ * draw the same splats from the same file.
19
+ */
20
+ import type { SplatAttributes } from '../character/types';
21
+ /**
22
+ * Whether a PLY header (the text before `end_header`) declares the
23
+ * compressed layout: a `chunk` element and a `vertex` element of packed
24
+ * `uint`s. Told by the header, not the file name, so a compressed file
25
+ * renamed to plain `.ply` still reads.
26
+ */
27
+ export declare function isCompressedPlyHeader(header: string): boolean;
28
+ /**
29
+ * Decode a `.compressed.ply` into float splat attributes.
30
+ *
31
+ * @param file - The whole file.
32
+ * @param headerText - The header up to (not including) `end_header`.
33
+ * @param dataStart - Byte offset of the first element's data.
34
+ * @throws If the file is not binary little-endian, lacks a property the layout needs, or is truncated.
35
+ * @internal Reached through {@link parseGaussianPly}, which recognises the layout.
36
+ */
37
+ export declare function parseCompressedPly(file: ArrayBuffer, headerText: string, dataStart: number): {
38
+ numSplats: number;
39
+ splats: SplatAttributes;
40
+ };
@@ -8,6 +8,9 @@ import type { SplatAttributes } from '../character/types';
8
8
  * Higher-order SH (`f_rest_*`) and normals are skipped: splats here are lit
9
9
  * flat, by their DC colour.
10
10
  *
11
+ * PlayCanvas's quantised `.compressed.ply` (SuperSplat / splat-transform) is
12
+ * read too, recognised from its header, and decoded to the same attributes.
13
+ *
11
14
  * @throws If the file is not a binary little-endian PLY, or lacks a required property.
12
15
  */
13
16
  export declare function parseGaussianPly(file: ArrayBuffer): {
@@ -45,8 +45,9 @@ export declare function sharedDecode<T>(kind: string, url: string, decode: () =>
45
45
  */
46
46
  export declare function decodeSplatFile(data: ArrayBuffer, filename: string): Promise<SplatSource>;
47
47
  /**
48
- * Fetch and decode a splat file: `.ply` (uncompressed 3D Gaussian Splatting),
49
- * `.spz` (versions 1-4), `.sog`, or an unbundled SOG's `meta.json`.
48
+ * Fetch and decode a splat file: `.ply` (uncompressed 3D Gaussian Splatting,
49
+ * or PlayCanvas's `.compressed.ply`), `.spz` (versions 1-4), `.sog`, or an
50
+ * unbundled SOG's `meta.json`.
50
51
  *
51
52
  * The bytes go through the asset cache (`cachedFetch`). With
52
53
  * {@link setShareSplatResources} on, repeated loads of one file share one decode.
@@ -5,8 +5,13 @@
5
5
  * the decode worker's (`sog-decode.ts`).
6
6
  */
7
7
  import type { PackedSplats } from '../../splat/packed-splats';
8
+ import type { SogMeta } from './sog-decode';
8
9
  /** `url` resolved against `base`, itself resolved against the page. */
9
10
  export declare function resolveUrl(url: string, base: string): string;
11
+ /** Decode a SOG's images, given in {@link sogImageFiles} order, in the decode worker. */
12
+ export declare function decodeImages(meta: SogMeta, images: Uint8Array[]): Promise<PackedSplats>;
13
+ /** The image files a DC-only decode reads, in `SogPixels` order. */
14
+ export declare function imageFiles(meta: SogMeta): string[];
10
15
  /**
11
16
  * Fetch and decode an unbundled SOG from its `meta.json`; the images are
12
17
  * fetched from beside it. Higher SH bands (`shN`) are not fetched: splats here
@@ -15,6 +15,12 @@ import type { Splat } from './splat';
15
15
  export interface SplatRenderImpl {
16
16
  readonly geometry: BufferGeometry;
17
17
  readonly material: Material;
18
+ /**
19
+ * The depth-only material of {@link SplatQuality.depthWriteAlpha}: drawn as
20
+ * a second group of the same geometry, in the transparent list straight
21
+ * after {@link material}. Its uniforms are kept current by {@link beforeRender}.
22
+ */
23
+ readonly depthMaterial: Material;
18
24
  /**
19
25
  * Whether the splat's centres must be re-skinned on the CPU every frame.
20
26
  * True when the depth sort runs on the CPU; false when the GPU skins for its
@@ -36,7 +42,10 @@ export interface SplatRenderImpl {
36
42
  syncVariantGroups(): void;
37
43
  /** Rebind the relight inputs after {@link Splat.setRelightBinding} swapped one binding for another. */
38
44
  syncRelight(): void;
39
- /** Called from the host mesh's `onBeforeRender`, once per draw. */
45
+ /**
46
+ * Called from the host mesh's `onBeforeRender`: once per frame, before
47
+ * whichever of the two draws comes first.
48
+ */
40
49
  beforeRender(renderer: unknown, camera: Camera): void;
41
50
  /** Release GPU resources. The splat's own textures are not this object's to free. */
42
51
  dispose(): void;
@@ -116,6 +116,49 @@ export declare const SplatQuality: {
116
116
  * application wants - a character deliberately drawn over the scene.
117
117
  */
118
118
  depthOcclusion: boolean;
119
+ /**
120
+ * Alpha at which a splat writes depth, so that a splat object drawn later
121
+ * is hidden behind the solid parts of one drawn earlier. `0` (the default)
122
+ * writes no depth: the behaviour before this setting existed.
123
+ *
124
+ * Every splat object is sorted and drawn on its own, so where two of them
125
+ * overlap - a weapon in a hand, two fighters in a clinch, a character
126
+ * behind a prop - whichever draws second paints over the other across the
127
+ * whole overlap, whatever is really in front. The PlayCanvas build sorts
128
+ * every splat on a layer together and does not have the problem. With this
129
+ * on, each splat object follows its colour draw with a depth-only draw of
130
+ * its solid parts: the fragments of single splats whose alpha (the
131
+ * gaussian's falloff times the splat's opacity) reaches this value. An
132
+ * object drawn after it depth-tests against that, so its parts behind the
133
+ * first object's solid parts are hidden; its parts in front paint over it,
134
+ * as they should. An object never tests against its own depth, so one that
135
+ * overlaps nothing draws exactly as it did.
136
+ *
137
+ * `0.1`-`0.2` came closest to the PlayCanvas build in the A/B suite's
138
+ * overlap cases (a staff through a hand). Lower, the faint edges of the
139
+ * first object hide the second; higher, too little of a character is solid
140
+ * enough to hide anything.
141
+ *
142
+ * What it costs:
143
+ * - A second, depth-only draw of every splat object. Its quads are cut to
144
+ * where a splat is above this alpha, so the fragments are few; the vertex
145
+ * work, which under WebGL includes the skinning, is paid twice.
146
+ * - Where the first object is faint but above this alpha, it hides the
147
+ * second outright instead of letting it show through: a harder edge
148
+ * where the two overlap.
149
+ * - Where the first object is fainter than this alpha, the second still
150
+ * paints over it, as before.
151
+ * - The alpha is taken after {@link Splat.setOpacity}, so an object fading
152
+ * out keeps hiding what is behind it at its cores until its opacity
153
+ * falls below this value. Opt a fading object out with its own
154
+ * {@link Splat.depthWriteAlpha} for the fade.
155
+ * - Splats now hide whatever draws after them in depth: transparent meshes
156
+ * and particles behind a character, and post-processing that reads the
157
+ * depth buffer sees them.
158
+ *
159
+ * Read per frame. A splat's own {@link Splat.depthWriteAlpha} overrides it.
160
+ */
161
+ depthWriteAlpha: number;
119
162
  /**
120
163
  * Collect {@link SplatQuality.timings}. Off by default.
121
164
  *
@@ -158,6 +201,8 @@ export declare const SplatQuality: {
158
201
  /** Restore every knob to its default. Call when tearing the engine down. */
159
202
  resetStatics(): void;
160
203
  };
204
+ /** The depth-write alpha for one splat: its own setting, or else the global one. `0` is off. */
205
+ export declare function effectiveDepthWriteAlpha(splatAlpha: number | null): number;
161
206
  /** The effective sub-pixel cull for one splat: its own floor or the global one. */
162
207
  export declare function effectiveMinPixelSize(splatMinPixelSize: number): number;
163
208
  /**
@@ -32,6 +32,8 @@ export declare class SplatMesh extends Mesh {
32
32
  private readonly _engine;
33
33
  private readonly _asyncSort;
34
34
  private _impl;
35
+ /** Set by the first of this frame's two draws, which prepared it, for the second. */
36
+ private _prepared;
35
37
  /**
36
38
  * @param asyncSort - See {@link SplatBackend.createImpl}.
37
39
  * @internal Construct a {@link Splat} instead; it creates its own mesh.
@@ -48,7 +50,18 @@ export declare class SplatMesh extends Mesh {
48
50
  syncBoneData(): void;
49
51
  syncVariantGroups(): void;
50
52
  syncRelight(): void;
51
- onBeforeRender(renderer: unknown, _scene: unknown, camera: Camera): void;
53
+ onBeforeRender(renderer: unknown, _scene: unknown, camera: Camera, _geometry?: unknown, material?: unknown): void;
54
+ /**
55
+ * Draw the depth group from the next frame on when this splat writes
56
+ * depth, and only the colour group when it does not. The render list for
57
+ * this frame is already made.
58
+ *
59
+ * Both groups are transparent, so they draw in the transparent list one
60
+ * after the other: three.js sorts by render order, then depth, then object,
61
+ * and keeps a group's order within that. The depth this object writes is
62
+ * there for the splat objects drawn after it, never for its own colour.
63
+ */
64
+ private _syncDepthWrite;
52
65
  /**
53
66
  * A second mesh drawing the same splat data, at the same transform. The
54
67
  * decoded data is shared; the GPU copy of it is not.
@@ -102,6 +102,12 @@ export declare class Splat {
102
102
  readonly localBounds: Box3;
103
103
  /** Discard splats smaller than this many pixels on screen. `0` draws everything. */
104
104
  minPixelSize: number;
105
+ /**
106
+ * This splat's own {@link SplatQuality.depthWriteAlpha}: the alpha above which
107
+ * it writes depth. `null` (the default) follows the global setting; `0`
108
+ * never writes depth, whatever the global one says.
109
+ */
110
+ depthWriteAlpha: number | null;
105
111
  private _activeSplatCount;
106
112
  private _importanceOrder;
107
113
  /** `_importanceOrder` inverted: each splat's place in it. @internal */
@@ -3,4 +3,4 @@
3
3
  * where given. See SplatColorModifier.
4
4
  */
5
5
  export declare function splatVertexGLSL(colorModifier?: string): string;
6
- export declare const SPLAT_FRAGMENT_GLSL = "\nprecision highp float;\n\nin mediump vec2 gaussianUV;\nin mediump vec4 gaussianColor;\n\nlayout(location = 0) out highp vec4 fragColor;\n\nconst float EXP4 = exp(-4.0);\nconst float INV_EXP4 = 1.0 / (1.0 - EXP4);\n\n// exp(-4x) rescaled to hit exactly 0 at the quad edge (x = 1).\nfloat normExp(float x) {\n return (exp(x * -4.0) - EXP4) * INV_EXP4;\n}\n\nvoid main(void) {\n mediump float A = dot(gaussianUV, gaussianUV);\n if (A > 1.0) {\n discard;\n }\n mediump float alpha = normExp(A) * gaussianColor.a;\n if (alpha < 1.0 / 255.0) {\n discard;\n }\n // Premultiplied.\n fragColor = vec4(gaussianColor.rgb * alpha, alpha);\n}\n";
6
+ export declare const SPLAT_FRAGMENT_GLSL = "\nprecision highp float;\n\nin mediump vec2 gaussianUV;\nin mediump vec4 gaussianColor;\n\nlayout(location = 0) out highp vec4 fragColor;\n\n#ifdef DEPTH_ONLY\n// SplatQuality.depthWriteAlpha: the alpha at which a fragment writes depth.\nuniform float uDepthAlpha;\n#endif\n\nconst float EXP4 = exp(-4.0);\nconst float INV_EXP4 = 1.0 / (1.0 - EXP4);\n\n// exp(-4x) rescaled to hit exactly 0 at the quad edge (x = 1).\nfloat normExp(float x) {\n return (exp(x * -4.0) - EXP4) * INV_EXP4;\n}\n\nvoid main(void) {\n mediump float A = dot(gaussianUV, gaussianUV);\n if (A > 1.0) {\n discard;\n }\n mediump float alpha = normExp(A) * gaussianColor.a;\n #ifdef DEPTH_ONLY\n if (alpha < uDepthAlpha) {\n discard;\n }\n fragColor = vec4(0.0);\n #else\n if (alpha < 1.0 / 255.0) {\n discard;\n }\n // Premultiplied.\n fragColor = vec4(gaussianColor.rgb * alpha, alpha);\n #endif\n}\n";
@@ -15,6 +15,7 @@ import type { Splat } from '../splat';
15
15
  export declare class WebGLSplatImpl implements SplatRenderImpl {
16
16
  readonly geometry: InstancedBufferGeometry;
17
17
  readonly material: RawShaderMaterial;
18
+ readonly depthMaterial: RawShaderMaterial;
18
19
  /** The depth sort runs on the CPU, so it needs CPU-side centres. */
19
20
  readonly needsCpuCenters = true;
20
21
  private readonly _host;
@@ -29,6 +29,7 @@ export declare const MAX_VARIANT_GROUPS = 64;
29
29
  export declare class WebGPUSplatImpl implements SplatRenderImpl {
30
30
  readonly geometry: InstancedBufferGeometry;
31
31
  readonly material: NodeMaterial;
32
+ readonly depthMaterial: NodeMaterial;
32
33
  /** Skinning for the sort happens in compute; the CPU never touches a splat. */
33
34
  readonly needsCpuCenters = false;
34
35
  private readonly _host;
@@ -55,8 +55,10 @@ export declare class SplatClipLoader extends SplatLoaderBase<Animation> {
55
55
  parseAsync(data: ArrayBuffer, name?: string): Promise<Animation>;
56
56
  }
57
57
  /**
58
- * Loads an uncompressed 3D Gaussian Splatting `.ply` as a static
59
- * {@link SplatMesh} - an environment, a prop, a scanned object.
58
+ * Loads a 3D Gaussian Splatting `.ply` as a static {@link SplatMesh} - an
59
+ * environment, a prop, a scanned object. Reads the uncompressed layout and
60
+ * PlayCanvas's quantised `.compressed.ply` (SuperSplat / splat-transform),
61
+ * told apart by the file's header.
60
62
  *
61
63
  * ```ts
62
64
  * const room = await new SplatPLYLoader().loadAsync('/assets/room.ply');
@@ -0,0 +1,50 @@
1
+ import { Loader } from 'three';
2
+ import type { LoadingManager } from 'three';
3
+ import { SplatEngine } from '../engine';
4
+ import type { SplatMesh } from '../splat/splat-mesh';
5
+ /**
6
+ * Loads a SOG Gaussian-splat scene - a `.sog` bundle, or an unbundled
7
+ * `meta.json` with its WebP images beside it, as splat-transform writes
8
+ * either - as a static {@link SplatMesh}, the way {@link SplatPLYLoader}
9
+ * loads a `.ply`.
10
+ *
11
+ * ```ts
12
+ * const room = await new SplatSOGLoader().loadAsync('/assets/room.sog');
13
+ * scene.add(room);
14
+ *
15
+ * // Unbundled: the images are fetched from beside the meta.json.
16
+ * const hall = await new SplatSOGLoader().setPath('/assets/hall/').loadAsync('meta.json');
17
+ * ```
18
+ *
19
+ * Every file is fetched through a `FileLoader`, so the `LoadingManager`
20
+ * (including its URL modifier), base path, request headers and credentials
21
+ * mode apply to the images of an unbundled scene as well. The images decode
22
+ * in a worker. Higher SH bands (`shN`) are not fetched: splats here are lit
23
+ * by their DC colour. The mesh is given `renderOrder = -1` so it draws before
24
+ * characters, as {@link SplatPLYLoader}'s is.
25
+ *
26
+ * SOG stores the axes splat-transform wrote and none are changed here; turn
27
+ * a Y-down capture upright with `mesh.rotation.x = Math.PI`.
28
+ *
29
+ * @group Loaders
30
+ */
31
+ export declare class SplatSOGLoader extends Loader<SplatMesh> {
32
+ /**
33
+ * The engine loaded meshes belong to: the lights they respond to. Leave
34
+ * unset to use {@link SplatEngine.shared}.
35
+ */
36
+ engine: SplatEngine | null;
37
+ constructor(manager?: LoadingManager);
38
+ setEngine(engine: SplatEngine | null): this;
39
+ /**
40
+ * Decode a `.sog` bundle already in memory. `name` labels the mesh; for a
41
+ * loaded file it is the file's base name. An unbundled `meta.json` cannot
42
+ * be parsed this way, since its images are separate files: {@link load} it.
43
+ */
44
+ parseAsync(data: ArrayBuffer, name?: string): Promise<SplatMesh>;
45
+ load(url: string, onLoad: (result: SplatMesh) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): void;
46
+ private _loadMeta;
47
+ /** A `FileLoader` carrying this loader's manager, headers and credentials mode. */
48
+ private _fileLoader;
49
+ private _toMesh;
50
+ }
package/dist/webgpu.js CHANGED
@@ -71,6 +71,7 @@ import {
71
71
  SplatPLYLoader,
72
72
  SplatQuality,
73
73
  SplatRelight,
74
+ SplatSOGLoader,
74
75
  SplatSPZLoader,
75
76
  SpriteLayerRenderer,
76
77
  SunLight,
@@ -115,6 +116,7 @@ import {
115
116
  decodeSpz,
116
117
  defaultLayerRegistry,
117
118
  defaultProxySettings,
119
+ effectiveDepthWriteAlpha,
118
120
  effectiveMinPixelSize,
119
121
  evictExpired,
120
122
  extractSurface,
@@ -150,7 +152,7 @@ import {
150
152
  setShareSplatResources,
151
153
  uninstallFetchInterceptor,
152
154
  validateShaderGLSL
153
- } from "./chunks/chunk-2GKWT24B.js";
155
+ } from "./chunks/chunk-NNGE5LDC.js";
154
156
 
155
157
  // src/webgpu.ts
156
158
  import { WebGPURenderer } from "three/webgpu";
@@ -652,6 +654,7 @@ import {
652
654
  InstancedBufferGeometry,
653
655
  Matrix3,
654
656
  Matrix4,
657
+ NoBlending as NoBlending2,
655
658
  NodeMaterial as NodeMaterial4,
656
659
  Quaternion,
657
660
  SRGBColorSpace,
@@ -833,6 +836,7 @@ var INPUT_SLOTS = 100;
833
836
  var WebGPUSplatImpl = class {
834
837
  geometry;
835
838
  material;
839
+ depthMaterial;
836
840
  /** Skinning for the sort happens in compute; the CPU never touches a splat. */
837
841
  needsCpuCenters = false;
838
842
  _host;
@@ -889,6 +893,10 @@ var WebGPUSplatImpl = class {
889
893
  // two expressions it feeds reduce to what they were before the cutoff was
890
894
  // a setting. See SplatQuality.quadAlphaCutoff.
891
895
  alphaCutoffScale: uniform5(255),
896
+ // The depth write (SplatQuality.depthWriteAlpha): 1 / its alpha, which
897
+ // its quads are cut to, and the alpha itself, which a fragment must reach.
898
+ depthCutoffScale: uniform5(0),
899
+ depthAlpha: uniform5(2),
892
900
  // x: far depth, y: 1 / (far - near), along the view axis.
893
901
  sortRange: uniform5(new Vector23(1, 1)),
894
902
  tint: uniform5(new Vector44(1, 1, 1, 0)),
@@ -927,8 +935,19 @@ var WebGPUSplatImpl = class {
927
935
  material.forceSinglePass = true;
928
936
  material.premultipliedAlpha = true;
929
937
  material.fog = false;
938
+ const depth = new NodeMaterial4();
939
+ depth.name = "SplatDepthWrite";
940
+ depth.transparent = true;
941
+ depth.depthTest = true;
942
+ depth.depthWrite = true;
943
+ depth.colorWrite = false;
944
+ depth.blending = NoBlending2;
945
+ depth.side = DoubleSide;
946
+ depth.forceSinglePass = true;
947
+ depth.fog = false;
930
948
  this.geometry = geometry;
931
949
  this.material = material;
950
+ this.depthMaterial = depth;
932
951
  this._host = host;
933
952
  this._splat = splat;
934
953
  this._lighting = lighting;
@@ -1334,8 +1353,8 @@ var WebGPUSplatImpl = class {
1334
1353
  workWrite.element(slot).assign(select(culled, vec43(0, 0, 2, 1), centerProj));
1335
1354
  workWrite.element(slot.add(1)).assign(select(culled, vec43(0), vec43(v1, v2)));
1336
1355
  workWrite.element(slot.add(2)).assign(vec43(rgb, select(culled, float4(0), alpha)));
1337
- const depth = (cutOn ? u.view.mul(u.model.mul(vec43(sortCenter, 1))).z : centerView.z).negate();
1338
- const normalized = clamp2(u.sortRange.x.sub(depth).mul(u.sortRange.y), 0, 1);
1356
+ const depth2 = (cutOn ? u.view.mul(u.model.mul(vec43(sortCenter, 1))).z : centerView.z).negate();
1357
+ const normalized = clamp2(u.sortRange.x.sub(depth2).mul(u.sortRange.y), 0, 1);
1339
1358
  const key = uint2(normalized.mul(SORT_BINS - 1)).toVar();
1340
1359
  sort.keysWrite.element(instanceIndex2).assign(key);
1341
1360
  sort.countFirstDigit(instanceIndex2, key);
@@ -1346,33 +1365,44 @@ var WebGPUSplatImpl = class {
1346
1365
  this._buildId++;
1347
1366
  const workRead = storage2(workAttribute, "vec4", count * 3).toReadOnly();
1348
1367
  const orderRead = sort.orderRead;
1349
- const gaussianUV = varyingProperty("vec2", "vGaussianUV");
1350
- const gaussianColor = varyingProperty("vec4", "vGaussianColor");
1368
+ const drawNodes = (cutoffScale, minAlpha) => {
1369
+ const gaussianUV = varyingProperty("vec2", "vGaussianUV");
1370
+ const gaussianColor = varyingProperty("vec4", "vGaussianColor");
1371
+ const vertex = Fn4(() => {
1372
+ const slot = orderRead.element(instanceIndex2).mul(3).toVar();
1373
+ const centerProj = workRead.element(slot).toVar();
1374
+ const axes = workRead.element(slot.add(1)).toVar();
1375
+ const shade = workRead.element(slot.add(2)).toVar();
1376
+ const clip = min(float4(1), sqrt2(log(max2(shade.w.mul(cutoffScale), 1))).mul(0.5)).toVar();
1377
+ const corner = positionGeometry.xy.toVar();
1378
+ const offset = axes.xy.mul(corner.x).add(axes.zw.mul(corner.y)).mul(clip);
1379
+ gaussianUV.assign(corner.mul(clip));
1380
+ gaussianColor.assign(shade);
1381
+ return centerProj.add(vec43(offset, 0, 0));
1382
+ })();
1383
+ const color = Fn4(() => {
1384
+ const A = dot2(gaussianUV, gaussianUV).toVar();
1385
+ If3(A.greaterThan(1), () => {
1386
+ Discard();
1387
+ });
1388
+ const alpha = exp(A.mul(-4)).sub(EXP4).mul(INV_EXP4).mul(gaussianColor.w).toVar();
1389
+ If3(alpha.lessThan(minAlpha), () => {
1390
+ Discard();
1391
+ });
1392
+ return vec43(gaussianColor.xyz, alpha);
1393
+ })();
1394
+ return { vertex, color };
1395
+ };
1396
+ const draw = drawNodes(u.alphaCutoffScale, 1 / 255);
1351
1397
  const material = this.material;
1352
- material.vertexNode = Fn4(() => {
1353
- const slot = orderRead.element(instanceIndex2).mul(3).toVar();
1354
- const centerProj = workRead.element(slot).toVar();
1355
- const axes = workRead.element(slot.add(1)).toVar();
1356
- const shade = workRead.element(slot.add(2)).toVar();
1357
- const clip = min(float4(1), sqrt2(log(max2(shade.w.mul(u.alphaCutoffScale), 1))).mul(0.5)).toVar();
1358
- const corner = positionGeometry.xy.toVar();
1359
- const offset = axes.xy.mul(corner.x).add(axes.zw.mul(corner.y)).mul(clip);
1360
- gaussianUV.assign(corner.mul(clip));
1361
- gaussianColor.assign(shade);
1362
- return centerProj.add(vec43(offset, 0, 0));
1363
- })();
1364
- material.colorNode = Fn4(() => {
1365
- const A = dot2(gaussianUV, gaussianUV).toVar();
1366
- If3(A.greaterThan(1), () => {
1367
- Discard();
1368
- });
1369
- const alpha = exp(A.mul(-4)).sub(EXP4).mul(INV_EXP4).mul(gaussianColor.w).toVar();
1370
- If3(alpha.lessThan(1 / 255), () => {
1371
- Discard();
1372
- });
1373
- return vec43(gaussianColor.xyz, alpha);
1374
- })();
1398
+ material.vertexNode = draw.vertex;
1399
+ material.colorNode = draw.color;
1375
1400
  material.needsUpdate = true;
1401
+ const depthDraw = drawNodes(u.depthCutoffScale, u.depthAlpha);
1402
+ const depth = this.depthMaterial;
1403
+ depth.vertexNode = depthDraw.vertex;
1404
+ depth.colorNode = depthDraw.color;
1405
+ depth.needsUpdate = true;
1376
1406
  }
1377
1407
  beforeRender(renderer, camera) {
1378
1408
  if (!SplatQuality.passTimings) {
@@ -1428,7 +1458,11 @@ var WebGPUSplatImpl = class {
1428
1458
  u.alphaCutoffScale.value = 1 / Math.max(1 / 65535, SplatQuality.quadAlphaCutoff);
1429
1459
  if (this.material.depthTest !== SplatQuality.depthOcclusion) {
1430
1460
  this.material.depthTest = SplatQuality.depthOcclusion;
1461
+ this.depthMaterial.depthTest = SplatQuality.depthOcclusion;
1431
1462
  }
1463
+ const depthAlpha = effectiveDepthWriteAlpha(splat.depthWriteAlpha);
1464
+ u.depthCutoffScale.value = depthAlpha > 0 ? 1 / depthAlpha : 0;
1465
+ u.depthAlpha.value = depthAlpha > 0 ? depthAlpha : 2;
1432
1466
  u.tint.value.copy(splat.tint);
1433
1467
  u.grade.value.copy(splat.grade);
1434
1468
  u.effects.value.copy(splat.effects);
@@ -1526,6 +1560,7 @@ var WebGPUSplatImpl = class {
1526
1560
  dispose() {
1527
1561
  this.geometry.dispose();
1528
1562
  this.material.dispose();
1563
+ this.depthMaterial.dispose();
1529
1564
  this._retired.push({ nodes: [...this._projectNodes, ...this._sortNodes], buffers: this._buffers });
1530
1565
  this._projectNodes = [];
1531
1566
  this._sortNodes = [];
@@ -1752,6 +1787,7 @@ export {
1752
1787
  SplatPLYLoader,
1753
1788
  SplatQuality,
1754
1789
  SplatRelight,
1790
+ SplatSOGLoader,
1755
1791
  SplatSPZLoader,
1756
1792
  SpriteLayerRenderer,
1757
1793
  SunLight,