# GSplatFormat

Class · category: Graphics

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/scene/gsplat/gsplat-format.js#L89

Gsplat resources store per-splat data (positions, colors, rotations, scales, spherical
harmonics) in GPU textures. This class describes those texture streams and generates the
shader code needed to access them.

Each stream defines a texture with a name and pixel format. The class automatically generates
shader declarations (uniforms/samplers) and load functions (e.g. `loadColor()`) for each
stream. A read shader can be provided to define how splat attributes are extracted from
these textures.

Users can add extra streams via [addExtraStreams](https://api.playcanvas.com/engine/classes/GSplatFormat.md#addextrastreams) for custom per-splat data. These
can be per-resource (shared across instances) or per-instance (unique to each gsplat
component).

For loaded gsplat resources, base streams are automatically configured based on the loaded
data format. For [GSplatContainer](https://api.playcanvas.com/engine/classes/GSplatContainer.md), users define both base and extra streams to
specify the complete data layout.

## Constructors

### constructor

```ts
new GSplatFormat(device: GraphicsDevice, streams: GSplatStreamDescriptor[], options: object)
```

Creates a new GSplatFormat instance.

**Parameters**

- `device` ([`GraphicsDevice`](https://api.playcanvas.com/engine/classes/GraphicsDevice.md)): The graphics device.
- `streams` ([`GSplatStreamDescriptor`](https://api.playcanvas.com/engine/interfaces/GSplatStreamDescriptor.md)`[]`): Array of stream descriptors.
- `options` (`object`): Format options.
    - `options.readGLSL` (`string`, optional): GLSL code defining getCenter(), getColor(),
      getRotation(), getScale() functions. Can include additional declarations at module scope.
      Required for WebGL.
    - `options.readWGSL` (`string`, optional): WGSL code defining getCenter(), getColor(),
      getRotation(), getScale() functions. Can include additional declarations at module scope.
      Required for WebGPU.

## Properties

### streams

```ts
readonly streams: GSplatStreamDescriptor[]
```

Array of stream descriptors.

## Accessors

### extraStreams

```ts
get extraStreams(): GSplatStreamDescriptor[]
```

Gets the extra streams array. Streams can only be added via [addExtraStreams](https://api.playcanvas.com/engine/classes/GSplatFormat.md#addextrastreams),
not removed. Do not modify the returned array directly.

## Methods

### addExtraStreams

```ts
addExtraStreams(streams: GSplatStreamDescriptor[]): void
```

Adds additional texture streams for custom gsplat data. Each stream defines a texture
that can store extra information, accessible in shaders via generated load functions.
Streams with `storage: GSPLAT_STREAM_INSTANCE` are created per gsplat component instance,
while others are shared across all instances of the same resource.

Note: Streams cannot be removed once added currently.

**Parameters**

- `streams` ([`GSplatStreamDescriptor`](https://api.playcanvas.com/engine/interfaces/GSplatStreamDescriptor.md)`[]`): Array of stream descriptors to add.

### createDefaultFormat

```ts
static createDefaultFormat(device: GraphicsDevice): GSplatFormat
```

Creates a default format using 32F/16F textures, simple to use for CPU data population.
This format can be rendered to by [GSplatProcessor](https://api.playcanvas.com/engine/classes/GSplatProcessor.md) when supported. Check
[GraphicsDevice#textureFloatRenderable](https://api.playcanvas.com/engine/classes/GraphicsDevice.md#texturefloatrenderable) (for RGBA32F) and
[GraphicsDevice#textureHalfFloatRenderable](https://api.playcanvas.com/engine/classes/GraphicsDevice.md#texturehalffloatrenderable) (for RGBA16F).

The format stores:
- `dataColor` (RGBA16F): color.rgba as half floats
- `dataCenter` (RGBA32F): center.xyz as floats (w unused)
- `dataScale` (RGBA16F): scale.xyz as half floats (w unused)
- `dataRotation` (RGBA16F): rotation.xyzw as half floats (w stored directly, not derived)

**Parameters**

- `device` ([`GraphicsDevice`](https://api.playcanvas.com/engine/classes/GraphicsDevice.md)): The graphics device.

**Returns** [`GSplatFormat`](https://api.playcanvas.com/engine/classes/GSplatFormat.md): The default format.

### createSimpleFormat

```ts
static createSimpleFormat(device: GraphicsDevice): GSplatFormat
```

Creates a simple format with uniform-scale splats and no rotation.
Streams:
- `dataCenter` (RGBA32F): center.xyz + uniform size in w
- `dataColor` (RGBA16F): color.rgba as half floats

**Parameters**

- `device` ([`GraphicsDevice`](https://api.playcanvas.com/engine/classes/GraphicsDevice.md)): The graphics device.

**Returns** [`GSplatFormat`](https://api.playcanvas.com/engine/classes/GSplatFormat.md): The simple format.
