NgtpChromaticAberration
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-chromatic-aberration', 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: 'chromatic-aberration-demo relative block h-full' }, imports: [NgtCanvas, PostprocessingWrapper, SceneGraph],})export default class ChromaticAberration { static clientProviders = [provideNgtRenderer()];}import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, viewChild } from '@angular/core';import { beforeRender, NgtArgs } from 'angular-three';import { NgtpChromaticAberration, NgtpEffectComposer } from 'angular-three-postprocessing';import * as THREE from 'three';
@Component({ selector: 'app-scene-graph', template: ` <ngt-mesh #mesh> <ngt-torus-knot-geometry *args="[1, 0.35, 128, 32]" /> <ngt-mesh-standard-material color="white" [metalness]="0.5" [roughness]="0.2" /> </ngt-mesh>
<ngtp-effect-composer> <ngtp-chromatic-aberration [options]="{ offset: [0.006, 0.006], radialModulation: true, modulationOffset: 0.5, }" /> </ngtp-effect-composer> `, schemas: [CUSTOM_ELEMENTS_SCHEMA], changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgtArgs, NgtpEffectComposer, NgtpChromaticAberration],})export class SceneGraph { private meshRef = viewChild.required<ElementRef<THREE.Mesh>>('mesh');
constructor() { beforeRender(({ delta }) => { const mesh = this.meshRef().nativeElement; mesh.rotation.x += delta * 0.3; mesh.rotation.y += delta * 0.4; }); }}Chromatic aberration simulates the color fringing that occurs in real camera lenses, where different wavelengths of light are focused at slightly different points.
import { NgtpEffectComposer, NgtpChromaticAberration } from 'angular-three-postprocessing';
@Component({ template: ` <ngtp-effect-composer> <ngtp-chromatic-aberration [options]="{ offset: [0.002, 0.002] }" /> </ngtp-effect-composer> `, imports: [NgtpEffectComposer, NgtpChromaticAberration],})export class SceneGraph {}Options
Section titled “Options”| Property | Type | Default | Description |
|---|---|---|---|
offset | [number, number] | [0.001, 0.001] | Color channel offset (x, y) |
radialModulation | boolean | false | Apply radial modulation |
modulationOffset | number | 0.15 | Modulation offset |
Example: Subtle Effect
Section titled “Example: Subtle Effect”<ngtp-effect-composer> <ngtp-chromatic-aberration [options]="{ offset: [0.001, 0.001], radialModulation: true, modulationOffset: 0.5 }" /></ngtp-effect-composer>