Skip to content

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.

Extends

Constructors

new ErosionShader()

new ErosionShader(gl, size, radius): ErosionShader

Constructor

Parameters

gl: WebGL2RenderingContext

WebGL context where program is instantiated

size: Size

Size of processed (input & output) image

radius: number = 1

Erosion operation radius

Returns

ErosionShader

Overrides

ShaderProgram.constructor

Properties

fragShader

protected fragShader: null | WebGLShader

Fragment shader

Inherited from

ShaderProgram.fragShader


frameBuffer

protected frameBuffer: null | WebGLFramebuffer

Frame buffer (output)

Inherited from

ShaderProgram.frameBuffer


gl

protected gl: WebGL2RenderingContext

WebGL context where program is instantiated

Inherited from

ShaderProgram.gl


inputs

protected inputs: string[]

Shader texture inputs (names of sampler uniforms)

Inherited from

ShaderProgram.inputs


outputTexture?

protected optional outputTexture: ImageTexture

Output image texture

Inherited from

ShaderProgram.outputTexture


shaderProgram

protected shaderProgram: null | WebGLProgram

Shader program

Inherited from

ShaderProgram.shaderProgram


size

protected size: Size

Size of processed (input & output) image

Inherited from

ShaderProgram.size


uniforms

protected uniforms: object

Shader uniforms as name-type map object

Index Signature

[key: string]: UniformType

Inherited from

ShaderProgram.uniforms


uniformsLoc

protected uniformsLoc: object

Unifrom locations

Index Signature

[key: string]: WebGLUniformLocation | null

Inherited from

ShaderProgram.uniformsLoc


vertAttrs

protected vertAttrs: null | WebGLVertexArrayObject

Vertex attributes

Inherited from

ShaderProgram.vertAttrs


vertBuffer

protected vertBuffer: null | WebGLBuffer

Vertex buffer

Inherited from

ShaderProgram.vertBuffer


vertShader

protected vertShader: null | WebGLShader

Vertex shader

Inherited from

ShaderProgram.vertShader

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

fragSrc: string

Fragment shader source (copy shader by default)

vertSrc: string

Vertex shader source (copy shader by default)

Returns

void

Inherited from

ShaderProgram.compile


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

ShaderProgram.dispose


output()

output(): null | WebGLTexture

Output image texture

Returns

null | WebGLTexture

Image texture

Inherited from

ShaderProgram.output


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

gl: WebGL2RenderingContext

Context of shader program

inputs: (null | WebGLTexture)[]

Input image textures

uniforms?

Values of shader uniforms

Returns

void

Inherited from

ShaderProgram.prepare


process()

process(inputs, uniforms?): null | WebGLTexture

Process input image

Applies shader program to input image, output is written to image texture using framebuffer.

Parameters

inputs: (null | WebGLTexture)[]

Input image textures

uniforms?

Values of shader uniforms

Returns

null | WebGLTexture

Output image texture

Inherited from

ShaderProgram.process


program()

program(): null | WebGLProgram

Shader program instance

Returns

null | WebGLProgram

Instance of shader program

Inherited from

ShaderProgram.program


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

inputs: (null | WebGLTexture)[]

Input image textures

uniforms?

Values of shader uniforms

Returns

void

Inherited from

ShaderProgram.render


resize()

resize(size): void

Resize

Resizes output image texture and updates uniforms.

Parameters

size: Size

Main/output shader size

Returns

void

Inherited from

ShaderProgram.resize


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

gl: WebGL2RenderingContext

Context to restore state

state

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

ShaderProgram.restore


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

gl: WebGL2RenderingContext

Context which state will be recorded

Returns

object

Current state of WebGL context

activeTexture

activeTexture: number

arrayBuffer

arrayBuffer: null | WebGLBuffer

colorMask

colorMask: boolean[]

cullFace

cullFace: boolean

framebuffer

framebuffer: null | WebGLFramebuffer

program

program: null | WebGLProgram

scissor

scissor: Int32Array

textures

textures: (null | WebGLTexture)[]

vertexArray

vertexArray: null | WebGLVertexArrayObject

viewport

viewport: Int32Array

Inherited from

ShaderProgram.save


setUniform()

setUniform(uniform, val): void

Set uniform value

Parameters

uniform: string

Uniform name

val: number[]

Uniform value

Returns

void

Inherited from

ShaderProgram.setUniform


setUniformUnsafe()

protected setUniformUnsafe(uniform, val): void

Set uniform value unsafely

Parameters

uniform: string

Uniform name

val: number[]

Uniform value

Returns

void

Inherited from

ShaderProgram.setUniformUnsafe