Skip to main content

Class: DilationShader

@geenee/bodyrenderers-common.DilationShader

Image dilation shader

Specialization of ShaderProgram performing dilation operation on image.

Hierarchy

Constructors

constructor

new DilationShader(gl, size, radius?)

Constructor

Parameters

NameTypeDefault valueDescription
glWebGL2RenderingContextundefinedWebGL context where program is instantiated
sizeSizeundefinedSize of processed (input & output) image
radiusnumber1Dilation operation radius

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

NameTypeDescription
fragSrcstringFragment shader source (copy shader by default)
vertSrcstringVertex 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

NameTypeDescription
glWebGL2RenderingContextContext of shader program
inputs(null | WebGLTexture)[]Input image textures
uniforms?ObjectValues 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

NameTypeDescription
inputs(null | WebGLTexture)[]Input image textures
uniforms?ObjectValues 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

NameTypeDescription
inputs(null | WebGLTexture)[]Input image textures
uniforms?ObjectValues of shader uniforms

Returns

void

Inherited from

ShaderProgram.render


resize

resize(size): void

Resize

Resizes output image texture and updates uniforms.

Parameters

NameTypeDescription
sizeSizeMain/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

NameTypeDescription
glWebGL2RenderingContextContext to restore state
stateObjectPreviously recorded state
state.activeTexturenumber-
state.arrayBuffernull | WebGLBuffer-
state.colorMaskboolean[]-
state.cullFaceboolean-
state.framebuffernull | WebGLFramebuffer-
state.programnull | WebGLProgram-
state.scissorInt32Array-
state.textures(null | WebGLTexture)[]-
state.vertexArraynull | WebGLVertexArrayObject-
state.viewportInt32Array-

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

NameTypeDescription
glWebGL2RenderingContextContext which state will be recorded

Returns

Object

Current state of WebGL context

NameType
activeTexturenumber
arrayBuffernull | WebGLBuffer
colorMaskboolean[]
cullFaceboolean
framebuffernull | WebGLFramebuffer
programnull | WebGLProgram
scissorInt32Array
textures(null | WebGLTexture)[]
vertexArraynull | WebGLVertexArrayObject
viewportInt32Array

Inherited from

ShaderProgram.save