Nano WebGPU API - v0.11.0
    Preparing search index...

    Type Alias ShaderParameters

    ShaderParameters: Record<string, number | number[] | Float32Array>

    A record mapping custom WGSL parameter names to their numeric values, arrays, or Float32Arrays.

    Important

    Uniform Packing & Alignment: WebGPU uniform buffers require strict layout alignment (std140 standard). For float-based structures in WGSL:

    • f32 requires 4-byte alignment (1 float)
    • vec2<f32> requires 8-byte alignment (2 floats)
    • vec3<f32> and vec4<f32> require 16-byte alignment (4 floats)
    • mat4x4<f32> requires 64-byte alignment (16 floats)

    Parameters are packed sequentially based on the object's key insertion order. Ensure that your parameters object keys match the exact sequence and type alignment declared in your WGSL struct. You can use flat Float32Arrays or pad values manually to ensure alignment.

    const material = new ShaderMaterial({
    shaderCode: myShader,
    parameters: {
    color: [1.0, 0.0, 0.0, 1.0], // vec4<f32> - 16 bytes
    intensity: 1.5, // f32 - 4 bytes
    _padding: [0.0, 0.0, 0.0], // pad to 16-byte boundary (12 bytes)
    }
    });