Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Effect

Effect containing vertex and fragment shader that can be executed on an object.

Hierarchy

  • Effect

Implements

Index

Constructors

constructor

  • Instantiates an effect. An effect can be used to create/manage/execute vertex and fragment shaders.

    Parameters

    • baseName: any

      Name of the effect.

    • attributesNamesOrOptions: string[] | IEffectCreationOptions

      List of attribute names that will be passed to the shader or set of all options to create the effect.

    • uniformsNamesOrEngine: string[] | ThinEngine

      List of uniform variable names that will be passed to the shader or the engine that will be used to render effect.

    • Optional samplers: Nullable<string[]>

      List of sampler variables that will be passed to the shader.

    • Optional engine: ThinEngine

      Engine to be used to render the effect

    • Optional defines: Nullable<string>

      Define statements to be added to the shader.

    • Optional fallbacks: Nullable<IEffectFallbacks>

      Possible fallbacks for this effect to improve performance when needed.

    • Optional onCompiled: Nullable<(effect: Effect) => void>

      Callback that will be called when the shader is compiled.

    • Optional onError: Nullable<(effect: Effect, errors: string) => void>

      Callback that will be called if an error occurs during shader compilation.

    • Optional indexParameters: any

      Parameters to be used with Babylons include syntax to iterate over an array (eg. {lights: 10})

    • Optional key: string

      Effect Key identifying uniquely compiled shader variants

    • Optional shaderLanguage: ShaderLanguage

      the language the shader is written in (default: GLSL)

    Returns Effect

Properties

definesSearch playground for defines

defines: string

String container all the define statements that should be set on the shader.

nameSearch playground for name

name: any

Name of the effect.

onBindSearch playground for onBind

onBind: Nullable<(effect: Effect) => void>

Callback that will be called when effect is bound.

onCompileObservableSearch playground for onCompileObservable

onCompileObservable: Observable<Effect>

Observable that will be called when the shader is compiled. It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.

onCompiledSearch playground for onCompiled

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

Callback that will be called when the shader is compiled.

onErrorSearch playground for onError

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

Callback that will be called if an error occurs during shader compilation.

onErrorObservableSearch playground for onErrorObservable

onErrorObservable: Observable<Effect>

Observable that will be called if an error occurs during shader compilation.

uniqueIdSearch playground for uniqueId

uniqueId: number

Unique ID of the effect.

Static IncludesShadersStoreSearch playground for IncludesShadersStore

IncludesShadersStore: {}

Store of each included file for a shader (The can be looked up using effect.key)

Type declaration

  • [key: string]: string

Static LogShaderCodeOnCompilationErrorSearch playground for LogShaderCodeOnCompilationError

LogShaderCodeOnCompilationError: boolean

Enable logging of the shader code when a compilation error occurs

Static ShadersStoreSearch playground for ShadersStore

ShadersStore: {}

Store of each shader (The can be looked up using effect.key)

Type declaration

  • [key: string]: string

Accessors

fragmentSourceCode

  • get fragmentSourceCode(): string
  • Gets the fragment shader source code of this effect

    Returns string

isSupported

  • get isSupported(): boolean
  • Checks if the effect is supported. (Must be called after compilation)

    Returns boolean

key

  • get key(): string
  • Unique key for this effect

    Returns string

onBindObservable

  • Observable that will be called when effect is bound.

    Returns Observable<Effect>

rawFragmentSourceCode

  • get rawFragmentSourceCode(): string
  • Gets the fragment shader source code before it has been processed by the preprocessor

    Returns string

rawVertexSourceCode

  • get rawVertexSourceCode(): string
  • Gets the vertex shader source code before it has been processed by the preprocessor

    Returns string

vertexSourceCode

  • get vertexSourceCode(): string
  • Gets the vertex shader source code of this effect

    Returns string

Static ShadersRepository

  • get ShadersRepository(): string
  • set ShadersRepository(repo: string): any
  • Gets or sets the relative url used to load shaders if using the engine in non-minified mode

    Returns string

  • Gets or sets the relative url used to load shaders if using the engine in non-minified mode

    Parameters

    • repo: string

    Returns any

Methods

allFallbacksProcessedSearch playground for allFallbacksProcessed

  • allFallbacksProcessed(): boolean
  • Gets a boolean indicating that all fallbacks were used during compilation

    Returns boolean

    true if all fallbacks were used

bindUniformBlockSearch playground for bindUniformBlock

  • bindUniformBlock(blockName: string, index: number): void
  • Binds block to a uniform.

    Parameters

    • blockName: string

      Name of the block to bind.

    • index: number

      Index to bind.

    Returns void

bindUniformBufferSearch playground for bindUniformBuffer

  • bindUniformBuffer(buffer: DataBuffer, name: string): void
  • Binds a buffer to a uniform.

    Parameters

    • buffer: DataBuffer

      Buffer to bind.

    • name: string

      Name of the uniform variable to bind to.

    Returns void

disposeSearch playground for dispose

  • dispose(): void
  • Release all associated resources.

    Returns void

executeWhenCompiledSearch playground for executeWhenCompiled

  • executeWhenCompiled(func: (effect: Effect) => void): void
  • Adds a callback to the onCompiled observable and call the callback immediately if already ready.

    Parameters

    • func: (effect: Effect) => void

      The callback to be used.

        • Parameters

          Returns void

    Returns void

getAttributeLocationSearch playground for getAttributeLocation

  • getAttributeLocation(index: number): number
  • Returns the attribute at the given index.

    Parameters

    • index: number

      The index of the attribute.

    Returns number

    The location of the attribute.

getAttributeLocationByNameSearch playground for getAttributeLocationByName

  • getAttributeLocationByName(name: string): number
  • Returns the attribute based on the name of the variable.

    Parameters

    • name: string

      of the attribute to look up.

    Returns number

    the attribute location.

getAttributesCountSearch playground for getAttributesCount

  • getAttributesCount(): number
  • The number of attributes.

    Returns number

    the number of attributes.

getAttributesNamesSearch playground for getAttributesNames

  • getAttributesNames(): string[]
  • The set of names of attribute variables for the shader.

    Returns string[]

    An array of attribute names.

getCompilationErrorSearch playground for getCompilationError

  • getCompilationError(): string
  • The error from the last compilation.

    Returns string

    the error string.

getEngineSearch playground for getEngine

  • The engine the effect was initialized with.

    Returns Engine

    the engine.

getIndexParametersSearch playground for getIndexParameters

  • getIndexParameters(): any
  • Returns the index parameters used to create the effect

    Returns any

    The index parameters object

getPipelineContextSearch playground for getPipelineContext

  • The pipeline context for this effect

    Returns Nullable<IPipelineContext>

    the associated pipeline context

getSamplersSearch playground for getSamplers

  • getSamplers(): string[]
  • Returns an array of sampler variable names

    Returns string[]

    The array of sampler variable names.

getUniformSearch playground for getUniform

  • Returns the attribute based on the name of the variable.

    Parameters

    • uniformName: string

      of the uniform to look up.

    Returns Nullable<WebGLUniformLocation>

    the location of the uniform.

getUniformBuffersNamesSearch playground for getUniformBuffersNames

  • getUniformBuffersNames(): string[]
  • Returns an array of uniform buffer variable names

    Returns string[]

    The array of uniform buffer variable names.

getUniformIndexSearch playground for getUniformIndex

  • getUniformIndex(uniformName: string): number
  • Gets the index of a uniform variable.

    Parameters

    • uniformName: string

      of the uniform to look up.

    Returns number

    the index.

getUniformNamesSearch playground for getUniformNames

  • getUniformNames(): string[]
  • Returns an array of uniform variable names

    Returns string[]

    The array of uniform variable names.

isReadySearch playground for isReady

  • isReady(): boolean
  • If the effect has been compiled and prepared.

    Returns boolean

    if the effect is compiled and prepared.

setArraySearch playground for setArray

  • setArray(uniformName: string, array: number[]): Effect
  • Sets an array on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • array: number[]

      array to be set.

    Returns Effect

    this effect.

setArray2Search playground for setArray2

  • setArray2(uniformName: string, array: number[]): Effect
  • Sets an array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: number[]

      array to be set.

    Returns Effect

    this effect.

setArray3Search playground for setArray3

  • setArray3(uniformName: string, array: number[]): Effect
  • Sets an array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: number[]

      array to be set.

    Returns Effect

    this effect.

setArray4Search playground for setArray4

  • setArray4(uniformName: string, array: number[]): Effect
  • Sets an array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: number[]

      array to be set.

    Returns Effect

    this effect.

setBoolSearch playground for setBool

  • setBool(uniformName: string, bool: boolean): Effect
  • Sets a boolean on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • bool: boolean

      value to be set.

    Returns Effect

    this effect.

setColor3Search playground for setColor3

  • setColor3(uniformName: string, color3: IColor3Like): Effect
  • Sets a Color3 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • color3: IColor3Like

      Value to be set.

    Returns Effect

    this effect.

setColor4Search playground for setColor4

  • setColor4(uniformName: string, color3: IColor3Like, alpha: number): Effect
  • Sets a Color4 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • color3: IColor3Like

      Value to be set.

    • alpha: number

      Alpha value to be set.

    Returns Effect

    this effect.

setDepthStencilTextureSearch playground for setDepthStencilTexture

  • Sets a depth stencil texture from a render target on the engine to be used in the shader.

    Parameters

    Returns void

setDirectColor4Search playground for setDirectColor4

  • setDirectColor4(uniformName: string, color4: IColor4Like): Effect
  • Sets a Color4 on a uniform variable

    Parameters

    • uniformName: string

      defines the name of the variable

    • color4: IColor4Like

      defines the value to be set

    Returns Effect

    this effect.

setExternalTextureSearch playground for setExternalTexture

  • Sets an external texture on the engine to be used in the shader.

    Parameters

    Returns void

setFloatSearch playground for setFloat

  • setFloat(uniformName: string, value: number): Effect
  • Sets a float on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • value: number

      value to be set.

    Returns Effect

    this effect.

setFloat2Search playground for setFloat2

  • setFloat2(uniformName: string, x: number, y: number): Effect
  • Sets a float2 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • x: number

      First float in float2.

    • y: number

      Second float in float2.

    Returns Effect

    this effect.

setFloat3Search playground for setFloat3

  • setFloat3(uniformName: string, x: number, y: number, z: number): Effect
  • Sets a float3 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • x: number

      First float in float3.

    • y: number

      Second float in float3.

    • z: number

      Third float in float3.

    Returns Effect

    this effect.

setFloat4Search playground for setFloat4

  • setFloat4(uniformName: string, x: number, y: number, z: number, w: number): Effect
  • Sets a float4 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • x: number

      First float in float4.

    • y: number

      Second float in float4.

    • z: number

      Third float in float4.

    • w: number

      Fourth float in float4.

    Returns Effect

    this effect.

setFloatArraySearch playground for setFloatArray

  • Sets an float array on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • array: FloatArray

      array to be set.

    Returns Effect

    this effect.

setFloatArray2Search playground for setFloatArray2

  • Sets an float array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: FloatArray

      array to be set.

    Returns Effect

    this effect.

setFloatArray3Search playground for setFloatArray3

  • Sets an float array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: FloatArray

      array to be set.

    Returns Effect

    this effect.

setFloatArray4Search playground for setFloatArray4

  • Sets an float array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: FloatArray

      array to be set.

    Returns Effect

    this effect.

setIntSearch playground for setInt

  • setInt(uniformName: string, value: number): Effect
  • Sets an integer value on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • value: number

      Value to be set.

    Returns Effect

    this effect.

setInt2Search playground for setInt2

  • setInt2(uniformName: string, x: number, y: number): Effect
  • Sets an int2 value on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • x: number

      First int in int2.

    • y: number

      Second int in int2.

    Returns Effect

    this effect.

setInt3Search playground for setInt3

  • setInt3(uniformName: string, x: number, y: number, z: number): Effect
  • Sets an int3 value on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • x: number

      First int in int3.

    • y: number

      Second int in int3.

    • z: number

      Third int in int3.

    Returns Effect

    this effect.

setInt4Search playground for setInt4

  • setInt4(uniformName: string, x: number, y: number, z: number, w: number): Effect
  • Sets an int4 value on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • x: number

      First int in int4.

    • y: number

      Second int in int4.

    • z: number

      Third int in int4.

    • w: number

      Fourth int in int4.

    Returns Effect

    this effect.

setIntArraySearch playground for setIntArray

  • setIntArray(uniformName: string, array: Int32Array): Effect
  • Sets an int array on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • array: Int32Array

      array to be set.

    Returns Effect

    this effect.

setIntArray2Search playground for setIntArray2

  • setIntArray2(uniformName: string, array: Int32Array): Effect
  • Sets an int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: Int32Array

      array to be set.

    Returns Effect

    this effect.

setIntArray3Search playground for setIntArray3

  • setIntArray3(uniformName: string, array: Int32Array): Effect
  • Sets an int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: Int32Array

      array to be set.

    Returns Effect

    this effect.

setIntArray4Search playground for setIntArray4

  • setIntArray4(uniformName: string, array: Int32Array): Effect
  • Sets an int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)

    Parameters

    • uniformName: string

      Name of the variable.

    • array: Int32Array

      array to be set.

    Returns Effect

    this effect.

setMatricesSearch playground for setMatrices

  • setMatrices(uniformName: string, matrices: Float32Array | Array<number>): Effect
  • Sets matrices on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • matrices: Float32Array | Array<number>

      matrices to be set.

    Returns Effect

    this effect.

setMatrixSearch playground for setMatrix

  • setMatrix(uniformName: string, matrix: IMatrixLike): Effect
  • Sets matrix on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • matrix: IMatrixLike

      matrix to be set.

    Returns Effect

    this effect.

setMatrix2x2Search playground for setMatrix2x2

  • setMatrix2x2(uniformName: string, matrix: Float32Array | Array<number>): Effect
  • Sets a 2x2 matrix on a uniform variable. (Specified as [1,2,3,4] will result in [1,2][3,4] matrix)

    Parameters

    • uniformName: string

      Name of the variable.

    • matrix: Float32Array | Array<number>

      matrix to be set.

    Returns Effect

    this effect.

setMatrix3x3Search playground for setMatrix3x3

  • setMatrix3x3(uniformName: string, matrix: Float32Array | Array<number>): Effect
  • Sets a 3x3 matrix on a uniform variable. (Specified as [1,2,3,4,5,6,7,8,9] will result in [1,2,3][4,5,6][7,8,9] matrix)

    Parameters

    • uniformName: string

      Name of the variable.

    • matrix: Float32Array | Array<number>

      matrix to be set.

    Returns Effect

    this effect.

setQuaternionSearch playground for setQuaternion

  • Sets a Quaternion on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • quaternion: IQuaternionLike

      Value to be set.

    Returns Effect

    this effect.

setStorageBufferSearch playground for setStorageBuffer

  • Sets a storage buffer on the engine to be used in the shader.

    Parameters

    • name: string

      Name of the storage buffer variable.

    • buffer: Nullable<StorageBuffer>

      Storage buffer to set.

    Returns void

setTextureSearch playground for setTexture

  • Sets a texture on the engine to be used in the shader.

    Parameters

    Returns void

setTextureArraySearch playground for setTextureArray

  • setTextureArray(channel: string, textures: ThinTexture[]): void
  • Sets an array of textures on the engine to be used in the shader.

    Parameters

    • channel: string

      Name of the variable.

    • textures: ThinTexture[]

      Textures to set.

    Returns void

setTextureFromPostProcessSearch playground for setTextureFromPostProcess

  • Sets a texture to be the input of the specified post process. (To use the output, pass in the next post process in the pipeline)

    Parameters

    • channel: string

      Name of the sampler variable.

    • postProcess: Nullable<PostProcess>

      Post process to get the input texture from.

    Returns void

setTextureFromPostProcessOutputSearch playground for setTextureFromPostProcessOutput

  • (Warning! setTextureFromPostProcessOutput may be desired instead) Sets the input texture of the passed in post process to be input of this effect. (To use the output of the passed in post process use setTextureFromPostProcessOutput)

    Parameters

    • channel: string

      Name of the sampler variable.

    • postProcess: Nullable<PostProcess>

      Post process to get the output texture from.

    Returns void

setTextureSamplerSearch playground for setTextureSampler

  • Sets a sampler on the engine to be used in the shader.

    Parameters

    Returns void

setVector2Search playground for setVector2

  • setVector2(uniformName: string, vector2: IVector2Like): Effect
  • Sets a Vector2 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • vector2: IVector2Like

      vector2 to be set.

    Returns Effect

    this effect.

setVector3Search playground for setVector3

  • setVector3(uniformName: string, vector3: IVector3Like): Effect
  • Sets a Vector3 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • vector3: IVector3Like

      Value to be set.

    Returns Effect

    this effect.

setVector4Search playground for setVector4

  • setVector4(uniformName: string, vector4: IVector4Like): Effect
  • Sets a Vector4 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • vector4: IVector4Like

      Value to be set.

    Returns Effect

    this effect.

Static RegisterShaderSearch playground for RegisterShader

  • RegisterShader(name: string, pixelShader?: string, vertexShader?: string, shaderLanguage?: ShaderLanguage): void
  • This function will add a new shader to the shader store

    Parameters

    • name: string

      the name of the shader

    • Optional pixelShader: string

      optional pixel shader content

    • Optional vertexShader: string

      optional vertex shader content

    • Optional shaderLanguage: ShaderLanguage

      the language the shader is written in (default: GLSL)

    Returns void

Static ResetCacheSearch playground for ResetCache

  • ResetCache(): void
  • Resets the cache of effects.

    Returns void

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method