Effect

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

Hierarchy

  • Effect

Index

Constructors

constructor

Find examples in Playground
  • 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[] | EffectCreationOptions

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

    • uniformsNamesOrEngine: string[] | Engine

      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: Engine

      Engine to be used to render the effect

    • Optional defines: Nullable<string>

      Define statements to be added to the shader.

    • Optional fallbacks: Nullable<EffectFallbacks>

      Possible fallbacks for this effect to improve performance when needed.

    • Optional onCompiled: Nullable<function>

      Callback that will be called when the shader is compiled.

    • Optional onError: Nullable<function>

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

    Returns Effect

Properties

defines

Find examples in Playground
defines: string

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

isSupported

Find examples in Playground
isSupported: boolean

Checks if the effect is supported. (Must be called after compilation)

key

Find examples in Playground
key: string

Unique key for this effect

name

Find examples in Playground
name: any

Name of the effect.

onBind

Find examples in Playground
onBind: Nullable<function>

Callback that will be called when effect is bound.

onBindObservable

Find examples in Playground
onBindObservable: Observable<Effect>

Observable that will be called when effect is bound.

onCompileObservable

Find examples in Playground
onCompileObservable: Observable<Effect>

Observable that will be called when the shader is compiled.

onCompiled

Find examples in Playground
onCompiled: Nullable<function>

Callback that will be called when the shader is compiled.

onError

Find examples in Playground
onError: Nullable<function>

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

onErrorObservable

Find examples in Playground
onErrorObservable: Observable<Effect>

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

uniqueId

Find examples in Playground
uniqueId: number

Unique ID of the effect.

Static IncludesShadersStore

Find examples in Playground
IncludesShadersStore: object

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

Type declaration

  • [key: string]: string

Static ShadersStore

Find examples in Playground
ShadersStore: object

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

Type declaration

  • [key: string]: string

Methods

bindUniformBlock

Find examples in Playground
  • 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

bindUniformBuffer

Find examples in Playground
  • bindUniformBuffer(buffer: WebGLBuffer, name: string): void
  • Binds a buffer to a uniform.

    Parameters

    • buffer: WebGLBuffer

      Buffer to bind.

    • name: string

      Name of the uniform variable to bind to.

    Returns void

executeWhenCompiled

Find examples in Playground
  • executeWhenCompiled(func: function): void
  • Adds a callback to the onCompiled observable and call the callback imediatly if already ready.

    Parameters

    • func: function

      The callback to be used.

        • Parameters

          Returns void

    Returns void

getAttributeLocation

Find examples in Playground
  • 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.

getAttributeLocationByName

Find examples in Playground
  • 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.

getAttributesCount

Find examples in Playground
  • getAttributesCount(): number
  • The number of attributes.

    Returns number

    the numnber of attributes.

getAttributesNames

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

    Returns string[]

    An array of attribute names.

getCompilationError

Find examples in Playground
  • getCompilationError(): string
  • The error from the last compilation.

    Returns string

    the error string.

getEngine

Find examples in Playground
  • The engine the effect was initialized with.

    Returns Engine

    the engine.

getProgram

Find examples in Playground
  • getProgram(): WebGLProgram
  • The compiled webGL program for the effect

    Returns WebGLProgram

    the webGL program.

getSamplers

Find examples in Playground
  • getSamplers(): string[]
  • Returns an array of sampler variable names

    Returns string[]

    The array of sampler variable neames.

getSpecificUniformLocations

Find examples in Playground
  • getSpecificUniformLocations(names: string[]): Nullable<WebGLUniformLocation>[]
  • Gets the uniform locations of the the specified variable names

    Parameters

    • names: string[]

      THe names of the variables to lookup.

    Returns Nullable<WebGLUniformLocation>[]

    Array of locations in the same order as variable names.

getUniform

Find examples in Playground
  • getUniform(uniformName: string): Nullable<WebGLUniformLocation>
  • 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.

getUniformIndex

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

    Parameters

    • uniformName: string

      of the uniform to look up.

    Returns number

    the index.

isReady

Find examples in Playground
  • isReady(): boolean
  • If the effect has been compiled and prepared.

    Returns boolean

    if the effect is compiled and prepared.

setArray

Find examples in Playground
  • 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.

setArray2

Find examples in Playground
  • 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.

setArray3

Find examples in Playground
  • 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.

setArray4

Find examples in Playground
  • 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.

setBool

Find examples in Playground
  • 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.

setColor3

Find examples in Playground
  • Sets a Color3 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • color3: Color3

      Value to be set.

    Returns Effect

    this effect.

setColor4

Find examples in Playground
  • setColor4(uniformName: string, color3: Color3, alpha: number): Effect
  • Sets a Color4 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • color3: Color3

      Value to be set.

    • alpha: number

      Alpha value to be set.

    Returns Effect

    this effect.

setDepthStencilTexture

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

    Parameters

    Returns void

setDirectColor4

Find examples in Playground
  • setDirectColor4(uniformName: string, color4: Color4): Effect
  • Sets a Color4 on a uniform variable

    Parameters

    • uniformName: string

      defines the name of the variable

    • color4: Color4

      defines the value to be set

    Returns Effect

    this effect.

setFloat

Find examples in Playground
  • 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.

setFloat2

Find examples in Playground
  • 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.

setFloat3

Find examples in Playground
  • 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.

setFloat4

Find examples in Playground
  • 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.

setFloatArray

Find examples in Playground
  • setFloatArray(uniformName: string, array: Float32Array): Effect
  • Sets an float array on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • array: Float32Array

      array to be set.

    Returns Effect

    this effect.

setFloatArray2

Find examples in Playground
  • setFloatArray2(uniformName: string, array: Float32Array): Effect
  • 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: Float32Array

      array to be set.

    Returns Effect

    this effect.

setFloatArray3

Find examples in Playground
  • setFloatArray3(uniformName: string, array: Float32Array): Effect
  • 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: Float32Array

      array to be set.

    Returns Effect

    this effect.

setFloatArray4

Find examples in Playground
  • setFloatArray4(uniformName: string, array: Float32Array): Effect
  • 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: Float32Array

      array to be set.

    Returns Effect

    this effect.

setInt

Find examples in Playground
  • setInt(uniformName: string, value: number): Effect
  • Sets an interger value on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • value: number

      Value to be set.

    Returns Effect

    this effect.

setIntArray

Find examples in Playground
  • 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.

setIntArray2

Find examples in Playground
  • 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.

setIntArray3

Find examples in Playground
  • 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.

setIntArray4

Find examples in Playground
  • 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.

setMatrices

Find examples in Playground
  • setMatrices(uniformName: string, matrices: Float32Array): Effect
  • Sets matrices on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • matrices: Float32Array

      matrices to be set.

    Returns Effect

    this effect.

setMatrix

Find examples in Playground
  • Sets matrix on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • matrix: Matrix

      matrix to be set.

    Returns Effect

    this effect.

setMatrix2x2

Find examples in Playground
  • setMatrix2x2(uniformName: string, matrix: Float32Array): Effect
  • Sets a 2x2 matrix on a uniform variable. (Speicified as [1,2,3,4] will result in [1,2][3,4] matrix)

    Parameters

    • uniformName: string

      Name of the variable.

    • matrix: Float32Array

      matrix to be set.

    Returns Effect

    this effect.

setMatrix3x3

Find examples in Playground
  • setMatrix3x3(uniformName: string, matrix: Float32Array): Effect
  • Sets a 3x3 matrix on a uniform variable. (Speicified 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

      matrix to be set.

    Returns Effect

    this effect.

setTexture

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

    Parameters

    Returns void

setTextureArray

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

    Parameters

    • channel: string

      Name of the variable.

    • textures: BaseTexture[]

      Textures to set.

    Returns void

setTextureFromPostProcess

Find examples in Playground
  • 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

setTextureFromPostProcessOutput

Find examples in Playground
  • (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

setVector2

Find examples in Playground
  • Sets a Vector2 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • vector2: Vector2

      vector2 to be set.

    Returns Effect

    this effect.

setVector3

Find examples in Playground
  • Sets a Vector3 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • vector3: Vector3

      Value to be set.

    Returns Effect

    this effect.

setVector4

Find examples in Playground
  • Sets a Vector4 on a uniform variable.

    Parameters

    • uniformName: string

      Name of the variable.

    • vector4: Vector4

      Value to be set.

    Returns Effect

    this effect.

Static RegisterShader

Find examples in Playground
  • RegisterShader(name: string, pixelShader?: string, vertexShader?: string): 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

    Returns void

Static ResetCache

Find examples in Playground
  • ResetCache(): void
  • Resets the cache of effects.

    Returns void

Generated using TypeDoc