Home Reference Source
import {GlitchEffect} from 'postprocessing/src/effects/GlitchEffect.js'
public class | source

GlitchEffect

Extends:

Effect → 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.

Private Members
private

A random glitch break point.

private

distortion: Vector2

A distortion vector.

private

perturbationMap: Texture

The current perturbation map.

private

seed: Vector2

Random seeds.

private

A time accumulator.

Method Summary

Public Methods
public

generatePerturbationMap(size: Number): DataTexture

Generates a perturbation map.

public

getPerturbationMap(): Texture

Returns the current perturbation map.

public

setPerturbationMap(perturbationMap: Texture)

Replaces the current perturbation map with the given one.

public

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

Updates this effect.

Inherited Summary

From class Effect
public

[key]: *

public

The effect attributes.

public

The blend mode of this effect.

public

Preprocessor macro definitions.

public

The fragment shader.

public

The name of this effect.

public

uniforms: Map<String, Uniform>

Shader uniforms.

public

The vertex shader.

public

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

public

initialize(renderer: WebGLRenderer, alpha: Boolean)

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, delta: Number)

Updates the effect by performing supporting operations.

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.

Private Members

private breakPoint: Number source

A random glitch break point.

private distortion: Vector2 source

A distortion vector.

private perturbationMap: Texture source

The current perturbation map.

private seed: Vector2 source

Random seeds.

private time: Number source

A time accumulator.

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(perturbationMap: 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
perturbationMap Texture

The new perturbation map.

public update(renderer: WebGLRenderer, inputBuffer: WebGLRenderTarget, delta: 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.

delta Number
  • optional

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