@needle-tools/engine 4.6.1-next.f9f2e7d → 4.6.2-next.fb486b2
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/{needle-engine.bundle-DoQP-VX2.min.js → needle-engine.bundle-CJ4jhuta.min.js} +173 -161
- package/dist/{needle-engine.bundle-ntX9QTqT.js → needle-engine.bundle-CQzZighj.js} +7390 -7295
- package/dist/{needle-engine.bundle-CbE5i73R.umd.cjs → needle-engine.bundle-CdAK5p8o.umd.cjs} +177 -165
- package/dist/needle-engine.js +48 -48
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/engine_context.d.ts +2 -1
- package/lib/engine/engine_context.js +3 -2
- 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/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/postprocessing/Effects/BloomEffect.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/BloomEffect.js +2 -5
- 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 +23 -71
- 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 +7 -7
- package/lib/engine-components/postprocessing/PostProcessingEffect.js +9 -9
- package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +10 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +152 -23
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/postprocessing/Volume.js +19 -24
- package/lib/engine-components/postprocessing/Volume.js.map +1 -1
- package/lib/engine-components/postprocessing/index.d.ts +1 -1
- package/lib/engine-components/postprocessing/index.js +1 -1
- package/lib/engine-components/postprocessing/index.js.map +1 -1
- package/lib/engine-components/postprocessing/utils.d.ts +13 -7
- package/lib/engine-components/postprocessing/utils.js +37 -53
- package/lib/engine-components/postprocessing/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_context.ts +5 -3
- 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/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/postprocessing/Effects/BloomEffect.ts +2 -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 +26 -80
- package/src/engine-components/postprocessing/Effects/Tonemapping.utils.ts +60 -0
- package/src/engine-components/postprocessing/PostProcessingEffect.ts +9 -9
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +174 -27
- package/src/engine-components/postprocessing/Volume.ts +19 -26
- package/src/engine-components/postprocessing/index.ts +2 -2
- package/src/engine-components/postprocessing/utils.ts +41 -56
|
@@ -48,10 +48,10 @@ export class BloomEffect extends PostProcessingEffect {
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Scatter value. The higher the value, the more the bloom will scatter.
|
|
51
|
-
* @default 0.
|
|
51
|
+
* @default 0.7
|
|
52
52
|
*/
|
|
53
53
|
@serializable(VolumeParameter)
|
|
54
|
-
readonly scatter: VolumeParameter = new VolumeParameter(.
|
|
54
|
+
readonly scatter: VolumeParameter = new VolumeParameter(.7);
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Set to true to use selective bloom when the effect gets created.
|
|
@@ -93,8 +93,6 @@ export class BloomEffect extends PostProcessingEffect {
|
|
|
93
93
|
radius: 0.85, // default value
|
|
94
94
|
intensity: this.intensity.value,
|
|
95
95
|
});
|
|
96
|
-
// @ts-ignore Well... it's protected but bloom needs this :(
|
|
97
|
-
bloom.setAttributes(EffectAttribute.CONVOLUTION);
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
this.intensity.onValueChanged = newValue => {
|
|
@@ -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,70 +1,18 @@
|
|
|
1
1
|
import type { ToneMappingEffect as _TonemappingEffect, ToneMappingMode } from "postprocessing";
|
|
2
|
-
import { ACESFilmicToneMapping, AgXToneMapping, LinearToneMapping, NeutralToneMapping, NoToneMapping, ReinhardToneMapping, WebGLRenderer } 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
|
-
if(debug) console.warn("[Postprocessing] Unknown tone mapping mode", mode);
|
|
40
|
-
return NeutralToneMapping;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function threeToNeToneMapping(mode: number | undefined): NEToneMappingMode {
|
|
45
|
-
switch (mode) {
|
|
46
|
-
case LinearToneMapping: return NEToneMappingMode.None;
|
|
47
|
-
case ACESFilmicToneMapping: return NEToneMappingMode.ACES;
|
|
48
|
-
case AgXToneMapping: return NEToneMappingMode.AgX;
|
|
49
|
-
case NeutralToneMapping: return NEToneMappingMode.Neutral;
|
|
50
|
-
case ReinhardToneMapping: return NEToneMappingMode.Neutral;
|
|
51
|
-
default: return NEToneMappingMode.None;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
function threeToneMappingToEffectMode(mode: number | undefined): ToneMappingMode {
|
|
58
|
-
switch (mode) {
|
|
59
|
-
case LinearToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;
|
|
60
|
-
case ACESFilmicToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.ACES_FILMIC;
|
|
61
|
-
case AgXToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.AGX;
|
|
62
|
-
case NeutralToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.NEUTRAL;
|
|
63
|
-
case ReinhardToneMapping: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.REINHARD;
|
|
64
|
-
default: return MODULES.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
16
|
/**
|
|
69
17
|
* @category Effects
|
|
70
18
|
* @group Components
|
|
@@ -102,54 +50,52 @@ export class ToneMappingEffect extends PostProcessingEffect {
|
|
|
102
50
|
super.onEffectEnabled(ppmanager);
|
|
103
51
|
}
|
|
104
52
|
|
|
53
|
+
private _tonemappingEffect: _TonemappingEffect | null = null;
|
|
105
54
|
onCreateEffect(): EffectProviderResult | undefined {
|
|
106
55
|
|
|
107
|
-
// TODO: this should be done in the PostProcessingHandler
|
|
108
|
-
if (this.postprocessingContext) {
|
|
109
|
-
for (const other of this.postprocessingContext.components) {
|
|
110
|
-
// If we're the first tonemapping effect it's all good
|
|
111
|
-
if (other === this) break;
|
|
112
|
-
// If another tonemapping effect is found, warn the user
|
|
113
|
-
if (other != this && other instanceof ToneMappingEffect) {
|
|
114
|
-
console.warn("[PostProcessing] Multiple tonemapping effects found in the same postprocessing stack: Please check your scene setup.", { activeEffect: other, ignoredEffect: this });
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
56
|
|
|
121
57
|
// ensure the effect tonemapping value is initialized
|
|
122
58
|
if (this.mode.isInitialized == false) {
|
|
123
|
-
const mode =
|
|
124
|
-
if(debug) console.log("[PostProcessing] Initializing ToneMapping mode to renderer.toneMapping", this.context.renderer.toneMapping + " → " + 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);
|
|
125
61
|
this.mode.initialize(mode);
|
|
126
62
|
}
|
|
127
63
|
|
|
64
|
+
this._tonemappingEffect?.dispose();
|
|
65
|
+
|
|
128
66
|
const threeMode = toThreeToneMapping(this.mode.value);
|
|
129
|
-
const tonemapping = new MODULES.POSTPROCESSING.MODULE.ToneMappingEffect({
|
|
67
|
+
const tonemapping = this._tonemappingEffect = new MODULES.POSTPROCESSING.MODULE.ToneMappingEffect({
|
|
130
68
|
mode: threeToneMappingToEffectMode(threeMode),
|
|
131
69
|
});
|
|
132
70
|
this.mode.onValueChanged = (newValue) => {
|
|
133
|
-
|
|
134
|
-
|
|
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] + ")";
|
|
135
80
|
if (debug) console.log("[PostProcessing] ToneMapping mode changed to", NEToneMappingMode[newValue], threeMode, tonemapping.mode);
|
|
136
81
|
};
|
|
137
|
-
if (debug) console.log("[PostProcessing] Use ToneMapping", NEToneMappingMode[this.mode.value], threeMode, tonemapping.mode, "renderer.tonemapping: " + this.context.renderer.toneMapping);
|
|
138
82
|
|
|
139
83
|
|
|
140
|
-
this.
|
|
141
|
-
this.context.renderer.toneMappingExposure = newValue;
|
|
142
|
-
};
|
|
84
|
+
if (debug) console.log("[PostProcessing] Use ToneMapping", NEToneMappingMode[this.mode.value], threeMode, tonemapping.mode, "renderer.tonemapping: " + this.context.renderer.toneMapping);
|
|
143
85
|
|
|
144
86
|
return tonemapping;
|
|
145
87
|
}
|
|
146
88
|
|
|
147
89
|
|
|
148
90
|
onBeforeRender(): void {
|
|
149
|
-
if (this.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
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
|
+
}
|
|
153
99
|
}
|
|
154
100
|
|
|
155
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
|
+
}
|
|
@@ -56,23 +56,23 @@ export abstract class PostProcessingEffect extends Component implements IEffectP
|
|
|
56
56
|
get isPostProcessingEffect() { return true; }
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* The
|
|
59
|
+
* The order of this effect. The higher the order the later the effect will be applied in the post processing stack.
|
|
60
60
|
* This can be used to control the order of effects when multiple effects are applied.
|
|
61
|
-
* It is recommended to use the
|
|
62
|
-
* @default `undefined` (no specific
|
|
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
63
|
*
|
|
64
64
|
* @example
|
|
65
65
|
* ```typescript
|
|
66
|
-
* import {
|
|
66
|
+
* import { PostProcessingEffectOrder } from "@needle-tools/engine"
|
|
67
67
|
*
|
|
68
68
|
* export class MyCustomEffect extends PostProcessingEffect {
|
|
69
|
-
*
|
|
70
|
-
*
|
|
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
71
|
* // ... the rest of your effect code
|
|
72
72
|
* }
|
|
73
73
|
* ```
|
|
74
74
|
*/
|
|
75
|
-
|
|
75
|
+
order: number | undefined = undefined;
|
|
76
76
|
|
|
77
77
|
constructor(params: any = undefined) {
|
|
78
78
|
super();
|
|
@@ -105,7 +105,7 @@ export abstract class PostProcessingEffect extends Component implements IEffectP
|
|
|
105
105
|
|
|
106
106
|
onEnable(): void {
|
|
107
107
|
super.onEnable();
|
|
108
|
-
if (debug) console.warn("
|
|
108
|
+
if (debug) console.warn("Enable", this.constructor.name + (!this.__internalDidAwakeAndStart ? " (awake)" : ""));
|
|
109
109
|
// Dont override the serialized value by enabling (we could also just disable this component / map enabled to active)
|
|
110
110
|
if (this.__internalDidAwakeAndStart)
|
|
111
111
|
this.active = true;
|
|
@@ -114,7 +114,7 @@ export abstract class PostProcessingEffect extends Component implements IEffectP
|
|
|
114
114
|
|
|
115
115
|
onDisable(): void {
|
|
116
116
|
super.onDisable();
|
|
117
|
-
if (debug) console.warn("
|
|
117
|
+
if (debug) console.warn("Disable", this.constructor.name);
|
|
118
118
|
this._manager?.removeEffect(this);
|
|
119
119
|
this.active = false;
|
|
120
120
|
}
|