@needle-tools/engine 4.6.0 → 4.6.1-next.20d54cd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/generateMeshBVH.worker-BaNp_Xtp.js +25 -0
- package/dist/{gltf-progressive-Bm9eEfgu.min.js → gltf-progressive-Bl4okF1b.min.js} +1 -1
- package/dist/{gltf-progressive-GjIqwSG3.js → gltf-progressive-DSpdn0QT.js} +2 -2
- package/dist/{gltf-progressive-Dn6o99rH.umd.cjs → gltf-progressive-P8b8a0qY.umd.cjs} +1 -1
- package/dist/needle-engine.bundle-BVrLqIyi.umd.cjs +1575 -0
- package/dist/{needle-engine.bundle-DsrPZ9gj.js → needle-engine.bundle-BonYthMO.js} +8850 -8678
- package/dist/needle-engine.bundle-CokaG-YG.min.js +1575 -0
- package/dist/needle-engine.js +352 -351
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-CRQa6Qxn.umd.cjs → postprocessing-CjW23fio.umd.cjs} +18 -18
- package/dist/{postprocessing-D6W1EyZ-.js → postprocessing-DYLNOL3W.js} +4 -3
- package/dist/{postprocessing-DF8AlRgW.min.js → postprocessing-xYQWCHFu.min.js} +26 -26
- package/dist/{three-DMrv-4ar.umd.cjs → three-B_hneGZr.umd.cjs} +4 -4
- package/dist/{three-Bz6X1mrw.js → three-DrqIzZTH.js} +4198 -4198
- package/dist/{three-Boa-jOq-.min.js → three-DuDKwKB8.min.js} +33 -33
- package/dist/{three-examples-GggCDHv0.js → three-examples-B50TT3Iu.js} +5 -5
- package/dist/{three-examples-DuVhxqft.min.js → three-examples-DaDLBuy6.min.js} +14 -14
- package/dist/{three-examples-C7ryg8vN.umd.cjs → three-examples-X3OadjXB.umd.cjs} +3 -3
- package/dist/{three-mesh-ui-CY6Izc7C.min.js → three-mesh-ui-B3p3gyUz.min.js} +1 -1
- package/dist/{three-mesh-ui-CwlN0FUC.umd.cjs → three-mesh-ui-CQiIQIlA.umd.cjs} +1 -1
- package/dist/{three-mesh-ui-CLNOfsWn.js → three-mesh-ui-CxuWt7m-.js} +1 -1
- package/dist/{vendor-zxXa3Dmr.min.js → vendor-BlSxe9JJ.min.js} +3 -3
- package/dist/{vendor-BSD1RQIh.js → vendor-BmYIgaS1.js} +3 -3
- package/dist/{vendor-DHr4aqIZ.umd.cjs → vendor-Cavtu3CP.umd.cjs} +3 -3
- package/lib/engine/engine_assetdatabase.js +3 -1
- package/lib/engine/engine_assetdatabase.js.map +1 -1
- package/lib/engine/engine_context.d.ts +6 -3
- package/lib/engine/engine_context.js +20 -12
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_three_utils.d.ts +17 -14
- package/lib/engine/engine_three_utils.js +106 -53
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_tonemapping.d.ts +4 -0
- package/lib/engine/engine_tonemapping.js +21 -18
- package/lib/engine/engine_tonemapping.js.map +1 -1
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/engine_utils_screenshot.d.ts +1 -1
- package/lib/engine/engine_utils_screenshot.js +11 -2
- package/lib/engine/engine_utils_screenshot.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.d.ts +4 -1
- package/lib/engine/webcomponents/needle-engine.extras.js +3 -3
- package/lib/engine/webcomponents/needle-engine.extras.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.js +11 -21
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine-components/CameraUtils.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.d.ts +2 -1
- package/lib/engine-components/ReflectionProbe.js +4 -1
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/Renderer.js +9 -5
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js +3 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/BloomEffect.d.ts +2 -2
- package/lib/engine-components/postprocessing/Effects/BloomEffect.js +5 -2
- package/lib/engine-components/postprocessing/Effects/BloomEffect.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +8 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +27 -8
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +1 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +1 -0
- package/lib/engine-components/postprocessing/Effects/Sharpening.js +4 -0
- package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +2 -9
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js +29 -73
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +13 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js +52 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +18 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js +22 -3
- package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +21 -4
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +237 -125
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/postprocessing/Volume.d.ts +2 -1
- package/lib/engine-components/postprocessing/Volume.js +51 -33
- package/lib/engine-components/postprocessing/Volume.js.map +1 -1
- package/lib/engine-components/postprocessing/index.d.ts +1 -0
- package/lib/engine-components/postprocessing/index.js +1 -0
- package/lib/engine-components/postprocessing/index.js.map +1 -1
- package/lib/engine-components/postprocessing/utils.d.ts +43 -0
- package/lib/engine-components/postprocessing/utils.js +82 -0
- package/lib/engine-components/postprocessing/utils.js.map +1 -1
- package/package.json +2 -2
- package/plugins/vite/dependency-watcher.js +8 -2
- package/src/engine/engine_assetdatabase.ts +3 -1
- package/src/engine/engine_context.ts +27 -15
- package/src/engine/engine_three_utils.ts +134 -58
- package/src/engine/engine_tonemapping.ts +23 -24
- package/src/engine/engine_utils.ts +2 -2
- package/src/engine/engine_utils_screenshot.ts +13 -3
- package/src/engine/webcomponents/needle-engine.extras.ts +3 -3
- package/src/engine/webcomponents/needle-engine.ts +14 -25
- package/src/engine-components/CameraUtils.ts +3 -3
- package/src/engine-components/ReflectionProbe.ts +5 -1
- package/src/engine-components/Renderer.ts +10 -7
- package/src/engine-components/postprocessing/Effects/Antialiasing.ts +3 -1
- package/src/engine-components/postprocessing/Effects/BloomEffect.ts +6 -4
- package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +24 -13
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -0
- package/src/engine-components/postprocessing/Effects/Sharpening.ts +5 -0
- package/src/engine-components/postprocessing/Effects/Tonemapping.ts +29 -81
- package/src/engine-components/postprocessing/Effects/Tonemapping.utils.ts +60 -0
- package/src/engine-components/postprocessing/PostProcessingEffect.ts +23 -3
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +268 -132
- package/src/engine-components/postprocessing/Volume.ts +54 -38
- package/src/engine-components/postprocessing/index.ts +2 -1
- package/src/engine-components/postprocessing/utils.ts +102 -2
- package/dist/generateMeshBVH.worker-Cdfpaq5W.js +0 -25
- package/dist/needle-engine.bundle-BDO_N7gN.min.js +0 -1559
- package/dist/needle-engine.bundle-CoJqbtmp.umd.cjs +0 -1559
|
@@ -17,9 +17,18 @@ export class ColorAdjustments extends PostProcessingEffect {
|
|
|
17
17
|
return "ColorAdjustments";
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Whether values for contrast, hueshift or saturation are remapped to a different range.
|
|
22
|
+
*/
|
|
23
|
+
remap = true;
|
|
24
|
+
|
|
20
25
|
@serializable(VolumeParameter)
|
|
21
|
-
readonly postExposure: VolumeParameter = new VolumeParameter(
|
|
26
|
+
readonly postExposure: VolumeParameter = new VolumeParameter(1);
|
|
22
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Range -1 to 1, where 0 is the default value, -1 is the lowest contrast and 1 is the highest contrast.
|
|
30
|
+
* @default 0
|
|
31
|
+
*/
|
|
23
32
|
@serializable(VolumeParameter)
|
|
24
33
|
readonly contrast: VolumeParameter = new VolumeParameter(0);
|
|
25
34
|
|
|
@@ -31,11 +40,12 @@ export class ColorAdjustments extends PostProcessingEffect {
|
|
|
31
40
|
|
|
32
41
|
init() {
|
|
33
42
|
this.postExposure!.valueProcessor = v => {
|
|
43
|
+
if(!this.remap) return v;
|
|
34
44
|
v = Math.pow(2.0, v);
|
|
35
45
|
return v;
|
|
36
46
|
}
|
|
37
|
-
|
|
38
47
|
this.contrast.valueProcessor = (v: number) => {
|
|
48
|
+
if(!this.remap) return v;
|
|
39
49
|
let divisor = 1;
|
|
40
50
|
if (v > 0) divisor = 200;
|
|
41
51
|
else if (v < 0) divisor = 100;
|
|
@@ -45,10 +55,14 @@ export class ColorAdjustments extends PostProcessingEffect {
|
|
|
45
55
|
};
|
|
46
56
|
this.contrast.defaultValue = 0;
|
|
47
57
|
|
|
48
|
-
this.hueShift.valueProcessor = (v: number) =>
|
|
58
|
+
this.hueShift.valueProcessor = (v: number) => {
|
|
59
|
+
if(!this.remap) return v;
|
|
60
|
+
return Math.PI * v / 180;
|
|
61
|
+
}
|
|
49
62
|
this.hueShift.defaultValue = 0;
|
|
50
63
|
|
|
51
64
|
this.saturation.valueProcessor = (v: number) => {
|
|
65
|
+
if(!this.remap) return v;
|
|
52
66
|
if (v < 0) return (v / 100);
|
|
53
67
|
const sat = (v / (100 * Math.PI));
|
|
54
68
|
return sat;
|
|
@@ -60,36 +74,33 @@ export class ColorAdjustments extends PostProcessingEffect {
|
|
|
60
74
|
const effects: EffectProviderResult = [];
|
|
61
75
|
|
|
62
76
|
// TODO: do we still need this?
|
|
63
|
-
if (this.context.renderer.toneMapping !== NoToneMapping && this.postExposure.overrideState)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
// if (this.context.renderer.toneMapping !== NoToneMapping && this.postExposure.overrideState)
|
|
78
|
+
// this.context.renderer.toneMapping = NoToneMapping;
|
|
67
79
|
// find the ToneMapping effect because we need it to apply post exposure
|
|
68
80
|
let tonemappingEffect = this.postprocessingContext?.components.find(c => c instanceof ToneMappingEffect) as ToneMappingEffect;
|
|
69
81
|
if (!tonemappingEffect) {
|
|
70
82
|
tonemappingEffect = new ToneMappingEffect();
|
|
71
83
|
this.postprocessingContext?.components.push(tonemappingEffect);
|
|
72
84
|
}
|
|
73
|
-
|
|
74
85
|
// We need this effect if someone uses ACES or AgX tonemapping;
|
|
75
86
|
// problem is that we CAN'T use this effect for the "Linear" case, the package expects that in this case you remove the effect
|
|
76
87
|
this.postExposure!.onValueChanged = (v) => {
|
|
77
|
-
if (this.postExposure.overrideState) {
|
|
88
|
+
if (this.postExposure.overrideState && tonemappingEffect) {
|
|
78
89
|
tonemappingEffect.exposure.value = v;
|
|
79
90
|
}
|
|
91
|
+
else console.warn("[PostProcessing] PostExposure is set to override but no ToneMappingEffect found in the postprocessing stack. Please add a ToneMappingEffect to your postprocessing stack to use PostExposure.");
|
|
80
92
|
};
|
|
81
93
|
|
|
82
94
|
const brightnesscontrast = new MODULES.POSTPROCESSING.MODULE.BrightnessContrastEffect();
|
|
83
95
|
this.contrast!.onValueChanged = v => brightnesscontrast.contrast = v;
|
|
84
96
|
|
|
85
97
|
const hueSaturationEffect = new MODULES.POSTPROCESSING.MODULE.HueSaturationEffect();
|
|
86
|
-
|
|
87
|
-
effects.push(brightnesscontrast);
|
|
88
|
-
effects.push(hueSaturationEffect);
|
|
89
|
-
|
|
90
98
|
this.hueShift!.onValueChanged = v => hueSaturationEffect.hue = v;
|
|
91
99
|
this.saturation!.onValueChanged = v => hueSaturationEffect.saturation = v;
|
|
92
100
|
|
|
101
|
+
|
|
102
|
+
effects.push(brightnesscontrast);
|
|
103
|
+
effects.push(hueSaturationEffect);
|
|
93
104
|
return effects;
|
|
94
105
|
}
|
|
95
106
|
}
|
|
@@ -124,6 +124,7 @@ export class ScreenSpaceAmbientOcclusionN8 extends PostProcessingEffect {
|
|
|
124
124
|
cam,
|
|
125
125
|
width, height
|
|
126
126
|
) as N8AOPostPass;
|
|
127
|
+
ssao.name = "SSAO N8";
|
|
127
128
|
|
|
128
129
|
const mode = ScreenSpaceAmbientOcclusionN8QualityMode[this.quality];
|
|
129
130
|
ssao.setQualityMode(mode);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { EffectAttribute } from "postprocessing";
|
|
1
2
|
import { Uniform } from "three";
|
|
2
3
|
|
|
3
4
|
import { MODULES } from "../../../engine/engine_modules.js";
|
|
4
5
|
import { serializable } from "../../../engine/engine_serialization.js";
|
|
5
6
|
import { PostProcessingEffect } from "../PostProcessingEffect.js";
|
|
7
|
+
import { PostProcessingEffectOrder } from "../utils.js";
|
|
6
8
|
// import type { createSharpeningEffectType } from "./Sharpening.effect";
|
|
7
9
|
|
|
8
10
|
// let __SHARPENING_MODULE: typeof import("./Sharpening.effect");
|
|
@@ -21,6 +23,8 @@ export class SharpeningEffect extends PostProcessingEffect {
|
|
|
21
23
|
return "Sharpening";
|
|
22
24
|
}
|
|
23
25
|
|
|
26
|
+
order: number | undefined = PostProcessingEffectOrder.Sharpening;
|
|
27
|
+
|
|
24
28
|
private _effect?: any;
|
|
25
29
|
|
|
26
30
|
onCreateEffect() {
|
|
@@ -130,6 +134,7 @@ function createSharpeningEffectType() {
|
|
|
130
134
|
["radius", new Uniform(1)],
|
|
131
135
|
// ["threshold", new Uniform(0)],
|
|
132
136
|
]),
|
|
137
|
+
attributes: EffectAttribute.CONVOLUTION
|
|
133
138
|
});
|
|
134
139
|
}
|
|
135
140
|
}
|
|
@@ -1,69 +1,18 @@
|
|
|
1
1
|
import type { ToneMappingEffect as _TonemappingEffect, ToneMappingMode } from "postprocessing";
|
|
2
|
-
import { ACESFilmicToneMapping, AgXToneMapping, LinearToneMapping, NeutralToneMapping, NoToneMapping, ReinhardToneMapping } from "three";
|
|
3
2
|
|
|
4
3
|
import { MODULES } from "../../../engine/engine_modules.js";
|
|
5
4
|
import { serializable } from "../../../engine/engine_serialization.js";
|
|
5
|
+
import { nameToThreeTonemapping } from "../../../engine/engine_tonemapping.js";
|
|
6
6
|
import { getParam } from "../../../engine/engine_utils.js";
|
|
7
7
|
import { EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect.js";
|
|
8
8
|
import { findPostProcessingManager } from "../utils.js";
|
|
9
9
|
import { VolumeParameter } from "../VolumeParameter.js";
|
|
10
10
|
import { registerCustomEffectType } from "../VolumeProfile.js";
|
|
11
|
+
import { NEToneMappingMode, NEToneMappingModeNames, threeToNeedleToneMapping, threeToneMappingToEffectMode, toThreeToneMapping } from "./Tonemapping.utils.js";
|
|
11
12
|
|
|
12
13
|
const debug = getParam("debugpost");
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
enum NEToneMappingMode {
|
|
16
|
-
None = 0,
|
|
17
|
-
Neutral = 1, // Neutral tonemapper, close to Reinhard
|
|
18
|
-
ACES = 2, // ACES Filmic reference tonemapper (custom approximation)
|
|
19
|
-
AgX = 3, // AgX Filmic tonemapper
|
|
20
|
-
KhronosNeutral = 4, // PBR Neural tonemapper
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type NEToneMappingModeNames = keyof typeof NEToneMappingMode;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function toThreeToneMapping(mode: NEToneMappingMode | undefined) {
|
|
27
|
-
switch (mode) {
|
|
28
|
-
case NEToneMappingMode.None:
|
|
29
|
-
return LinearToneMapping;
|
|
30
|
-
case NEToneMappingMode.Neutral:
|
|
31
|
-
return ReinhardToneMapping;
|
|
32
|
-
case NEToneMappingMode.ACES:
|
|
33
|
-
return ACESFilmicToneMapping;
|
|
34
|
-
case NEToneMappingMode.AgX:
|
|
35
|
-
return AgXToneMapping;
|
|
36
|
-
case NEToneMappingMode.KhronosNeutral:
|
|
37
|
-
return NeutralToneMapping;
|
|
38
|
-
default:
|
|
39
|
-
return NeutralToneMapping;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function threeToNeToneMapping(mode: number | undefined): NEToneMappingMode {
|
|
44
|
-
switch (mode) {
|
|
45
|
-
case LinearToneMapping: return NEToneMappingMode.None;
|
|
46
|
-
case ACESFilmicToneMapping: return NEToneMappingMode.ACES;
|
|
47
|
-
case AgXToneMapping: return NEToneMappingMode.AgX;
|
|
48
|
-
case NeutralToneMapping: return NEToneMappingMode.Neutral;
|
|
49
|
-
case ReinhardToneMapping: return NEToneMappingMode.Neutral;
|
|
50
|
-
default: return NEToneMappingMode.None;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
function threeToneMappingToEffectMode(mode: number | undefined): ToneMappingMode {
|
|
57
|
-
switch (mode) {
|
|
58
|
-
case LinearToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;
|
|
59
|
-
case ACESFilmicToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.ACES_FILMIC;
|
|
60
|
-
case AgXToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.AGX;
|
|
61
|
-
case NeutralToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.NEUTRAL;
|
|
62
|
-
case ReinhardToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.REINHARD;
|
|
63
|
-
default: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
16
|
/**
|
|
68
17
|
* @category Effects
|
|
69
18
|
* @group Components
|
|
@@ -84,7 +33,7 @@ export class ToneMappingEffect extends PostProcessingEffect {
|
|
|
84
33
|
setMode(mode: NEToneMappingModeNames) {
|
|
85
34
|
const enumValue = NEToneMappingMode[mode as NEToneMappingModeNames];
|
|
86
35
|
if (enumValue === undefined) {
|
|
87
|
-
console.error("Invalid ToneMapping mode", mode);
|
|
36
|
+
console.error("[PostProcessing] Invalid ToneMapping mode", mode);
|
|
88
37
|
return this;
|
|
89
38
|
}
|
|
90
39
|
this.mode.value = enumValue;
|
|
@@ -101,53 +50,52 @@ export class ToneMappingEffect extends PostProcessingEffect {
|
|
|
101
50
|
super.onEffectEnabled(ppmanager);
|
|
102
51
|
}
|
|
103
52
|
|
|
53
|
+
private _tonemappingEffect: _TonemappingEffect | null = null;
|
|
104
54
|
onCreateEffect(): EffectProviderResult | undefined {
|
|
105
55
|
|
|
106
|
-
// TODO: this should be done in the PostProcessingHandler
|
|
107
|
-
if (this.postprocessingContext) {
|
|
108
|
-
for (const other of this.postprocessingContext.components) {
|
|
109
|
-
// If we're the first tonemapping effect it's all good
|
|
110
|
-
if (other === this) break;
|
|
111
|
-
// If another tonemapping effect is found, warn the user
|
|
112
|
-
if (other != this && other instanceof ToneMappingEffect) {
|
|
113
|
-
console.warn("Multiple tonemapping effects found in the same postprocessing stack: Please check your scene setup.", { activeEffect: other, ignoredEffect: this });
|
|
114
|
-
return undefined;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
56
|
|
|
120
57
|
// ensure the effect tonemapping value is initialized
|
|
121
58
|
if (this.mode.isInitialized == false) {
|
|
122
|
-
const
|
|
123
|
-
this.mode
|
|
59
|
+
const mode = threeToNeedleToneMapping(this.context.renderer.toneMapping);
|
|
60
|
+
if (debug) console.log("[PostProcessing] Initializing ToneMapping mode to renderer.toneMapping", this.context.renderer.toneMapping + " → " + mode);
|
|
61
|
+
this.mode.initialize(mode);
|
|
124
62
|
}
|
|
125
63
|
|
|
64
|
+
this._tonemappingEffect?.dispose();
|
|
65
|
+
|
|
126
66
|
const threeMode = toThreeToneMapping(this.mode.value);
|
|
127
|
-
const tonemapping = new MODULES.POSTPROCESSING.MODULE.ToneMappingEffect({
|
|
67
|
+
const tonemapping = this._tonemappingEffect = new MODULES.POSTPROCESSING.MODULE.ToneMappingEffect({
|
|
128
68
|
mode: threeToneMappingToEffectMode(threeMode),
|
|
129
69
|
});
|
|
130
70
|
this.mode.onValueChanged = (newValue) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
71
|
+
if (typeof newValue === "string") {
|
|
72
|
+
newValue = nameToThreeTonemapping(newValue);
|
|
73
|
+
tonemapping.mode = threeToneMappingToEffectMode(newValue);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const threeMode = toThreeToneMapping(newValue);
|
|
77
|
+
tonemapping.mode = threeToneMappingToEffectMode(threeMode);
|
|
78
|
+
}
|
|
79
|
+
tonemapping.name = "ToneMapping (" + NEToneMappingMode[newValue] + ")";
|
|
80
|
+
if (debug) console.log("[PostProcessing] ToneMapping mode changed to", NEToneMappingMode[newValue], threeMode, tonemapping.mode);
|
|
134
81
|
};
|
|
135
|
-
if (debug) console.log("Use ToneMapping", NEToneMappingMode[this.mode.value], threeMode, tonemapping.mode, "renderer.tonemapping: " + this.context.renderer.toneMapping);
|
|
136
82
|
|
|
137
83
|
|
|
138
|
-
this.
|
|
139
|
-
this.context.renderer.toneMappingExposure = newValue;
|
|
140
|
-
};
|
|
84
|
+
if (debug) console.log("[PostProcessing] Use ToneMapping", NEToneMappingMode[this.mode.value], threeMode, tonemapping.mode, "renderer.tonemapping: " + this.context.renderer.toneMapping);
|
|
141
85
|
|
|
142
86
|
return tonemapping;
|
|
143
87
|
}
|
|
144
88
|
|
|
145
89
|
|
|
146
90
|
onBeforeRender(): void {
|
|
147
|
-
if (this.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.
|
|
91
|
+
if (this._tonemappingEffect && this.postprocessingContext?.handler.getEffectIsActive(this._tonemappingEffect)) {
|
|
92
|
+
if (this.mode.overrideState)
|
|
93
|
+
this.context.renderer.toneMapping = toThreeToneMapping(this.mode.value);
|
|
94
|
+
if (this.exposure.overrideState && this.exposure.value !== undefined) {
|
|
95
|
+
const newValue = Math.max(0.01, this.exposure.value);
|
|
96
|
+
this.context.renderer.toneMappingExposure = newValue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
151
99
|
}
|
|
152
100
|
|
|
153
101
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ToneMappingMode } from "postprocessing";
|
|
2
|
+
import { ACESFilmicToneMapping, AgXToneMapping, LinearToneMapping, NeutralToneMapping, ReinhardToneMapping, ToneMapping } from "three";
|
|
3
|
+
|
|
4
|
+
import { MODULES } from "../../../engine/engine_modules.js";
|
|
5
|
+
|
|
6
|
+
export enum NEToneMappingMode {
|
|
7
|
+
None = 0,
|
|
8
|
+
Neutral = 1, // Neutral tonemapper, close to Reinhard
|
|
9
|
+
ACES = 2, // ACES Filmic reference tonemapper (custom approximation)
|
|
10
|
+
AgX = 3, // AgX Filmic tonemapper
|
|
11
|
+
KhronosNeutral = 4, // PBR Neural tonemapper
|
|
12
|
+
}
|
|
13
|
+
export type NEToneMappingModeNames = keyof typeof NEToneMappingMode;
|
|
14
|
+
|
|
15
|
+
const unknownTonemappingWarning = new Map<any, boolean>();
|
|
16
|
+
|
|
17
|
+
export function toThreeToneMapping(mode: NEToneMappingMode | undefined) {
|
|
18
|
+
switch (mode) {
|
|
19
|
+
case NEToneMappingMode.None:
|
|
20
|
+
return LinearToneMapping;
|
|
21
|
+
case NEToneMappingMode.Neutral:
|
|
22
|
+
return ReinhardToneMapping;
|
|
23
|
+
case NEToneMappingMode.ACES:
|
|
24
|
+
return ACESFilmicToneMapping;
|
|
25
|
+
case NEToneMappingMode.AgX:
|
|
26
|
+
return AgXToneMapping;
|
|
27
|
+
case NEToneMappingMode.KhronosNeutral:
|
|
28
|
+
return NeutralToneMapping;
|
|
29
|
+
default:
|
|
30
|
+
if(!unknownTonemappingWarning.has(mode)) {
|
|
31
|
+
unknownTonemappingWarning.set(mode, true);
|
|
32
|
+
console.warn("[Postprocessing] Unknown tone mapping mode", mode);
|
|
33
|
+
}
|
|
34
|
+
return NeutralToneMapping;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function threeToNeedleToneMapping(mode: ToneMapping | number | undefined): NEToneMappingMode {
|
|
39
|
+
switch (mode) {
|
|
40
|
+
case LinearToneMapping: return NEToneMappingMode.None;
|
|
41
|
+
case ACESFilmicToneMapping: return NEToneMappingMode.ACES;
|
|
42
|
+
case AgXToneMapping: return NEToneMappingMode.AgX;
|
|
43
|
+
case NeutralToneMapping: return NEToneMappingMode.Neutral;
|
|
44
|
+
case ReinhardToneMapping: return NEToneMappingMode.Neutral;
|
|
45
|
+
default: return NEToneMappingMode.None;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export function threeToneMappingToEffectMode(mode: number | undefined): ToneMappingMode {
|
|
52
|
+
switch (mode) {
|
|
53
|
+
case LinearToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;
|
|
54
|
+
case ACESFilmicToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.ACES_FILMIC;
|
|
55
|
+
case AgXToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.AGX;
|
|
56
|
+
case NeutralToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.NEUTRAL;
|
|
57
|
+
case ReinhardToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.REINHARD;
|
|
58
|
+
default: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -55,6 +55,25 @@ export abstract class PostProcessingEffect extends Component implements IEffectP
|
|
|
55
55
|
|
|
56
56
|
get isPostProcessingEffect() { return true; }
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* The order of this effect. The higher the order the later the effect will be applied in the post processing stack.
|
|
60
|
+
* This can be used to control the order of effects when multiple effects are applied.
|
|
61
|
+
* It is recommended to use the PostProcessingEffectOrder constant to order your custom effects before or after built-in effects.
|
|
62
|
+
* @default `undefined` (no specific order set, will be applied in the order of registration)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import { PostProcessingEffectOrder } from "@needle-tools/engine"
|
|
67
|
+
*
|
|
68
|
+
* export class MyCustomEffect extends PostProcessingEffect {
|
|
69
|
+
* order: PostProcessingEffectOrder.Bloom + 1; // render after bloom
|
|
70
|
+
* // This will ensure that the effect is applied after the bloom effect in the post processing stack.
|
|
71
|
+
* // ... the rest of your effect code
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
order: number | undefined = undefined;
|
|
76
|
+
|
|
58
77
|
constructor(params: any = undefined) {
|
|
59
78
|
super();
|
|
60
79
|
if (params) {
|
|
@@ -86,7 +105,7 @@ export abstract class PostProcessingEffect extends Component implements IEffectP
|
|
|
86
105
|
|
|
87
106
|
onEnable(): void {
|
|
88
107
|
super.onEnable();
|
|
89
|
-
if (debug) console.warn("
|
|
108
|
+
if (debug) console.warn("Enable", this.constructor.name + (!this.__internalDidAwakeAndStart ? " (awake)" : ""));
|
|
90
109
|
// Dont override the serialized value by enabling (we could also just disable this component / map enabled to active)
|
|
91
110
|
if (this.__internalDidAwakeAndStart)
|
|
92
111
|
this.active = true;
|
|
@@ -95,7 +114,7 @@ export abstract class PostProcessingEffect extends Component implements IEffectP
|
|
|
95
114
|
|
|
96
115
|
onDisable(): void {
|
|
97
116
|
super.onDisable();
|
|
98
|
-
if (debug) console.warn("
|
|
117
|
+
if (debug) console.warn("Disable", this.constructor.name);
|
|
99
118
|
this._manager?.removeEffect(this);
|
|
100
119
|
this.active = false;
|
|
101
120
|
}
|
|
@@ -103,7 +122,8 @@ export abstract class PostProcessingEffect extends Component implements IEffectP
|
|
|
103
122
|
protected onEffectEnabled(manager?: IPostProcessingManager) {
|
|
104
123
|
if (manager && manager.isPostProcessingManager === true) this._manager = manager;
|
|
105
124
|
else if (!this._manager) this._manager = getPostProcessingManager(this);
|
|
106
|
-
this._manager
|
|
125
|
+
this._manager!.addEffect(this);
|
|
126
|
+
this._manager!.dirty = true;
|
|
107
127
|
}
|
|
108
128
|
|
|
109
129
|
/** override to initialize bindings on parameters */
|