Class: ErosionShader
@geenee/bodyrenderers-common.ErosionShader
Image erosion shader
Specialization of ShaderProgram performing erosion operation on a grayscale image. Erosion is a morphological operations removing pixels on the boundaries of objects in an image. The value of the output pixel is minimum value of all pixels in the neighbourhood which radius is a modifiable parameter.
Hierarchy
-
↳
ErosionShader
Constructors
constructor
• new ErosionShader(gl
, size
, radius?
)
Constructor
Parameters
Name | Type | Default value | Description |
---|---|---|---|
gl | WebGL2RenderingContext | undefined | WebGL context where program is instantiated |
size | Size | undefined | Size of processed (input & output) image |
radius | number | 1 | Erosion operation radius |
Overrides
Properties
fragShader
• Protected
fragShader: null
| WebGLShader
Fragment shader
Inherited from
frameBuffer
• Protected
frameBuffer: null
| WebGLFramebuffer
Frame buffer (output)
Inherited from
gl
• Protected
gl: WebGL2RenderingContext
WebGL context where program is instantiated
Inherited from
inputs
• Protected
inputs: string
[]
Shader texture inputs (names of sampler uniforms)
Inherited from
outputTexture
• Protected
Optional
outputTexture: ImageTexture
Output image texture
Inherited from
shaderProgram
• Protected
shaderProgram: null
| WebGLProgram
Shader program
Inherited from
size
• Protected
size: Size
Size of processed (input & output) image
Inherited from
uniforms
• Protected
uniforms: Object
Shader uniforms as name-type map object
Index signature
▪ [key: string
]: UniformType
Inherited from
uniformsLoc
• Protected
uniformsLoc: Object
Unifrom locations
Index signature
▪ [key: string
]: WebGLUniformLocation
| null
Inherited from
vertAttrs
• Protected
vertAttrs: null
| WebGLVertexArrayObject
Vertex attributes
Inherited from
vertBuffer
• Protected
vertBuffer: null
| WebGLBuffer
Vertex buffer
Inherited from
vertShader
• Protected
vertShader: null
| WebGLShader
Vertex shader
Inherited from
Methods
compile
▸ Protected
compile(fragSrc
, vertSrc
): void
Compile shader program
Allocates and sets up all resources required for shader program, compiles and links shaders.
Parameters
Name | Type | Description |
---|---|---|
fragSrc | string | Fragment shader source (copy shader by default) |
vertSrc | string | Vertex shader source (copy shader by default) |
Returns
void
Inherited from
dispose
▸ dispose(): void
Dispose program object
Releases resources and instances allocated by program. Program object cannot be used after calling dispose().
Returns
void
Inherited from
output
▸ output(): null
| WebGLTexture
Output image texture
Returns
null
| WebGLTexture
Image texture
Inherited from
prepare
▸ Protected
prepare(gl
, inputs
, uniforms?
): void
Prepare execution of the shader
Set input textures and provided uniform values, bind program and setup vertex attribute arrays.
Parameters
Name | Type | Description |
---|---|---|
gl | WebGL2RenderingContext | Context of shader program |
inputs | (null | WebGLTexture )[] | Input image textures |
uniforms? | Object | Values of shader uniforms |
Returns
void
Inherited from
process
▸ process(inputs
, uniforms?
): null
| WebGLTexture
Process input image
Applies shader program to input image, output is written to image texture using framebuffer.
Parameters
Name | Type | Description |
---|---|---|
inputs | (null | WebGLTexture )[] | Input image textures |
uniforms? | Object | Values of shader uniforms |
Returns
null
| WebGLTexture
Output image texture
Inherited from
program
▸ program(): null
| WebGLProgram
Shader program instance
Returns
null
| WebGLProgram
Instance of shader program
Inherited from
render
▸ render(inputs
, uniforms?
): void
Process input image and render the result
Applies shader program to input image, output is renderer to canvas providing WebGL context.
Parameters
Name | Type | Description |
---|---|---|
inputs | (null | WebGLTexture )[] | Input image textures |
uniforms? | Object | Values of shader uniforms |
Returns
void
Inherited from
resize
▸ resize(size
): void
Resize
Resizes output image texture and updates uniforms.
Parameters
Name | Type | Description |
---|---|---|
size | Size | Main/output shader size |
Returns
void
Inherited from
restore
▸ Protected
restore(gl
, state
): void
Restore context state
Restores state of WebGL context to recorded checkpoint. This allows to safely share context with other engines.
Parameters
Name | Type | Description |
---|---|---|
gl | WebGL2RenderingContext | Context to restore state |
state | Object | Previously recorded state |
state.activeTexture | number | - |
state.arrayBuffer | null | WebGLBuffer | - |
state.colorMask | boolean [] | - |
state.cullFace | boolean | - |
state.framebuffer | null | WebGLFramebuffer | - |
state.program | null | WebGLProgram | - |
state.scissor | Int32Array | - |
state.textures | (null | WebGLTexture )[] | - |
state.vertexArray | null | WebGLVertexArrayObject | - |
state.viewport | Int32Array | - |
Returns
void
Inherited from
save
▸ Protected
save(gl
): Object
Save context state
Saves state of WebGL including program in use, bound array buffers, framebuffer, and textures. Returned state can be restored later to safely share context with other frameworks or renderers.
Parameters
Name | Type | Description |
---|---|---|
gl | WebGL2RenderingContext | Context which state will be recorded |
Returns
Object
Current state of WebGL context
Name | Type |
---|---|
activeTexture | number |
arrayBuffer | null | WebGLBuffer |
colorMask | boolean [] |
cullFace | boolean |
framebuffer | null | WebGLFramebuffer |
program | null | WebGLProgram |
scissor | Int32Array |
textures | (null | WebGLTexture )[] |
vertexArray | null | WebGLVertexArrayObject |
viewport | Int32Array |
Inherited from
setUniform
▸ setUniform(uniform
, val
): void
Set uniform value
Parameters
Name | Type | Description |
---|---|---|
uniform | string | Uniform name |
val | number [] | Uniform value |
Returns
void
Inherited from
setUniformUnsafe
▸ Protected
setUniformUnsafe(uniform
, val
): void
Set uniform value unsafely
Parameters
Name | Type | Description |
---|---|---|
uniform | string | Uniform name |
val | number [] | Uniform value |
Returns
void