Options
All
  • Public
  • Public/Protected
  • All
Menu

Options for ShaderProgram

Common functions, variables and constants avialable in both fragment and vertex shaders:

  • PI: The constant pi
  • u_resolution: a vec2 with the frame's width and height
  • u_srcTexture: when swapFrame is true then this is a reference to the previous texture
  • getSrcColorAtPos(vec2 pos): when swapFrame is true, this gives the color at given position in the previous texture

Type parameters

  • ValueType

Hierarchy

  • IShaderOpts

Index

Properties

Optional bindings

bindings: IBindings

Variable bindings for the shader.

Optional blendMode

blendMode: BlendMode

Specifies the default blend mode for this shader.

Optional blendValue

blendValue: 0.5

Specifies the blendValue when defaultBlend mode is ADJUSTABLE

Optional copyOnSwap

copyOnSwap: boolean

If enabled, then immediately after a frame swap on the TextureSetManager we also copy the previous frame into current frame

Optional drawHook

drawHook: function

A hook function that'd called instead of the default draw call behavior. drawHook can also return a falsy value to indicate that draw has not been handled, causing the shader to fallback to default draw call behavior.

Type declaration

    • (values: ValueType, gl: WebGLRenderingContext, shader: ShaderProgram): any
    • Parameters

      • values: ValueType
      • gl: WebGLRenderingContext
      • shader: ShaderProgram

      Returns any

Optional dynamicBlend

dynamicBlend: boolean

If enabled then default blendMode is not baked into the shader and blendMode can be set on ShaderProgram.run call

fragmentShader

fragmentShader: string | string[]

Source for fragment shader.

variables and functions available in fragment shaders:

  • v_position: a [0-1,0-1] varying of the position
  • getSrcColor(): equivalent to getSrcColorAtPos(v_position)
  • setFragColor(vec3 color): sets gl_FragColor with correct blending

Optional swapFrame

swapFrame: boolean

If enabled then everytime this shader is run, we cycle to next frame in the TextureSetManager that's passed in to the run call. The shader program may also choose to do this if a blendMode is not supported by gl.BlendFunc

Optional vertexShader

vertexShader: string | string[]

Source for vertex shader. If no vertex shader is provided then a a default vertex shader with squareGeometry values is provided.

variables and functions available in fragment shaders:

  • v_position: a [0-1,0-1] varying of the position
  • setPosition(vec2 position): correctly sets the gl_position