Skip to content

Commit fcaff3b

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
add postprocessing blob
1 parent 6d183d3 commit fcaff3b

17 files changed

+1266
-9
lines changed

package-lock.json

+1,124-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"angular-three": "^1.9.14",
3232
"angular-three-cannon": "^1.5.2",
3333
"angular-three-postprocessing": "^1.5.2",
34-
"angular-three-soba": "^1.12.4",
34+
"angular-three-soba": "^1.13.0",
3535
"cannon-es": "^0.20.0",
3636
"daisyui": "^2.51.5",
3737
"gsap": "^3.11.5",
@@ -52,13 +52,15 @@
5252
"@nrwl/vite": "~15.9.2",
5353
"@types/three": "^0.150.1",
5454
"autoprefixer": "^10.4.14",
55+
"glsl-noise": "^0.0.0",
5556
"jsdom": "^21.1.1",
5657
"postcss": "^8.4.21",
5758
"prettier": "^2.8.7",
5859
"prettier-plugin-organize-imports": "^3.2.2",
5960
"tailwindcss": "^3.3.1",
6061
"typescript": "~4.9.5",
6162
"vite": "^4.2.1",
63+
"vite-plugin-glslify": "^2.0.1",
6264
"vitest": "^0.29.8"
6365
}
6466
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<ngts-mesh-distort-material
2+
[materialRef]="materialRef"
3+
[envMap]="envMap$ | ngtPush"
4+
[bumpMap]="bumpMap$ | ngtPush"
5+
[roughness]="0.1"
6+
[metalness]="1"
7+
[bumpScale]="0.005"
8+
[clearcoat]="1"
9+
[clearcoatRoughness]="1"
10+
[radius]="1"
11+
[distort]="0.4"
12+
color="#010101"
13+
/>
14+
<SphereInstances *ngIf="materialRef.nativeElement" [material]="materialRef.nativeElement" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { NgFor, NgIf } from '@angular/common';
2+
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';
3+
import { injectNgtRef, NgtArgs, NgtBeforeRenderEvent, NgtCanvas, NgtPush } from 'angular-three';
4+
import { NgtpEffectComposer } from 'angular-three-postprocessing';
5+
import { NgtpBloom, NgtpNoise, NgtpVignette } from 'angular-three-postprocessing/effects';
6+
import { NgtsMeshDistortMaterial } from 'angular-three-soba/materials';
7+
import * as THREE from 'three';
8+
9+
import { RouteMeta } from '@analogjs/router';
10+
import distortVert from 'angular-three-soba/assets/distort.vert.glsl';
11+
import { injectCubeTextureLoader, injectNgtsTextureLoader } from 'angular-three-soba/loaders';
12+
import { MeshDistortMaterial, provideNgtsMeshDistortMaterialShader } from 'angular-three-soba/shaders';
13+
14+
export const routeMeta: RouteMeta = {
15+
title: 'Postprocessing Blob',
16+
};
17+
18+
@Component({
19+
selector: 'MainSphere[material]',
20+
standalone: true,
21+
templateUrl: 'main-sphere.html',
22+
imports: [NgtArgs],
23+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
24+
})
25+
class MainSphere {
26+
@Input() material!: THREE.Material;
27+
28+
onBeforeRender({ state: { clock, pointer }, object: mesh }: NgtBeforeRenderEvent<THREE.Mesh>) {
29+
mesh.rotation.z = clock.getElapsedTime();
30+
mesh.rotation.y = THREE.MathUtils.lerp(mesh.rotation.y, pointer.x * Math.PI, 0.1);
31+
mesh.rotation.x = THREE.MathUtils.lerp(mesh.rotation.x, pointer.y * Math.PI, 0.1);
32+
}
33+
}
34+
35+
@Component({
36+
selector: 'SphereInstances[material]',
37+
standalone: true,
38+
templateUrl: 'sphere-instances.html',
39+
imports: [MainSphere, NgFor, NgtArgs],
40+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
41+
})
42+
class SphereInstances {
43+
@Input() material!: THREE.Material;
44+
45+
readonly initialPositions = [
46+
[-4, 20, -12],
47+
[-10, 12, -4],
48+
[-11, -12, -23],
49+
[-16, -6, -10],
50+
[12, -2, -3],
51+
[13, 4, -12],
52+
[14, -2, -23],
53+
[8, 10, -20],
54+
];
55+
56+
onBeforeRender(mesh: THREE.Mesh) {
57+
mesh.position.y += 0.02;
58+
if (mesh.position.y > 19) mesh.position.y = -18;
59+
mesh.rotation.x += 0.06;
60+
mesh.rotation.y += 0.06;
61+
mesh.rotation.z += 0.02;
62+
}
63+
}
64+
65+
@Component({
66+
selector: 'Environment',
67+
standalone: true,
68+
templateUrl: 'environment.html',
69+
imports: [SphereInstances, NgtsMeshDistortMaterial, NgIf, NgtPush],
70+
providers: [provideNgtsMeshDistortMaterialShader(distortVert)],
71+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
72+
})
73+
class Environment {
74+
readonly bumpMap$ = injectNgtsTextureLoader('bump.jpg');
75+
readonly envMap$ = injectCubeTextureLoader(['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'], '/cube/');
76+
77+
readonly materialRef = injectNgtRef<InstanceType<MeshDistortMaterial>>();
78+
}
79+
80+
@Component({
81+
standalone: true,
82+
templateUrl: 'scene.html',
83+
imports: [NgtArgs, NgtpEffectComposer, NgtpBloom, NgtpNoise, NgtpVignette, Environment],
84+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
85+
})
86+
class Scene {}
87+
88+
@Component({
89+
standalone: true,
90+
templateUrl: 'postprocessing-blob.html',
91+
imports: [NgtCanvas],
92+
})
93+
export default class PostprocessingBlob {
94+
readonly scene = Scene;
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<ngt-mesh [material]="material" (beforeRender)="onBeforeRender($any($event))">
2+
<ngt-icosahedron-geometry *args="[1, 4]" />
3+
</ngt-mesh>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ngt-canvas [camera]="{position: [0, 0, 3]}" [sceneGraph]="scene" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<ngt-color *args="['#050505']" attach="background" />
2+
<ngt-fog color="#161616" [near]="8" [far]="30" attach="fog" />
3+
4+
<Environment />
5+
6+
<ngtp-effect-composer [multisampling]="0" [disableNormalPass]="true">
7+
<ngtp-bloom [luminanceThreshold]="0" [height]="300" [opacity]="5" />
8+
<ngtp-noise [opacity]="0.025" />
9+
<ngtp-vignette [eskil]="false" [offset]="0.1" [darkness]="0.1" />
10+
</ngtp-effect-composer>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<MainSphere [material]="material" />
2+
<ngt-mesh
3+
*ngFor="let position of initialPositions"
4+
[position]="position"
5+
[material]="material"
6+
(beforeRender)="onBeforeRender($any($event).object)"
7+
>
8+
<ngt-icosahedron-geometry *args="[1, 4]" />
9+
</ngt-mesh>

src/assets/bump.jpg

254 KB
Loading

src/assets/cube/nx.png

68.2 KB
Loading

src/assets/cube/ny.png

79.3 KB
Loading

src/assets/cube/nz.png

81.3 KB
Loading

src/assets/cube/px.png

68.6 KB
Loading

src/assets/cube/py.png

69.9 KB
Loading

src/assets/cube/pz.png

75.3 KB
Loading

src/vite-env.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
/// <reference types="vite/client" />
2+
3+
declare module '*.glsl' {
4+
const shader: string;
5+
export default shader;
6+
}

vite.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import analog from '@analogjs/platform';
44
import { defineConfig } from 'vite';
5+
import glslify from 'vite-plugin-glslify';
56

67
// https://vitejs.dev/config/
78
export default defineConfig(({ mode }) => ({
@@ -12,7 +13,7 @@ export default defineConfig(({ mode }) => ({
1213
resolve: {
1314
mainFields: ['module'],
1415
},
15-
plugins: [analog({ static: true })],
16+
plugins: [glslify(), analog({ static: true })],
1617
test: {
1718
globals: true,
1819
environment: 'jsdom',

0 commit comments

Comments
 (0)