ShaderPlugin
Generic shader plugin
ShaderPlugin is a specialization of a Plugin for ShaderRenderer. They apply complex computationally demanding post-processing effects to the input stream. For example, simple mono-chrome or sepia effects, or more complex face beatification and dynamic geometry filters. ShaderPlugin shares webgl context with the main renderer. Basic implementation uses ShaderProgram created for shaders provided to plugin’s constructor. Plugins are organized in chain within ShaderRenderer, input of the next shader is output of the previous and initial input is original video image, output of the last plugin is rendered.
Extends
Section titled “Extends”Plugin
<ResultT
>
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”ResultT
Section titled “ResultT”ResultT
extends object
= { }
Type of processing results
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ShaderPlugin<
ResultT
>(inputs?
,uniforms?
,fragSrc?
,vertSrc?
):ShaderPlugin
<ResultT
>
Constructor
Parameters
Section titled “Parameters”inputs?
Section titled “inputs?”string
[]
Shader texture inputs (names of sampler uniforms)
uniforms?
Section titled “uniforms?”Shader uniforms as name-type map object
fragSrc?
Section titled “fragSrc?”string
Code of fragment shader (copy shader by default)
vertSrc?
Section titled “vertSrc?”string
Vertex shader source (copy shader by default)
Returns
Section titled “Returns”ShaderPlugin
<ResultT
>
Overrides
Section titled “Overrides”Properties
Section titled “Properties”fragSrc?
Section titled “fragSrc?”
protected
optional
fragSrc:string
Code of fragment shader (copy shader by default)
inputs?
Section titled “inputs?”
protected
optional
inputs:string
[]
Shader texture inputs (names of sampler uniforms)
loaded
Section titled “loaded”loaded:
boolean
=false
Loaded state
Inherited from
Section titled “Inherited from”ordinal
Section titled “ordinal”ordinal:
number
=PluginOrdinal.Render
Ordinal number
Inherited from
Section titled “Inherited from”renderer?
Section titled “renderer?”
protected
optional
renderer:Renderer
<ResultT
>
Renderer loaded the plugin
Inherited from
Section titled “Inherited from”shader?
Section titled “shader?”
protected
optional
shader:ShaderProgram
Rendering shader
shaderCtx?
Section titled “shaderCtx?”
protected
optional
shaderCtx:WebGL2RenderingContext
Rendering context
protected
size:Size
Image size
uniforms?
Section titled “uniforms?”
protected
optional
uniforms:object
Shader uniforms as name-type map object
Index Signature
Section titled “Index Signature”[key
: string
]: UniformType
vertSrc?
Section titled “vertSrc?”
protected
optional
vertSrc:string
Vertex shader source (copy shader by default)
Methods
Section titled “Methods”dispose()
Section titled “dispose()”dispose():
void
Dispose video plugin
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”load()
Section titled “load()”load(
renderer
):Promise
<void
>
Initialize plugin
Initializes resources required for shader effect. Acquires webgl context of the main webgl renderer. Basic implementation creates and compiles rendering program for shaders provided to plugin’s constructor. Overridden by derived classes for particular effect.
Parameters
Section titled “Parameters”renderer
Section titled “renderer”Renderer
<ResultT
>
Renderer this plugin is attached to
Returns
Section titled “Returns”Promise
<void
>
Promise resolving when initialization is finished
Overrides
Section titled “Overrides”process()
Section titled “process()”process(
result
,input
):Promise
<boolean
>
Process the image
Main method implementing webgl shader effect or filter. It’s called by update() and should be overridden to add custom logic. process() should return true if effect is successfully applied and false if it is skipped, for example, if effect applies only when result is not empty.
Parameters
Section titled “Parameters”result
Section titled “result”ResultT
Results of video processing
WebGLTexture
Current image texture
Returns
Section titled “Returns”Promise
<boolean
>
True on success, false otherwise
setupCamera()
Section titled “setupCamera()”setupCamera(
ratio
,angle
):void
Set camera parameters
Could be overridden to adjust plugin’s pipeline.
Parameters
Section titled “Parameters”number
Aspect ration of input video
number
Vertical field of view in radians
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”setupVideo()
Section titled “setupVideo()”setupVideo(
size
):void
Set video size
Adjusts shader and texture to a new size.
Parameters
Section titled “Parameters”Resolution of input video
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”unload()
Section titled “unload()”unload():
void
Reset plugin
Releases all resources and instances created in load(). Overridden by derived classes for particular effect.
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”update()
Section titled “update()”update(
result
,stream
):Promise
<void
>
Sealed
Update the image
Main method implementing webgl shader effect or filter. ShaderRenderer keeps track of the current iamge texture that will be be rendered. ShaderPlugin uses the current texture as input and writes results to ShaderPlugin#output. ShaderPlugin#output becomes new current texture of ShaderRenderer. This way all ShaderPlugins attached to renderer organize a chain of effects applied on top of each other. Method process() implements shader effect itself, it’s intended to be overridden by effect authors.
Parameters
Section titled “Parameters”result
Section titled “result”ResultT
Results of video processing
stream
Section titled “stream”HTMLCanvasElement
Captured video frame
Returns
Section titled “Returns”Promise
<void
>
Promise resolving when update is finished