@needle-tools/engine 4.6.1-next.1e3d612 → 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/dist/{needle-engine.bundle-DsI9yYlp.umd.cjs → needle-engine.bundle-BVrLqIyi.umd.cjs} +174 -162
- package/dist/{needle-engine.bundle-Dx31Hfkf.js → needle-engine.bundle-BonYthMO.js} +6830 -6751
- package/dist/{needle-engine.bundle-BYdv-DmQ.min.js → needle-engine.bundle-CokaG-YG.min.js} +165 -153
- 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 -2
- 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/Sharpening.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/Sharpening.js +2 -2
- 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 +7 -7
- 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 +128 -16
- 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 +6 -6
- package/lib/engine-components/postprocessing/utils.js +26 -25
- 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 -2
- package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +24 -13
- package/src/engine-components/postprocessing/Effects/Sharpening.ts +2 -2
- 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 +7 -7
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +143 -19
- package/src/engine-components/postprocessing/Volume.ts +19 -26
- package/src/engine-components/postprocessing/index.ts +1 -1
- package/src/engine-components/postprocessing/utils.ts +27 -26
|
@@ -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();
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import type { Effect, EffectComposer, Pass, ToneMappingEffect as _TonemappingEffect } from "postprocessing";
|
|
2
|
-
import { Camera as Camera3, HalfFloatType, NoToneMapping, Scene } from "three";
|
|
2
|
+
import { Camera as Camera3, DepthTexture, HalfFloatType, LinearFilter, NoToneMapping, Scene, Texture, ToneMapping, WebGLRenderTarget } from "three";
|
|
3
3
|
|
|
4
4
|
import { showBalloonWarning } from "../../engine/debug/index.js";
|
|
5
5
|
// import { internal_SetSharpeningEffectModule } from "./Effects/Sharpening.js";
|
|
6
6
|
import { MODULES } from "../../engine/engine_modules.js";
|
|
7
7
|
import { Context } from "../../engine/engine_setup.js";
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
8
|
+
import { Graphics } from "../../engine/engine_three_utils.js";
|
|
9
|
+
import { getParam } from "../../engine/engine_utils.js";
|
|
10
10
|
import { Camera } from "../Camera.js";
|
|
11
|
+
import { threeToneMappingToEffectMode } from "./Effects/Tonemapping.utils.js";
|
|
11
12
|
import { PostProcessingEffect, PostProcessingEffectContext } from "./PostProcessingEffect.js";
|
|
12
|
-
import { orderEffects, PostprocessingEffectData } from "./utils.js";
|
|
13
|
+
import { orderEffects, PostprocessingEffectData, PostProcessingEffectOrder } from "./utils.js";
|
|
13
14
|
|
|
14
15
|
declare const NEEDLE_USE_POSTPROCESSING: boolean;
|
|
15
16
|
globalThis["NEEDLE_USE_POSTPROCESSING"] = globalThis["NEEDLE_USE_POSTPROCESSING"] !== undefined ? globalThis["NEEDLE_USE_POSTPROCESSING"] : true;
|
|
@@ -19,6 +20,7 @@ const debug = getParam("debugpost");
|
|
|
19
20
|
|
|
20
21
|
const activeKey = Symbol("needle:postprocessing-handler");
|
|
21
22
|
const autoclearSetting = Symbol("needle:previous-autoclear-state");
|
|
23
|
+
const previousToneMapping = Symbol("needle:previous-tone-mapping");
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* PostProcessingHandler is responsible for applying post processing effects to the scene. It is internally used by the {@link Volume} component
|
|
@@ -29,6 +31,14 @@ export class PostProcessingHandler {
|
|
|
29
31
|
private _lastVolumeComponents?: PostProcessingEffect[];
|
|
30
32
|
private readonly _effects: Array<PostprocessingEffectData> = [];
|
|
31
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Returns true if a specific effect is currently active in the post processing stack.
|
|
36
|
+
*/
|
|
37
|
+
getEffectIsActive(effect: Effect): boolean {
|
|
38
|
+
if (!effect) return false;
|
|
39
|
+
return this._isActive && this._effects.some(e => e.effect === effect);
|
|
40
|
+
}
|
|
41
|
+
|
|
32
42
|
get isActive() {
|
|
33
43
|
return this._isActive;
|
|
34
44
|
}
|
|
@@ -78,6 +88,9 @@ export class PostProcessingHandler {
|
|
|
78
88
|
if (typeof context.renderer[autoclearSetting] === "boolean") {
|
|
79
89
|
context.renderer.autoClear = context.renderer[autoclearSetting];
|
|
80
90
|
}
|
|
91
|
+
if (typeof context.renderer[previousToneMapping] === "number") {
|
|
92
|
+
context.renderer.toneMapping = context.renderer[previousToneMapping] as ToneMapping;
|
|
93
|
+
}
|
|
81
94
|
}
|
|
82
95
|
|
|
83
96
|
this._composer?.removeAllPasses();
|
|
@@ -153,14 +166,14 @@ export class PostProcessingHandler {
|
|
|
153
166
|
for (const effect of res) {
|
|
154
167
|
this._effects.push({
|
|
155
168
|
effect,
|
|
156
|
-
priority: component.
|
|
169
|
+
priority: component.order
|
|
157
170
|
});
|
|
158
171
|
}
|
|
159
172
|
}
|
|
160
173
|
else {
|
|
161
174
|
this._effects.push({
|
|
162
175
|
effect: res,
|
|
163
|
-
priority: component.
|
|
176
|
+
priority: component.order
|
|
164
177
|
});
|
|
165
178
|
}
|
|
166
179
|
}
|
|
@@ -171,14 +184,6 @@ export class PostProcessingHandler {
|
|
|
171
184
|
}
|
|
172
185
|
}
|
|
173
186
|
|
|
174
|
-
// Ensure that we have a tonemapping effect if the renderer is set to use a tone mapping
|
|
175
|
-
if (this.context.renderer.toneMapping != NoToneMapping) {
|
|
176
|
-
if (!this._effects.find(e => e instanceof MODULES.POSTPROCESSING.MODULE.ToneMappingEffect)) {
|
|
177
|
-
const tonemapping = new MODULES.POSTPROCESSING.MODULE.ToneMappingEffect();
|
|
178
|
-
this._effects.push({ effect: tonemapping });
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
187
|
this.applyEffects(context);
|
|
183
188
|
}
|
|
184
189
|
|
|
@@ -191,6 +196,18 @@ export class PostProcessingHandler {
|
|
|
191
196
|
get hasSmaaEffect() { return this._hasSmaaEffect; }
|
|
192
197
|
|
|
193
198
|
|
|
199
|
+
|
|
200
|
+
private _customInputBuffer: WebGLRenderTarget<Texture> | null = null;
|
|
201
|
+
private _customInputBufferId = 0;
|
|
202
|
+
private _multisampling: number = 0;
|
|
203
|
+
set multisampling(value: number) {
|
|
204
|
+
this._multisampling = value;
|
|
205
|
+
}
|
|
206
|
+
get multisampling() {
|
|
207
|
+
return this._multisampling;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
|
|
194
211
|
/** Build composer passes */
|
|
195
212
|
private applyEffects(context: Context) {
|
|
196
213
|
// Reset state
|
|
@@ -198,8 +215,7 @@ export class PostProcessingHandler {
|
|
|
198
215
|
this._anyPassHasNormal = false;
|
|
199
216
|
this._hasSmaaEffect = false;
|
|
200
217
|
|
|
201
|
-
|
|
202
|
-
if (effectsOrPasses.length <= 0) {
|
|
218
|
+
if (this._effects.length <= 0) {
|
|
203
219
|
return;
|
|
204
220
|
}
|
|
205
221
|
|
|
@@ -217,6 +233,21 @@ export class PostProcessingHandler {
|
|
|
217
233
|
}
|
|
218
234
|
renderer[autoclearSetting] = renderer.autoClear;
|
|
219
235
|
|
|
236
|
+
if (typeof renderer[previousToneMapping] === "number") {
|
|
237
|
+
renderer.toneMapping = renderer[previousToneMapping] as ToneMapping;
|
|
238
|
+
}
|
|
239
|
+
renderer[previousToneMapping] = renderer.toneMapping;
|
|
240
|
+
|
|
241
|
+
// Ensure that we have a tonemapping effect if the renderer is set to use a tone mapping
|
|
242
|
+
if (renderer.toneMapping != NoToneMapping) {
|
|
243
|
+
if (!this._effects.find(e => e instanceof MODULES.POSTPROCESSING.MODULE.ToneMappingEffect)) {
|
|
244
|
+
const tonemapping = new MODULES.POSTPROCESSING.MODULE.ToneMappingEffect();
|
|
245
|
+
tonemapping.name = `ToneMapping (${renderer.toneMapping})`;
|
|
246
|
+
tonemapping.mode = threeToneMappingToEffectMode(renderer.toneMapping);
|
|
247
|
+
this._effects.push({ effect: tonemapping, priority: PostProcessingEffectOrder.ToneMapping });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
220
251
|
// create composer and set active on context
|
|
221
252
|
if (!this._composer) {
|
|
222
253
|
// const hdrRenderTarget = new WebGLRenderTarget(window.innerWidth, window.innerHeight, { type: HalfFloatType });
|
|
@@ -236,7 +267,7 @@ export class PostProcessingHandler {
|
|
|
236
267
|
composer.setRenderer(renderer);
|
|
237
268
|
composer.setMainScene(scene);
|
|
238
269
|
composer.autoRenderToScreen = true; // Must be enabled because it might be disabled during addPass by the composer itself (depending on the effect's settings or order)
|
|
239
|
-
composer.multisampling = 0;
|
|
270
|
+
composer.multisampling = 0; // Disable multisampling by default
|
|
240
271
|
|
|
241
272
|
for (const prev of composer.passes)
|
|
242
273
|
prev.dispose();
|
|
@@ -244,17 +275,95 @@ export class PostProcessingHandler {
|
|
|
244
275
|
|
|
245
276
|
// Render to screen pass
|
|
246
277
|
const screenpass = new MODULES.POSTPROCESSING.MODULE.RenderPass(scene, cam);
|
|
247
|
-
screenpass.name = "
|
|
278
|
+
screenpass.name = "RenderPass";
|
|
248
279
|
screenpass.mainScene = scene;
|
|
249
280
|
composer.addPass(screenpass);
|
|
250
281
|
|
|
282
|
+
const screenPassRender = screenpass.render;
|
|
283
|
+
this._customInputBuffer?.dispose();
|
|
284
|
+
this._customInputBuffer = null;
|
|
285
|
+
screenpass.render = (renderer, inputBuffer, outputBuffer, deltaTime, stencilTest) => {
|
|
286
|
+
if (!inputBuffer) return;
|
|
287
|
+
|
|
288
|
+
// screenPassRender.call(screenpass, renderer, inputBuffer, outputBuffer, deltaTime, stencilTest);
|
|
289
|
+
// return;
|
|
290
|
+
|
|
291
|
+
// Make sure multisampling is disabled on the composer buffers. Technically a user could still set multisampling directly on the composer so this is to override that and make sure these textures do NOT use multisampling
|
|
292
|
+
inputBuffer.samples = 0;
|
|
293
|
+
if (outputBuffer) {
|
|
294
|
+
outputBuffer.samples = 0;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Make sure the input buffer is a WebGLRenderTarget with the correct settings
|
|
298
|
+
if (!this._customInputBuffer
|
|
299
|
+
|| this._customInputBuffer.width !== inputBuffer.width
|
|
300
|
+
|| this._customInputBuffer.height !== inputBuffer.height
|
|
301
|
+
|| this._customInputBuffer.samples !== this._multisampling
|
|
302
|
+
|| this._customInputBuffer.texture.format !== inputBuffer.texture.format
|
|
303
|
+
|| this._customInputBuffer.texture.type !== HalfFloatType
|
|
304
|
+
) {
|
|
305
|
+
this._customInputBuffer?.dispose();
|
|
306
|
+
|
|
307
|
+
this._customInputBuffer = new WebGLRenderTarget(inputBuffer.width, inputBuffer.height, {
|
|
308
|
+
format: inputBuffer.texture.format,
|
|
309
|
+
type: HalfFloatType,
|
|
310
|
+
depthBuffer: inputBuffer.depthBuffer,
|
|
311
|
+
depthTexture: inputBuffer.depthTexture
|
|
312
|
+
? new DepthTexture(inputBuffer.width, inputBuffer.height)
|
|
313
|
+
: undefined,
|
|
314
|
+
stencilBuffer: inputBuffer.stencilBuffer,
|
|
315
|
+
samples: Math.max(0, this._multisampling),
|
|
316
|
+
minFilter: inputBuffer.texture.minFilter ?? LinearFilter,
|
|
317
|
+
magFilter: inputBuffer.texture.magFilter ?? LinearFilter,
|
|
318
|
+
generateMipmaps: inputBuffer.texture.generateMipmaps,
|
|
319
|
+
});
|
|
320
|
+
this._customInputBufferId++;
|
|
321
|
+
this._customInputBuffer.texture.name = `CustomInputBuffer-${this._customInputBufferId}`;
|
|
322
|
+
if (this._customInputBuffer.depthTexture && inputBuffer.depthTexture) {
|
|
323
|
+
this._customInputBuffer.depthTexture.format = inputBuffer.depthTexture.format;
|
|
324
|
+
this._customInputBuffer.depthTexture.type = inputBuffer.depthTexture.type;
|
|
325
|
+
}
|
|
326
|
+
// https://github.com/pmndrs/postprocessing/blob/ad338df710ef41fee4e5d10ad2c2c299030d46ef/src/core/EffectComposer.js#L366
|
|
327
|
+
if (this._customInputBuffer.samples > 0)
|
|
328
|
+
(this._customInputBuffer as any).ignoreDepthForMultisampleCopy = false;
|
|
329
|
+
|
|
330
|
+
if (debug) console.warn(`[PostProcessing] Input buffer created with size ${this._customInputBuffer.width}x${this._customInputBuffer.height} and samples ${this._customInputBuffer.samples}`);
|
|
331
|
+
}
|
|
332
|
+
// Calling the original render function with the input buffer
|
|
333
|
+
screenPassRender.call(screenpass, renderer, this._customInputBuffer, outputBuffer, deltaTime, stencilTest);
|
|
334
|
+
// Blit the resulting buffer to the input buffer passed in by the composer so it's used for subsequent effects
|
|
335
|
+
Graphics.blit(this._customInputBuffer.texture, inputBuffer, {
|
|
336
|
+
renderer,
|
|
337
|
+
depthTexture: this._customInputBuffer.depthTexture,
|
|
338
|
+
depthWrite: true,
|
|
339
|
+
depthTest: true,
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
|
|
251
344
|
try {
|
|
252
345
|
orderEffects(this._effects);
|
|
253
346
|
|
|
347
|
+
let foundTonemappingEffect = false;
|
|
348
|
+
let activeTonemappingEffect: _TonemappingEffect | null = null;
|
|
349
|
+
for (let i = this._effects.length - 1; i >= 0; i--) {
|
|
350
|
+
const ef = this._effects[i].effect;
|
|
351
|
+
if (ef instanceof MODULES.POSTPROCESSING.MODULE.ToneMappingEffect) {
|
|
352
|
+
// If we already have a tonemapping effect, we can skip this one
|
|
353
|
+
if (foundTonemappingEffect) {
|
|
354
|
+
if (debug) console.warn(`[PostProcessing] Found multiple tonemapping effects in the scene: ${ef.name} and ${activeTonemappingEffect?.name}. Only the last one added will be used.`);
|
|
355
|
+
this._effects.splice(i, 1);
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
activeTonemappingEffect = ef;
|
|
359
|
+
foundTonemappingEffect = true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
254
363
|
const effectsToMerge: Array<Effect> = [];
|
|
255
364
|
let hasConvolutionEffectInArray = false;
|
|
256
365
|
|
|
257
|
-
for (const entry of
|
|
366
|
+
for (const entry of this._effects) {
|
|
258
367
|
const ef = entry.effect;
|
|
259
368
|
|
|
260
369
|
if (ef instanceof MODULES.POSTPROCESSING.MODULE.SMAAEffect) {
|
|
@@ -264,6 +373,21 @@ export class PostProcessingHandler {
|
|
|
264
373
|
this._anyPassHasNormal = true;
|
|
265
374
|
}
|
|
266
375
|
|
|
376
|
+
|
|
377
|
+
// There can be only one tonemapping effect in the scene, so we can skip all others
|
|
378
|
+
if (ef instanceof MODULES.POSTPROCESSING.MODULE.ToneMappingEffect && activeTonemappingEffect !== ef) {
|
|
379
|
+
// If we already have a tonemapping effect, we can skip this one
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// We can also not merge multiple effects of the same type in one pass
|
|
384
|
+
// So we first need to create a new pass with whatever effects we have so far
|
|
385
|
+
// TODO: this seems to work fine for some effects (like ColorAdjustments) and only caused issues with multiple Tonemapping effects so far which is handled above
|
|
386
|
+
// const constructor = ef.constructor as Constructor<Effect | Pass>;
|
|
387
|
+
// if(effectsToMerge.find(e => e.constructor === constructor)) {
|
|
388
|
+
// // this.createPassForMergeableEffects(effectsToMerge, composer, cam, scene);
|
|
389
|
+
// }
|
|
390
|
+
|
|
267
391
|
if (ef instanceof MODULES.POSTPROCESSING.MODULE.Effect) {
|
|
268
392
|
const attributes = ef.getAttributes();
|
|
269
393
|
const convolution = MODULES.POSTPROCESSING.MODULE.EffectAttribute.CONVOLUTION;
|
|
@@ -187,14 +187,12 @@ export class Volume extends Behaviour implements IEditorModificationReceiver, IP
|
|
|
187
187
|
|
|
188
188
|
this.context.composer.setMainScene(this.context.scene);
|
|
189
189
|
|
|
190
|
-
const composer = this.context.composer as EffectComposer;
|
|
191
|
-
|
|
192
190
|
if (this.multisampling === "auto") {
|
|
193
191
|
|
|
194
192
|
// If the postprocessing handler is using depth+normals (e.g. with SMAA) we ALWAYS disable multisampling to avoid ugly edges
|
|
195
193
|
if (this._postprocessing && (this._postprocessing.hasSmaaEffect)) {
|
|
196
|
-
if (
|
|
197
|
-
|
|
194
|
+
if (this._postprocessing.multisampling !== 0) {
|
|
195
|
+
this._postprocessing.multisampling = 0;
|
|
198
196
|
if (debug || isDevEnvironment()) {
|
|
199
197
|
console.warn(`[PostProcessing] Disabling multisampling you're using SMAA and have set the 'multisampling: auto' on your PostprocessingManager/Volume component. If you need anti-aliasing, consider adding an Antialiasing component or SMAA effect to the PostprocessingManager.`);
|
|
200
198
|
}
|
|
@@ -206,45 +204,41 @@ export class Volume extends Behaviour implements IEditorModificationReceiver, IP
|
|
|
206
204
|
if (this.context.time.realtimeSinceStartup - this._componentEnabledTime > 2
|
|
207
205
|
&& timeSinceLastChange > .5
|
|
208
206
|
) {
|
|
209
|
-
const prev =
|
|
207
|
+
const prev = this._postprocessing.multisampling;
|
|
210
208
|
|
|
211
|
-
if (
|
|
209
|
+
if (this._postprocessing.multisampling > 0 && this.context.time.smoothedFps <= 50) {
|
|
212
210
|
this._multisampleAutoChangeTime = this.context.time.realtimeSinceStartup;
|
|
213
211
|
this._multisampleAutoDecreaseTime = this.context.time.realtimeSinceStartup;
|
|
214
|
-
let newMultiSample =
|
|
212
|
+
let newMultiSample = this._postprocessing.multisampling * .5;
|
|
215
213
|
newMultiSample = Math.floor(newMultiSample);
|
|
216
|
-
if (newMultiSample !=
|
|
217
|
-
|
|
214
|
+
if (newMultiSample != this._postprocessing.multisampling) {
|
|
215
|
+
this._postprocessing.multisampling = newMultiSample;
|
|
218
216
|
}
|
|
219
|
-
if (debug) console.debug(`[PostProcessing] Reduced multisampling from ${prev} to ${
|
|
217
|
+
if (debug) console.debug(`[PostProcessing] Reduced multisampling from ${prev} to ${this._postprocessing.multisampling}`);
|
|
220
218
|
}
|
|
221
219
|
// if performance is good for a while try increasing multisampling again
|
|
222
220
|
else if (timeSinceLastChange > 1
|
|
223
221
|
&& this.context.time.smoothedFps >= 59
|
|
224
|
-
&&
|
|
222
|
+
&& this._postprocessing.multisampling < this.context.renderer.capabilities.maxSamples
|
|
225
223
|
&& this.context.time.realtimeSinceStartup - this._multisampleAutoDecreaseTime > 10
|
|
226
224
|
) {
|
|
227
225
|
this._multisampleAutoChangeTime = this.context.time.realtimeSinceStartup;
|
|
228
|
-
let newMultiSample =
|
|
226
|
+
let newMultiSample = this._postprocessing.multisampling <= 0 ? 1 : this._postprocessing.multisampling * 2;
|
|
229
227
|
newMultiSample = Math.floor(newMultiSample);
|
|
230
|
-
if (newMultiSample !==
|
|
231
|
-
|
|
228
|
+
if (newMultiSample !== this._postprocessing.multisampling) {
|
|
229
|
+
this._postprocessing.multisampling = newMultiSample;
|
|
232
230
|
}
|
|
233
|
-
if (debug) console.debug(`[PostProcessing] Increased multisampling from ${prev} to ${
|
|
231
|
+
if (debug) console.debug(`[PostProcessing] Increased multisampling from ${prev} to ${this._postprocessing.multisampling}`);
|
|
234
232
|
}
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
235
|
}
|
|
238
236
|
else {
|
|
239
237
|
const newMultiSample = Math.max(0, Math.min(this.multisampling, this.context.renderer.capabilities.maxSamples));
|
|
240
|
-
if (newMultiSample !==
|
|
241
|
-
|
|
238
|
+
if (newMultiSample !== this._postprocessing.multisampling)
|
|
239
|
+
this._postprocessing.multisampling = newMultiSample;
|
|
242
240
|
}
|
|
243
241
|
|
|
244
|
-
// Fix multisampling for the composer, it ONLY needs to be done for the input buffer
|
|
245
|
-
// this is super important for performance a negative visual impact
|
|
246
|
-
composer.outputBuffer.samples = 0;
|
|
247
|
-
|
|
248
242
|
// only set the main camera if any pass has a different camera
|
|
249
243
|
// trying to avoid doing this regularly since it involves doing potentially unnecessary work
|
|
250
244
|
// https://github.com/pmndrs/postprocessing/blob/3d3df0576b6d49aec9e763262d5a1ff7429fd91a/src/core/EffectComposer.js#L406
|
|
@@ -309,17 +303,16 @@ export class Volume extends Behaviour implements IEditorModificationReceiver, IP
|
|
|
309
303
|
|
|
310
304
|
this._applyPostQueue();
|
|
311
305
|
|
|
312
|
-
|
|
313
|
-
if (composer) {
|
|
306
|
+
if (this._postprocessing) {
|
|
314
307
|
if (this.multisampling === "auto") {
|
|
315
|
-
|
|
308
|
+
this._postprocessing.multisampling = DeviceUtilities.isMobileDevice()
|
|
316
309
|
? 2
|
|
317
310
|
: 4;
|
|
318
311
|
}
|
|
319
312
|
else {
|
|
320
|
-
|
|
313
|
+
this._postprocessing.multisampling = Math.max(0, Math.min(this.multisampling, this.context.renderer.capabilities.maxSamples));
|
|
321
314
|
}
|
|
322
|
-
if (debug) console.debug(`[PostProcessing] Set multisampling to ${
|
|
315
|
+
if (debug) console.debug(`[PostProcessing] Set multisampling to ${this._postprocessing.multisampling} (Is Mobile: ${DeviceUtilities.isMobileDevice()})`);
|
|
323
316
|
}
|
|
324
317
|
else if (debug) {
|
|
325
318
|
console.warn(`[PostProcessing] No composer found`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./PostProcessingEffect.js";
|
|
2
2
|
export * from "./PostProcessingHandler.js"
|
|
3
|
-
export {
|
|
3
|
+
export { PostProcessingEffectOrder } from "./utils.js";
|
|
4
4
|
export { PostProcessingManager } from "./Volume.js"
|
|
5
5
|
export * from "./VolumeParameter.js"
|
|
6
6
|
export * from "./VolumeProfile.js";
|