@onerjs/core 8.28.4 → 8.28.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 (90) hide show
  1. package/Engines/abstractEngine.js +2 -2
  2. package/Engines/abstractEngine.js.map +1 -1
  3. package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.d.ts +1 -0
  4. package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.js.map +1 -1
  5. package/FrameGraph/Node/Blocks/Layers/highlightLayerBlock.d.ts +1 -0
  6. package/FrameGraph/Node/Blocks/Layers/highlightLayerBlock.js.map +1 -1
  7. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.d.ts +1 -0
  8. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js.map +1 -1
  9. package/FrameGraph/Node/Blocks/PostProcesses/convolutionPostProcessBlock.d.ts +1 -0
  10. package/FrameGraph/Node/Blocks/PostProcesses/convolutionPostProcessBlock.js.map +1 -1
  11. package/FrameGraph/Node/Blocks/PostProcesses/ssao2PostProcessBlock.d.ts +94 -0
  12. package/FrameGraph/Node/Blocks/PostProcesses/ssao2PostProcessBlock.js +312 -0
  13. package/FrameGraph/Node/Blocks/PostProcesses/ssao2PostProcessBlock.js.map +1 -0
  14. package/FrameGraph/Node/Blocks/PostProcesses/ssrPostProcessBlock.d.ts +1 -0
  15. package/FrameGraph/Node/Blocks/PostProcesses/ssrPostProcessBlock.js.map +1 -1
  16. package/FrameGraph/Node/Blocks/PostProcesses/tonemapPostProcessBlock.d.ts +1 -0
  17. package/FrameGraph/Node/Blocks/PostProcesses/tonemapPostProcessBlock.js.map +1 -1
  18. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.d.ts +1 -0
  19. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
  20. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.d.ts +1 -0
  21. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js.map +1 -1
  22. package/FrameGraph/Node/Blocks/Rendering/taaObjectRendererBlock.js +1 -1
  23. package/FrameGraph/Node/Blocks/Rendering/taaObjectRendererBlock.js.map +1 -1
  24. package/FrameGraph/Node/Blocks/index.d.ts +1 -0
  25. package/FrameGraph/Node/Blocks/index.js +1 -0
  26. package/FrameGraph/Node/Blocks/index.js.map +1 -1
  27. package/FrameGraph/Node/nodeRenderGraph.js +1 -1
  28. package/FrameGraph/Node/nodeRenderGraph.js.map +1 -1
  29. package/FrameGraph/Tasks/Layers/baseLayerTask.js +1 -7
  30. package/FrameGraph/Tasks/Layers/baseLayerTask.js.map +1 -1
  31. package/FrameGraph/Tasks/PostProcesses/bloomTask.js +0 -6
  32. package/FrameGraph/Tasks/PostProcesses/bloomTask.js.map +1 -1
  33. package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js +3 -4
  34. package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js.map +1 -1
  35. package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js +3 -4
  36. package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js.map +1 -1
  37. package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js +3 -4
  38. package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js.map +1 -1
  39. package/FrameGraph/Tasks/PostProcesses/depthOfFieldTask.js +0 -8
  40. package/FrameGraph/Tasks/PostProcesses/depthOfFieldTask.js.map +1 -1
  41. package/FrameGraph/Tasks/PostProcesses/postProcessTask.js +3 -5
  42. package/FrameGraph/Tasks/PostProcesses/postProcessTask.js.map +1 -1
  43. package/FrameGraph/Tasks/PostProcesses/ssao2BlurTask.d.ts +13 -0
  44. package/FrameGraph/Tasks/PostProcesses/ssao2BlurTask.js +25 -0
  45. package/FrameGraph/Tasks/PostProcesses/ssao2BlurTask.js.map +1 -0
  46. package/FrameGraph/Tasks/PostProcesses/ssao2RenderingPipelineTask.d.ts +76 -0
  47. package/FrameGraph/Tasks/PostProcesses/ssao2RenderingPipelineTask.js +147 -0
  48. package/FrameGraph/Tasks/PostProcesses/ssao2RenderingPipelineTask.js.map +1 -0
  49. package/FrameGraph/Tasks/PostProcesses/ssao2Task.d.ts +14 -0
  50. package/FrameGraph/Tasks/PostProcesses/ssao2Task.js +29 -0
  51. package/FrameGraph/Tasks/PostProcesses/ssao2Task.js.map +1 -0
  52. package/FrameGraph/Tasks/PostProcesses/ssrRenderingPipelineTask.js +2 -11
  53. package/FrameGraph/Tasks/PostProcesses/ssrRenderingPipelineTask.js.map +1 -1
  54. package/FrameGraph/Tasks/PostProcesses/ssrTask.js +8 -9
  55. package/FrameGraph/Tasks/PostProcesses/ssrTask.js.map +1 -1
  56. package/FrameGraph/index.d.ts +1 -0
  57. package/FrameGraph/index.js +1 -0
  58. package/FrameGraph/index.js.map +1 -1
  59. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.d.ts +4 -0
  60. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +6 -0
  61. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  62. package/Materials/Node/nodeMaterial.js +1 -1
  63. package/Materials/Node/nodeMaterial.js.map +1 -1
  64. package/Materials/PBR/openPbrMaterial.js +5 -5
  65. package/Materials/PBR/openPbrMaterial.js.map +1 -1
  66. package/Meshes/Node/nodeGeometry.js +1 -1
  67. package/Meshes/Node/nodeGeometry.js.map +1 -1
  68. package/Particles/Node/nodeParticleSystemSet.d.ts +14 -6
  69. package/Particles/Node/nodeParticleSystemSet.js +38 -7
  70. package/Particles/Node/nodeParticleSystemSet.js.map +1 -1
  71. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.d.ts +21 -30
  72. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +163 -256
  73. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
  74. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.d.ts +1 -3
  75. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
  76. package/PostProcesses/RenderPipeline/Pipelines/thinSSAO2RenderingPipeline.d.ts +130 -0
  77. package/PostProcesses/RenderPipeline/Pipelines/thinSSAO2RenderingPipeline.js +193 -0
  78. package/PostProcesses/RenderPipeline/Pipelines/thinSSAO2RenderingPipeline.js.map +1 -0
  79. package/PostProcesses/thinSSAO2BlurPostProcess.d.ts +26 -0
  80. package/PostProcesses/thinSSAO2BlurPostProcess.js +81 -0
  81. package/PostProcesses/thinSSAO2BlurPostProcess.js.map +1 -0
  82. package/PostProcesses/thinSSAO2CombinePostProcess.d.ts +15 -0
  83. package/PostProcesses/thinSSAO2CombinePostProcess.js +48 -0
  84. package/PostProcesses/thinSSAO2CombinePostProcess.js.map +1 -0
  85. package/PostProcesses/thinSSAO2PostProcess.d.ts +45 -0
  86. package/PostProcesses/thinSSAO2PostProcess.js +208 -0
  87. package/PostProcesses/thinSSAO2PostProcess.js.map +1 -0
  88. package/Shaders/ShadersInclude/shadowsFragmentFunctions.js +29 -4
  89. package/Shaders/ShadersInclude/shadowsFragmentFunctions.js.map +1 -1
  90. package/package.json +1 -1
@@ -3,8 +3,6 @@ import { __decorate } from "../../../tslib.es6.js";
3
3
  import { Logger } from "../../../Misc/logger.js";
4
4
  import { serialize } from "../../../Misc/decorators.js";
5
5
  import { SerializationHelper } from "../../../Misc/decorators.serialization.js";
6
- import { Vector3, TmpVectors, Vector2 } from "../../../Maths/math.vector.js";
7
- import { Camera } from "../../../Cameras/camera.js";
8
6
  import { Texture } from "../../../Materials/Textures/texture.js";
9
7
  import { PostProcess } from "../../../PostProcesses/postProcess.js";
10
8
  import { PostProcessRenderPipeline } from "../../../PostProcesses/RenderPipeline/postProcessRenderPipeline.js";
@@ -15,35 +13,61 @@ import { EngineStore } from "../../../Engines/engineStore.js";
15
13
  import { SSAO2Configuration } from "../../../Rendering/ssao2Configuration.js";
16
14
  import { GeometryBufferRenderer } from "../../../Rendering/geometryBufferRenderer.js";
17
15
 
18
- import { RandomRange } from "../../../Maths/math.scalar.functions.js";
19
- import { RawTexture } from "../../../Materials/Textures/rawTexture.js";
20
16
  import "../../../PostProcesses/RenderPipeline/postProcessRenderPipelineManagerSceneComponent.js";
17
+ import { ThinSSAO2RenderingPipeline } from "./thinSSAO2RenderingPipeline.js";
18
+ import { ThinSSAO2PostProcess } from "../../thinSSAO2PostProcess.js";
19
+ import { ThinSSAO2BlurPostProcess } from "../../thinSSAO2BlurPostProcess.js";
20
+ import { ThinSSAO2CombinePostProcess } from "../../thinSSAO2CombinePostProcess.js";
21
21
  /**
22
22
  * Render pipeline to produce ssao effect
23
23
  */
24
24
  export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
25
+ /**
26
+ * The output strength of the SSAO post-process. Default value is 1.0.
27
+ */
28
+ get totalStrength() {
29
+ return this._thinSSAORenderingPipeline.totalStrength;
30
+ }
31
+ set totalStrength(value) {
32
+ this._thinSSAORenderingPipeline.totalStrength = value;
33
+ }
34
+ /**
35
+ * Maximum depth value to still render AO. A smooth falloff makes the dimming more natural, so there will be no abrupt shading change.
36
+ */
37
+ get maxZ() {
38
+ return this._thinSSAORenderingPipeline.maxZ;
39
+ }
40
+ set maxZ(value) {
41
+ this._thinSSAORenderingPipeline.maxZ = value;
42
+ }
43
+ /**
44
+ * In order to save performances, SSAO radius is clamped on close geometry. This ratio changes by how much.
45
+ */
46
+ get minZAspect() {
47
+ return this._thinSSAORenderingPipeline.minZAspect;
48
+ }
49
+ set minZAspect(value) {
50
+ this._thinSSAORenderingPipeline.minZAspect = value;
51
+ }
25
52
  /**
26
53
  * Used in SSAO calculations to compensate for accuracy issues with depth values. Default 0.02.
27
54
  *
28
55
  * Normally you do not need to change this value, but you can experiment with it if you get a lot of in false self-occlusion on flat surfaces when using fewer than 16 samples. Useful range is normally [0..0.1] but higher values is allowed.
29
56
  */
30
57
  set epsilon(n) {
31
- this._epsilon = n;
32
- this._ssaoPostProcess.updateEffect(this._getDefinesForSSAO());
58
+ this._thinSSAORenderingPipeline.epsilon = n;
33
59
  }
34
60
  get epsilon() {
35
- return this._epsilon;
61
+ return this._thinSSAORenderingPipeline.epsilon;
36
62
  }
37
63
  /**
38
64
  * Number of samples used for the SSAO calculations. Default value is 8.
39
65
  */
40
66
  set samples(n) {
41
- this._samples = n;
42
- this._ssaoPostProcess.updateEffect(this._getDefinesForSSAO());
43
- this._sampleSphere = this._generateHemisphere();
67
+ this._thinSSAORenderingPipeline.samples = n;
44
68
  }
45
69
  get samples() {
46
- return this._samples;
70
+ return this._thinSSAORenderingPipeline.samples;
47
71
  }
48
72
  /**
49
73
  * Number of samples to use for antialiasing.
@@ -72,20 +96,35 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
72
96
  }
73
97
  return this._scene.prePassRenderer;
74
98
  }
99
+ /**
100
+ * The radius around the analyzed pixel used by the SSAO post-process. Default value is 2.0
101
+ */
102
+ get radius() {
103
+ return this._thinSSAORenderingPipeline.radius;
104
+ }
105
+ set radius(value) {
106
+ this._thinSSAORenderingPipeline.radius = value;
107
+ }
108
+ /**
109
+ * The base color of the SSAO post-process
110
+ * The final result is "base + ssao" between [0, 1]
111
+ */
112
+ get base() {
113
+ return this._thinSSAORenderingPipeline.base;
114
+ }
115
+ set base(value) {
116
+ this._thinSSAORenderingPipeline.base = value;
117
+ }
75
118
  /**
76
119
  * Skips the denoising (blur) stage of the SSAO calculations.
77
120
  *
78
121
  * Useful to temporarily set while experimenting with the other SSAO2 settings.
79
122
  */
80
123
  set bypassBlur(b) {
81
- const defines = this._getDefinesForBlur(this.expensiveBlur, b);
82
- const samplers = this._getSamplersForBlur(b);
83
- this._blurHPostProcess.updateEffect(defines.h, null, samplers);
84
- this._blurVPostProcess.updateEffect(defines.v, null, samplers);
85
- this._bypassBlur = b;
124
+ this._thinSSAORenderingPipeline.bypassBlur = b;
86
125
  }
87
126
  get bypassBlur() {
88
- return this._bypassBlur;
127
+ return this._thinSSAORenderingPipeline.bypassBlur;
89
128
  }
90
129
  /**
91
130
  * Enables the configurable bilateral denoising (blurring) filter. Default is true.
@@ -95,13 +134,51 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
95
134
  * configured in several ways to fit your scene.
96
135
  */
97
136
  set expensiveBlur(b) {
98
- const defines = this._getDefinesForBlur(b, this._bypassBlur);
99
- this._blurHPostProcess.updateEffect(defines.h);
100
- this._blurVPostProcess.updateEffect(defines.v);
101
- this._expensiveBlur = b;
137
+ this._thinSSAORenderingPipeline.expensiveBlur = b;
102
138
  }
103
139
  get expensiveBlur() {
104
- return this._expensiveBlur;
140
+ return this._thinSSAORenderingPipeline.expensiveBlur;
141
+ }
142
+ /**
143
+ * The number of samples the bilateral filter uses in both dimensions when denoising the SSAO calculations. Default value is 16.
144
+ *
145
+ * A higher value should result in smoother shadows but will use more processing time in the shaders.
146
+ *
147
+ * A high value can cause the shadows to get to blurry or create visible artifacts (bands) near sharp details in the geometry. The artifacts can sometimes be mitigated by increasing the bilateralSoften setting.
148
+ */
149
+ get bilateralSamples() {
150
+ return this._thinSSAORenderingPipeline.bilateralSamples;
151
+ }
152
+ set bilateralSamples(n) {
153
+ this._thinSSAORenderingPipeline.bilateralSamples = n;
154
+ }
155
+ /**
156
+ * Controls the shape of the denoising kernel used by the bilateral filter. Default value is 0.
157
+ *
158
+ * By default the bilateral filter acts like a box-filter, treating all samples on the same depth with equal weights. This is effective to maximize the denoising effect given a limited set of samples. However, it also often results in visible ghosting around sharp shadow regions and can spread out lines over large areas so they are no longer visible.
159
+ *
160
+ * Increasing this setting will make the filter pay less attention to samples further away from the center sample, reducing many artifacts but at the same time increasing noise.
161
+ *
162
+ * Useful value range is [0..1].
163
+ */
164
+ get bilateralSoften() {
165
+ return this._thinSSAORenderingPipeline.bilateralSoften;
166
+ }
167
+ set bilateralSoften(n) {
168
+ this._thinSSAORenderingPipeline.bilateralSoften = n;
169
+ }
170
+ /**
171
+ * How forgiving the bilateral denoiser should be when rejecting samples. Default value is 0.
172
+ *
173
+ * A higher value results in the bilateral filter being more forgiving and thus doing a better job at denoising slanted and curved surfaces, but can lead to shadows spreading out around corners or between objects that are close to each other depth wise.
174
+ *
175
+ * Useful value range is normally [0..1], but higher values are allowed.
176
+ */
177
+ get bilateralTolerance() {
178
+ return this._thinSSAORenderingPipeline.bilateralTolerance;
179
+ }
180
+ set bilateralTolerance(n) {
181
+ this._thinSSAORenderingPipeline.bilateralTolerance = n;
105
182
  }
106
183
  /**
107
184
  * Support test.
@@ -113,6 +190,15 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
113
190
  }
114
191
  return engine._features.supportSSAO2;
115
192
  }
193
+ /**
194
+ * Indicates that the combine stage should use the current camera viewport to render the SSAO result on only a portion of the output texture (default: true).
195
+ */
196
+ get useViewportInCombineStage() {
197
+ return this._thinSSAORenderingPipeline.useViewportInCombineStage;
198
+ }
199
+ set useViewportInCombineStage(b) {
200
+ this._thinSSAORenderingPipeline.useViewportInCombineStage = b;
201
+ }
116
202
  /**
117
203
  * Gets active scene
118
204
  */
@@ -156,68 +242,13 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
156
242
  * The PostProcess id in the pipeline that combines the SSAO-Blur output with the original scene color (SSAOOriginalSceneColorEffect)
157
243
  */
158
244
  this.SSAOCombineRenderEffect = "SSAOCombineRenderEffect";
159
- /**
160
- * The output strength of the SSAO post-process. Default value is 1.0.
161
- */
162
- this.totalStrength = 1.0;
163
- /**
164
- * Maximum depth value to still render AO. A smooth falloff makes the dimming more natural, so there will be no abrupt shading change.
165
- */
166
- this.maxZ = 100.0;
167
- /**
168
- * In order to save performances, SSAO radius is clamped on close geometry. This ratio changes by how much.
169
- */
170
- this.minZAspect = 0.2;
171
- this._epsilon = 0.02;
172
- this._samples = 8;
173
245
  this._textureSamples = 1;
174
246
  this._forcedGeometryBuffer = null;
175
247
  /**
176
248
  * Force rendering the geometry through geometry buffer.
177
249
  */
178
250
  this._forceGeometryBuffer = false;
179
- /**
180
- * The radius around the analyzed pixel used by the SSAO post-process. Default value is 2.0
181
- */
182
- this.radius = 2.0;
183
- /**
184
- * The base color of the SSAO post-process
185
- * The final result is "base + ssao" between [0, 1]
186
- */
187
- this.base = 0;
188
- this._bypassBlur = false;
189
- this._expensiveBlur = true;
190
- /**
191
- * The number of samples the bilateral filter uses in both dimensions when denoising the SSAO calculations. Default value is 16.
192
- *
193
- * A higher value should result in smoother shadows but will use more processing time in the shaders.
194
- *
195
- * A high value can cause the shadows to get to blurry or create visible artifacts (bands) near sharp details in the geometry. The artifacts can sometimes be mitigated by increasing the bilateralSoften setting.
196
- */
197
- this.bilateralSamples = 16;
198
- /**
199
- * Controls the shape of the denoising kernel used by the bilateral filter. Default value is 0.
200
- *
201
- * By default the bilateral filter acts like a box-filter, treating all samples on the same depth with equal weights. This is effective to maximize the denoising effect given a limited set of samples. However, it also often results in visible ghosting around sharp shadow regions and can spread out lines over large areas so they are no longer visible.
202
- *
203
- * Increasing this setting will make the filter pay less attention to samples further away from the center sample, reducing many artifacts but at the same time increasing noise.
204
- *
205
- * Useful value range is [0..1].
206
- */
207
- this.bilateralSoften = 0;
208
- /**
209
- * How forgiving the bilateral denoiser should be when rejecting samples. Default value is 0.
210
- *
211
- * A higher value results in the bilateral filter being more forgiving and thus doing a better job at denoising slanted and curved surfaces, but can lead to shadows spreading out around corners or between objects that are close to each other depth wise.
212
- *
213
- * Useful value range is normally [0..1], but higher values are allowed.
214
- */
215
- this.bilateralTolerance = 0;
216
- /**
217
- * Indicates that the combine stage should use the current camera viewport to render the SSAO result on only a portion of the output texture (default: true).
218
- */
219
- this.useViewportInCombineStage = true;
220
- this._bits = new Uint32Array(1);
251
+ this._thinSSAORenderingPipeline = new ThinSSAO2RenderingPipeline(name, scene);
221
252
  this._scene = scene;
222
253
  this._ratio = ratio;
223
254
  this._textureType = textureType;
@@ -249,7 +280,6 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
249
280
  Logger.Error("SSAO2RenderingPipeline does not support generateNormalsInWorldSpace=true for the prepass renderer!");
250
281
  }
251
282
  }
252
- this._createRandomTexture();
253
283
  this._originalColorPostProcess = new PassPostProcess("SSAOOriginalSceneColor", 1.0, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), undefined, this._textureType);
254
284
  this._originalColorPostProcess.samples = this.textureSamples;
255
285
  this._createSSAOPostProcess(1.0, textureType);
@@ -298,12 +328,12 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
298
328
  this._blurVPostProcess.dispose(camera);
299
329
  this._ssaoCombinePostProcess.dispose(camera);
300
330
  }
301
- this._randomTexture.dispose();
302
331
  if (disableGeometryBufferRenderer && !this._forcedGeometryBuffer) {
303
332
  this._scene.disableGeometryBufferRenderer();
304
333
  }
305
334
  this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._scene.cameras);
306
335
  this._scene.postProcessRenderPipelineManager.removePipeline(this._name);
336
+ this._thinSSAORenderingPipeline.dispose();
307
337
  super.dispose();
308
338
  }
309
339
  // Private Methods
@@ -311,45 +341,24 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
311
341
  _rebuild() {
312
342
  super._rebuild();
313
343
  }
314
- _getSamplersForBlur(disabled) {
315
- return disabled ? ["textureSampler"] : ["textureSampler", "depthSampler"];
316
- }
317
- _getDefinesForBlur(bilateral, disabled) {
318
- let define = "#define BLUR\n";
319
- if (disabled) {
320
- define += "#define BLUR_BYPASS\n";
321
- }
322
- if (!bilateral) {
323
- define += "#define BLUR_LEGACY\n";
324
- }
325
- return { h: define + "#define BLUR_H\n", v: define };
326
- }
327
344
  _createBlurPostProcess(ssaoRatio, blurRatio, textureType) {
328
- const defines = this._getDefinesForBlur(this.expensiveBlur, this.bypassBlur);
329
- const samplers = this._getSamplersForBlur(this.bypassBlur);
330
- this._blurHPostProcess = this._createBlurFilter("BlurH", samplers, ssaoRatio, defines.h, textureType, true);
331
- this._blurVPostProcess = this._createBlurFilter("BlurV", samplers, blurRatio, defines.v, textureType, false);
332
- }
333
- _createBlurFilter(name, samplers, ratio, defines, textureType, horizontal) {
334
- const blurFilter = new PostProcess(name, "ssao2", ["outSize", "samples", "soften", "tolerance"], samplers, ratio, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, defines, textureType, undefined, undefined, undefined, undefined, this._scene.getEngine().isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */, (useWebGPU, list) => {
335
- if (useWebGPU) {
336
- list.push(import("../../../ShadersWGSL/ssao2.fragment.js"));
337
- }
338
- else {
339
- list.push(import("../../../Shaders/ssao2.fragment.js"));
340
- }
345
+ this._blurHPostProcess = this._createBlurFilter("BlurH", ssaoRatio, textureType, true);
346
+ this._blurVPostProcess = this._createBlurFilter("BlurV", blurRatio, textureType, false);
347
+ }
348
+ _createBlurFilter(name, ratio, textureType, horizontal) {
349
+ const blurFilter = new PostProcess(name, ThinSSAO2BlurPostProcess.FragmentUrl, {
350
+ size: ratio,
351
+ samplingMode: 2,
352
+ engine: this._scene.getEngine(),
353
+ textureType: this._textureType,
354
+ effectWrapper: horizontal ? this._thinSSAORenderingPipeline._ssaoBlurXPostProcess : this._thinSSAORenderingPipeline._ssaoBlurYPostProcess,
341
355
  });
342
356
  blurFilter.onApply = (effect) => {
343
- if (!this._scene.activeCamera) {
344
- return;
345
- }
346
357
  const ratio = this._ratio.blurRatio || this._ratio;
347
358
  const ssaoCombineSize = horizontal ? this._originalColorPostProcess.width * ratio : this._originalColorPostProcess.height * ratio;
348
359
  const originalColorSize = horizontal ? this._originalColorPostProcess.width : this._originalColorPostProcess.height;
349
- effect.setFloat("outSize", ssaoCombineSize > 0 ? ssaoCombineSize : originalColorSize);
350
- effect.setInt("samples", this.bilateralSamples);
351
- effect.setFloat("soften", this.bilateralSoften);
352
- effect.setFloat("tolerance", this.bilateralTolerance);
360
+ this._thinSSAORenderingPipeline._ssaoBlurXPostProcess.textureSize = ssaoCombineSize > 0 ? ssaoCombineSize : originalColorSize;
361
+ this._thinSSAORenderingPipeline._ssaoBlurYPostProcess.textureSize = ssaoCombineSize > 0 ? ssaoCombineSize : originalColorSize;
353
362
  if (this._geometryBufferRenderer) {
354
363
  effect.setTexture("depthSampler", this._geometryBufferRenderer.getGBuffer().textures[0]);
355
364
  }
@@ -361,111 +370,33 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
361
370
  blurFilter.autoClear = false;
362
371
  return blurFilter;
363
372
  }
364
- //Van der Corput radical inverse
365
- _radicalInverse_VdC(i) {
366
- this._bits[0] = i;
367
- this._bits[0] = ((this._bits[0] << 16) | (this._bits[0] >> 16)) >>> 0;
368
- this._bits[0] = ((this._bits[0] & 0x55555555) << 1) | (((this._bits[0] & 0xaaaaaaaa) >>> 1) >>> 0);
369
- this._bits[0] = ((this._bits[0] & 0x33333333) << 2) | (((this._bits[0] & 0xcccccccc) >>> 2) >>> 0);
370
- this._bits[0] = ((this._bits[0] & 0x0f0f0f0f) << 4) | (((this._bits[0] & 0xf0f0f0f0) >>> 4) >>> 0);
371
- this._bits[0] = ((this._bits[0] & 0x00ff00ff) << 8) | (((this._bits[0] & 0xff00ff00) >>> 8) >>> 0);
372
- return this._bits[0] * 2.3283064365386963e-10; // / 0x100000000 or / 4294967296
373
- }
374
- _hammersley(i, n) {
375
- return [i / n, this._radicalInverse_VdC(i)];
376
- }
377
- _hemisphereSample_uniform(u, v) {
378
- const phi = v * 2.0 * Math.PI;
379
- // rejecting samples that are close to tangent plane to avoid z-fighting artifacts
380
- const cosTheta = 1.0 - u * 0.85;
381
- const sinTheta = Math.sqrt(1.0 - cosTheta * cosTheta);
382
- return new Vector3(Math.cos(phi) * sinTheta, Math.sin(phi) * sinTheta, cosTheta);
383
- }
384
- _generateHemisphere() {
385
- const numSamples = this.samples;
386
- const result = [];
387
- let vector;
388
- let i = 0;
389
- while (i < numSamples) {
390
- if (numSamples < 16) {
391
- vector = this._hemisphereSample_uniform(Math.random(), Math.random());
392
- }
393
- else {
394
- const rand = this._hammersley(i, numSamples);
395
- vector = this._hemisphereSample_uniform(rand[0], rand[1]);
373
+ _getTextureSize() {
374
+ const engine = this._scene.getEngine();
375
+ const prePassRenderer = this._prePassRenderer;
376
+ let textureSize = { width: engine.getRenderWidth(), height: engine.getRenderHeight() };
377
+ if (prePassRenderer && this._scene.activeCamera?._getFirstPostProcess() === this._ssaoPostProcess) {
378
+ const renderTarget = prePassRenderer.getRenderTarget();
379
+ if (renderTarget && renderTarget.textures) {
380
+ textureSize = renderTarget.textures[prePassRenderer.getIndex(4)].getSize();
396
381
  }
397
- result.push(vector.x, vector.y, vector.z);
398
- i++;
399
382
  }
400
- return result;
401
- }
402
- _getDefinesForSSAO() {
403
- let defines = `#define SSAO\n#define SAMPLES ${this.samples}\n#define EPSILON ${this.epsilon.toFixed(4)}`;
404
- if (this._scene.activeCamera?.mode === Camera.ORTHOGRAPHIC_CAMERA) {
405
- defines += `\n#define ORTHOGRAPHIC_CAMERA`;
383
+ else if (this._ssaoPostProcess.inputTexture) {
384
+ textureSize.width = this._ssaoPostProcess.inputTexture.width;
385
+ textureSize.height = this._ssaoPostProcess.inputTexture.height;
406
386
  }
407
- return defines;
387
+ return textureSize;
408
388
  }
409
389
  _createSSAOPostProcess(ratio, textureType) {
410
- this._sampleSphere = this._generateHemisphere();
411
- const defines = this._getDefinesForSSAO();
412
- const samplers = ["randomSampler", "depthSampler", "normalSampler"];
413
- this._ssaoPostProcess = new PostProcess("ssao2", "ssao2", [
414
- "sampleSphere",
415
- "samplesFactor",
416
- "randTextureTiles",
417
- "totalStrength",
418
- "radius",
419
- "base",
420
- "range",
421
- "projection",
422
- "near",
423
- "texelSize",
424
- "xViewport",
425
- "yViewport",
426
- "viewport",
427
- "maxZ",
428
- "minZAspect",
429
- "depthProjection",
430
- ], samplers, ratio, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, defines, textureType, undefined, undefined, undefined, undefined, this._scene.getEngine().isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */, (useWebGPU, list) => {
431
- if (useWebGPU) {
432
- list.push(import("../../../ShadersWGSL/ssao2.fragment.js"));
433
- }
434
- else {
435
- list.push(import("../../../Shaders/ssao2.fragment.js"));
436
- }
390
+ this._ssaoPostProcess = new PostProcess("ssao", ThinSSAO2PostProcess.FragmentUrl, {
391
+ size: ratio,
392
+ samplingMode: 2,
393
+ engine: this._scene.getEngine(),
394
+ textureType,
395
+ effectWrapper: this._thinSSAORenderingPipeline._ssaoPostProcess,
437
396
  });
438
397
  this._ssaoPostProcess.autoClear = false;
439
398
  this._ssaoPostProcess.onApply = (effect) => {
440
- if (!this._scene.activeCamera) {
441
- return;
442
- }
443
- effect.setArray3("sampleSphere", this._sampleSphere);
444
- effect.setFloat("randTextureTiles", 32.0);
445
- effect.setFloat("samplesFactor", 1 / this.samples);
446
- effect.setFloat("totalStrength", this.totalStrength);
447
- effect.setFloat2("texelSize", 1 / this._ssaoPostProcess.width, 1 / this._ssaoPostProcess.height);
448
- effect.setFloat("radius", this.radius);
449
- effect.setFloat("maxZ", this.maxZ);
450
- effect.setFloat("minZAspect", this.minZAspect);
451
- effect.setFloat("base", this.base);
452
- effect.setFloat("near", this._scene.activeCamera.minZ);
453
- if (this._scene.activeCamera.mode === Camera.PERSPECTIVE_CAMERA) {
454
- effect.setMatrix3x3("depthProjection", SSAO2RenderingPipeline.PERSPECTIVE_DEPTH_PROJECTION);
455
- effect.setFloat("xViewport", Math.tan(this._scene.activeCamera.fov / 2) * this._scene.getEngine().getAspectRatio(this._scene.activeCamera, true));
456
- effect.setFloat("yViewport", Math.tan(this._scene.activeCamera.fov / 2));
457
- }
458
- else {
459
- const halfWidth = this._scene.getEngine().getRenderWidth() / 2.0;
460
- const halfHeight = this._scene.getEngine().getRenderHeight() / 2.0;
461
- const orthoLeft = this._scene.activeCamera.orthoLeft ?? -halfWidth;
462
- const orthoRight = this._scene.activeCamera.orthoRight ?? halfWidth;
463
- const orthoBottom = this._scene.activeCamera.orthoBottom ?? -halfHeight;
464
- const orthoTop = this._scene.activeCamera.orthoTop ?? halfHeight;
465
- effect.setMatrix3x3("depthProjection", SSAO2RenderingPipeline.ORTHO_DEPTH_PROJECTION);
466
- effect.setFloat4("viewport", orthoLeft, orthoRight, orthoBottom, orthoTop);
467
- }
468
- effect.setMatrix("projection", this._scene.getProjectionMatrix());
399
+ this._thinSSAORenderingPipeline._ssaoPostProcess.camera = this._scene.activeCamera;
469
400
  if (this._geometryBufferRenderer) {
470
401
  effect.setTexture("depthSampler", this._geometryBufferRenderer.getGBuffer().textures[0]);
471
402
  effect.setTexture("normalSampler", this._geometryBufferRenderer.getGBuffer().textures[1]);
@@ -474,7 +405,9 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
474
405
  effect.setTexture("depthSampler", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(5)]);
475
406
  effect.setTexture("normalSampler", this._prePassRenderer.getRenderTarget().textures[this._prePassRenderer.getIndex(6)]);
476
407
  }
477
- effect.setTexture("randomSampler", this._randomTexture);
408
+ const textureSize = this._getTextureSize();
409
+ this._thinSSAORenderingPipeline._ssaoPostProcess.textureWidth = textureSize.width;
410
+ this._thinSSAORenderingPipeline._ssaoPostProcess.textureHeight = textureSize.height;
478
411
  };
479
412
  this._ssaoPostProcess.samples = this.textureSamples;
480
413
  if (!this._forceGeometryBuffer) {
@@ -482,44 +415,20 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
482
415
  }
483
416
  }
484
417
  _createSSAOCombinePostProcess(ratio, textureType) {
485
- this._ssaoCombinePostProcess = new PostProcess("ssaoCombine", "ssaoCombine", [], ["originalColor", "viewport"], ratio, null, Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine(), false, undefined, textureType, undefined, undefined, undefined, undefined, this._scene.getEngine().isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */, (useWebGPU, list) => {
486
- if (useWebGPU) {
487
- list.push(import("../../../ShadersWGSL/ssaoCombine.fragment.js"));
488
- }
489
- else {
490
- list.push(import("../../../Shaders/ssaoCombine.fragment.js"));
491
- }
418
+ this._ssaoCombinePostProcess = new PostProcess("ssaoCombine", ThinSSAO2CombinePostProcess.FragmentUrl, {
419
+ size: ratio,
420
+ samplingMode: 2,
421
+ engine: this._scene.getEngine(),
422
+ textureType,
423
+ effectWrapper: this._thinSSAORenderingPipeline._ssaoCombinePostProcess,
492
424
  });
493
425
  this._ssaoCombinePostProcess.onApply = (effect) => {
494
- const viewport = this._scene.activeCamera.viewport;
495
- if (this.useViewportInCombineStage) {
496
- effect.setVector4("viewport", TmpVectors.Vector4[0].copyFromFloats(viewport.x, viewport.y, viewport.width, viewport.height));
497
- }
498
- else {
499
- effect.setVector4("viewport", TmpVectors.Vector4[0].copyFromFloats(0, 0, 1, 1));
500
- }
426
+ this._thinSSAORenderingPipeline._ssaoCombinePostProcess.camera = this._scene.activeCamera;
501
427
  effect.setTextureFromPostProcessOutput("originalColor", this._originalColorPostProcess);
502
428
  };
503
429
  this._ssaoCombinePostProcess.autoClear = false;
504
430
  this._ssaoCombinePostProcess.samples = this.textureSamples;
505
431
  }
506
- _createRandomTexture() {
507
- const size = 128;
508
- const data = new Uint8Array(size * size * 4);
509
- const randVector = Vector2.Zero();
510
- for (let index = 0; index < data.length;) {
511
- randVector.set(RandomRange(0, 1), RandomRange(0, 1)).normalize().scaleInPlace(255);
512
- data[index++] = Math.floor(randVector.x);
513
- data[index++] = Math.floor(randVector.y);
514
- data[index++] = 0;
515
- data[index++] = 255;
516
- }
517
- const texture = RawTexture.CreateRGBATexture(data, size, size, this._scene, false, false, 2);
518
- texture.name = "SSAORandomTexture";
519
- texture.wrapU = Texture.WRAP_ADDRESSMODE;
520
- texture.wrapV = Texture.WRAP_ADDRESSMODE;
521
- this._randomTexture = texture;
522
- }
523
432
  /**
524
433
  * Serialize the rendering pipeline (Used when exporting)
525
434
  * @returns the serialized object
@@ -540,23 +449,21 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
540
449
  return SerializationHelper.Parse(() => new SSAO2RenderingPipeline(source._name, scene, source._ratio, undefined, source._forceGeometryBuffer, source._textureType), source, scene, rootUrl);
541
450
  }
542
451
  }
543
- SSAO2RenderingPipeline.ORTHO_DEPTH_PROJECTION = [1, 0, 0, 0, 1, 0, 0, 0, 1];
544
- SSAO2RenderingPipeline.PERSPECTIVE_DEPTH_PROJECTION = [0, 0, 0, 0, 0, 0, 1, 1, 1];
545
452
  __decorate([
546
453
  serialize()
547
- ], SSAO2RenderingPipeline.prototype, "totalStrength", void 0);
454
+ ], SSAO2RenderingPipeline.prototype, "totalStrength", null);
548
455
  __decorate([
549
456
  serialize()
550
- ], SSAO2RenderingPipeline.prototype, "maxZ", void 0);
457
+ ], SSAO2RenderingPipeline.prototype, "maxZ", null);
551
458
  __decorate([
552
459
  serialize()
553
- ], SSAO2RenderingPipeline.prototype, "minZAspect", void 0);
460
+ ], SSAO2RenderingPipeline.prototype, "minZAspect", null);
554
461
  __decorate([
555
462
  serialize("epsilon")
556
- ], SSAO2RenderingPipeline.prototype, "_epsilon", void 0);
463
+ ], SSAO2RenderingPipeline.prototype, "epsilon", null);
557
464
  __decorate([
558
465
  serialize("samples")
559
- ], SSAO2RenderingPipeline.prototype, "_samples", void 0);
466
+ ], SSAO2RenderingPipeline.prototype, "samples", null);
560
467
  __decorate([
561
468
  serialize("textureSamples")
562
469
  ], SSAO2RenderingPipeline.prototype, "_textureSamples", void 0);
@@ -571,24 +478,24 @@ __decorate([
571
478
  ], SSAO2RenderingPipeline.prototype, "_textureType", void 0);
572
479
  __decorate([
573
480
  serialize()
574
- ], SSAO2RenderingPipeline.prototype, "radius", void 0);
481
+ ], SSAO2RenderingPipeline.prototype, "radius", null);
575
482
  __decorate([
576
483
  serialize()
577
- ], SSAO2RenderingPipeline.prototype, "base", void 0);
484
+ ], SSAO2RenderingPipeline.prototype, "base", null);
578
485
  __decorate([
579
486
  serialize("bypassBlur")
580
- ], SSAO2RenderingPipeline.prototype, "_bypassBlur", void 0);
487
+ ], SSAO2RenderingPipeline.prototype, "bypassBlur", null);
581
488
  __decorate([
582
489
  serialize("expensiveBlur")
583
- ], SSAO2RenderingPipeline.prototype, "_expensiveBlur", void 0);
490
+ ], SSAO2RenderingPipeline.prototype, "expensiveBlur", null);
584
491
  __decorate([
585
492
  serialize()
586
- ], SSAO2RenderingPipeline.prototype, "bilateralSamples", void 0);
493
+ ], SSAO2RenderingPipeline.prototype, "bilateralSamples", null);
587
494
  __decorate([
588
495
  serialize()
589
- ], SSAO2RenderingPipeline.prototype, "bilateralSoften", void 0);
496
+ ], SSAO2RenderingPipeline.prototype, "bilateralSoften", null);
590
497
  __decorate([
591
498
  serialize()
592
- ], SSAO2RenderingPipeline.prototype, "bilateralTolerance", void 0);
499
+ ], SSAO2RenderingPipeline.prototype, "bilateralTolerance", null);
593
500
  RegisterClass("BABYLON.SSAO2RenderingPipeline", SSAO2RenderingPipeline);
594
501
  //# sourceMappingURL=ssao2RenderingPipeline.js.map