Class ComputeShader
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.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
nameSearch playground for name
The name of the shader
on CompiledSearch playground for onCompiled
Callback triggered when the shader is compiled
on ErrorSearch playground for onError
Callback triggered when an error occurs
Readonly unique IdSearch playground for uniqueId
Gets the unique id of the compute shader
Accessors
options
The options used to create the shader
Returns IComputeShaderOptions
shader Path
The shaderPath used to create the shader
Returns any
Methods
dispatchSearch playground for dispatch
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)
dispatch When ReadySearch playground for dispatchWhenReady
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!
get Class NameSearch playground for getClassName
Gets the current class name of the material e.g. "ComputeShader" Mainly use in serialization.
Returns string
the class name
is ReadySearch playground for isReady
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
Serializes this compute shader in a JSON representation
Returns any
the serialized compute shader object
set Storage BufferSearch 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
set Storage TextureSearch playground for setStorageTexture
Binds a storage texture to the shader
Parameters
name: string
Binding name of the texture
texture: BaseTexture
Texture to bind
Returns void
set TextureSearch playground for setTexture
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
set Texture SamplerSearch playground for setTextureSampler
Binds a texture sampler to the shader
Parameters
name: string
Binding name of the sampler
sampler: TextureSampler
Sampler to bind
Returns void
set Uniform BufferSearch 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
The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)