@needle-tools/engine 4.6.1-next.f9f2e7d → 4.6.2

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{needle-engine.bundle-DoQP-VX2.min.js → needle-engine.bundle-D0XWaCQs.min.js} +173 -161
  3. package/dist/{needle-engine.bundle-ntX9QTqT.js → needle-engine.bundle-DGcStTA7.js} +7382 -7295
  4. package/dist/{needle-engine.bundle-CbE5i73R.umd.cjs → needle-engine.bundle-DmYMLdWP.umd.cjs} +177 -165
  5. package/dist/needle-engine.js +48 -48
  6. package/dist/needle-engine.min.js +1 -1
  7. package/dist/needle-engine.umd.cjs +1 -1
  8. package/lib/engine/engine_context.d.ts +2 -1
  9. package/lib/engine/engine_context.js +3 -2
  10. package/lib/engine/engine_context.js.map +1 -1
  11. package/lib/engine/engine_three_utils.d.ts +17 -14
  12. package/lib/engine/engine_three_utils.js +106 -53
  13. package/lib/engine/engine_three_utils.js.map +1 -1
  14. package/lib/engine/engine_tonemapping.d.ts +4 -0
  15. package/lib/engine/engine_tonemapping.js +21 -18
  16. package/lib/engine/engine_tonemapping.js.map +1 -1
  17. package/lib/engine/engine_utils.js.map +1 -1
  18. package/lib/engine/webcomponents/needle-engine.d.ts +4 -1
  19. package/lib/engine/webcomponents/needle-engine.extras.js +3 -3
  20. package/lib/engine/webcomponents/needle-engine.extras.js.map +1 -1
  21. package/lib/engine/webcomponents/needle-engine.js +11 -21
  22. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  23. package/lib/engine-components/CameraUtils.js.map +1 -1
  24. package/lib/engine-components/postprocessing/Effects/BloomEffect.d.ts +1 -1
  25. package/lib/engine-components/postprocessing/Effects/BloomEffect.js +2 -2
  26. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +8 -0
  27. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +27 -8
  28. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -1
  29. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +1 -0
  30. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
  31. package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +1 -0
  32. package/lib/engine-components/postprocessing/Effects/Sharpening.js +4 -0
  33. package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
  34. package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +2 -9
  35. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +23 -71
  36. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
  37. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +13 -0
  38. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js +52 -0
  39. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js.map +1 -0
  40. package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +7 -7
  41. package/lib/engine-components/postprocessing/PostProcessingEffect.js +9 -9
  42. package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -1
  43. package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +10 -1
  44. package/lib/engine-components/postprocessing/PostProcessingHandler.js +130 -19
  45. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  46. package/lib/engine-components/postprocessing/Volume.js +19 -24
  47. package/lib/engine-components/postprocessing/Volume.js.map +1 -1
  48. package/lib/engine-components/postprocessing/index.d.ts +1 -1
  49. package/lib/engine-components/postprocessing/index.js +1 -1
  50. package/lib/engine-components/postprocessing/index.js.map +1 -1
  51. package/lib/engine-components/postprocessing/utils.d.ts +12 -7
  52. package/lib/engine-components/postprocessing/utils.js +37 -53
  53. package/lib/engine-components/postprocessing/utils.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/engine/engine_context.ts +5 -3
  56. package/src/engine/engine_three_utils.ts +134 -58
  57. package/src/engine/engine_tonemapping.ts +23 -24
  58. package/src/engine/engine_utils.ts +2 -2
  59. package/src/engine/webcomponents/needle-engine.extras.ts +3 -3
  60. package/src/engine/webcomponents/needle-engine.ts +14 -25
  61. package/src/engine-components/CameraUtils.ts +3 -3
  62. package/src/engine-components/postprocessing/Effects/BloomEffect.ts +2 -2
  63. package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +24 -13
  64. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -0
  65. package/src/engine-components/postprocessing/Effects/Sharpening.ts +5 -0
  66. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +26 -80
  67. package/src/engine-components/postprocessing/Effects/Tonemapping.utils.ts +60 -0
  68. package/src/engine-components/postprocessing/PostProcessingEffect.ts +9 -9
  69. package/src/engine-components/postprocessing/PostProcessingHandler.ts +145 -23
  70. package/src/engine-components/postprocessing/Volume.ts +19 -26
  71. package/src/engine-components/postprocessing/index.ts +2 -2
  72. package/src/engine-components/postprocessing/utils.ts +40 -56
@@ -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 type { Constructor } from "../../engine/engine_types.js";
9
- import { DeviceUtilities, getParam } from "../../engine/engine_utils.js";
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.priority
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.priority
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
- const effectsOrPasses = this._effects;
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 = "Render To Screen";
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 effectsOrPasses) {
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,16 +373,29 @@ 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;
270
394
  if (attributes & convolution) {
271
- if(debug) console.log("[PostProcessing] Convolution effect detected: " + ef.name, hasConvolutionEffectInArray);
395
+ if (debug) console.log("[PostProcessing] Convolution effect: " + ef.name);
272
396
  if (hasConvolutionEffectInArray) {
273
- hasConvolutionEffectInArray = false;
274
- if(debug) console.log("[PostProcessing] Merging effects with convolution effect in array", effectsToMerge.map(e => e.name).join(", "));
397
+ if (debug) console.log("[PostProcessing] Merging effects with convolution", effectsToMerge.map(e => e.name).join(", "));
275
398
  this.createPassForMergeableEffects(effectsToMerge, composer, cam, scene);
276
-
277
399
  }
278
400
  hasConvolutionEffectInArray = true;
279
401
  }
@@ -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 (composer.multisampling !== 0) {
197
- composer.multisampling = 0;
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 = composer.multisampling;
207
+ const prev = this._postprocessing.multisampling;
210
208
 
211
- if (composer.multisampling > 0 && this.context.time.smoothedFps <= 50) {
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 = composer.multisampling * .5;
212
+ let newMultiSample = this._postprocessing.multisampling * .5;
215
213
  newMultiSample = Math.floor(newMultiSample);
216
- if (newMultiSample != composer.multisampling) {
217
- composer.multisampling = newMultiSample;
214
+ if (newMultiSample != this._postprocessing.multisampling) {
215
+ this._postprocessing.multisampling = newMultiSample;
218
216
  }
219
- if (debug) console.debug(`[PostProcessing] Reduced multisampling from ${prev} to ${composer.multisampling}`);
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
- && composer.multisampling < this.context.renderer.capabilities.maxSamples
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 = composer.multisampling <= 0 ? 1 : composer.multisampling * 2;
226
+ let newMultiSample = this._postprocessing.multisampling <= 0 ? 1 : this._postprocessing.multisampling * 2;
229
227
  newMultiSample = Math.floor(newMultiSample);
230
- if (newMultiSample !== composer.multisampling) {
231
- composer.multisampling = newMultiSample;
228
+ if (newMultiSample !== this._postprocessing.multisampling) {
229
+ this._postprocessing.multisampling = newMultiSample;
232
230
  }
233
- if (debug) console.debug(`[PostProcessing] Increased multisampling from ${prev} to ${composer.multisampling}`);
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 !== composer.multisampling)
241
- composer.multisampling = newMultiSample;
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
- const composer = this._postprocessing?.composer;
313
- if (composer) {
306
+ if (this._postprocessing) {
314
307
  if (this.multisampling === "auto") {
315
- composer.multisampling = DeviceUtilities.isMobileDevice()
308
+ this._postprocessing.multisampling = DeviceUtilities.isMobileDevice()
316
309
  ? 2
317
310
  : 4;
318
311
  }
319
312
  else {
320
- composer.multisampling = Math.max(0, Math.min(this.multisampling, this.context.renderer.capabilities.maxSamples));
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 ${composer.multisampling} (Is Mobile: ${DeviceUtilities.isMobileDevice()})`);
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 { PostProcessingEffectOrder } from "./utils.js";
3
4
  export { PostProcessingManager } from "./Volume.js"
4
5
  export * from "./VolumeParameter.js"
5
- export * from "./VolumeProfile.js";
6
- export { PostProcessingEffectPriority } from "./utils.js";
6
+ export * from "./VolumeProfile.js";
@@ -64,25 +64,28 @@ export type PostprocessingEffectData = {
64
64
  }
65
65
 
66
66
  /**
67
- * Default priority for post-processing effects. This can be used to sort effects by their rendering order when creating custom effects.
68
- * E.g. in your custom effect, you can set `priority: PostProcessingEffectPriority.Bloom + 1;` to ensure it gets rendered after the bloom effect.
69
- * OR `priority: PostProcessingEffectPriority.Bloom - 1;` to ensure it gets rendered before the bloom effect.
67
+ * Default order for post-processing effects. This can be used to sort effects by their rendering order when creating custom effects.
68
+ * E.g. in your custom effect, you can set `order: PostProcessingEffectOrder.Bloom + 1;` to ensure it gets rendered after the bloom effect.
69
+ * OR `order: PostProcessingEffectOrder.Bloom - 1;` to ensure it gets rendered before the bloom effect.
70
70
  * @example
71
71
  * ```typescript
72
- * import { PostProcessingEffectPriority } from "@needle-tools/engine"
73
- *
72
+ * import { PostProcessingEffectOrder } from "@needle-tools/engine"
73
+ *
74
74
  * export class MyCustomEffect extends PostProcessingEffect {
75
- * priority: PostProcessingEffectPriority.Bloom + 1; // render after bloom
75
+ * order: PostProcessingEffectPriority.Bloom + 1; // render after bloom
76
76
  *
77
77
  * // ... your effect code
78
78
  * }
79
79
  * ```
80
80
  */
81
- export const PostProcessingEffectPriority = {
81
+ export const PostProcessingEffectOrder = {
82
+ /** Used to render effects at the start of the post-processing chain */
83
+ AT_START: -10_000,
84
+
82
85
  NormalPass: 0,
83
86
  DepthDownsamplingPass: 10,
84
- SMAA: 20,
85
- SSAO: 30,
87
+ SSAO: 20,
88
+ SMAA: 30,
86
89
  TiltShift: 40,
87
90
  DepthOfField: 50,
88
91
  ChromaticAberration: 60,
@@ -92,7 +95,10 @@ export const PostProcessingEffectPriority = {
92
95
  ToneMapping: 100,
93
96
  HueSaturation: 110,
94
97
  BrightnessContrast: 120,
95
- // Sharpening: 130,
98
+ Sharpening: 130,
99
+
100
+ /** Used to render effects at the end of the post-processing chain, e.g. for final adjustments or overlays. */
101
+ AT_END: 10_000,
96
102
  }
97
103
  // let effectsOrder: Array<Constructor<Effect | Pass>> | null = null;
98
104
 
@@ -103,65 +109,43 @@ export function orderEffects(effects: Array<PostprocessingEffectData>) {
103
109
 
104
110
  if (!builtinOrder) {
105
111
  builtinOrder = new Map<Constructor<Effect | Pass>, number>();
106
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.NormalPass, PostProcessingEffectPriority.NormalPass);
107
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.DepthDownsamplingPass, PostProcessingEffectPriority.DepthDownsamplingPass);
108
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.SMAAEffect, PostProcessingEffectPriority.SMAA);
109
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.SSAOEffect, PostProcessingEffectPriority.SSAO);
110
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.TiltShiftEffect, PostProcessingEffectPriority.TiltShift);
111
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.DepthOfFieldEffect, PostProcessingEffectPriority.DepthOfField);
112
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.ChromaticAberrationEffect, PostProcessingEffectPriority.ChromaticAberration);
113
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.BloomEffect, PostProcessingEffectPriority.Bloom);
114
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.VignetteEffect, PostProcessingEffectPriority.Vignette);
115
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.PixelationEffect, PostProcessingEffectPriority.Pixelation);
116
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.ToneMappingEffect, PostProcessingEffectPriority.ToneMapping);
117
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.HueSaturationEffect, PostProcessingEffectPriority.HueSaturation);
118
- builtinOrder.set(MODULES.POSTPROCESSING.MODULE.BrightnessContrastEffect, PostProcessingEffectPriority.BrightnessContrast);
112
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.NormalPass, PostProcessingEffectOrder.NormalPass);
113
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.DepthDownsamplingPass, PostProcessingEffectOrder.DepthDownsamplingPass);
114
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.SMAAEffect, PostProcessingEffectOrder.SMAA);
115
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.SSAOEffect, PostProcessingEffectOrder.SSAO);
116
+ builtinOrder.set(MODULES.POSTPROCESSING_AO.MODULE.N8AOPostPass, PostProcessingEffectOrder.SSAO);
117
+ builtinOrder.set(MODULES.POSTPROCESSING_AO.MODULE.N8AOPass, PostProcessingEffectOrder.SSAO);
118
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.TiltShiftEffect, PostProcessingEffectOrder.TiltShift);
119
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.DepthOfFieldEffect, PostProcessingEffectOrder.DepthOfField);
120
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.ChromaticAberrationEffect, PostProcessingEffectOrder.ChromaticAberration);
121
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.BloomEffect, PostProcessingEffectOrder.Bloom);
122
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.SelectiveBloomEffect, PostProcessingEffectOrder.Bloom);
123
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.VignetteEffect, PostProcessingEffectOrder.Vignette);
124
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.PixelationEffect, PostProcessingEffectOrder.Pixelation);
125
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.ToneMappingEffect, PostProcessingEffectOrder.ToneMapping);
126
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.HueSaturationEffect, PostProcessingEffectOrder.HueSaturation);
127
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.BrightnessContrastEffect, PostProcessingEffectOrder.BrightnessContrast);
119
128
  }
120
129
 
121
130
  // enforce correct order of effects (e.g. DOF before Bloom)
122
131
  effects.sort((a, b) => {
123
132
  // we use find index here because sometimes constructor names are prefixed with `_`
124
133
  // TODO: find a more robust solution that isnt name based (not sure if that exists tho... maybe we must give effect TYPES some priority/index)
125
- const aidx = typeof a.priority === "number" ? a.priority : builtinOrder!.get(a.effect.constructor as Constructor<Effect | Pass>) || -1;
126
- const bidx = typeof b.priority === "number" ? b.priority : builtinOrder!.get(b.effect.constructor as Constructor<Effect | Pass>) || -1;
134
+ const aidx = typeof a.priority === "number" ? a.priority : builtinOrder!.get(a.effect.constructor as Constructor<Effect | Pass>) ?? Number.NEGATIVE_INFINITY;
135
+ const bidx = typeof b.priority === "number" ? b.priority : builtinOrder!.get(b.effect.constructor as Constructor<Effect | Pass>) ?? Number.NEGATIVE_INFINITY;
127
136
 
128
137
  // Unknown effects should be rendered first
129
- if (aidx < 0) {
130
- if (debug) console.warn("Unknown effect found: ", a.constructor.name);
131
- return -1;
132
- }
133
- else if (bidx < 0) {
134
- if (debug) console.warn("Unknown effect found: ", b.constructor.name);
138
+ if (aidx === Number.NEGATIVE_INFINITY) {
139
+ if (debug) console.warn("Unknown effect found: ", a.constructor.name, a);
135
140
  return 1;
136
141
  }
137
- // if (aidx < 0) return 1;
138
- // if (bidx < 0) return -1;
142
+ else if (bidx === Number.NEGATIVE_INFINITY) {
143
+ if (debug) console.warn("Unknown effect found: ", b.constructor.name, b);
144
+ return -1;
145
+ }
139
146
  return aidx - bidx;
140
147
  });
141
148
 
142
- // effects.sort((a, b) => {
143
- // if (a.beforeEffect) {
144
- // const beforeA = effectsOrder!.findIndex(e => a.beforeEffect!.constructor.name.endsWith(e.name));
145
- // if (beforeA >= 0) {
146
- // return -1; // before effect should be rendered first
147
- // }
148
- // else {
149
- // return 1; // no before effect, so we can keep the order
150
- // }
151
- // }
152
- // else if (b.beforeEffect) {
153
- // const beforeB = effectsOrder!.findIndex(e => b.beforeEffect!.constructor.name.endsWith(e.name));
154
- // if (beforeB >= 0) {
155
- // return 1; // before effect should be rendered first
156
- // }
157
- // else if (a.beforeEffect) {
158
- // return -1; // no before effect, so we can keep the order
159
- // }
160
-
161
- // }
162
- // return 0; // no before effect, so we can keep the order
163
- // });
164
-
165
149
 
166
150
  if (debug === "verbose") console.debug("After ordering effects", [...effects]);
167
151
  }