Skip to main content

Shader

Index

Constructors

constructor

  • Create a shader program in excalibur


    Parameters

    Returns Shader

Properties

publicattributes

attributes: {} = {}

Type declaration

publicreadonlyfragmentSource

fragmentSource: string

images

images: Record<string, ImageSource> = {}

Set images to load into the shader as a sampler2d

publicreadonlyname

name: string = 'anonymous shader'

publicprogram

program: WebGLProgram

uniforms

uniforms: UniformDictionary = ...

Set uniforms key value pairs

publicreadonlyvertexSource

vertexSource: string

Accessors

publiccompiled

  • get compiled(): boolean
  • Returns whether the shader is compiled


    Returns boolean

Methods

_setImages

  • _setImages(suppressWarning?: boolean): void
  • Parameters

    • suppressWarning: boolean = false

    Returns void

addImageSource

  • addImageSource(samplerName: string, image: ImageSource): void
  • Parameters

    Returns void

compile

  • compile(): WebGLProgram
  • Compile the current shader against a webgl context


    Returns WebGLProgram

dispose

  • dispose(): void
  • Deletes the webgl program from the gpu


    Returns void

publicflagUniformsDirty

  • flagUniformsDirty(): void
  • Flags uniforms need to be re-uploaded on the next call to .use()


    Returns void

getAttributeDefinitions

getUniformDefinitions

isCurrentlyBound

  • isCurrentlyBound(): boolean
  • Returns boolean

removeImageSource

  • removeImageSource(samplerName: string): void
  • Parameters

    • samplerName: string

    Returns void

setTexture

  • setTexture(slotNumber: number, texture: WebGLTexture): void
  • Set a texture in a gpu texture slot


    Parameters

    • slotNumber: number
    • texture: WebGLTexture

    Returns void

setUniform

  • setUniform<TUniformType>(uniformType: TUniformType, name: string, ...value: RemoveFirstFromTuple<Parameters<WebGL2RenderingContext[TUniformType]>>): void
  • Set any available uniform type in webgl

    For example setUniform('uniformMatrix2fv', 'u_my2x2_mat`, ...);


    Type parameters

    Parameters

    • uniformType: TUniformType
    • name: string
    • rest...value: RemoveFirstFromTuple<Parameters<WebGL2RenderingContext[TUniformType]>>

    Returns void

setUniformAffineMatrix

  • setUniformAffineMatrix(name: string, value: AffineMatrix): void

setUniformBoolean

  • setUniformBoolean(name: string, value: boolean): void
  • Set a boolean uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: boolean

    Returns void

setUniformBuffer

  • setUniformBuffer(name: string, data: Float32Array, bindingPoint?: number): void
  • Set a uniform buffer block with a Float32Array


    Parameters

    • name: string

      The of the binding block

    • data: Float32Array

      Float32Array

    • optionalbindingPoint: number = 0

    Returns void

setUniformFloat

  • setUniformFloat(name: string, value: number): void
  • Set a float uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number

    Returns void

setUniformFloatArray

  • setUniformFloatArray(name: string, value: number[]): void
  • Set a float array uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number[]

    Returns void

setUniformFloatColor

  • setUniformFloatColor(name: string, value: Color): void
  • Set a Color uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns void

setUniformFloatVector

  • setUniformFloatVector(name: string, value: Vector): void
  • Set a Vector uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns void

setUniformInt

  • setUniformInt(name: string, value: number): void
  • Set an integer uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number

    Returns void

setUniformIntArray

  • setUniformIntArray(name: string, value: number[]): void
  • Set an integer array uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number[]

    Returns void

setUniformMatrix

  • setUniformMatrix(name: string, value: Matrix): void
  • Set an Matrix uniform for the current shader

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns void

trySetUniform

  • trySetUniform<TUniformType>(uniformType: TUniformType, name: string, ...value: RemoveFirstFromTuple<Parameters<WebGL2RenderingContext[TUniformType]>>): boolean
  • Set any available uniform type in webgl. Will try to set the uniform, will return false if the uniform didn't exist, true if it was set.

    WILL NOT THROW on error

    For example setUniform('uniformMatrix2fv', 'u_my2x2_mat`, ...);


    Type parameters

    Parameters

    • uniformType: TUniformType
    • name: string
    • rest...value: RemoveFirstFromTuple<Parameters<WebGL2RenderingContext[TUniformType]>>

    Returns boolean

trySetUniformBoolean

  • trySetUniformBoolean(name: string, value: boolean): boolean
  • Set a boolean uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: boolean

    Returns boolean

trySetUniformBuffer

  • trySetUniformBuffer(name: string, data: Float32Array, bindingPoint?: number): boolean
  • Parameters

    • name: string
    • data: Float32Array
    • bindingPoint: number = 0

    Returns boolean

trySetUniformFloat

  • trySetUniformFloat(name: string, value: number): boolean
  • Set a float uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number

    Returns boolean

trySetUniformFloatArray

  • trySetUniformFloatArray(name: string, value: number[]): boolean
  • Set a float array uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number[]

    Returns boolean

trySetUniformFloatColor

  • trySetUniformFloatColor(name: string, value: Color): boolean
  • Set a Color uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns boolean

trySetUniformFloatVector

  • trySetUniformFloatVector(name: string, value: Vector): boolean
  • Set a Vector uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns boolean

trySetUniformInt

  • trySetUniformInt(name: string, value: number): boolean
  • Set an integer uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number

    Returns boolean

trySetUniformIntArray

  • trySetUniformIntArray(name: string, value: number[]): boolean
  • Set an integer array uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    • name: string
    • value: number[]

    Returns boolean

trySetUniformMatrix

  • trySetUniformMatrix(name: string, value: Matrix): boolean
  • Set an Matrix uniform for the current shader, WILL NOT THROW on error.

    Important Must call ex.Shader.use() before setting a uniform!


    Parameters

    Returns boolean

unuse

  • unuse(): void
  • Returns void

use

  • use(): void
  • Binds the shader program


    Returns void