@xviewer.js/postprocessing 1.0.0-alpha.5 → 1.0.0-alpha.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.
package/dist/main.js CHANGED
@@ -4,18 +4,282 @@ var core = require('@xviewer.js/core');
4
4
  var postprocessing = require('postprocessing');
5
5
  var three = require('three');
6
6
 
7
- function _extends() {
8
- _extends = Object.assign || function assign(target) {
9
- for (var i = 1; i < arguments.length; i++) {
10
- var source = arguments[i];
11
- for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
7
+ class EffectComposerPlugin extends core.Plugin {
8
+ static Instance(viewer) {
9
+ return viewer.getPlugin(EffectComposerPlugin, true);
10
+ }
11
+ get multisampling() {
12
+ return this._composer.multisampling;
13
+ }
14
+ set multisampling(v) {
15
+ this._composer.multisampling = v;
16
+ }
17
+ getPass(constructor) {
18
+ return this._composer.passes.find((v)=>v.constructor === constructor);
19
+ }
20
+ addPass(pass) {
21
+ this._composer.addPass(pass, this._composer.passes.length - 1);
22
+ this._checkOutputPass();
23
+ return pass;
24
+ }
25
+ removePass(pass) {
26
+ this._composer.removePass(pass);
27
+ this._checkOutputPass();
28
+ }
29
+ activePass(pass, v) {
30
+ pass.enabled = v;
31
+ this._checkOutputPass();
32
+ return pass;
33
+ }
34
+ _checkOutputPass() {
35
+ const count = this._composer.passes.filter((v)=>v.enabled && v.name !== "VelocityDepthNormalPass" && v !== this._outputPass).length;
36
+ this._outputPass.enabled = this._composer.multisampling > 0 && count === 1;
37
+ this._setRenderToScreen();
38
+ }
39
+ _setRenderToScreen() {
40
+ const passes = this._composer.passes;
41
+ for(let k = 0, i = passes.length; i--;){
42
+ let pass = passes[i];
43
+ if (pass.enabled && pass.name !== "VelocityDepthNormalPass" && k === 0) {
44
+ k = i;
45
+ }
46
+ pass.renderToScreen = k === i;
12
47
  }
48
+ }
49
+ constructor(props){
50
+ super();
51
+ this.install = ()=>{
52
+ const { renderer, scene, camera } = this.viewer;
53
+ this._renderPass = new postprocessing.RenderPass(scene, camera);
54
+ this._outputPass = new postprocessing.EffectPass(camera);
55
+ this._composer = new postprocessing.EffectComposer(renderer, Object.assign({
56
+ frameBufferType: three.HalfFloatType
57
+ }, props));
58
+ this._composer.addPass(this._renderPass);
59
+ this._composer.addPass(this._outputPass);
60
+ this.viewer._onResize = (width, height)=>this._composer.setSize(width, height);
61
+ this.viewer._onRender = (dt)=>this._composer.render(dt);
62
+ };
63
+ this.uninstall = ()=>{
64
+ this._composer.dispose();
65
+ };
66
+ }
67
+ }
13
68
 
14
- return target;
15
- };
69
+ /******************************************************************************
70
+ Copyright (c) Microsoft Corporation.
71
+
72
+ Permission to use, copy, modify, and/or distribute this software for any
73
+ purpose with or without fee is hereby granted.
74
+
75
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
76
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
77
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
78
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
79
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
80
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
81
+ PERFORMANCE OF THIS SOFTWARE.
82
+ ***************************************************************************** */
83
+ /* global Reflect, Promise, SuppressedError, Symbol */
84
+
85
+
86
+ function __decorate(decorators, target, key, desc) {
87
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
88
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
89
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
90
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
91
+ }
92
+
93
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
94
+ var e = new Error(message);
95
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
96
+ };
97
+
98
+ class PassPlugin extends core.Plugin {
99
+ get enable() {
100
+ return this.pass.enabled;
101
+ }
102
+ set enable(v) {
103
+ this.setEnable(v);
104
+ }
105
+ get composer() {
106
+ return EffectComposerPlugin.Instance(this.viewer);
107
+ }
108
+ setEnable(v) {
109
+ this.composer.activePass(this.pass, v);
110
+ }
111
+ }
112
+ __decorate([
113
+ core.property
114
+ ], PassPlugin.prototype, "enable", null);
115
+
116
+ class ToneMappingPlugin extends PassPlugin {
117
+ get mode() {
118
+ return this.effect.mode;
119
+ }
120
+ set mode(v) {
121
+ this.effect.mode = v;
122
+ }
123
+ constructor(props){
124
+ super();
125
+ this.install = ()=>{
126
+ this.effect = new postprocessing.ToneMappingEffect(props);
127
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
128
+ };
129
+ this.uninstall = ()=>{
130
+ this.composer.removePass(this.pass);
131
+ };
132
+ }
133
+ }
134
+ __decorate([
135
+ core.property({
136
+ value: postprocessing.ToneMappingMode
137
+ })
138
+ ], ToneMappingPlugin.prototype, "mode", null);
139
+
140
+ class BloomPlugin extends PassPlugin {
141
+ get intensity() {
142
+ return this.effect.intensity;
143
+ }
144
+ set intensity(v) {
145
+ this.effect.intensity = v;
146
+ }
147
+ get luminanceThreshold() {
148
+ return this.effect.luminanceMaterial.threshold;
149
+ }
150
+ set luminanceThreshold(v) {
151
+ this.effect.luminanceMaterial.threshold = v;
152
+ }
153
+ get luminanceSmoothing() {
154
+ return this.effect.luminanceMaterial.smoothing;
155
+ }
156
+ set luminanceSmoothing(v) {
157
+ this.effect.luminanceMaterial.smoothing = v;
158
+ }
159
+ constructor(props){
160
+ super();
161
+ this.install = ()=>{
162
+ this.effect = new postprocessing.BloomEffect({
163
+ blendFunction: postprocessing.BlendFunction.ADD,
164
+ ...props
165
+ });
166
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
167
+ };
168
+ this.uninstall = ()=>{
169
+ this.composer.removePass(this.pass);
170
+ };
171
+ }
172
+ }
173
+ __decorate([
174
+ core.property({
175
+ min: 0,
176
+ max: 2,
177
+ step: 0.01
178
+ })
179
+ ], BloomPlugin.prototype, "intensity", null);
180
+ __decorate([
181
+ core.property({
182
+ min: 0,
183
+ max: 10,
184
+ step: 0.01
185
+ })
186
+ ], BloomPlugin.prototype, "luminanceThreshold", null);
187
+ __decorate([
188
+ core.property({
189
+ min: 0,
190
+ max: 10,
191
+ step: 0.01
192
+ })
193
+ ], BloomPlugin.prototype, "luminanceSmoothing", null);
194
+
195
+ class FXAAPlugin extends PassPlugin {
196
+ constructor(){
197
+ super();
198
+ this.install = ()=>{
199
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, new postprocessing.FXAAEffect()));
200
+ };
201
+ this.uninstall = ()=>{
202
+ this.composer.removePass(this.pass);
203
+ };
204
+ }
205
+ }
206
+
207
+ class SMAAPlugin extends PassPlugin {
208
+ get preset() {
209
+ return this._preset;
210
+ }
211
+ set preset(v) {
212
+ if (this._preset !== v) {
213
+ this._preset = v;
214
+ this.effect.applyPreset(v);
215
+ }
216
+ }
217
+ get edgeDetectionMode() {
218
+ return this.effect.edgeDetectionMaterial.edgeDetectionMode;
219
+ }
220
+ set edgeDetectionMode(v) {
221
+ this.effect.edgeDetectionMaterial.edgeDetectionMode = v;
222
+ }
223
+ get predicationMode() {
224
+ return this.effect.edgeDetectionMaterial.predicationMode;
225
+ }
226
+ set predicationMode(v) {
227
+ this.effect.edgeDetectionMaterial.predicationMode = v;
228
+ }
229
+ constructor(props = {}){
230
+ super();
231
+ this._preset = postprocessing.SMAAPreset.MEDIUM;
232
+ this.install = ()=>{
233
+ this.effect = new postprocessing.SMAAEffect(props);
234
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
235
+ };
236
+ this.uninstall = ()=>{
237
+ this.composer.removePass(this.pass);
238
+ };
239
+ }
240
+ }
241
+ __decorate([
242
+ core.property({
243
+ value: postprocessing.SMAAPreset
244
+ })
245
+ ], SMAAPlugin.prototype, "preset", null);
246
+ __decorate([
247
+ core.property({
248
+ value: postprocessing.EdgeDetectionMode
249
+ })
250
+ ], SMAAPlugin.prototype, "edgeDetectionMode", null);
251
+ __decorate([
252
+ core.property({
253
+ value: postprocessing.PredicationMode
254
+ })
255
+ ], SMAAPlugin.prototype, "predicationMode", null);
16
256
 
17
- return _extends.apply(this, arguments);
257
+ class MSAAPlugin extends core.Plugin {
258
+ get enable() {
259
+ return this.composer.multisampling > 0;
260
+ }
261
+ set enable(v) {
262
+ this.composer.multisampling = v ? this._maxSamples : 0;
263
+ }
264
+ get composer() {
265
+ return EffectComposerPlugin.Instance(this.viewer);
266
+ }
267
+ constructor(){
268
+ super();
269
+ this._maxSamples = 4;
270
+ this.install = ()=>{
271
+ const { renderer } = this.viewer;
272
+ this._maxSamples = Math.min(4, renderer.capabilities.maxSamples);
273
+ this.composer.multisampling = this._maxSamples;
274
+ };
275
+ this.uninstall = ()=>{
276
+ this.composer.multisampling = 0;
277
+ };
278
+ }
18
279
  }
280
+ __decorate([
281
+ core.property
282
+ ], MSAAPlugin.prototype, "enable", null);
19
283
 
20
284
  // from: https://news.ycombinator.com/item?id=17876741
21
285
  // reference: http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
@@ -298,7 +562,10 @@ class TemporalReprojectPass extends postprocessing.Pass {
298
562
  this._scene = scene;
299
563
  this._camera = camera;
300
564
  this.textureCount = textureCount;
301
- options = _extends({}, defaultTemporalReprojectPassOptions, options);
565
+ options = {
566
+ ...defaultTemporalReprojectPassOptions,
567
+ ...options
568
+ };
302
569
  this.renderTarget = new three.WebGLRenderTarget(1, 1, {
303
570
  count: textureCount,
304
571
  minFilter: three.NearestFilter,
@@ -391,15 +658,21 @@ class TRAAEffect extends postprocessing.Effect {
391
658
  this._scene = scene;
392
659
  this._camera = camera;
393
660
  this.velocityDepthNormalPass = velocityDepthNormalPass;
394
- options = _extends({}, options, {
395
- maxBlend: 0.9,
396
- neighborhoodClamp: true,
397
- neighborhoodClampIntensity: 1,
398
- neighborhoodClampRadius: 1,
399
- logTransform: true,
400
- confidencePower: 4
401
- });
402
- this.options = _extends({}, defaultTemporalReprojectPassOptions, options);
661
+ options = {
662
+ ...options,
663
+ ...{
664
+ maxBlend: 0.9,
665
+ neighborhoodClamp: true,
666
+ neighborhoodClampIntensity: 1,
667
+ neighborhoodClampRadius: 1,
668
+ logTransform: true,
669
+ confidencePower: 4
670
+ }
671
+ };
672
+ this.options = {
673
+ ...defaultTemporalReprojectPassOptions,
674
+ ...options
675
+ };
403
676
  this.setSize(options.width, options.height);
404
677
  }
405
678
  }
@@ -412,8 +685,8 @@ class CubeToEquirectEnvPass extends postprocessing.Pass {
412
685
  generateEquirectEnvMap(renderer, cubeMap, width = null, height = null, maxWidth = 4096) {
413
686
  if (width === null && height === null) {
414
687
  const w = cubeMap.source.data[0].width;
415
- const widthEquirect = Math.pow(2, Math.ceil(Math.log2(2 * w * Math.pow(3, 0.5))));
416
- const heightEquirect = Math.pow(2, Math.ceil(Math.log2(w * Math.pow(3, 0.5))));
688
+ const widthEquirect = 2 ** Math.ceil(Math.log2(2 * w * 3 ** 0.5));
689
+ const heightEquirect = 2 ** Math.ceil(Math.log2(w * 3 ** 0.5));
417
690
  width = widthEquirect;
418
691
  height = heightEquirect;
419
692
  }
@@ -525,7 +798,10 @@ const setupBlueNoise = (fragmentShader)=>{
525
798
  const useBlueNoise = (material)=>{
526
799
  const { fragmentShader, uniforms } = setupBlueNoise(material.fragmentShader);
527
800
  material.fragmentShader = fragmentShader;
528
- material.uniforms = _extends({}, material.uniforms, uniforms);
801
+ material.uniforms = {
802
+ ...material.uniforms,
803
+ ...uniforms
804
+ };
529
805
  material.needsUpdate = true;
530
806
  };
531
807
 
@@ -602,7 +878,10 @@ class GBufferMaterial extends three.MeshPhysicalMaterial {
602
878
 
603
879
  gl_FragColor = gBuffer;`);
604
880
  const { uniforms, fragmentShader } = setupBlueNoise(shader.fragmentShader);
605
- shader.uniforms = _extends({}, shader.uniforms, uniforms);
881
+ shader.uniforms = {
882
+ ...shader.uniforms,
883
+ ...uniforms
884
+ };
606
885
  shader.fragmentShader = fragmentShader;
607
886
  }
608
887
  }
@@ -1268,11 +1547,14 @@ const velocity_uniforms = {
1268
1547
  class VelocityDepthNormalMaterial extends three.ShaderMaterial {
1269
1548
  constructor(camera){
1270
1549
  super({
1271
- uniforms: _extends({}, three.UniformsUtils.clone(velocity_uniforms), {
1272
- cameraMatrixWorld: {
1273
- value: camera.matrixWorld
1550
+ uniforms: {
1551
+ ...three.UniformsUtils.clone(velocity_uniforms),
1552
+ ...{
1553
+ cameraMatrixWorld: {
1554
+ value: camera.matrixWorld
1555
+ }
1274
1556
  }
1275
- }),
1557
+ },
1276
1558
  vertexShader: /* glsl */ `
1277
1559
  #include <common>
1278
1560
  #include <uv_pars_vertex>
@@ -1736,7 +2018,10 @@ class PoissonDenoisePass extends postprocessing.Pass {
1736
2018
  super("PoissonBlurPass");
1737
2019
  this.iterations = defaultPoissonBlurOptions.iterations;
1738
2020
  this.index = 0;
1739
- options = _extends({}, defaultPoissonBlurOptions, options);
2021
+ options = {
2022
+ ...defaultPoissonBlurOptions,
2023
+ ...options
2024
+ };
1740
2025
  this.textures = textures;
1741
2026
  let isTextureSpecular = [
1742
2027
  false,
@@ -1880,13 +2165,16 @@ class Denoiser {
1880
2165
  }
1881
2166
  constructor(scene, camera, texture, options = defaultDenosierOptions){
1882
2167
  var _this_denoisePass;
1883
- options = _extends({}, defaultDenosierOptions, options);
2168
+ options = {
2169
+ ...defaultDenosierOptions,
2170
+ ...options
2171
+ };
1884
2172
  this.options = options;
1885
2173
  var _options_velocityDepthNormalPass;
1886
2174
  this.velocityDepthNormalPass = (_options_velocityDepthNormalPass = options.velocityDepthNormalPass) != null ? _options_velocityDepthNormalPass : new VelocityDepthNormalPass(scene, camera);
1887
2175
  this.isOwnVelocityDepthNormalPass = !options.velocityDepthNormalPass;
1888
2176
  const textureCount = options.inputType === "diffuseSpecular" ? 2 : 1;
1889
- this.temporalReprojectPass = new TemporalReprojectPass(scene, camera, this.velocityDepthNormalPass, texture, textureCount, _extends({
2177
+ this.temporalReprojectPass = new TemporalReprojectPass(scene, camera, this.velocityDepthNormalPass, texture, textureCount, {
1890
2178
  fullAccumulate: true,
1891
2179
  logTransform: true,
1892
2180
  copyTextures: !options.denoise,
@@ -1899,8 +2187,9 @@ class Denoiser {
1899
2187
  true
1900
2188
  ],
1901
2189
  neighborhoodClampRadius: 2,
1902
- neighborhoodClampIntensity: 0.5
1903
- }, options));
2190
+ neighborhoodClampIntensity: 0.5,
2191
+ ...options
2192
+ });
1904
2193
  const textures = this.temporalReprojectPass.renderTarget.texture.slice(0, textureCount);
1905
2194
  if (this.options.denoiseMode === "full" || this.options.denoiseMode === "denoised") {
1906
2195
  this.denoisePass = new PoissonDenoisePass(camera, textures, options);
@@ -2278,7 +2567,10 @@ class SSGIEffect extends postprocessing.Effect {
2278
2567
  }
2279
2568
  constructor(composer, scene, camera, options){
2280
2569
  var _scene_fog;
2281
- options = _extends({}, defaultSSGIOptions, options);
2570
+ options = {
2571
+ ...defaultSSGIOptions,
2572
+ ...options
2573
+ };
2282
2574
  let fragmentShader = ssgi_compose.replace("#include <fog_pars_fragment>", three.ShaderChunk.fog_pars_fragment.replace("varying", ""));
2283
2575
  // delete the line starting with gl_FragColor using a regex
2284
2576
  fragmentShader = fragmentShader.replace("#include <fog_fragment>", three.ShaderChunk.fog_fragment.replace(/.*gl_FragColor.*/g, ""));
@@ -2376,10 +2668,11 @@ class SSGIEffect extends postprocessing.Effect {
2376
2668
  }
2377
2669
  }
2378
2670
  this.ssgiPass = new SSGIPass(this, options);
2379
- this.denoiser = new Denoiser(scene, camera, this.ssgiPass.texture, _extends({
2671
+ this.denoiser = new Denoiser(scene, camera, this.ssgiPass.texture, {
2380
2672
  gBufferPass: this.ssgiPass.gBufferPass,
2381
- velocityDepthNormalPass: options.velocityDepthNormalPass
2382
- }, options));
2673
+ velocityDepthNormalPass: options.velocityDepthNormalPass,
2674
+ ...options
2675
+ });
2383
2676
  this.lastSize = {
2384
2677
  width: options.width,
2385
2678
  height: options.height,
@@ -2463,7 +2756,10 @@ class MotionBlurEffect extends postprocessing.Effect {
2463
2756
  }
2464
2757
  }
2465
2758
  constructor(velocityPass, options = defaultOptions){
2466
- options = _extends({}, defaultOptions, options);
2759
+ options = {
2760
+ ...defaultOptions,
2761
+ ...options
2762
+ };
2467
2763
  const { fragmentShader, uniforms } = setupBlueNoise(motion_blur);
2468
2764
  // convert the uniforms from type { uniform: value,... } to type ["uniform", value,...]
2469
2765
  const formattedUniforms = [];
@@ -2524,7 +2820,7 @@ class MotionBlurEffect extends postprocessing.Effect {
2524
2820
 
2525
2821
  var ao_compose = "#define GLSLIFY 1\nuniform sampler2D inputTexture;uniform highp sampler2D depthTexture;uniform float power;uniform vec3 color;void mainImage(const in vec4 inputColor,const in vec2 uv,out vec4 outputColor){float unpackedDepth=textureLod(depthTexture,uv,0.).r;float ao=unpackedDepth>0.9999 ? 1.0 : textureLod(inputTexture,uv,0.0).a;ao=pow(ao,power);vec3 aoColor=mix(color,vec3(1.),ao);aoColor*=inputColor.rgb;outputColor=vec4(aoColor,inputColor.a);}"; // eslint-disable-line
2526
2822
 
2527
- const defaultAOOptions = _extends({
2823
+ const defaultAOOptions = {
2528
2824
  resolutionScale: 1,
2529
2825
  spp: 8,
2530
2826
  distance: 2,
@@ -2535,8 +2831,9 @@ const defaultAOOptions = _extends({
2535
2831
  color: new three.Color("black"),
2536
2832
  useNormalPass: false,
2537
2833
  velocityDepthNormalPass: null,
2538
- normalTexture: null
2539
- }, PoissonDenoisePass.DefaultOptions);
2834
+ normalTexture: null,
2835
+ ...PoissonDenoisePass.DefaultOptions
2836
+ };
2540
2837
  class AOEffect extends postprocessing.Effect {
2541
2838
  makeOptionsReactive(options) {
2542
2839
  for (const key of Object.keys(options)){
@@ -2559,431 +2856,158 @@ class AOEffect extends postprocessing.Effect {
2559
2856
  this.setSize(this.lastSize.width, this.lastSize.height);
2560
2857
  break;
2561
2858
  case "power":
2562
- this.uniforms.get("power").value = value;
2563
- break;
2564
- case "color":
2565
- this.uniforms.get("color").value.copy(new three.Color(value));
2566
- break;
2567
- // denoiser
2568
- case "iterations":
2569
- case "radius":
2570
- case "rings":
2571
- case "samples":
2572
- this.PoissonDenoisePass[key] = value;
2573
- break;
2574
- case "lumaPhi":
2575
- case "depthPhi":
2576
- case "normalPhi":
2577
- this.PoissonDenoisePass.fullscreenMaterial.uniforms[key].value = Math.max(value, 0.0001);
2578
- break;
2579
- default:
2580
- if (key in this.aoPass.fullscreenMaterial.uniforms) {
2581
- this.aoPass.fullscreenMaterial.uniforms[key].value = value;
2582
- }
2583
- }
2584
- },
2585
- configurable: true
2586
- });
2587
- // apply all uniforms and defines
2588
- this[key] = options[key];
2589
- }
2590
- }
2591
- setSize(width, height) {
2592
- var _this_normalPass;
2593
- if (width === undefined || height === undefined) return;
2594
- if (width === this.lastSize.width && height === this.lastSize.height && this.resolutionScale === this.lastSize.resolutionScale) {
2595
- return;
2596
- }
2597
- (_this_normalPass = this.normalPass) == null ? void 0 : _this_normalPass.setSize(width, height);
2598
- this.aoPass.setSize(width * this.resolutionScale, height * this.resolutionScale);
2599
- this.PoissonDenoisePass.setSize(width, height);
2600
- this.lastSize = {
2601
- width,
2602
- height,
2603
- resolutionScale: this.resolutionScale
2604
- };
2605
- }
2606
- get texture() {
2607
- if (this.iterations > 0) {
2608
- return this.PoissonDenoisePass.texture;
2609
- }
2610
- return this.aoPass.texture;
2611
- }
2612
- update(renderer) {
2613
- var _this_normalPass;
2614
- // check if TRAA is being used so we can animate the noise
2615
- const hasTRAA = this.composer.passes.some((pass)=>{
2616
- var _pass_effects;
2617
- return pass.enabled && !pass.skipRendering && ((_pass_effects = pass.effects) == null ? void 0 : _pass_effects.some((effect)=>effect instanceof TRAAEffect));
2618
- });
2619
- // set animated noise depending on TRAA
2620
- if (hasTRAA && !("animatedNoise" in this.aoPass.fullscreenMaterial.defines)) {
2621
- this.aoPass.fullscreenMaterial.defines.animatedNoise = "";
2622
- this.aoPass.fullscreenMaterial.needsUpdate = true;
2623
- } else if (!hasTRAA && "animatedNoise" in this.aoPass.fullscreenMaterial.defines) {
2624
- delete this.aoPass.fullscreenMaterial.defines.animatedNoise;
2625
- this.aoPass.fullscreenMaterial.needsUpdate = true;
2626
- }
2627
- this.uniforms.get("inputTexture").value = this.texture;
2628
- (_this_normalPass = this.normalPass) == null ? void 0 : _this_normalPass.render(renderer);
2629
- this.aoPass.render(renderer);
2630
- this.PoissonDenoisePass.render(renderer);
2631
- }
2632
- constructor(composer, camera, scene, aoPass, options = defaultAOOptions){
2633
- super("AOEffect", ao_compose, {
2634
- type: "FinalAOMaterial",
2635
- uniforms: new Map([
2636
- [
2637
- "inputTexture",
2638
- new three.Uniform(null)
2639
- ],
2640
- [
2641
- "depthTexture",
2642
- new three.Uniform(null)
2643
- ],
2644
- [
2645
- "power",
2646
- new three.Uniform(0)
2647
- ],
2648
- [
2649
- "color",
2650
- new three.Uniform(new three.Color("black"))
2651
- ]
2652
- ])
2653
- });
2654
- this.lastSize = {
2655
- width: 0,
2656
- height: 0,
2657
- resolutionScale: 0
2658
- };
2659
- this.composer = composer;
2660
- this.aoPass = aoPass;
2661
- options = _extends({}, defaultAOOptions, options);
2662
- // set up depth texture
2663
- if (!composer.depthTexture) composer.createDepthTexture();
2664
- this.aoPass.fullscreenMaterial.uniforms.depthTexture.value = composer.depthTexture;
2665
- this.uniforms.get("depthTexture").value = composer.depthTexture;
2666
- // set up optional normal texture
2667
- if (options.useNormalPass || options.normalTexture) {
2668
- if (options.useNormalPass) this.normalPass = new postprocessing.NormalPass(scene, camera);
2669
- var _options_normalTexture;
2670
- const normalTexture = (_options_normalTexture = options.normalTexture) != null ? _options_normalTexture : this.normalPass.texture;
2671
- this.aoPass.fullscreenMaterial.uniforms.normalTexture.value = normalTexture;
2672
- this.aoPass.fullscreenMaterial.defines.useNormalTexture = "";
2673
- }
2674
- this.PoissonDenoisePass = new PoissonDenoisePass(camera, this.aoPass.texture, composer.depthTexture, {
2675
- normalInRgb: true
2676
- });
2677
- this.makeOptionsReactive(options);
2678
- }
2679
- }
2680
- AOEffect.DefaultOptions = defaultAOOptions;
2681
-
2682
- class EffectComposerPlugin extends core.Plugin {
2683
- static Instance(viewer) {
2684
- return viewer.getPlugin(EffectComposerPlugin, true);
2685
- }
2686
- get multisampling() {
2687
- return this._composer.multisampling;
2688
- }
2689
- set multisampling(v) {
2690
- this._composer.multisampling = v;
2691
- }
2692
- getPass(constructor) {
2693
- return this._composer.passes.find((v)=>v.constructor === constructor);
2694
- }
2695
- addPass(pass) {
2696
- this._composer.addPass(pass, this._composer.passes.length - 1);
2697
- this._checkOutputPass();
2698
- return pass;
2699
- }
2700
- removePass(pass) {
2701
- this._composer.removePass(pass);
2702
- this._checkOutputPass();
2703
- }
2704
- activePass(pass, v) {
2705
- pass.enabled = v;
2706
- this._checkOutputPass();
2707
- return pass;
2708
- }
2709
- getVelocityDepthNormalPass(autoAdd = false) {
2710
- let vdnPass = this.getPass(VelocityDepthNormalPass);
2711
- if (vdnPass === undefined && autoAdd) {
2712
- vdnPass = this.addPass(new VelocityDepthNormalPass(this.viewer.scene, this.viewer.camera));
2713
- }
2714
- return vdnPass;
2715
- }
2716
- _checkOutputPass() {
2717
- const vdnPass = this.getVelocityDepthNormalPass();
2718
- const count = this._composer.passes.filter((v)=>v.enabled && v !== vdnPass && v !== this._outputPass).length;
2719
- this._outputPass.enabled = this._composer.multisampling > 0 && count === 1;
2720
- this._setRenderToScreen();
2721
- }
2722
- _setRenderToScreen() {
2723
- const vdnPass = this.getVelocityDepthNormalPass();
2724
- const passes = this._composer.passes;
2725
- for(let k = 0, i = passes.length; i--;){
2726
- let pass = passes[i];
2727
- if (pass.enabled && pass !== vdnPass && k === 0) {
2728
- k = i;
2729
- }
2730
- pass.renderToScreen = k === i;
2731
- }
2732
- }
2733
- constructor(props){
2734
- super();
2735
- this.install = ()=>{
2736
- const { renderer, scene, camera } = this.viewer;
2737
- this._renderPass = new postprocessing.RenderPass(scene, camera);
2738
- this._outputPass = new postprocessing.EffectPass(camera);
2739
- this._composer = new postprocessing.EffectComposer(renderer, Object.assign({
2740
- frameBufferType: three.HalfFloatType
2741
- }, props));
2742
- this._composer.addPass(this._renderPass);
2743
- this._composer.addPass(this._outputPass);
2744
- this.viewer._onResize = (width, height)=>this._composer.setSize(width, height);
2745
- this.viewer._onRender = (dt)=>this._composer.render(dt);
2746
- };
2747
- this.uninstall = ()=>{
2748
- this._composer.dispose();
2749
- };
2750
- }
2751
- }
2752
-
2753
- /******************************************************************************
2754
- Copyright (c) Microsoft Corporation.
2755
-
2756
- Permission to use, copy, modify, and/or distribute this software for any
2757
- purpose with or without fee is hereby granted.
2758
-
2759
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2760
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2761
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2762
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2763
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2764
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2765
- PERFORMANCE OF THIS SOFTWARE.
2766
- ***************************************************************************** */
2767
- /* global Reflect, Promise, SuppressedError, Symbol */
2768
-
2769
-
2770
- function __decorate(decorators, target, key, desc) {
2771
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2772
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2773
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2774
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2775
- }
2776
-
2777
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
2778
- var e = new Error(message);
2779
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2780
- };
2781
-
2782
- class PassPlugin extends core.Plugin {
2783
- get enable() {
2784
- return this.pass.enabled;
2785
- }
2786
- set enable(v) {
2787
- this.setEnable(v);
2788
- }
2789
- get composer() {
2790
- return EffectComposerPlugin.Instance(this.viewer);
2791
- }
2792
- setEnable(v) {
2793
- this.composer.activePass(this.pass, v);
2794
- }
2795
- }
2796
- __decorate([
2797
- core.property
2798
- ], PassPlugin.prototype, "enable", null);
2799
-
2800
- class ToneMappingPlugin extends PassPlugin {
2801
- get mode() {
2802
- return this.effect.mode;
2803
- }
2804
- set mode(v) {
2805
- this.effect.mode = v;
2806
- }
2807
- constructor(props){
2808
- super();
2809
- this.install = ()=>{
2810
- this.effect = new postprocessing.ToneMappingEffect(props);
2811
- this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
2812
- };
2813
- this.uninstall = ()=>{
2814
- this.composer.removePass(this.pass);
2815
- };
2859
+ this.uniforms.get("power").value = value;
2860
+ break;
2861
+ case "color":
2862
+ this.uniforms.get("color").value.copy(new three.Color(value));
2863
+ break;
2864
+ // denoiser
2865
+ case "iterations":
2866
+ case "radius":
2867
+ case "rings":
2868
+ case "samples":
2869
+ this.PoissonDenoisePass[key] = value;
2870
+ break;
2871
+ case "lumaPhi":
2872
+ case "depthPhi":
2873
+ case "normalPhi":
2874
+ this.PoissonDenoisePass.fullscreenMaterial.uniforms[key].value = Math.max(value, 0.0001);
2875
+ break;
2876
+ default:
2877
+ if (key in this.aoPass.fullscreenMaterial.uniforms) {
2878
+ this.aoPass.fullscreenMaterial.uniforms[key].value = value;
2879
+ }
2880
+ }
2881
+ },
2882
+ configurable: true
2883
+ });
2884
+ // apply all uniforms and defines
2885
+ this[key] = options[key];
2886
+ }
2816
2887
  }
2817
- }
2818
- __decorate([
2819
- core.property({
2820
- value: postprocessing.ToneMappingMode
2821
- })
2822
- ], ToneMappingPlugin.prototype, "mode", null);
2823
-
2824
- class MotionBlurPlugin extends PassPlugin {
2825
- constructor(){
2826
- super();
2827
- this.install = ()=>{
2828
- const effect = new MotionBlurEffect(this.composer.getVelocityDepthNormalPass(true));
2829
- this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, effect));
2830
- };
2831
- this.uninstall = ()=>{
2832
- this.composer.removePass(this.pass);
2888
+ setSize(width, height) {
2889
+ var _this_normalPass;
2890
+ if (width === undefined || height === undefined) return;
2891
+ if (width === this.lastSize.width && height === this.lastSize.height && this.resolutionScale === this.lastSize.resolutionScale) {
2892
+ return;
2893
+ }
2894
+ (_this_normalPass = this.normalPass) == null ? void 0 : _this_normalPass.setSize(width, height);
2895
+ this.aoPass.setSize(width * this.resolutionScale, height * this.resolutionScale);
2896
+ this.PoissonDenoisePass.setSize(width, height);
2897
+ this.lastSize = {
2898
+ width,
2899
+ height,
2900
+ resolutionScale: this.resolutionScale
2833
2901
  };
2834
2902
  }
2835
- }
2836
-
2837
- class BloomPlugin extends PassPlugin {
2838
- get intensity() {
2839
- return this.effect.intensity;
2840
- }
2841
- set intensity(v) {
2842
- this.effect.intensity = v;
2843
- }
2844
- get luminanceThreshold() {
2845
- return this.effect.luminanceMaterial.threshold;
2846
- }
2847
- set luminanceThreshold(v) {
2848
- this.effect.luminanceMaterial.threshold = v;
2849
- }
2850
- get luminanceSmoothing() {
2851
- return this.effect.luminanceMaterial.smoothing;
2903
+ get texture() {
2904
+ if (this.iterations > 0) {
2905
+ return this.PoissonDenoisePass.texture;
2906
+ }
2907
+ return this.aoPass.texture;
2852
2908
  }
2853
- set luminanceSmoothing(v) {
2854
- this.effect.luminanceMaterial.smoothing = v;
2909
+ update(renderer) {
2910
+ var _this_normalPass;
2911
+ // check if TRAA is being used so we can animate the noise
2912
+ const hasTRAA = this.composer.passes.some((pass)=>{
2913
+ var _pass_effects;
2914
+ return pass.enabled && !pass.skipRendering && ((_pass_effects = pass.effects) == null ? void 0 : _pass_effects.some((effect)=>effect instanceof TRAAEffect));
2915
+ });
2916
+ // set animated noise depending on TRAA
2917
+ if (hasTRAA && !("animatedNoise" in this.aoPass.fullscreenMaterial.defines)) {
2918
+ this.aoPass.fullscreenMaterial.defines.animatedNoise = "";
2919
+ this.aoPass.fullscreenMaterial.needsUpdate = true;
2920
+ } else if (!hasTRAA && "animatedNoise" in this.aoPass.fullscreenMaterial.defines) {
2921
+ delete this.aoPass.fullscreenMaterial.defines.animatedNoise;
2922
+ this.aoPass.fullscreenMaterial.needsUpdate = true;
2923
+ }
2924
+ this.uniforms.get("inputTexture").value = this.texture;
2925
+ (_this_normalPass = this.normalPass) == null ? void 0 : _this_normalPass.render(renderer);
2926
+ this.aoPass.render(renderer);
2927
+ this.PoissonDenoisePass.render(renderer);
2855
2928
  }
2856
- constructor(props){
2857
- super();
2858
- this.install = ()=>{
2859
- this.effect = new postprocessing.BloomEffect(_extends({
2860
- blendFunction: postprocessing.BlendFunction.ADD
2861
- }, props));
2862
- this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
2929
+ constructor(composer, camera, scene, aoPass, options = defaultAOOptions){
2930
+ super("AOEffect", ao_compose, {
2931
+ type: "FinalAOMaterial",
2932
+ uniforms: new Map([
2933
+ [
2934
+ "inputTexture",
2935
+ new three.Uniform(null)
2936
+ ],
2937
+ [
2938
+ "depthTexture",
2939
+ new three.Uniform(null)
2940
+ ],
2941
+ [
2942
+ "power",
2943
+ new three.Uniform(0)
2944
+ ],
2945
+ [
2946
+ "color",
2947
+ new three.Uniform(new three.Color("black"))
2948
+ ]
2949
+ ])
2950
+ });
2951
+ this.lastSize = {
2952
+ width: 0,
2953
+ height: 0,
2954
+ resolutionScale: 0
2863
2955
  };
2864
- this.uninstall = ()=>{
2865
- this.composer.removePass(this.pass);
2956
+ this.composer = composer;
2957
+ this.aoPass = aoPass;
2958
+ options = {
2959
+ ...defaultAOOptions,
2960
+ ...options
2866
2961
  };
2962
+ // set up depth texture
2963
+ if (!composer.depthTexture) composer.createDepthTexture();
2964
+ this.aoPass.fullscreenMaterial.uniforms.depthTexture.value = composer.depthTexture;
2965
+ this.uniforms.get("depthTexture").value = composer.depthTexture;
2966
+ // set up optional normal texture
2967
+ if (options.useNormalPass || options.normalTexture) {
2968
+ if (options.useNormalPass) this.normalPass = new postprocessing.NormalPass(scene, camera);
2969
+ var _options_normalTexture;
2970
+ const normalTexture = (_options_normalTexture = options.normalTexture) != null ? _options_normalTexture : this.normalPass.texture;
2971
+ this.aoPass.fullscreenMaterial.uniforms.normalTexture.value = normalTexture;
2972
+ this.aoPass.fullscreenMaterial.defines.useNormalTexture = "";
2973
+ }
2974
+ this.PoissonDenoisePass = new PoissonDenoisePass(camera, this.aoPass.texture, composer.depthTexture, {
2975
+ normalInRgb: true
2976
+ });
2977
+ this.makeOptionsReactive(options);
2867
2978
  }
2868
2979
  }
2869
- __decorate([
2870
- core.property({
2871
- min: 0,
2872
- max: 2,
2873
- step: 0.01
2874
- })
2875
- ], BloomPlugin.prototype, "intensity", null);
2876
- __decorate([
2877
- core.property({
2878
- min: 0,
2879
- max: 10,
2880
- step: 0.01
2881
- })
2882
- ], BloomPlugin.prototype, "luminanceThreshold", null);
2883
- __decorate([
2884
- core.property({
2885
- min: 0,
2886
- max: 10,
2887
- step: 0.01
2888
- })
2889
- ], BloomPlugin.prototype, "luminanceSmoothing", null);
2980
+ AOEffect.DefaultOptions = defaultAOOptions;
2890
2981
 
2891
- class FXAAPlugin extends PassPlugin {
2892
- constructor(){
2893
- super();
2894
- this.install = ()=>{
2895
- this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, new postprocessing.FXAAEffect()));
2896
- };
2897
- this.uninstall = ()=>{
2898
- this.composer.removePass(this.pass);
2899
- };
2982
+ function getVelocityDepthNormalPass(viewer, autoAdd = true) {
2983
+ const composer = EffectComposerPlugin.Instance(viewer);
2984
+ let vdnPass = composer.getPass(VelocityDepthNormalPass);
2985
+ if (vdnPass === undefined && autoAdd) {
2986
+ vdnPass = composer.addPass(new VelocityDepthNormalPass(viewer.scene, viewer.camera));
2900
2987
  }
2988
+ return vdnPass;
2901
2989
  }
2902
2990
 
2903
- class SMAAPlugin extends PassPlugin {
2904
- get preset() {
2905
- return this._preset;
2906
- }
2907
- set preset(v) {
2908
- if (this._preset !== v) {
2909
- this._preset = v;
2910
- this.effect.applyPreset(v);
2911
- }
2912
- }
2913
- get edgeDetectionMode() {
2914
- return this.effect.edgeDetectionMaterial.edgeDetectionMode;
2915
- }
2916
- set edgeDetectionMode(v) {
2917
- this.effect.edgeDetectionMaterial.edgeDetectionMode = v;
2918
- }
2919
- get predicationMode() {
2920
- return this.effect.edgeDetectionMaterial.predicationMode;
2921
- }
2922
- set predicationMode(v) {
2923
- this.effect.edgeDetectionMaterial.predicationMode = v;
2924
- }
2991
+ class TRAAPlugin extends PassPlugin {
2925
2992
  constructor(props = {}){
2926
2993
  super();
2927
- this._preset = postprocessing.SMAAPreset.MEDIUM;
2928
2994
  this.install = ()=>{
2929
- this.effect = new postprocessing.SMAAEffect(props);
2930
- this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, this.effect));
2995
+ const { scene, camera } = this.viewer;
2996
+ this._effect = new TRAAEffect(scene, camera, getVelocityDepthNormalPass(this.viewer), props);
2997
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(camera, this._effect));
2931
2998
  };
2932
2999
  this.uninstall = ()=>{
2933
3000
  this.composer.removePass(this.pass);
2934
3001
  };
2935
3002
  }
2936
3003
  }
2937
- __decorate([
2938
- core.property({
2939
- value: postprocessing.SMAAPreset
2940
- })
2941
- ], SMAAPlugin.prototype, "preset", null);
2942
- __decorate([
2943
- core.property({
2944
- value: postprocessing.EdgeDetectionMode
2945
- })
2946
- ], SMAAPlugin.prototype, "edgeDetectionMode", null);
2947
- __decorate([
2948
- core.property({
2949
- value: postprocessing.PredicationMode
2950
- })
2951
- ], SMAAPlugin.prototype, "predicationMode", null);
2952
3004
 
2953
- class MSAAPlugin extends core.Plugin {
2954
- get enable() {
2955
- return this.composer.multisampling > 0;
2956
- }
2957
- set enable(v) {
2958
- this.composer.multisampling = v ? this._maxSamples : 0;
2959
- }
2960
- get composer() {
2961
- return EffectComposerPlugin.Instance(this.viewer);
2962
- }
3005
+ class MotionBlurPlugin extends PassPlugin {
2963
3006
  constructor(){
2964
- super();
2965
- this._maxSamples = 4;
2966
- this.install = ()=>{
2967
- const { renderer } = this.viewer;
2968
- this._maxSamples = Math.min(4, renderer.capabilities.maxSamples);
2969
- this.composer.multisampling = this._maxSamples;
2970
- };
2971
- this.uninstall = ()=>{
2972
- this.composer.multisampling = 0;
2973
- };
2974
- }
2975
- }
2976
- __decorate([
2977
- core.property
2978
- ], MSAAPlugin.prototype, "enable", null);
2979
-
2980
- class TRAAPlugin extends PassPlugin {
2981
- constructor(props = {}){
2982
3007
  super();
2983
3008
  this.install = ()=>{
2984
- const { scene, camera } = this.viewer;
2985
- this._effect = new TRAAEffect(scene, camera, this.composer.getVelocityDepthNormalPass(true), props);
2986
- this.pass = this.composer.addPass(new postprocessing.EffectPass(camera, this._effect));
3009
+ const effect = new MotionBlurEffect(getVelocityDepthNormalPass(this.viewer));
3010
+ this.pass = this.composer.addPass(new postprocessing.EffectPass(this.viewer.camera, effect));
2987
3011
  };
2988
3012
  this.uninstall = ()=>{
2989
3013
  this.composer.removePass(this.pass);