Appearance
Splat
The GPU buffers behind a Gaussian splat, for handing to a compute kernel.
Reached via entity.representation.splat on a splat representation; null for any other kind. Each attribute vends .read and .write tokens that go into a kernel's inputBuffers / outputBuffers maps, exactly as texture.read / texture.write do.
Important: pass
threadsPerThreadgroupwhenever the group count was divided by a number of your own. Left out, it defaults to the GPU's thread execution width (32 on Apple silicon), so dividing by 64 covers half the capture and leaves the rest of a.writebuffer undefined.Warning: a
.writetoken hands the kernel an uninitialised buffer, not last frame's contents. Whatever the kernel does not write is undefined. To change part of an attribute, bind.readas an input in the same dispatch and copy the rest across.
Example:
javascript
const splat = entity.representation.splat;
const THREADS = 64;
kernel.run({
uniforms: new Float32Array([scene.time, splat.count]),
inputBuffers: { src: splat.position.read },
outputBuffers: { dst: splat.position.write },
threadGroups: [Math.ceil(splat.count / THREADS), 1, 1],
threadsPerThreadgroup: [THREADS, 1, 1]
});Properties
boundingBox read-only
- Type: BoundingBox
- The box around the capture, in the same space as the values in
position.
count read-only
- Type: number
- How many splats the capture holds. Size a dispatch from this, and guard on it in the kernel: a thread that runs past the end writes into memory the renderer is using.
opacity read-only
- Type: SplatAttribute
- Opacity of each splat, 1 float per splat, stored pre-sigmoid so 0 is half opaque rather than invisible. Fade the alpha and convert back rather than interpolating the stored value.
position read-only
- Type: SplatAttribute
- Centre of each splat, 3 floats per splat, read in a kernel as
packed_float3.
rotation read-only
- Type: SplatAttribute
- Orientation of each splat as a quaternion, 4 floats per splat, stored w first as
(w, x, y, z). Identity is(1, 0, 0, 0); anxyzwidentity is a half turn.
scale read-only
- Type: SplatAttribute
- Per-axis size of each splat, 3 floats per splat, in log space and read in a kernel as
packed_float3. Halving a splat means subtractinglog(2), not multiplying by 0.5.
sphericalHarmonicDegree read-only
- Type: number
- Spherical harmonic degree of the capture, 0 through 3.
sphericalHarmonics read-only
- Type: SplatAttribute
- View-dependent colour: the DC triplet first, then one triplet per higher-order coefficient, so
itemSizeis3 * (bands + 1)and a splat's base colour is the first three floats of its block. Read in a kernel asfloat, indexed by that stride.
Methods
setParameter()
javascript
setParameter(name: string, value: any, typeHint?: any): SplatSets a parameter of the shader running on this splat, the Shader slot's or one set with setShader, until the object next loads. An unknown name is reported in the console.
Parameters:
name(string) - The parameter's name, as the shader's settings panel shows it.value(any) - Number, boolean, string, array (vector2/3/4),Vector3, or a color ('#RRGGBB',Color).typeHint(any) (optional) - Overrides the inferred type:{ type: "float" | "int" | "vector2" | "vector3" | "vector4" | "color" | "bool" | "string" }.
Returns: Splat
setShader()
javascript
setShader(kernel: Kernel, options: { parameters?: object, inputTextures?: object, runs?: 'everyFrame' | 'once' }): voidRuns a compute shader's update on this splat every frame, or once, in place of its Shader slot, until the object next loads. Element fields bind by attribute name. Pass null to stop it.
Parameters:
kernel(Kernel) - fromKernel.fromAsset(...)of a shader that updates elements, ornull.options({ parameters?: object, inputTextures?: object, runs?: 'everyFrame' | 'once' }) -inputTexturesfills the shader's texture inputs by name, each with a texture's.read.
Returns: void