Home Reference Source
import {GlitchEffect} from 'postprocessing'
public class | source

GlitchEffect

Extends:

three~EventDispatcherEffect → GlitchEffect

Indirect Implements:

A glitch effect.

This effect can influence the ChromaticAberrationEffect.

Reference: https://github.com/staffantan/unityglitch

Warning: This effect cannot be merged with convolution effects.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Constructs a new glitch effect.

Member Summary

Public Members
public get

Indicates whether the glitch effect is currently active.

public

The chromatic aberration offset.

public

delay: Vector2

The minimum and maximum delay between glitch activations in seconds.

public

duration: Vector2

The minimum and maximum duration of a glitch in seconds.

public

The effect mode.

public

The threshold for strong glitches, ranging from 0 to 1 where 0 means no weak glitches and 1 means no strong ones.

public

strength: Vector2

The strength of weak and strong glitches.

Method Summary

Public Methods
public

generatePerturbationMap(size: Number): DataTexture

Generates a perturbation map.

public

getPerturbationMap(): Texture

Returns the current perturbation map.

public

setPerturbationMap(map: Texture)

Replaces the current perturbation map with the given one.

public

update(renderer: WebGLRenderer, inputBuffer: WebGLRenderTarget, deltaTime: Number)

Updates this effect.

Inherited Summary

From class Effect
public

The blend mode of this effect.

public

Preprocessor macro definitions.

public

WebGL extensions that are required by this effect.

public

The name of this effect.

public

uniforms: Map<String, Uniform>

Shader uniforms.

public

Performs a shallow search for properties that define a dispose method and deletes them.

public

Returns the effect attributes.

public

Returns the fragment shader.

public

Returns the vertex shader.

public

initialize(renderer: WebGLRenderer, alpha: Boolean, frameBufferType: Number)

Performs initialization tasks.

public

setDepthTexture(depthTexture: Texture, depthPacking: Number)

Sets the depth texture.

public

setSize(width: Number, height: Number)

Updates the size of this effect.

public

update(renderer: WebGLRenderer, inputBuffer: WebGLRenderTarget, deltaTime: Number)

Updates the effect by performing supporting operations.

protected

Sets the effect attributes.

protected

Informs the associated EffectPass that this effect has changed in a way that requires a shader recompilation.

protected

setFragmentShader(fragmentShader: String)

Sets the fragment shader.

protected

setVertexShader(vertexShader: String)

Sets the vertex shader.

Public Constructors

public constructor(options: Object) source

Constructs a new glitch effect.

Override:

Effect#constructor

Params:

NameTypeAttributeDescription
options Object
  • optional

The options.

options.blendFunction BlendFunction
  • optional
  • default: BlendFunction.NORMAL

The blend function of this effect.

options.chromaticAberrationOffset Vector2
  • optional

A chromatic aberration offset. If provided, the glitch effect will influence this offset.

options.delay Vector2
  • optional

The minimum and maximum delay between glitch activations in seconds.

options.duration Vector2
  • optional

The minimum and maximum duration of a glitch in seconds.

options.strength Vector2
  • optional

The strength of weak and strong glitches.

options.perturbationMap Texture
  • optional

A perturbation map. If none is provided, a noise texture will be created.

options.dtSize Number
  • optional
  • default: 64

The size of the generated noise map. Will be ignored if a perturbation map is provided.

options.columns Number
  • optional
  • default: 0.05

The scale of the blocky glitch columns.

options.ratio Number
  • optional
  • default: 0.85

The threshold for strong glitches.

Public Members

public get active: Boolean source

Indicates whether the glitch effect is currently active.

public chromaticAberrationOffset: Vector2 source

The chromatic aberration offset.

public delay: Vector2 source

The minimum and maximum delay between glitch activations in seconds.

public duration: Vector2 source

The minimum and maximum duration of a glitch in seconds.

public mode: GlitchMode source

The effect mode.

public ratio: Number source

The threshold for strong glitches, ranging from 0 to 1 where 0 means no weak glitches and 1 means no strong ones. The default ratio of 0.85 offers a decent balance.

public strength: Vector2 source

The strength of weak and strong glitches.

Public Methods

public generatePerturbationMap(size: Number): DataTexture source

Generates a perturbation map.

Params:

NameTypeAttributeDescription
size Number
  • optional
  • default: 64

The texture size.

Return:

DataTexture

The perturbation map.

public getPerturbationMap(): Texture source

Returns the current perturbation map.

Return:

Texture

The current perturbation map.

public setPerturbationMap(map: Texture) source

Replaces the current perturbation map with the given one.

The current map will be disposed if it was generated by this effect.

Params:

NameTypeAttributeDescription
map Texture

The new perturbation map.

public update(renderer: WebGLRenderer, inputBuffer: WebGLRenderTarget, deltaTime: Number) source

Updates this effect.

Override:

Effect#update

Params:

NameTypeAttributeDescription
renderer WebGLRenderer

The renderer.

inputBuffer WebGLRenderTarget

A frame buffer that contains the result of the previous pass.

deltaTime Number
  • optional

The time between the last frame and the current one in seconds.