API Reference

ShaderPad

ShaderPad is the core class exported by the library.

import ShaderPad from 'shaderpad';

Constructor

new ShaderPad(fragmentShaderSrc: string, options?: Options)

ShaderPad creates a WebGL2 program, initializes built-in uniforms, allocates its render targets, optionally allocates output history, and installs plugins.

Constructor Options Reference

OptionTypeDefaultNotes
canvasHTMLCanvasElement | OffscreenCanvas | { width: number; height: number } | nullnew OffscreenCanvas(1, 1)If you pass an actual canvas, ShaderPad renders into it. If you pass { width, height }, null, or omit the option, ShaderPad creates a headless OffscreenCanvas.
pluginsPlugin[][]Installed during construction, before the final fragment shader is compiled, so plugins can inject GLSL and hooks.
historynumber0Number of previous output frames to store. 0 disables output history entirely.
cursorTargetWindow | ElementThe HTML canvas passed as canvas, otherwise undefinedUsed for built-in u_cursor and u_click input tracking. Offscreen or headless setups only get pointer listeners if you pass a target explicitly.
internalFormatGLInternalFormatStringDerived from type, otherwise 'RGBA8'Float color targets such as 'RGBA16F' and 'RGBA32F' require EXT_color_buffer_float.
formatGLFormatStringDerived from internalFormatDefaults to 'RGBA' for normalized and float color formats, and 'RGBA_INTEGER' for integer color formats.
typeGLTypeStringDerived from internalFormat, otherwise 'UNSIGNED_BYTE'Texel data type.
minFilterGLFilterString'LINEAR'Minification filter.
magFilterGLFilterString'LINEAR'Magnification filter.
wrapSGLWrapString'CLAMP_TO_EDGE'Horizontal wrap mode.
wrapTGLWrapString'CLAMP_TO_EDGE'Vertical wrap mode.

Constructor-level texture settings control:

  • the intermediate render texture used for drawing
  • the output history texture when history > 0
  • the texture exposed when another ShaderPad samples this instance directly

Exported Types

Root shaderpad exports Options, StepOptions, TextureOptions, InitializeTextureOptions, TextureSource, UpdateTextureSource, CustomTexture, PartialCustomTexture, Plugin, PluginContext, ShaderPadEventName, and the GL literal string types. shaderpad/util exports ToBlobOptions and SaveOptions.

GL Literal Types

The render-texture options above use these literal unions:

  • GLInternalFormatString: every combination of channel prefix 'R', 'RG', 'RGB', or 'RGBA' with suffix '8', '16F', '32F', '8UI', '8I', '16UI', '16I', '32UI', or '32I' (36 total values, from 'R8' through 'RGBA32I')
  • GLFormatString: 'RED', 'RG', 'RGB', 'RGBA', 'RED_INTEGER', 'RG_INTEGER', 'RGB_INTEGER', 'RGBA_INTEGER'
  • GLTypeString: 'UNSIGNED_BYTE', 'BYTE', 'FLOAT', 'HALF_FLOAT', 'UNSIGNED_SHORT', 'SHORT', 'UNSIGNED_INT', 'INT'
  • GLFilterString: 'LINEAR', 'NEAREST'
  • GLWrapString: 'CLAMP_TO_EDGE', 'REPEAT', 'MIRRORED_REPEAT'

API Sections

Previous
segmenter