@xviewer.js/postprocessing 1.0.0-alpha.5 → 1.0.0-alpha.7

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