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

    Class ShaderMaterial

    ShaderMaterial represents a fully customizable, user-driven shading material. Enables integration of bespoke WGSL vertex and fragment shader scripts, providing dynamic group 3 uniform buffers to drive animations and parameters. Automatically maps dummy group 2 resources to fulfill baseline pipeline signatures.

    Hierarchy (View Summary)

    Index

    Accessors

    • get aoIntensity(): number

      Gets the ambient occlusion shadow intensity multiplier.

      Returns number

    • set aoIntensity(val: number): void

      Sets the ambient occlusion shadow intensity multiplier and marks the material parameters as dirty.

      Parameters

      • val: number

      Returns void

    • get depthCompare(): GPUCompareFunction

      Gets the depth check comparison function.

      Returns GPUCompareFunction

    • set depthCompare(value: GPUCompareFunction): void

      Sets the depth check comparison function.

      Parameters

      • value: GPUCompareFunction

      Returns void

    • get depthWriteEnabled(): boolean

      Gets whether depth buffer updates are enabled.

      Returns boolean

    • set depthWriteEnabled(value: boolean): void

      Sets whether depth buffer updates are enabled.

      Parameters

      • value: boolean

      Returns void

    • get doubleSided(): boolean

      Gets the double-sided rendering state.

      Returns boolean

    • set doubleSided(val: boolean): void

      Sets the double-sided rendering state, adjusting internal cull modes accordingly.

      Parameters

      • val: boolean

      Returns void

    • get emissiveStrength(): number

      Gets the emissive intensity multiplier.

      Returns number

    • set emissiveStrength(val: number): void

      Sets the emissive intensity multiplier and marks the material parameters as dirty.

      Parameters

      • val: number

      Returns void

    • get metallic(): number

      Gets the microfacet metallic factor.

      Returns number

    • set metallic(val: number): void

      Sets the microfacet metallic factor and marks the material parameters as dirty.

      Parameters

      • val: number

      Returns void

    • get normalScale(): number

      Gets the normal tangent scale.

      Returns number

    • set normalScale(val: number): void

      Sets the normal tangent scale and marks the material parameters as dirty.

      Parameters

      • val: number

      Returns void

    • get opacity(): number

      Gets the opacity component of the albedo color.

      Returns number

    • set opacity(value: number): void

      Sets the opacity component of the albedo color, automatically enabling transparent rendering and disabling depth writing if opacity is less than 1.0.

      Parameters

      • value: number

      Returns void

    • get roughness(): number

      Gets the microfacet roughness factor.

      Returns number

    • set roughness(val: number): void

      Sets the microfacet roughness factor and marks the material parameters as dirty.

      Parameters

      • val: number

      Returns void

    • get transparent(): boolean

      Gets whether transparency blending is enabled.

      Returns boolean

    • set transparent(value: boolean): void

      Sets whether transparency blending is enabled. Automatically sets depthWriteEnabled to false if transparent is true.

      Parameters

      • value: boolean

      Returns void

    Constructors

    Methods

    • Resolves GPUBindGroup (group index 2) containing baseline material bindings. Updates baseline uniform buffers and binds actual standard textures.

      Parameters

      • ctx: Context

        Active context.

      • _topology: GPUPrimitiveTopology = "triangle-list"
      • _indexFormat: GPUIndexFormat = "uint16"

      Returns GPUBindGroup

      Baseline material GPUBindGroup.

    • Resolves the custom GPUBindGroup (group index 3) containing active parameter values. Returns null if no custom parameters were initialized during construction.

      Parameters

      Returns GPUBindGroup | null

      Custom parameter GPUBindGroup or null.

    • Compiles or returns the cached GPURenderPipeline corresponding to this custom shader configuration.

      Parameters

      • ctx: Context

        Active context.

      • topology: GPUPrimitiveTopology = "triangle-list"

        Primitive geometry topology type.

      • indexFormat: GPUIndexFormat = "uint16"

        Geometry index buffer type.

      • OptionalcullMode: GPUCullMode

        Culling mode override.

      • useCSM: boolean = false

      Returns GPURenderPipeline

      The compiled GPURenderPipeline.

    • Updates custom shader parameters at runtime. Writes data to GPU uniform buffers immediately, altering visual features on the next frame. Re-allocates storage buffers if the float size count changes.

      Parameters

      Returns void

    Properties

    customBindGroup: GPUBindGroup | null = null

    Direct custom bind group override. Set customBindGroup directly for fully custom group(2) setups.

    id: number

    Unique material identification key.

    isDirty: boolean = true

    Flag indicating if parameter properties are dirty, requiring a new bind group build.

    nextPass: Material | null = null

    Secondary material rendered on top of the current pass. Assign a ShaderMaterial here to layer a second render pass (e.g., outline effect) over the primary material. The next pass automatically uses the same geometry and instance matrices, drawn immediately after.

    type: string = "Material"

    Material class type string tag used for fast runtime polymorphism checks.