@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.3.3 → 3.3.6

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 (71) hide show
  1. package/package.json +19 -20
  2. package/src/RenderingEngine.ts +0 -1336
  3. package/src/index.ts +0 -81
  4. package/src/injectors/Tag3dGeometryCreationInjector.ts +0 -154
  5. package/src/injectors/TextureUnifierInjector.ts +0 -214
  6. package/src/interfaces/ILoader.ts +0 -3
  7. package/src/interfaces/IPostProcessingEffectDefinitions.ts +0 -402
  8. package/src/interfaces/IRenderingEngine.ts +0 -48
  9. package/src/loaders/EnvironmentMapLoader.ts +0 -357
  10. package/src/loaders/GeometryLoader.ts +0 -585
  11. package/src/loaders/HTMLElementAnchorLoader.ts +0 -107
  12. package/src/loaders/LightLoader.ts +0 -171
  13. package/src/loaders/MaterialLoader.ts +0 -1413
  14. package/src/managers/CameraManager.ts +0 -178
  15. package/src/managers/EnvironmentGeometryManager.ts +0 -224
  16. package/src/managers/PostProcessingManager.ts +0 -1181
  17. package/src/managers/RenderingManager.ts +0 -657
  18. package/src/managers/SceneTracingManager.ts +0 -127
  19. package/src/managers/SceneTreeManager.ts +0 -576
  20. package/src/managers/postprocessing/GodRaysManager.ts +0 -52
  21. package/src/managers/postprocessing/OutlineManager.ts +0 -58
  22. package/src/managers/postprocessing/SSAARenderPass.ts +0 -339
  23. package/src/managers/postprocessing/SelectiveBloomManager.ts +0 -58
  24. package/src/managers/postprocessing/ao/ao/AOEffect.ts +0 -180
  25. package/src/managers/postprocessing/ao/ao/AOPass.ts +0 -128
  26. package/src/managers/postprocessing/ao/ao/shader/ao_compose.glsl +0 -17
  27. package/src/managers/postprocessing/ao/ao/shader/ao_compose.ts +0 -19
  28. package/src/managers/postprocessing/ao/hbao/HBAOEffect.ts +0 -41
  29. package/src/managers/postprocessing/ao/hbao/shader/hbao.glsl +0 -96
  30. package/src/managers/postprocessing/ao/hbao/shader/hbao.ts +0 -98
  31. package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.glsl +0 -92
  32. package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.ts +0 -95
  33. package/src/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.ts +0 -259
  34. package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.glsl +0 -125
  35. package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.ts +0 -127
  36. package/src/managers/postprocessing/ao/ssao/SSAOEffect.ts +0 -106
  37. package/src/managers/postprocessing/ao/ssao/shader/ssao.glsl +0 -128
  38. package/src/managers/postprocessing/ao/ssao/shader/ssao.ts +0 -130
  39. package/src/managers/postprocessing/ao/utils/shader/basic.glsl +0 -6
  40. package/src/managers/postprocessing/ao/utils/shader/basic.ts +0 -8
  41. package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.glsl +0 -36
  42. package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.ts +0 -38
  43. package/src/managers/postprocessing/utils/CopyMaterial.ts +0 -130
  44. package/src/managers/postprocessing/utils/CopyShader.ts +0 -39
  45. package/src/managers/postprocessing/utils/FullScreenQuad.ts +0 -47
  46. package/src/managers/postprocessing/utils/NormalPass.ts +0 -222
  47. package/src/managers/postprocessing/utils/RenderPass.ts +0 -366
  48. package/src/materials/GemMaterial.ts +0 -268
  49. package/src/materials/MeshUnlitMaterialParameters.ts +0 -4
  50. package/src/materials/MultiPointsMaterial.ts +0 -646
  51. package/src/materials/SpecularGlossinessMaterial.ts +0 -182
  52. package/src/objects/SDBone.ts +0 -51
  53. package/src/objects/SDColor.ts +0 -54
  54. package/src/objects/SDData.ts +0 -44
  55. package/src/objects/SDObject.ts +0 -58
  56. package/src/shaders/PCSS.ts +0 -124
  57. package/src/shaders/gem.ts +0 -579
  58. package/src/shaders/gem_frag.glsl +0 -522
  59. package/src/shaders/gem_vert.glsl +0 -53
  60. package/src/shaders/multi_points.ts +0 -291
  61. package/src/shaders/multi_points_frag.glsl +0 -166
  62. package/src/shaders/multi_points_vert.glsl +0 -120
  63. package/src/styling/viewport-css.ts +0 -113
  64. package/src/styling/viewport.css +0 -111
  65. package/src/three/font.ts +0 -2
  66. package/src/three/geometries/TextGeometry.ts +0 -58
  67. package/src/three/loaders/FontLoader.ts +0 -205
  68. package/src/three/loaders/RGBELoader.ts +0 -496
  69. package/src/types/IThreejsData.ts +0 -16
  70. package/src/types/ThreejsData.ts +0 -43
  71. package/tsconfig.json +0 -20
@@ -1,1181 +0,0 @@
1
- import * as THREE from 'three';
2
- import {
3
- BlendFunction,
4
- BloomEffect,
5
- ChromaticAberrationEffect,
6
- DepthOfFieldEffect,
7
- DotScreenEffect,
8
- Effect,
9
- EffectComposer,
10
- EffectPass,
11
- FXAAEffect,
12
- GodRaysEffect,
13
- GridEffect,
14
- HueSaturationEffect,
15
- KernelSize,
16
- NoiseEffect,
17
- OutlineEffect,
18
- OverrideMaterialManager,
19
- PixelationEffect,
20
- RenderPass,
21
- ScanlineEffect,
22
- SelectiveBloomEffect,
23
- SepiaEffect,
24
- SMAAEffect,
25
- SMAAPreset,
26
- TiltShiftEffect,
27
- VignetteEffect,
28
- VignetteTechnique
29
- } from 'postprocessing';
30
- import {
31
- Converter,
32
- EventEngine,
33
- EVENTTYPE,
34
- IEvent,
35
- SettingsEngine,
36
- SystemInfo,
37
- UuidGenerator
38
- } from '@shapediver/viewer.shared.services';
39
- import { GodRaysManager } from './postprocessing/GodRaysManager';
40
- import {
41
- ANTI_ALIASING_TECHNIQUE,
42
- IBloomEffectDefinition,
43
- IChromaticAberrationEffectDefinition,
44
- IDepthOfFieldEffectDefinition,
45
- IDotScreenEffectDefinition,
46
- IGodRaysEffectDefinition,
47
- IGridEffectDefinition,
48
- IHBAOEffectDefinition,
49
- IHueSaturationEffectDefinition,
50
- INoiseEffectDefinition,
51
- IOutlineEffectDefinition,
52
- IPixelationEffectDefinition,
53
- IPostProcessingEffectDefinition,
54
- IPostProcessingEffectsArray,
55
- IScanlineEffectDefinition,
56
- ISelectiveBloomEffectDefinition,
57
- ISepiaEffectDefinition,
58
- ISSAOEffectDefinition,
59
- ITiltShiftEffectDefinition,
60
- IVignetteEffectDefinition,
61
- POST_PROCESSING_EFFECT_TYPE
62
- } from '../interfaces/IPostProcessingEffectDefinitions';
63
- import { IManager } from '@shapediver/viewer.rendering-engine.rendering-engine';
64
- import { OutlineManager } from './postprocessing/OutlineManager';
65
- import { RenderingEngine } from '../RenderingEngine';
66
- import { SelectiveBloomManager } from './postprocessing/SelectiveBloomManager';
67
- import { SSAARenderPass } from './postprocessing/SSAARenderPass';
68
- import { SSAOEffect } from './postprocessing/ao/ssao/SSAOEffect';
69
- import { HBAOEffect } from './postprocessing/ao/hbao/HBAOEffect';
70
- import { ISceneEvent } from '@shapediver/viewer.shared.types';
71
- import { vec3 } from 'gl-matrix';
72
-
73
- export class PostProcessingManager implements IManager {
74
- // #region Properties (22)
75
-
76
- private readonly _converter: Converter = Converter.instance;
77
- private readonly _eventEngine: EventEngine = EventEngine.instance;
78
- private readonly _systemInfo: SystemInfo = SystemInfo.instance;
79
- private readonly _uuidGenerator: UuidGenerator = UuidGenerator.instance;
80
-
81
- private _antiAliasingTechnique: ANTI_ALIASING_TECHNIQUE = ANTI_ALIASING_TECHNIQUE.SMAA;
82
- private _antiAliasingTechniqueMobile: ANTI_ALIASING_TECHNIQUE = ANTI_ALIASING_TECHNIQUE.FXAA;
83
- private _composer?: EffectComposer;
84
- private _currentCameraId: string = '';
85
- private _effectDefinitions: {
86
- token: string,
87
- definition: IPostProcessingEffectDefinition
88
- }[] = [];
89
- private _effectPass?: EffectPass;
90
- private _effects: {
91
- token: string,
92
- effect: Effect
93
- }[] = [];
94
- private _enablePostProcessingOnMobile: boolean = true;
95
- private _fxaaEffect?: FXAAEffect;
96
- private _godRaysManagers: {
97
- [key: string]: GodRaysManager
98
- } = {};
99
- private _manualPostProcessing: boolean = false;
100
- private _outlineManagers: {
101
- [key: string]: OutlineManager
102
- } = {};
103
- private _renderPass?: RenderPass;
104
- private _sceneExtents = 0;
105
- private _selectiveBloomManagers: {
106
- [key: string]: SelectiveBloomManager
107
- } = {};
108
- private _smaaEffect?: SMAAEffect;
109
- private _ssaaRenderPass?: SSAARenderPass;
110
- private _suspendEffectPassUpdate = false;
111
-
112
- // #endregion Properties (22)
113
-
114
- // #region Constructors (1)
115
-
116
- constructor(private readonly _renderingEngine: RenderingEngine) {
117
- this._eventEngine.addListener(EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e: IEvent) => {
118
- const viewerEvent = <ISceneEvent>e;
119
- if (viewerEvent.viewportId === this._renderingEngine.id) {
120
- this._sceneExtents = vec3.distance(viewerEvent.boundingBox!.min, viewerEvent.boundingBox!.max);
121
- this.changeEffectPass();
122
- }
123
- });
124
-
125
- // const token = this._uuidGenerator.create();
126
- // this._effectDefinitions.push({
127
- // token,
128
- // definition: {
129
- // type: POST_PROCESSING_EFFECT_TYPE.SSAO,
130
- // properties: this.getDefaultEffectProperties(POST_PROCESSING_EFFECT_TYPE.SSAO)
131
- // }
132
- // });
133
- }
134
-
135
- // #endregion Constructors (1)
136
-
137
- // #region Public Getters And Setters (15)
138
-
139
- public get antiAliasingTechnique(): ANTI_ALIASING_TECHNIQUE {
140
- return this._antiAliasingTechnique;
141
- }
142
-
143
- public set antiAliasingTechnique(value: ANTI_ALIASING_TECHNIQUE) {
144
- this._antiAliasingTechnique = value;
145
- this.changeEffectPass();
146
- }
147
-
148
- public get antiAliasingTechniqueMobile(): ANTI_ALIASING_TECHNIQUE {
149
- return this._antiAliasingTechniqueMobile;
150
- }
151
-
152
- public set antiAliasingTechniqueMobile(value: ANTI_ALIASING_TECHNIQUE) {
153
- this._antiAliasingTechniqueMobile = value;
154
-
155
- // we don't allow SSAA on mobile devices anymore as it is too slow
156
- if(this._antiAliasingTechniqueMobile === ANTI_ALIASING_TECHNIQUE.SSAA)
157
- this._antiAliasingTechniqueMobile = ANTI_ALIASING_TECHNIQUE.SMAA;
158
-
159
- this.changeEffectPass();
160
- }
161
-
162
- public get effectComposer(): EffectComposer | undefined {
163
- return this._composer;
164
- }
165
-
166
- public get effects(): { token: string, effect: Effect }[] {
167
- return this._effects;
168
- }
169
-
170
- public get enablePostProcessingOnMobile(): boolean {
171
- return this._enablePostProcessingOnMobile;
172
- }
173
-
174
- public set enablePostProcessingOnMobile(value: boolean) {
175
- this._enablePostProcessingOnMobile = value;
176
- }
177
-
178
- public get godRaysManagers(): {
179
- [key: string]: GodRaysManager
180
- } {
181
- return this._godRaysManagers;
182
- }
183
-
184
- public get manualPostProcessing(): boolean {
185
- return this._manualPostProcessing;
186
- }
187
-
188
- public set manualPostProcessing(value: boolean) {
189
- this._manualPostProcessing = value;
190
- if (this._composer && this._manualPostProcessing === true)
191
- this._composer.removeAllPasses();
192
- }
193
-
194
- public get outlineManagers(): {
195
- [key: string]: OutlineManager
196
- } {
197
- return this._outlineManagers;
198
- }
199
-
200
- public get selectiveBloomManagers(): {
201
- [key: string]: SelectiveBloomManager
202
- } {
203
- return this._selectiveBloomManagers;
204
- }
205
-
206
- public get ssaaSampleLevel(): number {
207
- return this._ssaaRenderPass ? this._ssaaRenderPass.sampleLevel : 2;
208
- }
209
-
210
- public set ssaaSampleLevel(value: number) {
211
- if(this._ssaaRenderPass)
212
- this._ssaaRenderPass.sampleLevel = value;
213
- }
214
-
215
- // #endregion Public Getters And Setters (15)
216
-
217
- // #region Public Methods (13)
218
-
219
- public addEffect(definition: IPostProcessingEffectDefinition, t?: string): string {
220
- const token = t || this._uuidGenerator.create();
221
- this._effectDefinitions.push({ token, definition });
222
-
223
- switch (definition.type) {
224
- case POST_PROCESSING_EFFECT_TYPE.GOD_RAYS:
225
- if(!this._godRaysManagers[token])
226
- this._godRaysManagers[token] = new GodRaysManager(this._renderingEngine);
227
- break;
228
-
229
- case POST_PROCESSING_EFFECT_TYPE.OUTLINE:
230
- if(!this._outlineManagers[token])
231
- this._outlineManagers[token] = new OutlineManager(this._renderingEngine);
232
- break;
233
-
234
- case POST_PROCESSING_EFFECT_TYPE.SELECTIVE_BLOOM:
235
- if(!this._selectiveBloomManagers[token])
236
- this._selectiveBloomManagers[token] = new SelectiveBloomManager(this._renderingEngine);
237
- break;
238
-
239
- default:
240
- }
241
-
242
- this.changeEffectPass();
243
- return token;
244
- }
245
-
246
- public applySettings(settingsEngine: SettingsEngine) {
247
- this._suspendEffectPassUpdate = true;
248
-
249
- this.antiAliasingTechnique = settingsEngine.settings.postprocessing.antiAliasingTechnique as ANTI_ALIASING_TECHNIQUE;
250
- this.antiAliasingTechniqueMobile = settingsEngine.settings.postprocessing.antiAliasingTechniqueMobile as ANTI_ALIASING_TECHNIQUE;
251
-
252
- // we don't allow SSAA on mobile devices anymore as it is too slow
253
- if(this._antiAliasingTechniqueMobile === ANTI_ALIASING_TECHNIQUE.SSAA)
254
- this._antiAliasingTechniqueMobile = ANTI_ALIASING_TECHNIQUE.SMAA;
255
-
256
- this.enablePostProcessingOnMobile = settingsEngine.settings.postprocessing.enablePostProcessingOnMobile;
257
- this.ssaaSampleLevel = settingsEngine.settings.postprocessing.ssaaSampleLevel;
258
-
259
- this._effectDefinitions = [];
260
- const effects = settingsEngine.settings.postprocessing.effects;
261
- for(let i = 0; i < effects.length; i++) {
262
- const token = this._uuidGenerator.create();
263
-
264
- this._effectDefinitions.push({
265
- token,
266
- definition: {
267
- type: effects[i].type as POST_PROCESSING_EFFECT_TYPE,
268
- properties: effects[i].properties
269
- }
270
- });
271
- }
272
- this._suspendEffectPassUpdate = false;
273
- this.changeEffectPass();
274
- }
275
-
276
- public changeEffectPass() {
277
- if (!this._composer) return;
278
- if (this._suspendEffectPassUpdate === true) return;
279
- if (this._systemInfo.isMobile === true && this._enablePostProcessingOnMobile === false) return;
280
- if (this._manualPostProcessing) return;
281
-
282
- for(let i = 0; i < this._composer.passes.length; i++)
283
- this._composer.passes[i].dispose();
284
- this._composer.removeAllPasses();
285
-
286
- const antiAliasingTechnique = this._systemInfo.isMobile === true ? this._antiAliasingTechniqueMobile : this._antiAliasingTechnique;
287
- if (antiAliasingTechnique === ANTI_ALIASING_TECHNIQUE.SSAA) {
288
- this.addPassToEffectComposer(this._ssaaRenderPass!);
289
- } else {
290
- this.addPassToEffectComposer(this._renderPass!);
291
- }
292
-
293
- // remove the effects where the tokens are not in the effectDefinitions
294
- this._effects.forEach(e => e.effect.dispose());
295
- this._effects = [];
296
-
297
- for (let i = 0; i < this._effectDefinitions.length; i++) {
298
- switch (this._effectDefinitions[i].definition.type) {
299
- case POST_PROCESSING_EFFECT_TYPE.BLOOM:
300
- {
301
- const definition: IBloomEffectDefinition = this._effectDefinitions[i].definition as IBloomEffectDefinition;
302
- const properties = definition.properties || {};
303
- this._effects.push({
304
- token: this._effectDefinitions[i].token,
305
- effect: new BloomEffect({
306
- blendFunction: properties.blendFunction,
307
- luminanceThreshold: properties.luminanceThreshold,
308
- luminanceSmoothing: properties.luminanceSmoothing,
309
- mipmapBlur: properties.mipmapBlur,
310
- intensity: properties.intensity,
311
- kernelSize: properties.kernelSize
312
- })
313
- });
314
- }
315
- break;
316
-
317
- case POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION:
318
- {
319
- const definition: IChromaticAberrationEffectDefinition = this._effectDefinitions[i].definition as IChromaticAberrationEffectDefinition;
320
- const properties = definition.properties || {};
321
- const offsetArray = properties.offset !== undefined ? Array.isArray(properties.offset) ? properties.offset : [(<{x: number}>properties.offset).x, (<{y: number}>properties.offset).y] : undefined;
322
-
323
- this._effects.push({
324
- token: this._effectDefinitions[i].token,
325
- effect: new ChromaticAberrationEffect({
326
- blendFunction: properties.blendFunction,
327
- offset: offsetArray ? new THREE.Vector2(...offsetArray) : undefined,
328
- radialModulation: properties.radialModulation !== undefined ? properties.radialModulation : false,
329
- modulationOffset: properties.modulationOffset !== undefined ? properties.modulationOffset : 0.15
330
- })
331
- });
332
- }
333
- break;
334
-
335
- case POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD:
336
- {
337
- const definition: IDepthOfFieldEffectDefinition = this._effectDefinitions[i].definition as IDepthOfFieldEffectDefinition;
338
- const properties = definition.properties || {};
339
-
340
- const depthOfFieldEffect = new DepthOfFieldEffect(this._renderingEngine.camera, {
341
- blendFunction: properties.blendFunction,
342
- focusDistance: properties.focusDistance !== undefined ? properties.focusDistance : 0,
343
- focusRange: properties.focusRange !== undefined ? properties.focusRange : 0.01,
344
- bokehScale: properties.bokehScale !== undefined ? properties.bokehScale : 5,
345
- resolutionScale: 1
346
- });
347
-
348
- depthOfFieldEffect.resolution.height = 1080;
349
- depthOfFieldEffect.blurPass.kernelSize = KernelSize.HUGE;
350
-
351
- this._effects.push({
352
- token: this._effectDefinitions[i].token,
353
- effect: depthOfFieldEffect
354
- });
355
- }
356
- break;
357
-
358
- case POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN:
359
- {
360
- const definition: IDotScreenEffectDefinition = this._effectDefinitions[i].definition as IDotScreenEffectDefinition;
361
- const properties = definition.properties || {};
362
- this._effects.push({
363
- token: this._effectDefinitions[i].token,
364
- effect: new DotScreenEffect({
365
- blendFunction: properties.blendFunction,
366
- scale: properties.scale,
367
- angle: properties.angle
368
- })
369
- });
370
- }
371
- break;
372
-
373
- case POST_PROCESSING_EFFECT_TYPE.GOD_RAYS:
374
- {
375
- const definition: IGodRaysEffectDefinition = this._effectDefinitions[i].definition as IGodRaysEffectDefinition;
376
- const properties = definition.properties || {};
377
- const godRaysEffect = new GodRaysEffect(this._renderingEngine.camera, new THREE.Mesh(), {
378
- blendFunction: properties.blendFunction,
379
- density: properties.density,
380
- decay: properties.decay,
381
- weight: properties.weight,
382
- exposure: properties.exposure,
383
- clampMax: properties.clampMax,
384
- kernelSize: properties.kernelSize,
385
- blur: properties.blur
386
- });
387
- this._effects.push({
388
- token: this._effectDefinitions[i].token,
389
- effect: godRaysEffect
390
- });
391
-
392
- this._godRaysManagers[this._effectDefinitions[i].token].setEffect(godRaysEffect);
393
- }
394
- break;
395
-
396
- case POST_PROCESSING_EFFECT_TYPE.GRID:
397
- {
398
- const definition: IGridEffectDefinition = this._effectDefinitions[i].definition as IGridEffectDefinition;
399
- const properties = definition.properties || {};
400
- this._effects.push({
401
- token: this._effectDefinitions[i].token,
402
- effect: new GridEffect({
403
- blendFunction: properties.blendFunction !== undefined ? properties.blendFunction : BlendFunction.MULTIPLY,
404
- scale: properties.scale
405
- })
406
- });
407
- }
408
- break;
409
-
410
- case POST_PROCESSING_EFFECT_TYPE.HBAO:
411
- {
412
- // we currently do not support devices with WebGL 1: https://shapediver.atlassian.net/browse/SS-7069
413
- if(this._renderingEngine.renderer.capabilities.isWebGL2 === false) break;
414
-
415
- const definition: IHBAOEffectDefinition = this._effectDefinitions[i].definition as IHBAOEffectDefinition;
416
- const properties = definition.properties || {};
417
-
418
- // we adjust the scene size slightly to make the factor fit our requirements
419
- // with this adjusted factor, a distance value of 1 fits well as a default
420
- const sceneSizeFactor = this._sceneExtents / 10.0;
421
-
422
- const hbaoEffect = new HBAOEffect(this._composer, this._renderingEngine.camera, this._renderingEngine.scene, {
423
- resolutionScale: properties.resolutionScale !== undefined ? properties.resolutionScale : 1,
424
- spp: properties.spp !== undefined ? properties.spp : 8,
425
- distance: properties.distance !== undefined ? properties.distance * sceneSizeFactor : sceneSizeFactor,
426
- distancePower: properties.distanceIntensity !== undefined ? properties.distanceIntensity : 1,
427
- power: properties.intensity !== undefined ? properties.intensity : 2.5,
428
- bias: properties.bias !== undefined ? properties.bias : 10,
429
- thickness: properties.thickness !== undefined ? properties.thickness : 0.5,
430
- color: properties.color !== undefined ? new THREE.Color(this._converter.toHexColor(properties.color).substring(0, 7)) : new THREE.Color('black'),
431
- iterations: properties.iterations !== undefined ? properties.iterations : 1,
432
- radius: properties.radius !== undefined ? properties.radius : 15,
433
- rings: properties.rings !== undefined ? properties.rings : 4,
434
- lumaPhi: properties.lumaPhi !== undefined ? properties.lumaPhi : 10,
435
- depthPhi: properties.depthPhi !== undefined ? properties.depthPhi : 2,
436
- normalPhi: properties.normalPhi !== undefined ? properties.normalPhi : 3.25,
437
- samples: properties.samples !== undefined ? properties.samples : 16
438
- });
439
- this._effects.push({
440
- token: this._effectDefinitions[i].token,
441
- effect: hbaoEffect
442
- });
443
- }
444
- break;
445
-
446
- case POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION:
447
- {
448
- const definition: IHueSaturationEffectDefinition = this._effectDefinitions[i].definition as IHueSaturationEffectDefinition;
449
- const properties = definition.properties || {};
450
- this._effects.push({
451
- token: this._effectDefinitions[i].token,
452
- effect: new HueSaturationEffect({
453
- blendFunction: properties.blendFunction,
454
- hue: properties.hue,
455
- saturation: properties.saturation
456
- })
457
- });
458
- }
459
- break;
460
-
461
- case POST_PROCESSING_EFFECT_TYPE.NOISE:
462
- {
463
- const definition: INoiseEffectDefinition = this._effectDefinitions[i].definition as INoiseEffectDefinition;
464
- const properties = definition.properties || {};
465
- this._effects.push({
466
- token: this._effectDefinitions[i].token,
467
- effect: new NoiseEffect({
468
- blendFunction: properties.blendFunction,
469
- premultiply: properties.premultiply
470
- })
471
- });
472
- }
473
- break;
474
-
475
- case POST_PROCESSING_EFFECT_TYPE.OUTLINE:
476
- {
477
- const definition: IOutlineEffectDefinition = this._effectDefinitions[i].definition as IOutlineEffectDefinition;
478
- const properties = definition.properties || {};
479
- const outlineEffect = new OutlineEffect(this._renderingEngine.scene, this._renderingEngine.camera, {
480
- blendFunction: properties.blendFunction !== undefined ? properties.blendFunction : BlendFunction.SCREEN,
481
- edgeStrength: properties.edgeStrength,
482
- pulseSpeed: properties.pulseSpeed,
483
- visibleEdgeColor: <number><unknown>new THREE.Color(this._converter.toHexColor(properties.visibleEdgeColor).substring(0, 7)),
484
- hiddenEdgeColor: <number><unknown>new THREE.Color(this._converter.toHexColor(properties.hiddenEdgeColor).substring(0, 7)),
485
- kernelSize: properties.kernelSize,
486
- blur: properties.blur,
487
- xRay: properties.xRay,
488
- multisampling: properties.multisampling
489
- });
490
- this._effects.push({
491
- token: this._effectDefinitions[i].token,
492
- effect: outlineEffect
493
- });
494
- this._outlineManagers[this._effectDefinitions[i].token].setEffect(outlineEffect);
495
- }
496
- break;
497
-
498
- case POST_PROCESSING_EFFECT_TYPE.PIXELATION:
499
- {
500
- const definition: IPixelationEffectDefinition = this._effectDefinitions[i].definition as IPixelationEffectDefinition;
501
- const properties = definition.properties || {};
502
- this._effects.push({
503
- token: this._effectDefinitions[i].token,
504
- effect: new PixelationEffect(properties.granularity)
505
- });
506
- }
507
- break;
508
-
509
- case POST_PROCESSING_EFFECT_TYPE.SSAO:
510
- {
511
- // we currently do not support devices with WebGL 1: https://shapediver.atlassian.net/browse/SS-7069
512
- if(this._renderingEngine.renderer.capabilities.isWebGL2 === false) break;
513
-
514
- const definition: ISSAOEffectDefinition = this._effectDefinitions[i].definition as ISSAOEffectDefinition;
515
- const properties = definition.properties || {};
516
-
517
- // we adjust the scene size slightly to make the factor fit our requirements
518
- // with this adjusted factor, a distance value of 1 fits well as a default
519
- const sceneSizeFactor = this._sceneExtents / 50.0;
520
- const ssaoEffect = new SSAOEffect(this._composer, this._renderingEngine.camera, this._renderingEngine.scene, {
521
- resolutionScale: properties.resolutionScale !== undefined ? properties.resolutionScale : 1,
522
- spp: properties.spp !== undefined ? properties.spp : 8,
523
- distance: properties.distance !== undefined ? properties.distance * sceneSizeFactor : sceneSizeFactor,
524
- distancePower: properties.distanceIntensity !== undefined ? properties.distanceIntensity : 1,
525
- power: properties.intensity !== undefined ? properties.intensity : 2.5,
526
- color: properties.color !== undefined ? new THREE.Color(this._converter.toHexColor(properties.color).substring(0, 7)) : new THREE.Color('black'),
527
- iterations: properties.iterations !== undefined ? properties.iterations : 1,
528
- radius: properties.radius !== undefined ? properties.radius : 15,
529
- rings: properties.rings !== undefined ? properties.rings : 4,
530
- lumaPhi: properties.lumaPhi !== undefined ? properties.lumaPhi : 10,
531
- depthPhi: properties.depthPhi !== undefined ? properties.depthPhi : 2,
532
- normalPhi: properties.normalPhi !== undefined ? properties.normalPhi : 3.25,
533
- samples: properties.samples !== undefined ? properties.samples : 16
534
- });
535
-
536
- this._effects.push({
537
- token: this._effectDefinitions[i].token,
538
- effect: ssaoEffect
539
- });
540
- }
541
- break;
542
-
543
- case POST_PROCESSING_EFFECT_TYPE.SCANLINE:
544
- {
545
- const definition: IScanlineEffectDefinition = this._effectDefinitions[i].definition as IScanlineEffectDefinition;
546
- const properties = definition.properties || {};
547
- this._effects.push({
548
- token: this._effectDefinitions[i].token,
549
- effect: new ScanlineEffect({
550
- blendFunction: properties.blendFunction,
551
- density: properties.density
552
- })
553
- });
554
- }
555
- break;
556
-
557
- case POST_PROCESSING_EFFECT_TYPE.SELECTIVE_BLOOM:
558
- {
559
- const definition: ISelectiveBloomEffectDefinition = this._effectDefinitions[i].definition as ISelectiveBloomEffectDefinition;
560
- const properties = definition.properties || {};
561
- const selectiveBloomEffect = new SelectiveBloomEffect(this._renderingEngine.scene, this._renderingEngine.camera, {
562
- blendFunction: properties.blendFunction,
563
- mipmapBlur: properties.mipmapBlur,
564
- luminanceThreshold: properties.luminanceThreshold,
565
- luminanceSmoothing: properties.luminanceSmoothing,
566
- intensity: properties.intensity,
567
- kernelSize: properties.kernelSize
568
- });
569
- selectiveBloomEffect.ignoreBackground = properties.ignoreBackground !== undefined ? properties.ignoreBackground : true;
570
- this._effects.push({
571
- token: this._effectDefinitions[i].token,
572
- effect: selectiveBloomEffect
573
- });
574
-
575
- this._selectiveBloomManagers[this._effectDefinitions[i].token].setEffect(selectiveBloomEffect);
576
- }
577
- break;
578
-
579
- case POST_PROCESSING_EFFECT_TYPE.SEPIA:
580
- {
581
- const definition: ISepiaEffectDefinition = this._effectDefinitions[i].definition as ISepiaEffectDefinition;
582
- const properties = definition.properties || {};
583
- this._effects.push({
584
- token: this._effectDefinitions[i].token,
585
- effect: new SepiaEffect({
586
- blendFunction: properties.blendFunction
587
- })
588
- });
589
- }
590
- break;
591
-
592
- case POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT:
593
- {
594
- const definition: ITiltShiftEffectDefinition = this._effectDefinitions[i].definition as ITiltShiftEffectDefinition;
595
- const properties = definition.properties || {};
596
- this._effects.push({
597
- token: this._effectDefinitions[i].token,
598
- effect: new TiltShiftEffect({
599
- blendFunction: properties.blendFunction,
600
- offset: properties.offset,
601
- rotation: properties.rotation,
602
- focusArea: properties.focusArea,
603
- feather: properties.feather,
604
- kernelSize: properties.kernelSize
605
- })
606
- });
607
- }
608
- break;
609
-
610
- case POST_PROCESSING_EFFECT_TYPE.VIGNETTE:
611
- {
612
- const definition: IVignetteEffectDefinition = this._effectDefinitions[i].definition as IVignetteEffectDefinition;
613
- const properties = definition.properties || {};
614
- this._effects.push({
615
- token: this._effectDefinitions[i].token,
616
- effect: new VignetteEffect({
617
- blendFunction: properties.blendFunction,
618
- technique: properties.technique,
619
- offset: properties.offset,
620
- darkness: properties.darkness,
621
- })
622
- });
623
- }
624
- break;
625
-
626
- default:
627
- }
628
- }
629
-
630
- // sort effects by order in effectDefinitions
631
- this._effects.sort((a, b) => this._effectDefinitions.indexOf(this._effectDefinitions.find(e => e.token === a.token)!) - this._effectDefinitions.indexOf(this._effectDefinitions.find(e => e.token === b.token)!));
632
-
633
- const effectArray = this._effects.map(v => v.effect);
634
- if (antiAliasingTechnique === ANTI_ALIASING_TECHNIQUE.FXAA) {
635
- effectArray.unshift(this._fxaaEffect!);
636
- } else if (antiAliasingTechnique === ANTI_ALIASING_TECHNIQUE.SMAA) {
637
- effectArray.unshift(this._smaaEffect!);
638
- }
639
-
640
- this._effectPass = new EffectPass(this._renderingEngine.camera, ...this._effects.map(v => v.effect));
641
- this.addPassToEffectComposer(this._effectPass);
642
-
643
- // for the AO effects we need to add a separate AA pass at the end that anti-aliases the AO effect
644
- if (this._effectDefinitions.find(e => e.definition.type === POST_PROCESSING_EFFECT_TYPE.HBAO || e.definition.type === POST_PROCESSING_EFFECT_TYPE.SSAO)) {
645
- // respect the AA choice if one of the effects was selected, use SMAA otherwise
646
- this.addPassToEffectComposer(new EffectPass(this._renderingEngine.camera, antiAliasingTechnique === ANTI_ALIASING_TECHNIQUE.FXAA ? this._fxaaEffect! : this._smaaEffect!));
647
- }
648
- }
649
-
650
- public getDefaultEffectProperties(type: POST_PROCESSING_EFFECT_TYPE) {
651
- switch (type) {
652
- case POST_PROCESSING_EFFECT_TYPE.BLOOM:
653
- return {
654
- blendFunction: BlendFunction.ADD,
655
- intensity: 1.0,
656
- kernelSize: KernelSize.LARGE,
657
- luminanceSmoothing: 0.025,
658
- luminanceThreshold: 0.9,
659
- mipmapBlur: false,
660
- };
661
- case POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION:
662
- return {
663
- blendFunction: BlendFunction.NORMAL,
664
- modulationOffset: 0.15,
665
- offset: { x: 0.001, y: 0.0005 },
666
- radialModulation: false,
667
- };
668
-
669
- case POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD:
670
- return {
671
- blendFunction: BlendFunction.NORMAL,
672
- bokehScale: 5.0,
673
- focusDistance: 0.0,
674
- focusRange: 0.01,
675
- };
676
- case POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN:
677
- return {
678
- angle: 1.57,
679
- blendFunction: BlendFunction.NORMAL,
680
- scale: 1.0,
681
- };
682
- case POST_PROCESSING_EFFECT_TYPE.GOD_RAYS:
683
- return {
684
- blendFunction: BlendFunction.SCREEN,
685
- blur: true,
686
- clampMax: 1.0,
687
- decay: 0.9,
688
- density: 0.96,
689
- exposure: 0.6,
690
- kernelSize: KernelSize.SMALL,
691
- weight: 0.4,
692
- };
693
- case POST_PROCESSING_EFFECT_TYPE.GRID:
694
- return {
695
- blendFunction: BlendFunction.MULTIPLY,
696
- scale: 1.0,
697
- };
698
- case POST_PROCESSING_EFFECT_TYPE.HBAO:
699
- return {
700
- resolutionScale: 1,
701
- spp: 8,
702
- distance: 1,
703
- distanceIntensity: 1,
704
- intensity: 2.5,
705
- color: '#000000',
706
- bias: 10,
707
- thickness: 0.5,
708
-
709
- iterations: 1,
710
- radius: 15,
711
- rings: 4,
712
- lumaPhi: 10,
713
- depthPhi: 2,
714
- normalPhi: 3.25,
715
- samples: 16,
716
- };
717
-
718
- case POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION:
719
- return {
720
- blendFunction: BlendFunction.NORMAL,
721
- hue: 0.0,
722
- saturation: 0.0,
723
- };
724
- case POST_PROCESSING_EFFECT_TYPE.NOISE:
725
- return {
726
- blendFunction: BlendFunction.SCREEN,
727
- premultiply: false,
728
- };
729
- case POST_PROCESSING_EFFECT_TYPE.OUTLINE:
730
- return {
731
- blendFunction: BlendFunction.SCREEN,
732
- blur: false,
733
- edgeStrength: 1.0,
734
- hiddenEdgeColor: '#22090a',
735
- kernelSize: KernelSize.VERY_SMALL,
736
- multisampling: 0,
737
- pulseSpeed: 0.0,
738
- resolution: 480,
739
- visibleEdgeColor: '#ffffff',
740
- xRay: true,
741
- };
742
- case POST_PROCESSING_EFFECT_TYPE.PIXELATION:
743
- return {
744
- granularity: 30.0,
745
- };
746
- case POST_PROCESSING_EFFECT_TYPE.SSAO:
747
- return {
748
- resolutionScale: 1,
749
- spp: 8,
750
- distance: 1,
751
- distanceIntensity: 1,
752
- intensity: 2.5,
753
- color: '#000000',
754
-
755
- iterations: 1,
756
- radius: 15,
757
- rings: 4,
758
- lumaPhi: 10,
759
- depthPhi: 2,
760
- normalPhi: 3.25,
761
- samples: 16,
762
- };
763
- case POST_PROCESSING_EFFECT_TYPE.SCANLINE:
764
- return {
765
- blendFunction: BlendFunction.OVERLAY,
766
- density: 1.25,
767
- };
768
- case POST_PROCESSING_EFFECT_TYPE.SELECTIVE_BLOOM:
769
- return {
770
- blendFunction: BlendFunction.ADD,
771
- intensity: 1.0,
772
- kernelSize: KernelSize.LARGE,
773
- luminanceSmoothing: 0.025,
774
- luminanceThreshold: 0.9,
775
- mipmapBlur: false,
776
- ignoreBackground: true,
777
- };
778
- case POST_PROCESSING_EFFECT_TYPE.SEPIA:
779
- return {
780
- blendFunction: BlendFunction.NORMAL,
781
- };
782
- case POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT:
783
- return {
784
- blendFunction: BlendFunction.NORMAL,
785
- feather: 0.3,
786
- focusArea: 0.4,
787
- kernelSize: KernelSize.MEDIUM,
788
- offset: 0.0,
789
- rotation: 0.0,
790
- };
791
- case POST_PROCESSING_EFFECT_TYPE.VIGNETTE:
792
- return {
793
- blendFunction: BlendFunction.NORMAL,
794
- darkness: 0.5,
795
- offset: 0.5,
796
- technique: VignetteTechnique.DEFAULT,
797
- };
798
- default:
799
- return {};
800
- }
801
- }
802
-
803
- public getEffect(token: string): Effect {
804
- return this._effects.find(e => e.token === token)!.effect;
805
- }
806
-
807
- public getEffectTokens(): { [key: string]: POST_PROCESSING_EFFECT_TYPE} {
808
- return Object.assign({}, ...this._effectDefinitions.map((e) => ({[e.token]: e.definition.type})));
809
- }
810
-
811
- public getPostProcessingEffectsArray(): IPostProcessingEffectsArray {
812
- const effects: IPostProcessingEffectsArray = [];
813
-
814
- for (let i = 0; i < this._effectDefinitions.length; i++) {
815
- switch (this._effectDefinitions[i].definition.type) {
816
- case POST_PROCESSING_EFFECT_TYPE.BLOOM:
817
- {
818
- const definition: IBloomEffectDefinition = this._effectDefinitions[i].definition as IBloomEffectDefinition;
819
- const properties = definition.properties || {};
820
- effects.push({
821
- type: POST_PROCESSING_EFFECT_TYPE.BLOOM,
822
- token: this._effectDefinitions[i].token,
823
- properties: {
824
- blendFunction: properties.blendFunction,
825
- luminanceThreshold: properties.luminanceThreshold,
826
- luminanceSmoothing: properties.luminanceSmoothing,
827
- mipmapBlur: properties.mipmapBlur,
828
- intensity: properties.intensity,
829
- kernelSize: properties.kernelSize
830
- }
831
- });
832
- }
833
- break;
834
-
835
- case POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION:
836
- {
837
- const definition: IChromaticAberrationEffectDefinition = this._effectDefinitions[i].definition as IChromaticAberrationEffectDefinition;
838
- const properties = definition.properties || {};
839
- effects.push({
840
- type: POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION,
841
- token: this._effectDefinitions[i].token,
842
- properties: {
843
- blendFunction: properties.blendFunction,
844
- offset: properties.offset ? Array.isArray(properties.offset) ? { x: properties.offset[0], y: properties.offset[1] } : properties.offset : undefined,
845
- radialModulation: properties.radialModulation,
846
- modulationOffset: properties.modulationOffset
847
- }
848
- });
849
- }
850
- break;
851
-
852
- case POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD:
853
- {
854
- const definition: IDepthOfFieldEffectDefinition = this._effectDefinitions[i].definition as IDepthOfFieldEffectDefinition;
855
- const properties = definition.properties || {};
856
- effects.push({
857
- type: POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD,
858
- token: this._effectDefinitions[i].token,
859
- properties: {
860
- blendFunction: properties.blendFunction,
861
- focusDistance: properties.focusDistance,
862
- focusRange: properties.focusRange,
863
- bokehScale: properties.bokehScale
864
- }
865
- });
866
- }
867
- break;
868
-
869
- case POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN:
870
- {
871
- const definition: IDotScreenEffectDefinition = this._effectDefinitions[i].definition as IDotScreenEffectDefinition;
872
- const properties = definition.properties || {};
873
- effects.push({
874
- type: POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN,
875
- token: this._effectDefinitions[i].token,
876
- properties: {
877
- blendFunction: properties.blendFunction,
878
- scale: properties.scale,
879
- angle: properties.angle
880
- }
881
- });
882
- }
883
- break;
884
-
885
- case POST_PROCESSING_EFFECT_TYPE.GRID:
886
- {
887
- const definition: IGridEffectDefinition = this._effectDefinitions[i].definition as IGridEffectDefinition;
888
- const properties = definition.properties || {};
889
- effects.push({
890
- type: POST_PROCESSING_EFFECT_TYPE.GRID,
891
- token: this._effectDefinitions[i].token,
892
- properties: {
893
- blendFunction: properties.blendFunction,
894
- scale: properties.scale
895
- }
896
- });
897
- }
898
- break;
899
-
900
- case POST_PROCESSING_EFFECT_TYPE.HBAO:
901
- {
902
- const definition: IHBAOEffectDefinition = this._effectDefinitions[i].definition as IHBAOEffectDefinition;
903
- const properties = definition.properties || {};
904
- effects.push({
905
- type: POST_PROCESSING_EFFECT_TYPE.HBAO,
906
- token: this._effectDefinitions[i].token,
907
- properties: {
908
- resolutionScale: properties.resolutionScale,
909
- spp: properties.spp,
910
- distance: properties.distance,
911
- distanceIntensity: properties.distanceIntensity,
912
- intensity: properties.intensity,
913
- bias: properties.bias,
914
- thickness: properties.thickness,
915
- color: properties.color !== undefined ? this._converter.toHexColor(properties.color) : undefined,
916
- iterations: properties.iterations,
917
- radius: properties.radius,
918
- rings: properties.rings,
919
- lumaPhi: properties.lumaPhi,
920
- depthPhi: properties.depthPhi,
921
- normalPhi: properties.normalPhi,
922
- samples: properties.samples
923
- }
924
- });
925
- }
926
- break;
927
-
928
- case POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION:
929
- {
930
- const definition: IHueSaturationEffectDefinition = this._effectDefinitions[i].definition as IHueSaturationEffectDefinition;
931
- const properties = definition.properties || {};
932
- effects.push({
933
- type: POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION,
934
- token: this._effectDefinitions[i].token,
935
- properties: {
936
- blendFunction: properties.blendFunction,
937
- hue: properties.hue,
938
- saturation: properties.saturation
939
- }
940
- });
941
- }
942
- break;
943
-
944
- case POST_PROCESSING_EFFECT_TYPE.NOISE:
945
- {
946
- const definition: INoiseEffectDefinition = this._effectDefinitions[i].definition as INoiseEffectDefinition;
947
- const properties = definition.properties || {};
948
- effects.push({
949
- type: POST_PROCESSING_EFFECT_TYPE.NOISE,
950
- token: this._effectDefinitions[i].token,
951
- properties: {
952
- blendFunction: properties.blendFunction,
953
- premultiply: properties.premultiply
954
- }
955
- });
956
- }
957
- break;
958
-
959
- case POST_PROCESSING_EFFECT_TYPE.PIXELATION:
960
- {
961
- const definition: IPixelationEffectDefinition = this._effectDefinitions[i].definition as IPixelationEffectDefinition;
962
- const properties = definition.properties || {};
963
- effects.push({
964
- type: POST_PROCESSING_EFFECT_TYPE.PIXELATION,
965
- token: this._effectDefinitions[i].token,
966
- properties: {
967
- granularity: properties.granularity
968
- }
969
- });
970
- }
971
- break;
972
-
973
- case POST_PROCESSING_EFFECT_TYPE.SSAO:
974
- {
975
- const definition: ISSAOEffectDefinition = this._effectDefinitions[i].definition as ISSAOEffectDefinition;
976
- const properties = definition.properties || {};
977
- effects.push({
978
- type: POST_PROCESSING_EFFECT_TYPE.SSAO,
979
- token: this._effectDefinitions[i].token,
980
- properties: {
981
- resolutionScale: properties.resolutionScale,
982
- spp: properties.spp,
983
- distance: properties.distance,
984
- distanceIntensity: properties.distanceIntensity,
985
- intensity: properties.intensity,
986
- color: properties.color !== undefined ? this._converter.toHexColor(properties.color) : undefined,
987
- iterations: properties.iterations,
988
- radius: properties.radius,
989
- rings: properties.rings,
990
- lumaPhi: properties.lumaPhi,
991
- depthPhi: properties.depthPhi,
992
- normalPhi: properties.normalPhi,
993
- samples: properties.samples
994
- }
995
- });
996
- }
997
- break;
998
-
999
- case POST_PROCESSING_EFFECT_TYPE.SCANLINE:
1000
- {
1001
- const definition: IScanlineEffectDefinition = this._effectDefinitions[i].definition as IScanlineEffectDefinition;
1002
- const properties = definition.properties || {};
1003
- effects.push({
1004
- type: POST_PROCESSING_EFFECT_TYPE.SCANLINE,
1005
- token: this._effectDefinitions[i].token,
1006
- properties: {
1007
- blendFunction: properties.blendFunction,
1008
- density: properties.density
1009
- }
1010
- });
1011
- }
1012
- break;
1013
-
1014
- case POST_PROCESSING_EFFECT_TYPE.SEPIA:
1015
- {
1016
- const definition: ISepiaEffectDefinition = this._effectDefinitions[i].definition as ISepiaEffectDefinition;
1017
- const properties = definition.properties || {};
1018
- effects.push({
1019
- type: POST_PROCESSING_EFFECT_TYPE.SEPIA,
1020
- token: this._effectDefinitions[i].token,
1021
- properties: {
1022
- blendFunction: properties.blendFunction
1023
- }
1024
- });
1025
- }
1026
- break;
1027
-
1028
- case POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT:
1029
- {
1030
- const definition: ITiltShiftEffectDefinition = this._effectDefinitions[i].definition as ITiltShiftEffectDefinition;
1031
- const properties = definition.properties || {};
1032
- effects.push({
1033
- type: POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT,
1034
- token: this._effectDefinitions[i].token,
1035
- properties: {
1036
- blendFunction: properties.blendFunction,
1037
- offset: properties.offset,
1038
- rotation: properties.rotation,
1039
- focusArea: properties.focusArea,
1040
- feather: properties.feather,
1041
- kernelSize: properties.kernelSize
1042
- }
1043
- });
1044
- }
1045
- break;
1046
-
1047
- case POST_PROCESSING_EFFECT_TYPE.VIGNETTE:
1048
- {
1049
- const definition: IVignetteEffectDefinition = this._effectDefinitions[i].definition as IVignetteEffectDefinition;
1050
- const properties = definition.properties || {};
1051
- effects.push({
1052
- type: POST_PROCESSING_EFFECT_TYPE.VIGNETTE,
1053
- token: this._effectDefinitions[i].token,
1054
- properties: {
1055
- blendFunction: properties.blendFunction,
1056
- technique: properties.technique,
1057
- offset: properties.offset,
1058
- darkness: properties.darkness,
1059
- }
1060
- });
1061
- }
1062
- break;
1063
-
1064
- default:
1065
- }
1066
- }
1067
-
1068
- return effects;
1069
- }
1070
-
1071
- public init(): void {
1072
- OverrideMaterialManager.workaroundEnabled = true;
1073
-
1074
- const initComposer = () => {
1075
- this._composer = new EffectComposer(this._renderingEngine.renderer);
1076
- // EffectComposer disables autoClear, we enable/disable this in the postprocessing render loop
1077
- this._renderingEngine.renderer.autoClear = true;
1078
-
1079
- // create anti-aliasing effects and passes
1080
- this._fxaaEffect = new FXAAEffect();
1081
- this._smaaEffect = new SMAAEffect({ preset: SMAAPreset.ULTRA });
1082
- this._renderPass = new RenderPass(this._renderingEngine.scene, this._renderingEngine.camera);
1083
- this._ssaaRenderPass = new SSAARenderPass(this._renderingEngine.scene, this._renderingEngine.camera);
1084
- };
1085
-
1086
- if(this._sceneExtents === 0) {
1087
- const token = this._eventEngine.addListener(EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, async (e: IEvent) => {
1088
- const viewerEvent = <ISceneEvent>e;
1089
- if (viewerEvent.viewportId === this._renderingEngine.id) {
1090
- if(vec3.distance(viewerEvent.boundingBox!.min, viewerEvent.boundingBox!.max) > 0) {
1091
- initComposer();
1092
- this.changeEffectPass();
1093
- this._eventEngine.removeListener(token);
1094
- }
1095
- }
1096
- });
1097
- } else {
1098
- initComposer();
1099
- }
1100
- }
1101
-
1102
- public removeEffect(token: string): boolean {
1103
- const effectToRemove = this._effectDefinitions.find(e => e.token === token);
1104
- if (effectToRemove)
1105
- this._effectDefinitions.splice(this._effectDefinitions.indexOf(effectToRemove), 1);
1106
- this.changeEffectPass();
1107
- return true;
1108
- }
1109
-
1110
- public render(deltaTime: number, camera: THREE.Camera) {
1111
- if(!this._composer) return;
1112
-
1113
- const cameraId = `${camera.id}_${camera.type}${(camera.type === 'PerspectiveCamera' ? '' : '_' + camera.up.toArray().toString())}`;
1114
- if(cameraId !== this._currentCameraId) {
1115
- this._currentCameraId = cameraId;
1116
- this.changeEffectPass();
1117
- }
1118
-
1119
- const currentClearColor = this._renderingEngine.renderer.getClearColor(new THREE.Color());
1120
- const convertedClearColor = currentClearColor.clone().convertSRGBToLinear();
1121
- this._renderingEngine.renderer.setClearColor(convertedClearColor);
1122
- this._renderingEngine.renderer.setClearAlpha(this._renderingEngine.clearAlpha);
1123
- this._renderingEngine.renderer.autoClear = false;
1124
-
1125
- this._composer.setMainCamera(camera);
1126
- this._composer.render();
1127
-
1128
- this._renderingEngine.renderer.autoClear = true;
1129
- this._renderingEngine.renderer.setClearColor(currentClearColor);
1130
- }
1131
-
1132
- public resize(width: number, height: number) {
1133
- if(!this._composer) return;
1134
-
1135
- this.effects.forEach(e => {
1136
- if(e.effect.setSize)
1137
- e.effect.setSize(width, height);
1138
- });
1139
-
1140
- this._renderPass!.setSize(width, height);
1141
- this._ssaaRenderPass!.setSize(width, height);
1142
- this._effectPass?.setSize(width, height);
1143
- this._composer.setSize(width, height);
1144
- }
1145
-
1146
- public saveSettings(settingsEngine: SettingsEngine) {
1147
- settingsEngine.settings.postprocessing.antiAliasingTechnique = this.antiAliasingTechnique;
1148
- settingsEngine.settings.postprocessing.antiAliasingTechniqueMobile = this.antiAliasingTechniqueMobile;
1149
- settingsEngine.settings.postprocessing.enablePostProcessingOnMobile = this.enablePostProcessingOnMobile;
1150
- settingsEngine.settings.postprocessing.ssaaSampleLevel = this.ssaaSampleLevel;
1151
- const effects = this.getPostProcessingEffectsArray();
1152
- // delete the tokens as we don't want to save them
1153
- effects.forEach(e => delete e.token);
1154
- settingsEngine.settings.postprocessing.effects = effects;
1155
- }
1156
-
1157
- public updateEffect(token: string, definition: IPostProcessingEffectDefinition) {
1158
- const effectDefinition = this._effectDefinitions.find(e => e.token === token);
1159
- if (!effectDefinition) return;
1160
- this.removeEffect(token);
1161
- this.addEffect(definition, token);
1162
- }
1163
-
1164
- // #endregion Public Methods (13)
1165
-
1166
- // #region Private Methods (1)
1167
-
1168
- private addPassToEffectComposer(pass: EffectPass | RenderPass | SSAARenderPass ) {
1169
- if (this._composer) {
1170
- try {
1171
- this._composer.addPass(pass);
1172
- } catch (e) {
1173
- // in this case a WebGL error is thrown, when the WebGL context is lost
1174
- // as we already throw an error in the rendering engine, we can ignore this error here
1175
- // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getContextAttributes
1176
- }
1177
- }
1178
- }
1179
-
1180
- // #endregion Private Methods (1)
1181
- }