Class: ShaderPlugin<ResultT>
@geenee/armature.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.
Type parameters
Name | Type | Description |
---|---|---|
ResultT | extends Object = {} | Type of processing results |
Hierarchy
Plugin
<ResultT
>↳
ShaderPlugin
Constructors
constructor
• new ShaderPlugin<ResultT
>(inputs?
, uniforms?
, fragSrc?
, vertSrc?
)
Constructor
Type parameters
Name | Type |
---|---|
ResultT | extends Object = {} |
Parameters
Name | Type | Description |
---|---|---|
inputs? | string [] | Shader texture inputs (names of sampler uniforms) |
uniforms? | Object | Shader uniforms as name-type map object |
fragSrc? | string | Code of fragment shader (copy shader by default) |
vertSrc? | string | Vertex shader source (copy shader by default) |
Overrides
Properties
fragSrc
• Protected
Optional
fragSrc: string
inputs
• Protected
Optional
inputs: string
[]
loaded
• loaded: boolean
= false
Loaded state
Inherited from
renderer
• Protected
Optional
renderer: Renderer
<ResultT
>
Renderer loaded the plugin
Inherited from
shader
• Protected
Optional
shader: ShaderProgram
Rendering shader
size
• Protected
size: Size
Image size
uniforms
• Protected
Optional
uniforms: Object
Index signature
▪ [key: string
]: UniformType
vertSrc
• Protected
Optional
vertSrc: string
Methods
dispose
▸ dispose(): void
Dispose video plugin
Returns
void
Inherited from
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
Name | Type | Description |
---|---|---|
renderer | Renderer <ResultT > | Renderer this plugin is attached to |
Returns
Promise
<void
>
Promise resolving when initialization is finished
Overrides
process
▸ process(result
, input
): 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
Name | Type | Description |
---|---|---|
result | ResultT | Results of video processing |
input | WebGLTexture | Current image texture |
Returns
boolean
True on success, false otherwise
setupVideo
▸ setupVideo(size
): void
Set video size
Adjusts shader and texture to a new size.
Parameters
Name | Type |
---|---|
size | Size |
Returns
void
Overrides
unload
▸ unload(): void
Reset plugin
Releases all resources and instances created in load(). Overridden by derived classes for particular effect.
Returns
void
Overrides
update
▸ update(result
, stream
): Promise
<void
>
Update the image
Main method implementing webgl shader effect or filter. ShaderRenderer has current image texture that will be rendered. ShaderPlugin uses 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
Name | Type | Description |
---|---|---|
result | ResultT | Results of video processing |
stream | HTMLCanvasElement | Captured video frame |
Returns
Promise
<void
>
Promise resolving when update is finished