@luma.gl/engine 10.0.0-beta.2 → 10.0.0-beta.4
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/arrow/index.cjs.map +1 -1
- package/dist/arrow/renderers/path/transforms/gpu-path-float64-deltas.cjs +1 -0
- package/dist/arrow/renderers/path/transforms/gpu-path-float64-deltas.d.ts.map +1 -1
- package/dist/arrow/renderers/path/transforms/gpu-path-float64-deltas.js +1 -0
- package/dist/arrow/renderers/path/transforms/gpu-path-float64-deltas.js.map +1 -1
- package/dist/dist.dev.js +57 -2
- package/dist/dist.min.js +64 -50
- package/dist/gltf/gltf/create-composed-scenegraphs-from-gltf.cjs +80 -0
- package/dist/gltf/gltf/create-composed-scenegraphs-from-gltf.d.ts +28 -0
- package/dist/gltf/gltf/create-composed-scenegraphs-from-gltf.d.ts.map +1 -0
- package/dist/gltf/gltf/create-composed-scenegraphs-from-gltf.js +74 -0
- package/dist/gltf/gltf/create-composed-scenegraphs-from-gltf.js.map +1 -0
- package/dist/gltf/gltf/create-scenegraph-from-gltf.cjs +13 -4
- package/dist/gltf/gltf/create-scenegraph-from-gltf.d.ts.map +1 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.js +11 -0
- package/dist/gltf/gltf/create-scenegraph-from-gltf.js.map +1 -1
- package/dist/gltf/gltf/gltf-skin.cjs +1 -1
- package/dist/gltf/gltf/gltf-skin.js +2 -2
- package/dist/gltf/gltf/gltf-skin.js.map +1 -1
- package/dist/gltf/index.cjs +3 -0
- package/dist/gltf/index.cjs.map +3 -3
- package/dist/gltf/index.d.ts +1 -0
- package/dist/gltf/index.d.ts.map +1 -1
- package/dist/gltf/index.js +1 -0
- package/dist/gltf/index.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-joints.cjs +8 -1
- package/dist/gltf/parsers/parse-gltf-joints.d.ts +1 -0
- package/dist/gltf/parsers/parse-gltf-joints.d.ts.map +1 -1
- package/dist/gltf/parsers/parse-gltf-joints.js +8 -1
- package/dist/gltf/parsers/parse-gltf-joints.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-physics-pointer.cjs +1 -1
- package/dist/gltf/parsers/parse-gltf-physics-pointer.js +1 -1
- package/dist/gltf/parsers/parse-gltf-physics-pointer.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf.cjs +2 -1
- package/dist/gltf/parsers/parse-gltf.d.ts +2 -0
- package/dist/gltf/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/gltf/parsers/parse-gltf.js +3 -1
- package/dist/gltf/parsers/parse-gltf.js.map +1 -1
- package/dist/gltf/physics/export-state.cjs +115 -14
- package/dist/gltf/physics/export-state.d.ts +9 -2
- package/dist/gltf/physics/export-state.d.ts.map +1 -1
- package/dist/gltf/physics/export-state.js +171 -18
- package/dist/gltf/physics/export-state.js.map +1 -1
- package/dist/gltf/physics/index.cjs.map +1 -1
- package/dist/gltf/physics/index.d.ts +1 -1
- package/dist/gltf/physics/index.d.ts.map +1 -1
- package/dist/gltf/physics/index.js.map +1 -1
- package/dist/gltf/physics/parse-gltf-physics.cjs +11 -8
- package/dist/gltf/physics/parse-gltf-physics.d.ts.map +1 -1
- package/dist/gltf/physics/parse-gltf-physics.js +6 -2
- package/dist/gltf/physics/parse-gltf-physics.js.map +1 -1
- package/dist/gltf/physics/physics-types.d.ts +4 -0
- package/dist/gltf/physics/physics-types.d.ts.map +1 -1
- package/dist/gltf/physics/property-bindings.cjs +5 -2
- package/dist/gltf/physics/property-bindings.d.ts.map +1 -1
- package/dist/gltf/physics/property-bindings.js +11 -2
- package/dist/gltf/physics/property-bindings.js.map +1 -1
- package/dist/gltf/types/gltf-postprocessed-schema.d.ts +4 -0
- package/dist/gltf/types/gltf-postprocessed-schema.d.ts.map +1 -1
- package/dist/gltf/types/gltf-types.d.ts +2 -0
- package/dist/gltf/types/gltf-types.d.ts.map +1 -1
- package/dist/graph/models/index.cjs.map +1 -1
- package/dist/graph/physics/index.cjs +3 -0
- package/dist/graph/physics/index.cjs.map +3 -3
- package/dist/graph/physics/index.d.ts +1 -0
- package/dist/graph/physics/index.d.ts.map +1 -1
- package/dist/graph/physics/index.js +1 -0
- package/dist/graph/physics/index.js.map +1 -1
- package/dist/graph/physics/scenegraph-joints.cjs +1 -0
- package/dist/graph/physics/scenegraph-joints.d.ts.map +1 -1
- package/dist/graph/physics/scenegraph-joints.js +1 -0
- package/dist/graph/physics/scenegraph-joints.js.map +1 -1
- package/dist/graph/physics/scenegraph-motion.cjs +25 -3
- package/dist/graph/physics/scenegraph-motion.d.ts +1 -1
- package/dist/graph/physics/scenegraph-motion.d.ts.map +1 -1
- package/dist/graph/physics/scenegraph-motion.js +27 -2
- package/dist/graph/physics/scenegraph-motion.js.map +1 -1
- package/dist/graph/physics/scenegraph-ragdoll.cjs +132 -0
- package/dist/graph/physics/scenegraph-ragdoll.d.ts +32 -0
- package/dist/graph/physics/scenegraph-ragdoll.d.ts.map +1 -0
- package/dist/graph/physics/scenegraph-ragdoll.js +117 -0
- package/dist/graph/physics/scenegraph-ragdoll.js.map +1 -0
- package/dist/graph/physics/scenegraph-session.cjs +2 -2
- package/dist/graph/physics/scenegraph-session.d.ts +4 -2
- package/dist/graph/physics/scenegraph-session.d.ts.map +1 -1
- package/dist/graph/physics/scenegraph-session.js +2 -2
- package/dist/graph/physics/scenegraph-session.js.map +1 -1
- package/dist/graph/tables/index.cjs.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lighting/index.cjs.map +1 -1
- package/dist/model/gpu-vector-model.cjs +2 -2
- package/dist/model/gpu-vector-model.d.ts.map +1 -1
- package/dist/model/gpu-vector-model.js +2 -1
- package/dist/model/gpu-vector-model.js.map +1 -1
- package/dist/scenegraph/controllers/joint-controller.d.ts +2 -0
- package/dist/scenegraph/controllers/joint-controller.d.ts.map +1 -1
- package/dist/scenegraph/controllers/joint-controller.js.map +1 -1
- package/dist/scenegraph/controllers/skin-controller.cjs +20 -1
- package/dist/scenegraph/controllers/skin-controller.d.ts +4 -0
- package/dist/scenegraph/controllers/skin-controller.d.ts.map +1 -1
- package/dist/scenegraph/controllers/skin-controller.js +21 -1
- package/dist/scenegraph/controllers/skin-controller.js.map +1 -1
- package/dist/shader-plugins/depth-interval.cjs +60 -0
- package/dist/shader-plugins/depth-interval.d.ts +10 -0
- package/dist/shader-plugins/depth-interval.d.ts.map +1 -0
- package/dist/shader-plugins/depth-interval.js +42 -0
- package/dist/shader-plugins/depth-interval.js.map +1 -0
- package/dist/splats/index.cjs.map +2 -2
- package/dist/splats/index.d.ts +1 -1
- package/dist/splats/index.d.ts.map +1 -1
- package/dist/splats/index.js.map +1 -1
- package/dist/splats/splat-picking.d.ts +2 -2
- package/dist/splats/splat-picking.d.ts.map +1 -1
- package/dist/splats/splat-renderer.cjs +51 -2
- package/dist/splats/splat-renderer.d.ts +15 -1
- package/dist/splats/splat-renderer.d.ts.map +1 -1
- package/dist/splats/splat-renderer.js +61 -2
- package/dist/splats/splat-renderer.js.map +1 -1
- package/dist/splats/splat-shaders.cjs +46 -3
- package/dist/splats/splat-shaders.d.ts +5 -3
- package/dist/splats/splat-shaders.d.ts.map +1 -1
- package/dist/splats/splat-shaders.js +42 -3
- package/dist/splats/splat-shaders.js.map +1 -1
- package/package.json +8 -8
- package/src/arrow/renderers/path/transforms/gpu-path-float64-deltas.ts +1 -0
- package/src/gltf/gltf/create-composed-scenegraphs-from-gltf.ts +100 -0
- package/src/gltf/gltf/create-scenegraph-from-gltf.ts +12 -0
- package/src/gltf/gltf/gltf-skin.ts +2 -2
- package/src/gltf/index.ts +5 -0
- package/src/gltf/parsers/parse-gltf-joints.ts +9 -2
- package/src/gltf/parsers/parse-gltf-physics-pointer.ts +1 -1
- package/src/gltf/parsers/parse-gltf.ts +6 -4
- package/src/gltf/physics/README.md +16 -0
- package/src/gltf/physics/export-state.ts +215 -18
- package/src/gltf/physics/index.ts +1 -1
- package/src/gltf/physics/parse-gltf-physics.ts +5 -2
- package/src/gltf/physics/physics-types.ts +4 -0
- package/src/gltf/physics/property-bindings.ts +10 -2
- package/src/gltf/types/gltf-postprocessed-schema.ts +4 -0
- package/src/gltf/types/gltf-types.ts +2 -0
- package/src/graph/physics/index.ts +1 -0
- package/src/graph/physics/scenegraph-joints.ts +1 -0
- package/src/graph/physics/scenegraph-motion.ts +29 -2
- package/src/graph/physics/scenegraph-ragdoll.ts +133 -0
- package/src/graph/physics/scenegraph-session.ts +5 -2
- package/src/index.ts +2 -0
- package/src/model/gpu-vector-model.ts +8 -2
- package/src/scenegraph/controllers/joint-controller.ts +2 -0
- package/src/scenegraph/controllers/skin-controller.ts +20 -1
- package/src/shader-plugins/depth-interval.ts +45 -0
- package/src/splats/README.md +10 -0
- package/src/splats/index.ts +1 -0
- package/src/splats/splat-renderer.ts +82 -2
- package/src/splats/splat-shaders.ts +48 -3
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Buffer, type CommandEncoder, type Device} from '@luma.gl/core';
|
|
6
|
+
import {Matrix4} from '@math.gl/core/matrix';
|
|
7
|
+
import {Computation} from '../../compute/computation';
|
|
8
|
+
import type {SkinBinding, SkinController} from '../../scenegraph/controllers/skin-controller';
|
|
9
|
+
import type {ScenegraphPhysicsPublication} from './scenegraph-publication';
|
|
10
|
+
|
|
11
|
+
/** Writes the same mesh-local matrices consumed by the standard skin shader. */
|
|
12
|
+
const PALETTE_SOURCE = /* wgsl */ `
|
|
13
|
+
@group(0) @binding(0) var<storage, read> bodyPoses: array<mat4x4<f32>>;
|
|
14
|
+
@group(0) @binding(1) var<storage, read> bodyIndices: array<u32>;
|
|
15
|
+
@group(0) @binding(2) var<storage, read> paletteTransforms: array<mat4x4<f32>>;
|
|
16
|
+
@group(0) @binding(3) var<storage, read_write> jointPalette: array<mat4x4<f32>>;
|
|
17
|
+
|
|
18
|
+
@compute @workgroup_size(32)
|
|
19
|
+
fn main(@builtin(global_invocation_id) invocation: vec3<u32>) {
|
|
20
|
+
let joint = invocation.x;
|
|
21
|
+
if (joint >= arrayLength(&bodyIndices)) { return; }
|
|
22
|
+
jointPalette[joint] = paletteTransforms[0] * bodyPoses[bodyIndices[joint]]
|
|
23
|
+
* paletteTransforms[joint + 1];
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
/** Connects a physics publication to an existing WebGPU skin palette. */
|
|
28
|
+
export class ScenegraphRagdoll {
|
|
29
|
+
/** One body index for each skin joint, in original palette order. */
|
|
30
|
+
private readonly indices: Buffer;
|
|
31
|
+
/** Inverse mesh transform followed by body-local joint and inverse bind transforms. */
|
|
32
|
+
private readonly transforms: Buffer;
|
|
33
|
+
/** Borrowed storage palette owned by the SkinController. */
|
|
34
|
+
private readonly palette: Buffer;
|
|
35
|
+
/** Compute pipeline used exclusively to transfer solved poses to this skin. */
|
|
36
|
+
private readonly computation: Computation;
|
|
37
|
+
/** Identifies the publication revision from which the joint mappings were built. */
|
|
38
|
+
private publication?: ScenegraphPhysicsPublication;
|
|
39
|
+
/** Releases exclusive GPU write access to the palette. */
|
|
40
|
+
private releasePalette?: () => void;
|
|
41
|
+
|
|
42
|
+
/** Use an existing skin and its WebGPU storage palette. The caller owns its physics session. */
|
|
43
|
+
constructor(
|
|
44
|
+
device: Device,
|
|
45
|
+
private readonly skins: SkinController,
|
|
46
|
+
private readonly binding: SkinBinding
|
|
47
|
+
) {
|
|
48
|
+
if (
|
|
49
|
+
device.type !== 'webgpu' ||
|
|
50
|
+
!(binding.skinJointMatrices instanceof Buffer) ||
|
|
51
|
+
!binding.joints.length ||
|
|
52
|
+
!skins.bindings.includes(binding)
|
|
53
|
+
) {
|
|
54
|
+
throw new Error('ScenegraphRagdoll requires a WebGPU storage skin palette');
|
|
55
|
+
}
|
|
56
|
+
this.palette = binding.skinJointMatrices;
|
|
57
|
+
this.computation = new Computation(device, {id: 'ragdoll-palette', source: PALETTE_SOURCE});
|
|
58
|
+
this.indices = device.createBuffer({
|
|
59
|
+
id: 'ragdoll-body-indices',
|
|
60
|
+
byteLength: binding.joints.length * 4,
|
|
61
|
+
usage: Buffer.STORAGE | Buffer.COPY_DST
|
|
62
|
+
});
|
|
63
|
+
this.transforms = device.createBuffer({
|
|
64
|
+
id: 'ragdoll-palette-transforms',
|
|
65
|
+
byteLength: (binding.joints.length + 1) * 64,
|
|
66
|
+
usage: Buffer.STORAGE | Buffer.COPY_DST
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Encode after physics and before drawing. Supply the full mesh matrix in the publication's origin-relative frame. */
|
|
71
|
+
encode(
|
|
72
|
+
encoder: CommandEncoder,
|
|
73
|
+
publication: ScenegraphPhysicsPublication,
|
|
74
|
+
meshWorldMatrix: Matrix4
|
|
75
|
+
): void {
|
|
76
|
+
if (publication !== this.publication) this.bindPublication(publication);
|
|
77
|
+
/** Only the authored mesh frame is uploaded each frame. The solved transforms stay on the GPU. */
|
|
78
|
+
const inverseMesh = new Float32Array(meshWorldMatrix.clone().invert());
|
|
79
|
+
this.transforms.write(inverseMesh);
|
|
80
|
+
this.computation.predraw(encoder);
|
|
81
|
+
/** Schedule palette generation after physics pose publication in the same command buffer. */
|
|
82
|
+
const pass = encoder.beginComputePass({id: 'ragdoll-skinning'});
|
|
83
|
+
this.computation.dispatch(pass, Math.ceil(this.binding.joints.length / 32));
|
|
84
|
+
pass.end();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Return palette control to the scenegraph animator before sampling a fresh animation pose. */
|
|
88
|
+
reset(): void {
|
|
89
|
+
this.releasePalette?.();
|
|
90
|
+
this.releasePalette = undefined;
|
|
91
|
+
this.publication = undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Release compute resources. Destroy the ragdoll before its shared skin controller. */
|
|
95
|
+
destroy(): void {
|
|
96
|
+
this.reset();
|
|
97
|
+
this.computation.destroy();
|
|
98
|
+
this.indices.destroy();
|
|
99
|
+
this.transforms.destroy();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Resolve joints through the same scenegraph publication used by rigid rendering. */
|
|
103
|
+
private bindPublication(publication: ScenegraphPhysicsPublication): void {
|
|
104
|
+
/** Authoring resolves each joint to its closest ancestor body and body-local frame. */
|
|
105
|
+
const indices = new Uint32Array(this.binding.joints.length);
|
|
106
|
+
/** Fold each inverse bind matrix into its body-local joint frame once per handoff. */
|
|
107
|
+
const transforms = new Float32Array(this.binding.joints.length * 16);
|
|
108
|
+
for (const [index, joint] of this.binding.joints.entries()) {
|
|
109
|
+
/** Bones and rigid joint attachment nodes remain distinct scenegraph objects. */
|
|
110
|
+
const target = publication.bindings.get(joint);
|
|
111
|
+
if (!target) throw new Error(`No published rigid body for skin joint ${joint.id}`);
|
|
112
|
+
indices[index] = target.body;
|
|
113
|
+
/** The publication's transform retains authored scale and mesh-to-body offsets. */
|
|
114
|
+
const transform = target.localMatrix.clone();
|
|
115
|
+
if (this.binding.inverseBindMatrices) {
|
|
116
|
+
transform.multiplyRight(
|
|
117
|
+
this.binding.inverseBindMatrices.subarray(index * 16, index * 16 + 16)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
transforms.set(transform, index * 16);
|
|
121
|
+
}
|
|
122
|
+
this.releasePalette ??= this.skins.claimGPUPalette(this.binding);
|
|
123
|
+
this.indices.write(indices);
|
|
124
|
+
this.transforms.write(transforms, 64);
|
|
125
|
+
this.computation.setBindings({
|
|
126
|
+
bodyPoses: publication.matrices,
|
|
127
|
+
bodyIndices: this.indices,
|
|
128
|
+
paletteTransforms: this.transforms,
|
|
129
|
+
jointPalette: this.palette
|
|
130
|
+
});
|
|
131
|
+
this.publication = publication;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -141,8 +141,11 @@ export class ScenegraphPhysicsSession {
|
|
|
141
141
|
steps = 1,
|
|
142
142
|
animatedNodes = new Set<ScenegraphNode>(),
|
|
143
143
|
excludedNodes,
|
|
144
|
-
targetNodes
|
|
144
|
+
targetNodes,
|
|
145
|
+
angularDriveRows
|
|
145
146
|
}: {
|
|
147
|
+
/** Angular joint drive rows that follow the current scene pose while their bodies remain dynamic. */
|
|
148
|
+
angularDriveRows?: readonly number[];
|
|
146
149
|
steps?: number;
|
|
147
150
|
animatedNodes?: ReadonlySet<ScenegraphNode>;
|
|
148
151
|
excludedNodes?: ReadonlySet<ScenegraphNode>;
|
|
@@ -154,7 +157,7 @@ export class ScenegraphPhysicsSession {
|
|
|
154
157
|
// Validate the batch before mutating animation ownership or targets.
|
|
155
158
|
assert(Number.isSafeInteger(steps) && steps > 0);
|
|
156
159
|
this.motion.setAnimatedNodes(animatedNodes, {excludedNodes, targetNodes});
|
|
157
|
-
this.motion.update();
|
|
160
|
+
this.motion.update(angularDriveRows);
|
|
158
161
|
this.publication.update();
|
|
159
162
|
this.instance.encode(encoder, steps);
|
|
160
163
|
}
|
package/src/index.ts
CHANGED
|
@@ -373,3 +373,5 @@ export {deformPositions} from './animation/deform-positions';
|
|
|
373
373
|
export {createAreaLightLTCTextures} from './lighting/ltc-textures';
|
|
374
374
|
|
|
375
375
|
export {makeGPUVectorGeometry} from './geometry/gpu-vector-geometry-adapter';
|
|
376
|
+
|
|
377
|
+
export {makeDepthIntervalPlugin} from './shader-plugins/depth-interval';
|
|
@@ -1836,7 +1836,10 @@ export class GPUVectorModel {
|
|
|
1836
1836
|
renderPass as RenderPass & {
|
|
1837
1837
|
framebuffer?: {
|
|
1838
1838
|
colorAttachments?: Array<{texture?: {format?: TextureFormatColor}} | null>;
|
|
1839
|
-
depthStencilAttachment?: {
|
|
1839
|
+
depthStencilAttachment?: {
|
|
1840
|
+
props?: {format?: TextureFormatDepthStencil};
|
|
1841
|
+
texture?: {format?: TextureFormatDepthStencil};
|
|
1842
|
+
} | null;
|
|
1840
1843
|
};
|
|
1841
1844
|
}
|
|
1842
1845
|
).framebuffer || renderPass.props.framebuffer;
|
|
@@ -1854,7 +1857,10 @@ export class GPUVectorModel {
|
|
|
1854
1857
|
renderBundleProps.depthStencilAttachmentFormat === false
|
|
1855
1858
|
? undefined
|
|
1856
1859
|
: (renderBundleProps.depthStencilAttachmentFormat ??
|
|
1857
|
-
asDepthStencilAttachmentFormat(
|
|
1860
|
+
asDepthStencilAttachmentFormat(
|
|
1861
|
+
framebuffer?.depthStencilAttachment?.props?.format ??
|
|
1862
|
+
framebuffer?.depthStencilAttachment?.texture?.format
|
|
1863
|
+
));
|
|
1858
1864
|
|
|
1859
1865
|
if (
|
|
1860
1866
|
!deepEqual(this._colorAttachmentFormats, nextColorAttachmentFormats, 1) ||
|
|
@@ -18,6 +18,8 @@ export type {
|
|
|
18
18
|
} from '@luma.gl/graph/gpu-physics';
|
|
19
19
|
|
|
20
20
|
export type ScenegraphJoint = {
|
|
21
|
+
/** Instance-local actuator identifier shared by this attachment’s drive axes. */
|
|
22
|
+
id?: string;
|
|
21
23
|
first: ScenegraphNode;
|
|
22
24
|
second: ScenegraphNode;
|
|
23
25
|
limits?: readonly ScenegraphJointLimit[];
|
|
@@ -33,6 +33,9 @@ export type SkinControllerProps = {
|
|
|
33
33
|
export class SkinController {
|
|
34
34
|
readonly bindings: readonly SkinBinding[];
|
|
35
35
|
|
|
36
|
+
/** Palettes owned by a GPU producer for the duration of their binding. */
|
|
37
|
+
private readonly gpuDriven = new Set<SkinBinding>();
|
|
38
|
+
|
|
36
39
|
private readonly scenes: readonly GroupNode[];
|
|
37
40
|
|
|
38
41
|
constructor(props: SkinControllerProps) {
|
|
@@ -43,7 +46,7 @@ export class SkinController {
|
|
|
43
46
|
|
|
44
47
|
/** Re-evaluates every source skin after its animated node transforms have changed. */
|
|
45
48
|
update(): void {
|
|
46
|
-
if (this.
|
|
49
|
+
if (this.gpuDriven.size === this.bindings.length) {
|
|
47
50
|
return;
|
|
48
51
|
}
|
|
49
52
|
|
|
@@ -57,6 +60,7 @@ export class SkinController {
|
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
for (const binding of this.bindings) {
|
|
63
|
+
if (this.gpuDriven.has(binding)) continue;
|
|
60
64
|
updateSkinJointMatrices({
|
|
61
65
|
joints: binding.joints,
|
|
62
66
|
meshNode: binding.node,
|
|
@@ -84,6 +88,21 @@ export class SkinController {
|
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
|
|
91
|
+
/** Borrow a WebGPU storage palette and suspend CPU writes until the lease is released. */
|
|
92
|
+
claimGPUPalette(binding: SkinBinding): () => void {
|
|
93
|
+
if (!this.bindings.includes(binding) || !(binding.skinJointMatrices instanceof Buffer))
|
|
94
|
+
throw new Error('GPU skinning requires an owned storage palette');
|
|
95
|
+
if (this.gpuDriven.has(binding)) throw new Error('Skin palette already has a GPU producer');
|
|
96
|
+
this.gpuDriven.add(binding);
|
|
97
|
+
/** Only this lease can remove its claim, even if its disposer is called twice. */
|
|
98
|
+
let released = false;
|
|
99
|
+
return () => {
|
|
100
|
+
if (released) return;
|
|
101
|
+
released = true;
|
|
102
|
+
this.gpuDriven.delete(binding);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
87
106
|
/** Finds the palette driven by a scenegraph node. */
|
|
88
107
|
getBinding(node: GroupNode | undefined): SkinBinding | undefined {
|
|
89
108
|
return this.bindings.find(binding => binding.node === node);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {ShaderPlugin} from '@luma.gl/shaders';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WebGPU depth-bound filtering for a caller-owned texture matching the render target.
|
|
9
|
+
* Bind `depthIntervalBound` and a `vec4<u32>` uniform named `depthIntervalCompare`.
|
|
10
|
+
* A nonzero first component selects greater; zero selects less-equal.
|
|
11
|
+
* Pass framebuffer pixel coordinates, stored depth, and the host coverage mask.
|
|
12
|
+
* For MSAA, write the result to the fragment's `sample_mask` output.
|
|
13
|
+
*/
|
|
14
|
+
export function makeDepthIntervalPlugin(sampleCount: number, bindGroup = 1): ShaderPlugin {
|
|
15
|
+
const multisampled = sampleCount > 1;
|
|
16
|
+
const textureType = multisampled ? 'texture_depth_multisampled_2d' : 'texture_depth_2d';
|
|
17
|
+
const sampleLimit = multisampled ? 'textureNumSamples(depthIntervalBound)' : '1u';
|
|
18
|
+
const loadIndex = multisampled ? 'sampleIndex' : '0';
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
name: 'depthInterval',
|
|
22
|
+
module: {
|
|
23
|
+
name: 'depthInterval',
|
|
24
|
+
bindingLayout: [
|
|
25
|
+
{name: 'depthIntervalBound', group: bindGroup, visibility: 2},
|
|
26
|
+
{name: 'depthIntervalCompare', group: bindGroup, visibility: 2}
|
|
27
|
+
],
|
|
28
|
+
source: /* wgsl */ `
|
|
29
|
+
@group(${bindGroup}) @binding(auto) var depthIntervalBound: ${textureType};
|
|
30
|
+
@group(${bindGroup}) @binding(auto) var<uniform> depthIntervalCompare: vec4<u32>;
|
|
31
|
+
|
|
32
|
+
fn filterDepthInterval(pixel: vec2<i32>, depth: f32, coverage: u32) -> u32 {
|
|
33
|
+
let keepGreater = depthIntervalCompare.x != 0u;
|
|
34
|
+
var mask = 0u;
|
|
35
|
+
for (var sampleIndex = 0u; sampleIndex < ${sampleLimit}; sampleIndex++) {
|
|
36
|
+
if ((depth > textureLoad(depthIntervalBound, pixel, ${loadIndex})) == keepGreater) {
|
|
37
|
+
mask |= 1u << sampleIndex;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return coverage & mask;
|
|
41
|
+
}
|
|
42
|
+
`
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
package/src/splats/README.md
CHANGED
|
@@ -18,6 +18,16 @@ and in-place row updates. Both rendering paths evaluate view-dependent radiance
|
|
|
18
18
|
classes. `SplatPicker` and `GPUSplatGraphPicker` resolve original source rows; their corresponding
|
|
19
19
|
mixed-scene helpers compose splats with caller-owned depth-tested meshes.
|
|
20
20
|
|
|
21
|
+
For WebGPU scenes with transparent meshes, construct `SplatRenderer` with
|
|
22
|
+
`depthIntervalSamples` equal to the render target's sample count. Before each
|
|
23
|
+
draw, call `setDepthInterval({bound, compare})`, where `bound` is a caller-owned
|
|
24
|
+
depth texture or view with the same sample count and dimensions. `greater` keeps
|
|
25
|
+
samples whose splat depth is strictly greater than the bound; `less-equal` keeps
|
|
26
|
+
the complement, including equality. Draw the two sides in the order needed for
|
|
27
|
+
the scene's `depthConvention` (`standard` or `reverse`). The renderer never owns
|
|
28
|
+
or clears the bound. Without `depthIntervalSamples`, it uses the existing shader
|
|
29
|
+
and bindings, with no depth-texture lookup.
|
|
30
|
+
|
|
21
31
|
`SplatHierarchyManager` traverses frustum-culled, foveated source hierarchies while preserving
|
|
22
32
|
coarse parent fallback and bounded asynchronous loading. `SplatRADHierarchyManager` follows
|
|
23
33
|
Spark's authored per-row global child links, retaining mixed source-page leaves and parent
|
package/src/splats/index.ts
CHANGED
|
@@ -8,12 +8,15 @@ import {
|
|
|
8
8
|
type CompareFunction,
|
|
9
9
|
type CommandEncoder,
|
|
10
10
|
type Device,
|
|
11
|
-
type RenderPass
|
|
11
|
+
type RenderPass,
|
|
12
|
+
type Texture,
|
|
13
|
+
type TextureView
|
|
12
14
|
} from '@luma.gl/core';
|
|
13
15
|
import {ShaderInputs} from '@luma.gl/engine';
|
|
14
16
|
import {GPUData} from '@luma.gl/graph/gpu-data';
|
|
15
17
|
import {GPURecordBatch, GPUTable, type GPUInputSchema} from '@luma.gl/graph/gpu-tables';
|
|
16
18
|
import {GPUTableModel} from '@luma.gl/engine/tables';
|
|
19
|
+
import {makeDepthIntervalPlugin} from '../shader-plugins/depth-interval';
|
|
17
20
|
import {GPUSplatData} from './splat-data';
|
|
18
21
|
import {projectSplatCovarianceToScreen} from './splat-covariance';
|
|
19
22
|
import {acceptsSplatSemantic, type SplatSemanticFilter} from './splat-filter';
|
|
@@ -34,6 +37,7 @@ import {
|
|
|
34
37
|
SPLAT_STORAGE_SHADER_LAYOUT,
|
|
35
38
|
SPLAT_STORAGE_WGSL_SHADER,
|
|
36
39
|
SPLAT_VS_GLSL,
|
|
40
|
+
getSplatDepthIntervalWGSLShader,
|
|
37
41
|
splatUniforms,
|
|
38
42
|
type SplatUniforms
|
|
39
43
|
} from './splat-shaders';
|
|
@@ -56,6 +60,10 @@ export type SplatRendererProps = {
|
|
|
56
60
|
sortMode?: SplatSortMode;
|
|
57
61
|
/** Projected-depth convention for alpha ordering, independent of depthCompare. Defaults to standard. */
|
|
58
62
|
depthConvention?: 'standard' | 'reverse';
|
|
63
|
+
/** WebGPU only. Fixed render-target sample count for opt-in depth-interval filtering. */
|
|
64
|
+
depthIntervalSamples?: number;
|
|
65
|
+
/** Bound depth and side for a depth-interval draw; the texture remains caller-owned. */
|
|
66
|
+
depthInterval?: SplatDepthInterval;
|
|
59
67
|
/** Minimum fragment opacity retained after Gaussian attenuation. */
|
|
60
68
|
alphaCutoff?: number;
|
|
61
69
|
/** Alias for {@link alphaCutoff} when integrating opacity-threshold controls. */
|
|
@@ -84,6 +92,12 @@ export type SplatRendererProps = {
|
|
|
84
92
|
depthWriteEnabled?: boolean;
|
|
85
93
|
};
|
|
86
94
|
|
|
95
|
+
/** The two comparisons partition every sample, including samples exactly on the bound. */
|
|
96
|
+
export type SplatDepthInterval = {
|
|
97
|
+
bound: Texture | TextureView;
|
|
98
|
+
compare: 'greater' | 'less-equal';
|
|
99
|
+
};
|
|
100
|
+
|
|
87
101
|
/** Application-owned opaque or transparent mesh compatible with an existing render pass. */
|
|
88
102
|
export type SplatMeshRenderable = {
|
|
89
103
|
draw(renderPass: RenderPass): boolean | void;
|
|
@@ -127,6 +141,7 @@ type ResolvedSplatRendererProps = {
|
|
|
127
141
|
semanticFilter?: SplatSemanticFilter;
|
|
128
142
|
sortMode: SplatSortMode;
|
|
129
143
|
depthConvention: 'standard' | 'reverse';
|
|
144
|
+
depthIntervalSamples?: number;
|
|
130
145
|
alphaCutoff: number;
|
|
131
146
|
screenSizeCutoffPixels: number;
|
|
132
147
|
gaussianSupportRadius: number;
|
|
@@ -233,6 +248,11 @@ export class SplatRenderer {
|
|
|
233
248
|
private usesFloatWebGLColors = false;
|
|
234
249
|
private hasExplicitToneMapping = false;
|
|
235
250
|
private isDestroyed = false;
|
|
251
|
+
private depthIntervalBindings?: {
|
|
252
|
+
depthIntervalBound: Texture | TextureView;
|
|
253
|
+
depthIntervalCompare: Buffer;
|
|
254
|
+
};
|
|
255
|
+
private depthIntervalCompareBuffers?: Record<SplatDepthInterval['compare'], Buffer>;
|
|
236
256
|
|
|
237
257
|
/** Creates a renderer over optionally supplied caller-owned Gaussian source batches. */
|
|
238
258
|
constructor(device: Device, props: SplatRendererProps = {}) {
|
|
@@ -245,6 +265,7 @@ export class SplatRenderer {
|
|
|
245
265
|
semanticFilter: props.semanticFilter,
|
|
246
266
|
sortMode: props.sortMode ?? 'global',
|
|
247
267
|
depthConvention: props.depthConvention ?? 'standard',
|
|
268
|
+
depthIntervalSamples: props.depthIntervalSamples,
|
|
248
269
|
alphaCutoff: props.alphaCutoff ?? props.opacityThreshold ?? 1 / 255,
|
|
249
270
|
screenSizeCutoffPixels: props.screenSizeCutoffPixels ?? 0,
|
|
250
271
|
gaussianSupportRadius: props.gaussianSupportRadius ?? 3,
|
|
@@ -258,6 +279,9 @@ export class SplatRenderer {
|
|
|
258
279
|
depthWriteEnabled: props.depthWriteEnabled ?? false
|
|
259
280
|
};
|
|
260
281
|
this.hasExplicitToneMapping = props.toneMapping !== undefined;
|
|
282
|
+
if (props.depthInterval) {
|
|
283
|
+
this.setDepthInterval(props.depthInterval);
|
|
284
|
+
}
|
|
261
285
|
this.updateShaderInputs();
|
|
262
286
|
for (const batch of normalizeSplatBatches(props.data)) {
|
|
263
287
|
this.appendData(batch);
|
|
@@ -265,6 +289,32 @@ export class SplatRenderer {
|
|
|
265
289
|
this.update();
|
|
266
290
|
}
|
|
267
291
|
|
|
292
|
+
/** Selects the caller-owned bound and side for subsequent depth-interval draws. */
|
|
293
|
+
setDepthInterval(interval: SplatDepthInterval): void {
|
|
294
|
+
// A depth interval requires the WebGPU shader variant selected at construction.
|
|
295
|
+
if (this.device.type !== 'webgpu' || this.props.depthIntervalSamples === undefined) {
|
|
296
|
+
throw new Error('Depth interval requires a WebGPU renderer with depthIntervalSamples');
|
|
297
|
+
}
|
|
298
|
+
if (!this.depthIntervalCompareBuffers) {
|
|
299
|
+
this.depthIntervalCompareBuffers = {
|
|
300
|
+
greater: this.device.createBuffer({
|
|
301
|
+
id: 'splat-depth-interval-greater',
|
|
302
|
+
data: new Uint32Array([1, 0, 0, 0]),
|
|
303
|
+
usage: Buffer.UNIFORM
|
|
304
|
+
}),
|
|
305
|
+
'less-equal': this.device.createBuffer({
|
|
306
|
+
id: 'splat-depth-interval-less-equal',
|
|
307
|
+
data: new Uint32Array(4),
|
|
308
|
+
usage: Buffer.UNIFORM
|
|
309
|
+
})
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
this.depthIntervalBindings = {
|
|
313
|
+
depthIntervalBound: interval.bound,
|
|
314
|
+
depthIntervalCompare: this.depthIntervalCompareBuffers[interval.compare]
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
268
318
|
/** Current source rows, visibility, batch identity, and GPU allocation diagnostics. */
|
|
269
319
|
get stats(): SplatRendererStats {
|
|
270
320
|
return this.getStats();
|
|
@@ -312,6 +362,15 @@ export class SplatRenderer {
|
|
|
312
362
|
|
|
313
363
|
/** Updates camera, sorting, visibility, and styling controls in place. */
|
|
314
364
|
setProps(props: Partial<SplatRendererProps>): void {
|
|
365
|
+
if (
|
|
366
|
+
props.depthIntervalSamples !== undefined &&
|
|
367
|
+
props.depthIntervalSamples !== this.props.depthIntervalSamples
|
|
368
|
+
) {
|
|
369
|
+
throw new Error('depthIntervalSamples is fixed at construction');
|
|
370
|
+
}
|
|
371
|
+
if (props.depthInterval) {
|
|
372
|
+
this.setDepthInterval(props.depthInterval);
|
|
373
|
+
}
|
|
315
374
|
if (props.data !== undefined) {
|
|
316
375
|
const replacementBatches = normalizeSplatBatches(props.data);
|
|
317
376
|
const matchesRetainedBatches =
|
|
@@ -550,6 +609,10 @@ export class SplatRenderer {
|
|
|
550
609
|
this.placeholderSphericalHarmonicsBuffer?.destroy();
|
|
551
610
|
this.placeholderSphericalHarmonicsBuffer = undefined;
|
|
552
611
|
this.shaderInputs.destroy();
|
|
612
|
+
this.depthIntervalCompareBuffers?.greater.destroy();
|
|
613
|
+
this.depthIntervalCompareBuffers?.['less-equal'].destroy();
|
|
614
|
+
this.depthIntervalCompareBuffers = undefined;
|
|
615
|
+
this.depthIntervalBindings = undefined;
|
|
553
616
|
this.isDestroyed = true;
|
|
554
617
|
}
|
|
555
618
|
|
|
@@ -571,10 +634,18 @@ export class SplatRenderer {
|
|
|
571
634
|
}
|
|
572
635
|
return new GPUTableModel(this.device, {
|
|
573
636
|
id: 'gaussian-splat-renderer',
|
|
574
|
-
source: isWebGPU
|
|
637
|
+
source: isWebGPU
|
|
638
|
+
? this.props.depthIntervalSamples === undefined
|
|
639
|
+
? SPLAT_STORAGE_WGSL_SHADER
|
|
640
|
+
: getSplatDepthIntervalWGSLShader(this.props.depthIntervalSamples)
|
|
641
|
+
: SPLAT_ATTRIBUTE_WGSL_SHADER,
|
|
575
642
|
vs: SPLAT_VS_GLSL,
|
|
576
643
|
fs: SPLAT_FS_GLSL,
|
|
577
644
|
shaderLayout: isWebGPU ? SPLAT_STORAGE_SHADER_LAYOUT : SPLAT_ATTRIBUTE_SHADER_LAYOUT,
|
|
645
|
+
plugins:
|
|
646
|
+
isWebGPU && this.props.depthIntervalSamples !== undefined
|
|
647
|
+
? [makeDepthIntervalPlugin(this.props.depthIntervalSamples)]
|
|
648
|
+
: [],
|
|
578
649
|
modules: [splatUniforms],
|
|
579
650
|
shaderInputs: this.shaderInputs,
|
|
580
651
|
table,
|
|
@@ -600,6 +671,9 @@ export class SplatRenderer {
|
|
|
600
671
|
vertexCount: 4,
|
|
601
672
|
topology: 'triangle-strip',
|
|
602
673
|
parameters: {
|
|
674
|
+
...(!isWebGPU || this.props.depthIntervalSamples === undefined
|
|
675
|
+
? {}
|
|
676
|
+
: {sampleCount: this.props.depthIntervalSamples}),
|
|
603
677
|
depthWriteEnabled: this.props.depthWriteEnabled,
|
|
604
678
|
depthCompare: this.props.depthCompare,
|
|
605
679
|
blend: true,
|
|
@@ -913,6 +987,9 @@ export class SplatRenderer {
|
|
|
913
987
|
if (!this.model || !this.table) {
|
|
914
988
|
return false;
|
|
915
989
|
}
|
|
990
|
+
if (this.props.depthIntervalSamples !== undefined && !this.depthIntervalBindings) {
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
916
993
|
let drawSuccess = true;
|
|
917
994
|
for (const run of this.drawRuns) {
|
|
918
995
|
const batch = this.table.batches[run.batchIndex];
|
|
@@ -931,6 +1008,9 @@ export class SplatRenderer {
|
|
|
931
1008
|
this.batches[run.batchIndex].sphericalHarmonics?.data[0]?.buffer ??
|
|
932
1009
|
this.placeholderSphericalHarmonicsBuffer!
|
|
933
1010
|
});
|
|
1011
|
+
if (this.depthIntervalBindings) {
|
|
1012
|
+
this.model.setBindings(this.depthIntervalBindings);
|
|
1013
|
+
}
|
|
934
1014
|
this.model.setInstanceCount(run.rowIndices.length);
|
|
935
1015
|
drawSuccess = this.model.draw(renderPass) && drawSuccess;
|
|
936
1016
|
}
|
|
@@ -194,8 +194,7 @@ fn projectSplatVertex(
|
|
|
194
194
|
return output;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
fn fragmentMain(input : SplatFragmentInputs) -> @location(0) vec4<f32> {
|
|
197
|
+
fn evaluateSplatFragment(input : SplatFragmentInputs) -> vec4<f32> {
|
|
199
198
|
let gaussianWeight = exp(-0.5 * dot(input.gaussianCoordinate, input.gaussianCoordinate));
|
|
200
199
|
let alpha = input.color.a * gaussianWeight;
|
|
201
200
|
if (alpha <= 0.0 || alpha < splat.alphaCutoff) {
|
|
@@ -211,8 +210,41 @@ fn fragmentMain(input : SplatFragmentInputs) -> @location(0) vec4<f32> {
|
|
|
211
210
|
}
|
|
212
211
|
`;
|
|
213
212
|
|
|
213
|
+
const SPLAT_WGSL_DEFAULT_FRAGMENT = /* wgsl */ `\
|
|
214
|
+
@fragment
|
|
215
|
+
fn fragmentMain(input : SplatFragmentInputs) -> @location(0) vec4<f32> {
|
|
216
|
+
return evaluateSplatFragment(input);
|
|
217
|
+
}
|
|
218
|
+
`;
|
|
219
|
+
|
|
220
|
+
const SPLAT_DEPTH_INTERVAL_FRAGMENT_MULTISAMPLED = /* wgsl */ `\
|
|
221
|
+
struct SplatDepthIntervalOutput {
|
|
222
|
+
@location(0) color : vec4<f32>,
|
|
223
|
+
@builtin(sample_mask) sampleMask : u32,
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
@fragment
|
|
227
|
+
fn fragmentMain(input : SplatFragmentInputs) -> SplatDepthIntervalOutput {
|
|
228
|
+
let sampleMask = filterDepthInterval(vec2<i32>(input.position.xy), input.position.z, 0xffffffffu);
|
|
229
|
+
if (sampleMask == 0u) {
|
|
230
|
+
discard;
|
|
231
|
+
}
|
|
232
|
+
return SplatDepthIntervalOutput(evaluateSplatFragment(input), sampleMask);
|
|
233
|
+
}
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
const SPLAT_DEPTH_INTERVAL_FRAGMENT_SINGLE_SAMPLE = /* wgsl */ `\
|
|
237
|
+
@fragment
|
|
238
|
+
fn fragmentMain(input : SplatFragmentInputs) -> @location(0) vec4<f32> {
|
|
239
|
+
if (filterDepthInterval(vec2<i32>(input.position.xy), input.position.z, 1u) == 0u) {
|
|
240
|
+
discard;
|
|
241
|
+
}
|
|
242
|
+
return evaluateSplatFragment(input);
|
|
243
|
+
}
|
|
244
|
+
`;
|
|
245
|
+
|
|
214
246
|
/** WebGPU vertex shader that consumes source vectors directly through storage buffers. */
|
|
215
|
-
|
|
247
|
+
const SPLAT_STORAGE_WGSL_BASE = /* wgsl */ `\
|
|
216
248
|
${SPLAT_WGSL_SHARED}
|
|
217
249
|
|
|
218
250
|
@group(0) @binding(auto) var<storage, read> splatPositions : array<f32>;
|
|
@@ -312,9 +344,22 @@ fn vertexMain(
|
|
|
312
344
|
}
|
|
313
345
|
`;
|
|
314
346
|
|
|
347
|
+
/** Default storage shader retains the original fragment output and bindings. */
|
|
348
|
+
export const SPLAT_STORAGE_WGSL_SHADER = SPLAT_STORAGE_WGSL_BASE + SPLAT_WGSL_DEFAULT_FRAGMENT;
|
|
349
|
+
|
|
350
|
+
/** Storage shader that writes only the samples on the selected side of a depth bound. */
|
|
351
|
+
export function getSplatDepthIntervalWGSLShader(samples: number): string {
|
|
352
|
+
const fragment =
|
|
353
|
+
samples > 1
|
|
354
|
+
? SPLAT_DEPTH_INTERVAL_FRAGMENT_MULTISAMPLED
|
|
355
|
+
: SPLAT_DEPTH_INTERVAL_FRAGMENT_SINGLE_SAMPLE;
|
|
356
|
+
return SPLAT_STORAGE_WGSL_BASE + fragment;
|
|
357
|
+
}
|
|
358
|
+
|
|
315
359
|
/** WebGPU attribute-backed shader retained for shader inspection and device-independent smoke tests. */
|
|
316
360
|
export const SPLAT_ATTRIBUTE_WGSL_SHADER = /* wgsl */ `\
|
|
317
361
|
${SPLAT_WGSL_SHARED}
|
|
362
|
+
${SPLAT_WGSL_DEFAULT_FRAGMENT}
|
|
318
363
|
|
|
319
364
|
struct SplatVertexInputs {
|
|
320
365
|
@builtin(vertex_index) vertexIndex : u32,
|