class
WGSLLayer
extends LayerBase
implements ICustomShaderLayer
Custom WGSL shader layer. Write your own vertex/fragment shaders with full control over the GPU pipeline. Supports uniforms, textures, and animation.
Constructor
new WGSLLayer(options: WGSLLayerOptions) | Parameter | Type | Description | |
|---|---|---|---|
options | WGSLLayerOptions | required | Shader layer configuration |
WGSLLayerOptions
| Field | Type | Description | |
|---|---|---|---|
id | string | optional | Layer ID |
vertexShader | string | required | WGSL vertex shader source |
fragmentShader | string | required | WGSL fragment shader source |
vertexBufferLayouts | CustomVertexBufferLayout[] | required | Vertex buffer layout definitions |
animated | boolean | optional | Force continuous rendering (for animations) Default: false |
rawMode | boolean | optional | Skip preamble injection (advanced) Default: false |
blendState | GPUBlendState | optional | GPU blend state override |
topology | GPUPrimitiveTopology | optional | Primitive topology Default: 'triangle-list' |
Properties
| Name | Type | Access | Description |
|---|---|---|---|
type | 'custom-shader' | readonly | Layer type discriminant |
animated | boolean | readonly | Continuous render flag |
rawMode | boolean | readonly | Raw mode flag |
Methods
setVertexBuffer()
setVertexBuffer(index: number, buffer: GPUBuffer): void Set a vertex buffer at a specific slot.
Returns
void setIndexBuffer()
setIndexBuffer(buffer: GPUBuffer, format?: GPUIndexFormat): void Set the index buffer.
Returns
void setCustomUniforms()
setCustomUniforms(data: ArrayBuffer | Float32Array): void Set custom uniform data.
Returns
void setTexture()
setTexture(texture: GPUTexture, samplerDesc?: GPUSamplerDescriptor): void Set a texture binding.
Returns
void setDrawParams()
setDrawParams(params: { vertexCount?, instanceCount?, indexCount? }): void Set draw call parameters.
Returns
void requestRender()
requestRender(): void Trigger a repaint.
Returns
void Example
const shaderLayer = new WGSLLayer({
id: 'particles',
vertexShader: `/* your WGSL vertex shader */`,
fragmentShader: `/* your WGSL fragment shader */`,
vertexBufferLayouts: [{
arrayStride: 16,
attributes: [
{ shaderLocation: 0, offset: 0, format: 'float32x2' },
{ shaderLocation: 1, offset: 8, format: 'float32x2' },
],
}],
animated: true,
});