NgtpEffectComposer
angular-three-postprocessing
1import { NgtpEffectComposer } from 'angular-three-postprocessing';
1@Component({2 imports: [NgtpEffectComposer],3 template: `4 <ngtp-effect-composer>5 <!-- effects -->6 </ngtp-effect-composer>7 `,8 schemas: [CUSTOM_ELEMENTS_SCHEMA],9})10export class SceneGraph {}
1import { NgtpEffectComposer } from 'angular-three-postprocessing';2import { NgtpEffectComposer, NgtpBloom, NgtpNoise } from 'angular-three-postprocessing';3 4@Component({5 imports: [NgtpEffectComposer, NgtpBloom, NgtpNoise],6 template: `7 <ngtp-effect-composer>8 <ngtp-bloom />9 <ngtp-noise />10 </ngtp-effect-composer>11 `,12 schemas: [CUSTOM_ELEMENTS_SCHEMA],13})14export class SceneGraph {}
1/* credit: https://codesandbox.io/p/sandbox/react-postprocessing-dof-blob-forked-7hj8w3?file=/src/App.js:29,15 */2 3import {4 ChangeDetectionStrategy,5 Component,6 computed,7 CUSTOM_ELEMENTS_SCHEMA,8 type ElementRef,9 input,10 viewChild,11 viewChildren,12} from '@angular/core';13import { extend, injectBeforeRender, injectLoader, NgtArgs, NgtCanvas } from 'angular-three';14import { NgtpBloom, NgtpDepthOfField, NgtpEffectComposer, NgtpVignette } from 'angular-three-postprocessing';15import { injectTexture, NgtsLoader } from 'angular-three-soba/loaders';16import { NgtsMeshDistortMaterial } from 'angular-three-soba/materials';17import * as THREE from 'three';18import { CubeTextureLoader, Material, MathUtils, type Mesh } from 'three';19 20extend(THREE);21 22@Component({23 selector: 'app-main-sphere',24 template: `25 <ngt-mesh #mesh [material]="material()">26 <ngt-icosahedron-geometry *args="[1, 4]" />27 </ngt-mesh>28 `,29 schemas: [CUSTOM_ELEMENTS_SCHEMA],30 changeDetection: ChangeDetectionStrategy.OnPush,31 imports: [NgtArgs],32})33export class MainSphere {34 material = input.required<Material>();35 36 meshRef = viewChild.required<ElementRef<Mesh>>('mesh');37 38 constructor() {39 injectBeforeRender(({ clock, pointer }) => {40 const mesh = this.meshRef().nativeElement;41 mesh.rotation.z = clock.getElapsedTime();42 mesh.rotation.y = MathUtils.lerp(mesh.rotation.y, pointer.x * Math.PI, 0.1);43 mesh.rotation.x = MathUtils.lerp(mesh.rotation.x, pointer.y * Math.PI, 0.1);44 });45 }46}47 48@Component({49 selector: 'app-sphere-instances',50 template: `51 <!-- we render the material with attach="none" so we can share it between instances -->52 <ngts-mesh-distort-material #distortMaterial attach="none" [options]="materialOptions()" />53 54 <app-main-sphere [material]="distortMaterial.material" />55 @for (position of initialPositions; track $index) {56 <ngt-mesh #mesh [material]="distortMaterial.material" [position]="position">57 <ngt-icosahedron-geometry *args="[1, 4]" />58 </ngt-mesh>59 }60 `,61 schemas: [CUSTOM_ELEMENTS_SCHEMA],62 changeDetection: ChangeDetectionStrategy.OnPush,63 imports: [MainSphere, NgtArgs, NgtsMeshDistortMaterial],64})65export class SphereInstances {66 private envMap = injectLoader(67 // @ts-expect-error - CubeTextureLoader is ok68 () => CubeTextureLoader,69 () => [['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png']],70 { extensions: (loader) => loader.setPath('/cube/') },71 );72 private bumpMap = injectTexture(() => '/bump.jpg');73 74 materialOptions = computed(() => ({75 envMap: this.envMap()?.[0],76 bumpMap: this.bumpMap(),77 emissive: '#010101',78 emissiveIntensity: 2,79 roughness: 0.1,80 metalness: 1,81 bumpScale: 0.005,82 clearcoat: 1,83 clearcoatRoughness: 1,84 radius: 1,85 distort: 0.4,86 toneMapped: false,87 }));88 89 initialPositions = [90 [-4, 20, -12],91 [-10, 12, -4],92 [-11, -12, -23],93 [-16, -6, -10],94 [12, -2, -3],95 [13, 4, -12],96 [14, -2, -23],97 [8, 10, -20],98 ];99 100 private meshesRef = viewChildren<ElementRef<Mesh>>('mesh');101 102 constructor() {103 injectBeforeRender(() => {104 const meshes = this.meshesRef();105 meshes.forEach(({ nativeElement: mesh }) => {106 mesh.position.y += 0.02;107 if (mesh.position.y > 19) mesh.position.y = -18;108 mesh.rotation.x += 0.06;109 mesh.rotation.y += 0.06;110 mesh.rotation.z += 0.02;111 });112 });113 }114}115 116@Component({117 template: `118 <ngt-color attach="background" *args="['#050505']" />119 <ngt-fog attach="fog" *args="['#161616', 8, 30]" />120 121 <app-sphere-instances />122 123 <ngtp-effect-composer [options]="{ multisampling: 0, disableNormalPass: true }">124 <ngtp-depth-of-field [options]="{ focusDistance: 0, focalLength: 0.02, bokehScale: 2, height: 480 }" />125 <ngtp-bloom [options]="{ kernelSize: 3, luminanceThreshold: 0, luminanceSmoothing: 0.9, intensity: 1.5 }" />126 <ngtp-vignette [options]="{ eskil: false, offset: 0.1, darkness: 1.1 }" />127 </ngtp-effect-composer>128 `,129 schemas: [CUSTOM_ELEMENTS_SCHEMA],130 changeDetection: ChangeDetectionStrategy.OnPush,131 imports: [SphereInstances, NgtArgs, NgtpEffectComposer, NgtpDepthOfField, NgtpBloom, NgtpVignette],132})133export class SceneGraph {}134 135@Component({136 template: `137 <ngt-canvas [sceneGraph]="sceneGraph" [camera]="{ position: [0, 0, 3] }" />138 <ngts-loader />139 `,140 changeDetection: ChangeDetectionStrategy.OnPush,141 host: { class: 'postprocessing-sample' },142 imports: [NgtCanvas, NgtsLoader],143})144export default class PostprocessingSample {145 sceneGraph = SceneGraph;146}