NgtpGlitch
import { ChangeDetectionStrategy, Component } from '@angular/core';import { PostprocessingWrapper } from '@postprocessing/wrapper.ts';import { NgtCanvas, provideNgtRenderer } from 'angular-three/dom';import { SceneGraph } from './scene-graph';
@Component({ selector: 'app-glitch', template: ` <ngt-canvas [camera]="{ position: [0, 0, 5], fov: 50 }"> <app-postprocessing-wrapper *canvasContent [lights]="true"> <app-scene-graph /> </app-postprocessing-wrapper> </ngt-canvas> `, changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'glitch-demo relative block h-full' }, imports: [NgtCanvas, PostprocessingWrapper, SceneGraph],})export default class Glitch { static clientProviders = [provideNgtRenderer()];}import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, viewChild } from '@angular/core';import { beforeRender, NgtArgs } from 'angular-three';import { NgtpEffectComposer, NgtpGlitch } from 'angular-three-postprocessing';import { GlitchMode } from 'postprocessing';import * as THREE from 'three';
@Component({ selector: 'app-scene-graph', template: ` <ngt-mesh #mesh> <ngt-icosahedron-geometry *args="[1.2, 1]" /> <ngt-mesh-standard-material color="#ff00ff" [flatShading]="true" /> </ngt-mesh>
<ngtp-effect-composer> <ngtp-glitch [options]="{ mode: GlitchMode.SPORADIC, delay: [0.5, 1], duration: [0.1, 0.3], strength: [0.1, 0.3], }" /> </ngtp-effect-composer> `, schemas: [CUSTOM_ELEMENTS_SCHEMA], changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgtArgs, NgtpEffectComposer, NgtpGlitch],})export class SceneGraph { protected GlitchMode = GlitchMode;
private meshRef = viewChild.required<ElementRef<THREE.Mesh>>('mesh');
constructor() { beforeRender(({ delta }) => { const mesh = this.meshRef().nativeElement; mesh.rotation.x += delta * 0.2; mesh.rotation.y += delta * 0.3; }); }}The glitch effect creates digital distortion artifacts, simulating video signal interference or data corruption.
import { NgtpEffectComposer, NgtpGlitch } from 'angular-three-postprocessing';
@Component({ template: ` <ngtp-effect-composer> <ngtp-glitch [options]="{ delay: [1.5, 3.5], duration: [0.6, 1.0] }" /> </ngtp-effect-composer> `, imports: [NgtpEffectComposer, NgtpGlitch],})export class SceneGraph {}Options
Section titled “Options”| Property | Type | Default | Description |
|---|---|---|---|
delay | [number, number] | [1.5, 3.5] | Min/max delay between glitches (seconds) |
duration | [number, number] | [0.6, 1.0] | Min/max duration of glitches (seconds) |
strength | [number, number] | [0.3, 1.0] | Min/max strength of the effect |
active | boolean | true | Whether the effect is active |
ratio | number | 0.85 | Ratio of glitch occurrence |
Example: Intense Glitch
Section titled “Example: Intense Glitch”<ngtp-effect-composer> <ngtp-glitch [options]="{ delay: [0.5, 1.0], duration: [0.2, 0.5], strength: [0.5, 1.0], ratio: 0.9 }" /></ngtp-effect-composer>