A glitch effect.

This effect can be used in conjunction with the ChromaticAberrationEffect.

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

Hierarchy (view full)

Constructors

  • Constructs a new glitch effect.

    TODO Change ratio to 0.15.

    Parameters

    • Optionaloptions: {
          blendFunction?: BlendFunction;
          chromaticAberrationOffset?: Vector2;
          columns?: number;
          delay?: Vector2;
          dtSize?: number;
          duration?: Vector2;
          perturbationMap?: Texture;
          ratio?: number;
          strength?: Vector2;
      }

      The options.

      • OptionalblendFunction?: BlendFunction

        The blend function of this effect.

      • OptionalchromaticAberrationOffset?: Vector2

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

      • Optionalcolumns?: number

        The scale of the blocky glitch columns.

      • Optionaldelay?: Vector2

        The minimum and maximum delay between glitch activations in seconds.

      • OptionaldtSize?: number

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

      • Optionalduration?: Vector2

        The minimum and maximum duration of a glitch in seconds.

      • OptionalperturbationMap?: Texture

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

      • Optionalratio?: number

        The threshold for strong glitches.

      • Optionalstrength?: Vector2

        The strength of weak and strong glitches.

    Returns GlitchEffect

Properties

blendMode: BlendMode

The blend mode of this effect.

chromaticAberrationOffset: Vector2

The chromatic aberration offset.

defines: Map<string, string>

Preprocessor macro definitions.

Call Effect.setChanged after changing macro definitions.

delay: Vector2

The minimum and maximum delay between glitch activations in seconds.

Use minDelay and maxDelay instead.

duration: Vector2

The minimum and maximum duration of a glitch in seconds.

Use minDuration and maxDuration instead.

extensions: Set<WebGLExtension>

WebGL extensions that are required by this effect.

Call Effect.setChanged after adding or removing extensions.

The effect mode.

name: string

The name of this effect.

ratio: number

The ratio between weak (0.0) and strong (1.0) glitches. Range is [0.0, 1.0].

This value is currently being treated as a threshold for strong glitches, i.e. it's inverted.

TODO Resolve inversion.

renderer: WebGLRenderer

The renderer.

strength: Vector2

The strength of weak and strong glitches.

Use minStrength and maxStrength instead.

uniforms: Map<string, Uniform<any>>

Shader uniforms.

Call Effect.setChanged after adding or removing uniforms.

Accessors

  • get active(): boolean
  • Indicates whether the glitch effect is currently active.

    Returns boolean

  • get columns(): number
  • The glitch column size.

    Returns number

  • set columns(arg): void
  • Parameters

    • arg: number

    Returns void

  • get inputColorSpace(): ColorSpace
  • Experimental

    The input color space.

    Returns ColorSpace

  • set inputColorSpace(arg): void
  • Protected Experimental

    Parameters

    • arg: ColorSpace

    Returns void

  • set mainCamera(arg): void
  • Sets the main camera.

    Parameters

    • arg: Camera

    Returns void

  • set mainScene(arg): void
  • Sets the main scene.

    Parameters

    • arg: Scene

    Returns void

  • get maxDelay(): number
  • The maximum delay between glitch activations.

    Returns number

  • set maxDelay(arg): void
  • Parameters

    • arg: number

    Returns void

  • get maxDuration(): number
  • The maximum duration of sporadic glitches.

    Returns number

  • set maxDuration(arg): void
  • Parameters

    • arg: number

    Returns void

  • get maxStrength(): number
  • The strength of strong glitches.

    Returns number

  • set maxStrength(arg): void
  • Parameters

    • arg: number

    Returns void

  • get minDelay(): number
  • The minimum delay between glitch activations.

    Returns number

  • set minDelay(arg): void
  • Parameters

    • arg: number

    Returns void

  • get minDuration(): number
  • The minimum duration of sporadic glitches.

    Returns number

  • set minDuration(arg): void
  • Parameters

    • arg: number

    Returns void

  • get minStrength(): number
  • The strength of weak glitches.

    Returns number

  • set minStrength(arg): void
  • Parameters

    • arg: number

    Returns void

  • get outputColorSpace(): ColorSpace
  • Experimental

    The output color space.

    Should only be changed if this effect converts the input colors to a different color space.

    Returns ColorSpace

  • set outputColorSpace(arg): void
  • Protected Experimental

    Parameters

    • arg: ColorSpace

    Returns void

  • get perturbationMap(): Texture
  • The perturbation map.

    Returns Texture

  • set perturbationMap(arg): void
  • Parameters

    • arg: Texture

    Returns void

Methods

  • Adds a listener to an event type.

    Type Parameters

    • T extends keyof Event<string, unknown>

    Parameters

    • type: T

      The type of event to listen to.

    • listener: EventListener<Event<string, unknown>[T], T, GlitchEffect>

      The function that gets called when the event is fired.

    Returns void

  • Fire an event type.

    Type Parameters

    • T extends keyof Event<string, unknown>

    Parameters

    • event: BaseEvent<T> & Event<string, unknown>[T]

      The event that gets fired.

    Returns void

  • Deletes generated resources.

    Returns void

  • Generates a perturbation map.

    Parameters

    • Optionalvalue: number

      The texture size.

    Returns DataTexture

    The perturbation map.

    Use NoiseTexture instead.

  • Returns the blend mode.

    The result of this effect will be blended with the result of the previous effect using this blend mode.

    Returns BlendMode

    The blend mode.

    Use blendMode instead.

  • Returns the chromatic aberration offset.

    Returns Vector2

    The offset.

    Use chromaticAberrationOffset instead.

  • Returns the preprocessor macro definitions.

    Returns Map<string, string>

    The extensions.

    Use defines instead.

  • Returns the fragment shader.

    Returns string

    The fragment shader.

  • Returns the glitch column size.

    Returns number

    The glitch column size.

    Use columns instead.

  • Returns the glitch ratio.

    Returns number

    The ratio.

    Use ratio instead.

  • Returns the maximum delay between glitch activations.

    Returns number

    The maximum delay in seconds.

    Use maxDelay instead.

  • Returns the maximum duration of sporadic glitches.

    Returns number

    The maximum duration in seconds.

    Use maxDuration instead.

  • Returns the strength of strong glitches.

    Returns number

    The strength.

    Use maxStrength instead.

  • Returns the minimum delay between glitch activations.

    Returns number

    The minimum delay in seconds.

    Use minDelay instead.

  • Returns the minimum duration of sporadic glitches.

    Returns number

    The minimum duration in seconds.

    Use minDuration instead.

  • Returns the strength of weak glitches.

    Returns number

    The strength.

    Use minStrength instead.

  • Returns the current glitch mode.

    Returns GlitchMode

    The mode.

    Use mode instead.

  • Returns the name of this effect.

    Returns string

    The name.

    Use name instead.

  • Returns the current perturbation map.

    Returns Texture

    The current perturbation map.

    Use perturbationMap instead.

  • Returns the uniforms of this effect.

    Returns Map<string, Uniform<any>>

    The extensions.

    Use uniforms instead.

  • Returns the vertex shader.

    Returns string

    The vertex shader.

  • Checks if listener is added to an event type.

    Type Parameters

    • T extends keyof Event<string, unknown>

    Parameters

    • type: T

      The type of event to listen to.

    • listener: EventListener<Event<string, unknown>[T], T, GlitchEffect>

      The function that gets called when the event is fired.

    Returns boolean

  • Performs initialization tasks.

    This method is called when the associated EffectPass is added to an EffectComposer.

    Parameters

    • renderer: WebGLRenderer

      The renderer.

    • alpha: boolean

      Whether the renderer uses the alpha channel or not.

    • frameBufferType: number

      The type of the main frame buffers.

    Returns void

    if(!alpha && frameBufferType === UnsignedByteType) { this.myRenderTarget.texture.format = RGBFormat; }
    
  • Indicates whether the glitch effect is currently active.

    Returns boolean

    Whether the glitch effect is active.

    Use active instead.

  • Removes a listener from an event type.

    Type Parameters

    • T extends keyof Event<string, unknown>

    Parameters

    • type: T

      The type of the listener that gets removed.

    • listener: EventListener<Event<string, unknown>[T], T, GlitchEffect>

      The listener function that gets removed.

    Returns void

  • Protected

    Sets the effect attributes.

    Effects that have the same attributes will be executed in the order in which they were registered. Some attributes imply a higher priority.

    Parameters

    Returns void

  • Protected

    Informs the associated EffectPass that this effect requires a shader recompilation.

    Should be called after changing macros or extensions and after adding/removing uniforms.

    Returns void

  • Sets the chromatic aberration offset.

    Parameters

    • value: Vector2

      The offset.

    Returns void

    Use chromaticAberrationOffset instead.

  • Sets the depth texture.

    You may override this method if your effect requires direct access to the depth texture that is bound to the associated EffectPass.

    Parameters

    • depthTexture: Texture

      A depth texture.

    • OptionaldepthPacking: DepthPackingStrategies

      The depth packing.

    Returns void

  • Protected

    Sets the fragment shader.

    Parameters

    • fragmentShader: string

      The fragment shader.

    Returns void

  • Sets the glitch column size.

    Parameters

    • value: number

      The glitch column size.

    Returns void

    Use columns instead.

  • Sets the ratio of weak (0.0) and strong (1.0) glitches.

    Parameters

    • value: number

      The ratio. Range is [0.0, 1.0].

    Returns void

    Use ratio instead.

  • Sets the maximum delay between glitch activations.

    Parameters

    • value: number

      The maximum delay in seconds.

    Returns void

    Use maxDelay instead.

  • Sets the maximum duration of sporadic glitches.

    Parameters

    • value: number

      The maximum duration in seconds.

    Returns void

    Use maxDuration instead.

  • Sets the strength of strong glitches.

    Parameters

    • value: number

      The strength.

    Returns void

    Use maxStrength instead.

  • Sets the minimum delay between glitch activations.

    Parameters

    • value: number

      The minimum delay in seconds.

    Returns void

    Use minDelay instead.

  • Sets the minimum duration of sporadic glitches.

    Parameters

    • value: number

      The minimum duration in seconds.

    Returns void

    Use minDuration instead.

  • Sets the strength of weak glitches.

    Parameters

    • value: number

      The strength.

    Returns void

    Use minStrength instead.

  • Sets the current glitch mode.

    Parameters

    Returns void

    Use mode instead.

  • Replaces the current perturbation map with the given one.

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

    Parameters

    • value: Texture

      The new perturbation map.

    Returns void

    Use perturbationMap instead.

  • Sets the renderer.

    Parameters

    • renderer: WebGLRenderer

      The renderer.

    Returns void

  • Updates the size of this effect.

    You may override this method if you want to be informed about the size of the backbuffer/canvas. This method is called before initialize and every time the size of the EffectComposer changes.

    Parameters

    • width: number

      The width.

    • height: number

      The height.

    Returns void

  • Protected

    Sets the vertex shader.

    Parameters

    • vertexShader: string

      The vertex shader.

    Returns void

  • Updates this effect.

    Parameters

    • renderer: WebGLRenderer

      The renderer.

    • inputBuffer: WebGLRenderTarget<Texture>

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

    • OptionaldeltaTime: number

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

    Returns void