Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ComputeShader

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

Hierarchy

  • ComputeShader

Index

Constructors

constructor

  • 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.ShadersStore["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.ShadersStore[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

nameSearch playground for name

name: string

The name of the material

onCompiledSearch playground for onCompiled

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

Callback triggered when the shader is compiled

onErrorSearch playground for onError

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

Callback triggered when an error occurs

Readonly uniqueIdSearch playground for uniqueId

uniqueId: number

Gets the unique id of the compute shader

Methods

dispatchSearch playground for dispatch

  • 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)

dispatchWhenReadySearch playground for dispatchWhenReady

  • 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!

getClassNameSearch playground for getClassName

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

    Returns string

    the class name

isReadySearch playground for isReady

  • 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

serializeSearch playground for serialize

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

    Returns any

    the serialized compute shader object

setStorageBufferSearch playground for setStorageBuffer

  • Binds a storage buffer to the shader

    Parameters

    • name: string

      Binding name of the buffer

    • buffer: StorageBuffer

      Buffer to bind

    Returns void

setStorageTextureSearch playground for setStorageTexture

  • 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

setTextureSearch playground for setTexture

  • Binds a texture to the shader

    Parameters

    • name: string

      Binding name of the texture

    • texture: BaseTexture

      Texture to bind

    Returns void

setUniformBufferSearch playground for setUniformBuffer

  • Binds a uniform buffer to the shader

    Parameters

    • name: string

      Binding name of the buffer

    • buffer: UniformBuffer

      Buffer to bind

    Returns void

Static ParseSearch playground for Parse

  • 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 property
  • Inherited method
  • Static property
  • Static method