|
1 | | -import { ChangeDetectionStrategy, Component, computed, CUSTOM_ELEMENTS_SCHEMA, effect, input } from '@angular/core'; |
2 | | -import { NgtArgs, omit, pick } from 'angular-three'; |
3 | | -import { EffectAttribute, ToneMappingEffect } from 'postprocessing'; |
| 1 | +import { CUSTOM_ELEMENTS_SCHEMA, ChangeDetectionStrategy, Component, inject, input } from '@angular/core'; |
| 2 | +import { NgtArgs, extend } from 'angular-three'; |
| 3 | +import { ToneMappingEffect } from 'postprocessing'; |
| 4 | +import { NgtpEffect, NgtpEffectBlendMode } from '../effect'; |
4 | 5 |
|
5 | | -export type NgtpToneMappingOptions = Partial<NonNullable<ConstructorParameters<typeof ToneMappingEffect>[0]>>; |
| 6 | +extend({ ToneMappingEffect }); |
| 7 | + |
| 8 | +export type ToneMappingEffectOptions = NonNullable<ConstructorParameters<typeof ToneMappingEffect>[0]>; |
6 | 9 |
|
7 | 10 | @Component({ |
8 | | - selector: 'ngtp-tone-mapping', |
| 11 | + selector: 'ngtp-brightness-contrast', |
9 | 12 | template: ` |
10 | | - <ngt-primitive *args="[effect()]" [parameters]="parameters()" /> |
| 13 | + <ngt-tone-mapping-effect *args="[options()]" [camera]="effect.camera()"> |
| 14 | + <ngtp-effect-blend-mode /> |
| 15 | + <ng-content /> |
| 16 | + </ngt-tone-mapping-effect> |
11 | 17 | `, |
| 18 | + imports: [NgtArgs, NgtpEffectBlendMode], |
12 | 19 | schemas: [CUSTOM_ELEMENTS_SCHEMA], |
13 | 20 | changeDetection: ChangeDetectionStrategy.OnPush, |
14 | | - imports: [NgtArgs], |
| 21 | + hostDirectives: [{ directive: NgtpEffect, inputs: ['blendFunction', 'opacity'] }], |
15 | 22 | }) |
16 | | -export class NgtpToneMapping { |
17 | | - options = input({} as NgtpToneMappingOptions); |
18 | | - protected parameters = omit(this.options, [ |
19 | | - 'blendFunction', |
20 | | - 'adaptive', |
21 | | - 'mode', |
22 | | - 'resolution', |
23 | | - 'maxLuminance', |
24 | | - 'whitePoint', |
25 | | - 'middleGrey', |
26 | | - 'minLuminance', |
27 | | - 'averageLuminance', |
28 | | - 'adaptationRate', |
29 | | - ]); |
30 | | - |
31 | | - private blendFunction = pick(this.options, 'blendFunction'); |
32 | | - private adaptive = pick(this.options, 'adaptive'); |
33 | | - private mode = pick(this.options, 'mode'); |
34 | | - private resolution = pick(this.options, 'resolution'); |
35 | | - private maxLuminance = pick(this.options, 'maxLuminance'); |
36 | | - private whitePoint = pick(this.options, 'whitePoint'); |
37 | | - private middleGrey = pick(this.options, 'middleGrey'); |
38 | | - private minLuminance = pick(this.options, 'minLuminance'); |
39 | | - private averageLuminance = pick(this.options, 'averageLuminance'); |
40 | | - private adaptationRate = pick(this.options, 'adaptationRate'); |
41 | | - |
42 | | - effect = computed(() => { |
43 | | - const [ |
44 | | - blendFunction, |
45 | | - adaptive, |
46 | | - mode, |
47 | | - resolution, |
48 | | - maxLuminance, |
49 | | - whitePoint, |
50 | | - middleGrey, |
51 | | - minLuminance, |
52 | | - averageLuminance, |
53 | | - adaptationRate, |
54 | | - ] = [ |
55 | | - this.blendFunction(), |
56 | | - this.adaptive(), |
57 | | - this.mode(), |
58 | | - this.resolution(), |
59 | | - this.maxLuminance(), |
60 | | - this.whitePoint(), |
61 | | - this.middleGrey(), |
62 | | - this.minLuminance(), |
63 | | - this.averageLuminance(), |
64 | | - this.adaptationRate(), |
65 | | - ]; |
66 | | - |
67 | | - const effect = new ToneMappingEffect({ |
68 | | - blendFunction, |
69 | | - adaptive, |
70 | | - mode, |
71 | | - resolution, |
72 | | - maxLuminance, |
73 | | - whitePoint, |
74 | | - middleGrey, |
75 | | - minLuminance, |
76 | | - averageLuminance, |
77 | | - adaptationRate, |
78 | | - }); |
79 | | - |
80 | | - effect['setAttributes'](EffectAttribute.CONVOLUTION); |
81 | | - |
82 | | - return effect; |
83 | | - }); |
84 | | - |
85 | | - constructor() { |
86 | | - effect((onCleanup) => { |
87 | | - const toneMappingEffect = this.effect(); |
88 | | - onCleanup(() => toneMappingEffect.dispose()); |
89 | | - }); |
90 | | - } |
| 23 | +export class NgtpBrightnessContrast { |
| 24 | + effect = inject(NgtpEffect, { host: true }); |
| 25 | + options = input({} as Omit<ToneMappingEffectOptions, 'blendFunction'>); |
91 | 26 | } |
0 commit comments