NgtpPixelation
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-pixelation', 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: 'pixelation-demo relative block h-full' }, imports: [NgtCanvas, PostprocessingWrapper, SceneGraph],})export default class Pixelation { static clientProviders = [provideNgtRenderer()];}import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, viewChild } from '@angular/core';import { beforeRender, NgtArgs } from 'angular-three';import { NgtpColorDepth, NgtpEffectComposer, NgtpPixelation } from 'angular-three-postprocessing';import * as THREE from 'three';
@Component({ selector: 'app-scene-graph', template: ` <ngt-mesh #mesh [position]="[-1.5, 0, 0]"> <ngt-dodecahedron-geometry *args="[1]" /> <ngt-mesh-standard-material color="limegreen" /> </ngt-mesh>
<ngt-mesh #mesh2 [position]="[1.5, 0, 0]"> <ngt-icosahedron-geometry *args="[1]" /> <ngt-mesh-standard-material color="coral" /> </ngt-mesh>
<ngtp-effect-composer> <ngtp-pixelation [options]="{ granularity: 8 }" /> <ngtp-color-depth [options]="{ bits: 4 }" /> </ngtp-effect-composer> `, schemas: [CUSTOM_ELEMENTS_SCHEMA], changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgtArgs, NgtpEffectComposer, NgtpPixelation, NgtpColorDepth],})export class SceneGraph { private meshRef = viewChild.required<ElementRef<THREE.Mesh>>('mesh'); private mesh2Ref = viewChild.required<ElementRef<THREE.Mesh>>('mesh2');
constructor() { beforeRender(({ delta }) => { const mesh = this.meshRef().nativeElement; const mesh2 = this.mesh2Ref().nativeElement; mesh.rotation.x += delta * 0.4; mesh.rotation.y += delta * 0.2; mesh2.rotation.x -= delta * 0.3; mesh2.rotation.y += delta * 0.4; }); }}The pixelation effect reduces the resolution of the rendered image, creating a retro, 8-bit style appearance.
import { NgtpEffectComposer, NgtpPixelation } from 'angular-three-postprocessing';
@Component({ template: ` <ngtp-effect-composer> <ngtp-pixelation [options]="{ granularity: 8 }" /> </ngtp-effect-composer> `, imports: [NgtpEffectComposer, NgtpPixelation],})export class SceneGraph {}Options
Section titled “Options”| Property | Type | Default | Description |
|---|---|---|---|
granularity | number | 5 | Pixel size (higher = more pixelated) |
Example: Retro Game Style
Section titled “Example: Retro Game Style”@Component({ template: ` <ngt-mesh> <ngt-dodecahedron-geometry *args="[1]" /> <ngt-mesh-standard-material color="limegreen" /> </ngt-mesh>
<ngtp-effect-composer> <ngtp-pixelation [options]="{ granularity: 10 }" /> <!-- Add color depth reduction for full retro effect --> <ngtp-color-depth [options]="{ bits: 4 }" /> </ngtp-effect-composer> `, imports: [NgtpEffectComposer, NgtpPixelation, NgtpColorDepth, NgtArgs], schemas: [CUSTOM_ELEMENTS_SCHEMA],})export class SceneGraph {}- Higher
granularityvalues create larger pixels - Combine with
NgtpColorDepthfor authentic retro game aesthetics - Works well with
NgtpScanlinefor CRT monitor simulation - Consider reducing scene complexity when using heavy pixelation