Skip to content

Commit 0597d0c

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
feat(postprocessing): migrate LUT
1 parent 7cc706b commit 0597d0c

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

libs/postprocessing/effects/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './color-depth/color-depth';
44
export * from './depth/depth';
55
export * from './dot-screen/dot-screen';
66
export * from './hue-saturation/hue-saturation';
7+
export * from './lut/lut';
78
export * from './noise/noise';
89
export * from './scanline/scanline';
910
export * from './sepia/sepia';
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { CUSTOM_ELEMENTS_SCHEMA, Component, Input, computed, effect, inject } from '@angular/core';
2+
import { NgtArgs, NgtSignalStore, NgtStore, injectNgtRef, requestAnimationInInjectionContext } from 'angular-three';
3+
import { BlendFunction, LUT3DEffect } from 'postprocessing';
4+
5+
export interface NgtpLUTState {
6+
lut: THREE.Texture;
7+
blendFunction?: BlendFunction;
8+
tetrahedralInterpolation?: boolean;
9+
}
10+
11+
@Component({
12+
selector: 'ngtp-lut',
13+
standalone: true,
14+
template: ` <ngt-primitive *args="[effect()]" [ref]="effectRef" /> `,
15+
imports: [NgtArgs],
16+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
17+
})
18+
export class NgtpLUT extends NgtSignalStore<NgtpLUTState> {
19+
@Input() effectRef = injectNgtRef<LUT3DEffect>();
20+
21+
@Input({ required: true }) set lut(lut: THREE.Texture) {
22+
this.set({ lut });
23+
}
24+
25+
@Input() set blendFunction(blendFunction: BlendFunction) {
26+
this.set({ blendFunction });
27+
}
28+
29+
@Input() set tetrahedralInterpolation(tetrahedralInterpolation: boolean) {
30+
this.set({ tetrahedralInterpolation });
31+
}
32+
33+
readonly #lut = this.select('lut');
34+
readonly #tetrahedralInterpolation = this.select('tetrahedralInterpolation');
35+
readonly #blendFunction = this.select('blendFunction');
36+
37+
readonly #store = inject(NgtStore);
38+
readonly #invalidate = this.#store.select('invalidate');
39+
40+
readonly effect = computed(
41+
() =>
42+
new LUT3DEffect(this.#lut(), {
43+
blendFunction: this.#blendFunction(),
44+
tetrahedralInterpolation: this.#tetrahedralInterpolation(),
45+
})
46+
);
47+
48+
constructor() {
49+
super();
50+
requestAnimationInInjectionContext(() => {
51+
this.#setProps();
52+
});
53+
}
54+
55+
#setProps() {
56+
const trigger = computed(() => ({
57+
effect: this.effect(),
58+
invalidate: this.#invalidate(),
59+
lut: this.#lut(),
60+
tetrahedralInterpolation: this.#tetrahedralInterpolation(),
61+
}));
62+
effect(() => {
63+
const { effect, lut, invalidate, tetrahedralInterpolation } = trigger();
64+
if (!effect) return;
65+
if (tetrahedralInterpolation) effect.tetrahedralInterpolation = tetrahedralInterpolation;
66+
if (lut) effect.lut = lut;
67+
invalidate();
68+
});
69+
}
70+
}

0 commit comments

Comments
 (0)