Options
All
  • Public
  • Public/Protected
  • All
Menu

The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)

Hierarchy

  • ComputeShader

Index

Constructors

  • Instantiates a new compute shader.

    Parameters

    • name: string

      Defines the name of the compute shader in the scene

    • engine: ThinEngine

      Defines the engine the compute shader belongs to

    • shaderPath: any

      Defines the route to the shader code in one of three ways:

      • object: { compute: "custom" }, used with ShaderStore.ShadersStoreWGSL["customComputeShader"]
      • object: { computeElement: "HTMLElementId" }, used with shader code in script tags
      • object: { computeSource: "compute shader code string" using with string containing the shader code
      • string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + "ComputeShader"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.
    • Optional options: Partial<IComputeShaderOptions>

      Define the options used to create the shader

    Returns ComputeShader

Properties

name: string

The name of the shader

onCompiled: Nullable<(effect: ComputeEffect) => void>

Callback triggered when the shader is compiled

onError: Nullable<(effect: ComputeEffect, errors: string) => void>

Callback triggered when an error occurs

uniqueId: number

Gets the unique id of the compute shader

Accessors

  • The options used to create the shader

    Returns IComputeShaderOptions

  • get shaderPath(): any
  • The shaderPath used to create the shader

    Returns any

Methods

  • dispatch(x: number, y?: number, z?: number): boolean
  • Dispatches (executes) the compute shader

    Parameters

    • x: number

      Number of workgroups to execute on the X dimension

    • Optional y: number

      Number of workgroups to execute on the Y dimension (default: 1)

    • Optional z: number

      Number of workgroups to execute on the Z dimension (default: 1)

    Returns boolean

    True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)

  • dispatchWhenReady(x: number, y?: number, z?: number, delay?: number): Promise<void>
  • Waits for the compute shader to be ready and executes it

    Parameters

    • x: number

      Number of workgroups to execute on the X dimension

    • Optional y: number

      Number of workgroups to execute on the Y dimension (default: 1)

    • Optional z: number

      Number of workgroups to execute on the Z dimension (default: 1)

    • Optional delay: number

      Delay between the retries while the shader is not ready (in milliseconds - 10 by default)

    Returns Promise<void>

    A promise that is resolved once the shader has been sent to the GPU. Note that it does not mean that the shader execution itself is finished!

  • getClassName(): string
  • Gets the current class name of the material e.g. "ComputeShader" Mainly use in serialization.

    Returns string

    the class name

  • isReady(): boolean
  • Specifies that the compute shader is ready to be executed (the compute effect and all the resources are ready)

    Returns boolean

    true if the compute shader is ready to be executed

  • serialize(): any
  • Serializes this compute shader in a JSON representation

    Returns any

    the serialized compute shader object

  • Binds a storage buffer to the shader

    Parameters

    • name: string

      Binding name of the buffer

    • buffer: StorageBuffer

      Buffer to bind

    Returns void

  • setStorageTexture(name: string, texture: BaseTexture): void
  • Binds a storage texture to the shader

    Parameters

    • name: string

      Binding name of the texture

    • texture: BaseTexture

      Texture to bind

    Returns void

  • setTexture(name: string, texture: BaseTexture, bindSampler?: boolean): void
  • Binds a texture to the shader

    Parameters

    • name: string

      Binding name of the texture

    • texture: BaseTexture

      Texture to bind

    • Optional bindSampler: boolean

      Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture

    Returns void

  • Binds a texture sampler to the shader

    Parameters

    • name: string

      Binding name of the sampler

    • sampler: TextureSampler

      Sampler to bind

    Returns void

  • Binds a uniform buffer to the shader

    Parameters

    • name: string

      Binding name of the buffer

    • buffer: UniformBuffer

      Buffer to bind

    Returns void

  • Creates a compute shader from parsed compute shader data

    Parameters

    • source: any

      defines the JSON representation of the compute shader

    • scene: Scene

      defines the hosting scene

    • rootUrl: string

      defines the root URL to use to load textures and relative dependencies

    Returns ComputeShader

    a new compute shader

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited constructor
  • Static method

Settings

Theme