@babylonjs/core 5.47.1 → 5.48.0
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/Cameras/camera.js +5 -0
- package/Cameras/camera.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/index.d.ts +1 -0
- package/PostProcesses/RenderPipeline/Pipelines/index.js +1 -0
- package/PostProcesses/RenderPipeline/Pipelines/index.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.d.ts +255 -0
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +805 -0
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -0
- package/PostProcesses/screenSpaceReflectionPostProcess.d.ts +1 -0
- package/PostProcesses/screenSpaceReflectionPostProcess.js +1 -0
- package/PostProcesses/screenSpaceReflectionPostProcess.js.map +1 -1
- package/Rendering/depthRenderer.d.ts +12 -3
- package/Rendering/depthRenderer.js +22 -7
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.d.ts +1 -0
- package/Rendering/geometryBufferRenderer.js +4 -2
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/prePassRendererSceneComponent.d.ts +4 -0
- package/Rendering/prePassRendererSceneComponent.js +3 -3
- package/Rendering/prePassRendererSceneComponent.js.map +1 -1
- package/Rendering/screenSpaceReflections2Configuration.d.ts +19 -0
- package/Rendering/screenSpaceReflections2Configuration.js +22 -0
- package/Rendering/screenSpaceReflections2Configuration.js.map +1 -0
- package/Shaders/ShadersInclude/screenSpaceRayTrace.d.ts +5 -0
- package/Shaders/ShadersInclude/screenSpaceRayTrace.js +32 -0
- package/Shaders/ShadersInclude/screenSpaceRayTrace.js.map +1 -0
- package/Shaders/default.fragment.js +3 -3
- package/Shaders/default.fragment.js.map +1 -1
- package/Shaders/depth.fragment.js +8 -0
- package/Shaders/depth.fragment.js.map +1 -1
- package/Shaders/depth.vertex.js +6 -1
- package/Shaders/depth.vertex.js.map +1 -1
- package/Shaders/geometry.fragment.js +5 -13
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/pbr.fragment.js +2 -2
- package/Shaders/pbr.fragment.js.map +1 -1
- package/Shaders/screenSpaceReflection2.fragment.d.ts +7 -0
- package/Shaders/screenSpaceReflection2.fragment.js +61 -0
- package/Shaders/screenSpaceReflection2.fragment.js.map +1 -0
- package/Shaders/screenSpaceReflection2Blur.fragment.d.ts +5 -0
- package/Shaders/screenSpaceReflection2Blur.fragment.js +9 -0
- package/Shaders/screenSpaceReflection2Blur.fragment.js.map +1 -0
- package/Shaders/screenSpaceReflection2BlurCombiner.fragment.d.ts +6 -0
- package/Shaders/screenSpaceReflection2BlurCombiner.fragment.js +11 -0
- package/Shaders/screenSpaceReflection2BlurCombiner.fragment.js.map +1 -0
- package/XR/webXRCamera.d.ts +6 -0
- package/XR/webXRCamera.js +15 -0
- package/XR/webXRCamera.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +1 -0
- package/scene.js.map +1 -1
|
@@ -0,0 +1,805 @@
|
|
|
1
|
+
import { __decorate } from "../../../tslib.es6.js";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
3
|
+
import { Logger } from "../../../Misc/logger.js";
|
|
4
|
+
import { serialize, SerializationHelper } from "../../../Misc/decorators.js";
|
|
5
|
+
import { Vector3, Matrix, Quaternion, TmpVectors } from "../../../Maths/math.vector.js";
|
|
6
|
+
import { PostProcess } from "../../postProcess.js";
|
|
7
|
+
import { PostProcessRenderPipeline } from "../postProcessRenderPipeline.js";
|
|
8
|
+
import { PostProcessRenderEffect } from "../postProcessRenderEffect.js";
|
|
9
|
+
import { RegisterClass } from "../../../Misc/typeStore.js";
|
|
10
|
+
import { ScreenSpaceReflections2Configuration } from "../../../Rendering/screenSpaceReflections2Configuration.js";
|
|
11
|
+
import { GeometryBufferRenderer } from "../../../Rendering/geometryBufferRenderer.js";
|
|
12
|
+
|
|
13
|
+
import { DepthRenderer } from "../../../Rendering/depthRenderer.js";
|
|
14
|
+
import "../postProcessRenderPipelineManagerSceneComponent.js";
|
|
15
|
+
import "../../../Shaders/screenSpaceReflection2.fragment.js";
|
|
16
|
+
import "../../../Shaders/screenSpaceReflection2Blur.fragment.js";
|
|
17
|
+
import "../../../Shaders/screenSpaceReflection2BlurCombiner.fragment.js";
|
|
18
|
+
const trs = Matrix.Compose(new Vector3(0.5, 0.5, 0.5), Quaternion.Identity(), new Vector3(0.5, 0.5, 0.5));
|
|
19
|
+
const trsWebGPU = Matrix.Compose(new Vector3(0.5, 0.5, 1), Quaternion.Identity(), new Vector3(0.5, 0.5, 0));
|
|
20
|
+
/**
|
|
21
|
+
* Render pipeline to produce Screen Space Reflections (SSR) effect
|
|
22
|
+
*
|
|
23
|
+
* References:
|
|
24
|
+
* Screen Space Ray Tracing:
|
|
25
|
+
* - http://casual-effects.blogspot.com/2014/08/screen-space-ray-tracing.html
|
|
26
|
+
* - https://sourceforge.net/p/g3d/code/HEAD/tree/G3D10/data-files/shader/screenSpaceRayTrace.glsl
|
|
27
|
+
* - https://github.com/kode80/kode80SSR
|
|
28
|
+
* SSR:
|
|
29
|
+
* - general tips: https://sakibsaikia.github.io/graphics/2016/12/26/Screen-Space-Reflection-in-Killing-Floor-2.html
|
|
30
|
+
* - computation of blur radius from roughness and distance: https://github.com/godotengine/godot/blob/master/servers/rendering/renderer_rd/shaders/effects/screen_space_reflection.glsl
|
|
31
|
+
* - blur and usage of back depth buffer: https://github.com/kode80/kode80SSR
|
|
32
|
+
*/
|
|
33
|
+
export class SSRRenderingPipeline extends PostProcessRenderPipeline {
|
|
34
|
+
/**
|
|
35
|
+
* MSAA sample count, setting this to 4 will provide 4x anti aliasing. (default: 1)
|
|
36
|
+
*/
|
|
37
|
+
set samples(sampleCount) {
|
|
38
|
+
if (this._samples === sampleCount) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this._samples = sampleCount;
|
|
42
|
+
this._buildPipeline();
|
|
43
|
+
}
|
|
44
|
+
get samples() {
|
|
45
|
+
return this._samples;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Gets or sets the blur dispersion strength. Set this value to 0 to disable blurring (default: 0.05)
|
|
49
|
+
* The reflections are blurred based on the distance between the pixel shaded and the reflected pixel: the higher the distance the more blurry the reflection is.
|
|
50
|
+
* blurDispersionStrength allows to increase or decrease this effect.
|
|
51
|
+
*/
|
|
52
|
+
get blurDispersionStrength() {
|
|
53
|
+
return this._blurDispersionStrength;
|
|
54
|
+
}
|
|
55
|
+
set blurDispersionStrength(strength) {
|
|
56
|
+
if (strength === this._blurDispersionStrength) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const rebuild = (strength === 0 && this._blurDispersionStrength !== 0) || (strength !== 0 && this._blurDispersionStrength === 0);
|
|
60
|
+
this._blurDispersionStrength = strength;
|
|
61
|
+
if (rebuild) {
|
|
62
|
+
this._buildPipeline();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets or sets whether or not smoothing reflections is enabled.
|
|
67
|
+
* Enabling smoothing will require more GPU power and can generate a drop in FPS.
|
|
68
|
+
* Note that this setting has no effect if step = 1: it's only used if step \> 1.
|
|
69
|
+
*/
|
|
70
|
+
get enableSmoothReflections() {
|
|
71
|
+
return this._enableSmoothReflections;
|
|
72
|
+
}
|
|
73
|
+
set enableSmoothReflections(enabled) {
|
|
74
|
+
if (enabled === this._enableSmoothReflections) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this._enableSmoothReflections = enabled;
|
|
78
|
+
this._updateEffectDefines();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets or sets the environment cube texture used to define the reflection when the reflected rays of SSR leave the view space or when the maxDistance/maxSteps is reached.
|
|
82
|
+
*/
|
|
83
|
+
get environmentTexture() {
|
|
84
|
+
return this._environmentTexture;
|
|
85
|
+
}
|
|
86
|
+
set environmentTexture(texture) {
|
|
87
|
+
this._environmentTexture = texture;
|
|
88
|
+
this._updateEffectDefines();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Gets or sets the boolean defining if the environment texture is a standard cubemap (false) or a probe (true). Default value is false.
|
|
92
|
+
* Note: a probe cube texture is treated differently than an ordinary cube texture because the Y axis is reversed.
|
|
93
|
+
*/
|
|
94
|
+
get environmentTextureIsProbe() {
|
|
95
|
+
return this._environmentTextureIsProbe;
|
|
96
|
+
}
|
|
97
|
+
set environmentTextureIsProbe(isProbe) {
|
|
98
|
+
this._environmentTextureIsProbe = isProbe;
|
|
99
|
+
this._updateEffectDefines();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Gets or sets a boolean indicating if the reflections should be attenuated at the screen borders (default: true).
|
|
103
|
+
*/
|
|
104
|
+
get attenuateScreenBorders() {
|
|
105
|
+
return this._attenuateScreenBorders;
|
|
106
|
+
}
|
|
107
|
+
set attenuateScreenBorders(attenuate) {
|
|
108
|
+
if (this._attenuateScreenBorders === attenuate) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this._attenuateScreenBorders = attenuate;
|
|
112
|
+
this._updateEffectDefines();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Gets or sets a boolean indicating if the reflections should be attenuated according to the distance of the intersection (default: true).
|
|
116
|
+
*/
|
|
117
|
+
get attenuateIntersectionDistance() {
|
|
118
|
+
return this._attenuateIntersectionDistance;
|
|
119
|
+
}
|
|
120
|
+
set attenuateIntersectionDistance(attenuate) {
|
|
121
|
+
if (this._attenuateIntersectionDistance === attenuate) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this._attenuateIntersectionDistance = attenuate;
|
|
125
|
+
this._updateEffectDefines();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Gets or sets a boolean indicating if the reflections should be attenuated when the reflection ray is facing the camera (the view direction) (default: false).
|
|
129
|
+
*/
|
|
130
|
+
get attenuateFacingCamera() {
|
|
131
|
+
return this._attenuateFacingCamera;
|
|
132
|
+
}
|
|
133
|
+
set attenuateFacingCamera(attenuate) {
|
|
134
|
+
if (this._attenuateFacingCamera === attenuate) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this._attenuateFacingCamera = attenuate;
|
|
138
|
+
this._updateEffectDefines();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Gets or sets a boolean indicating if the backface reflections should be attenuated (default: false).
|
|
142
|
+
*/
|
|
143
|
+
get attenuateBackfaceReflection() {
|
|
144
|
+
return this._attenuateBackfaceReflection;
|
|
145
|
+
}
|
|
146
|
+
set attenuateBackfaceReflection(attenuate) {
|
|
147
|
+
if (this._attenuateBackfaceReflection === attenuate) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this._attenuateBackfaceReflection = attenuate;
|
|
151
|
+
this._updateEffectDefines();
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Gets or sets a boolean indicating if the ray should be clipped to the frustum (default: true).
|
|
155
|
+
* You can try to set this parameter to false to save some performances: it may produce some artefacts in some cases, but generally they won't really be visible
|
|
156
|
+
*/
|
|
157
|
+
get clipToFrustum() {
|
|
158
|
+
return this._clipToFrustum;
|
|
159
|
+
}
|
|
160
|
+
set clipToFrustum(clip) {
|
|
161
|
+
if (this._clipToFrustum === clip) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this._clipToFrustum = clip;
|
|
165
|
+
this._updateEffectDefines();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Gets or sets a boolean defining if geometry thickness should be computed automatically (default: false).
|
|
169
|
+
* When enabled, a depth renderer is created which will render the back faces of the scene to a depth texture (meaning additional work for the GPU).
|
|
170
|
+
* In that mode, the "thickness" property is still used as an offset to compute the ray intersection, but you can typically use a much lower
|
|
171
|
+
* value than when enableAutomaticThicknessComputation is false (it's even possible to use a value of 0 when using low values for "step")
|
|
172
|
+
* Note that for performance reasons, this option will only apply to the first camera to which the the rendering pipeline is attached!
|
|
173
|
+
*/
|
|
174
|
+
get enableAutomaticThicknessComputation() {
|
|
175
|
+
return this._enableAutomaticThicknessComputation;
|
|
176
|
+
}
|
|
177
|
+
set enableAutomaticThicknessComputation(automatic) {
|
|
178
|
+
if (this._enableAutomaticThicknessComputation === automatic) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
this._enableAutomaticThicknessComputation = automatic;
|
|
182
|
+
this._buildPipeline();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Gets the depth renderer used to render the back faces of the scene to a depth texture.
|
|
186
|
+
*/
|
|
187
|
+
get backfaceDepthRenderer() {
|
|
188
|
+
return this._depthRenderer;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Gets or sets the size factor used to create the backface depth texture, used only if enableAutomaticThicknessComputation = true (default: 1).
|
|
192
|
+
* This factor is used as a divisor of the full screen size (so, 2 means that the backface depth texture will be created at half the screen size, meaning better performances).
|
|
193
|
+
* Note that you will get rendering artefacts when using a value different from 1: it's a tradeoff between image quality and performances.
|
|
194
|
+
*/
|
|
195
|
+
get backfaceDepthTextureSizeFactor() {
|
|
196
|
+
return this._backfaceDepthTextureSizeFactor;
|
|
197
|
+
}
|
|
198
|
+
set backfaceDepthTextureSizeFactor(factor) {
|
|
199
|
+
if (this._backfaceDepthTextureSizeFactor === factor) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
this._backfaceDepthTextureSizeFactor = factor;
|
|
203
|
+
this._resizeDepthRenderer();
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Gets or sets a boolean indicating if the effect is enabled (default: true).
|
|
207
|
+
*/
|
|
208
|
+
get isEnabled() {
|
|
209
|
+
return this._isEnabled;
|
|
210
|
+
}
|
|
211
|
+
set isEnabled(value) {
|
|
212
|
+
if (this._isEnabled === value) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this._isEnabled = value;
|
|
216
|
+
if (!value) {
|
|
217
|
+
if (this._cameras !== null) {
|
|
218
|
+
this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._cameras);
|
|
219
|
+
this._cameras = this._camerasToBeAttached.slice();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else if (value) {
|
|
223
|
+
if (!this._isDirty) {
|
|
224
|
+
if (this._cameras !== null) {
|
|
225
|
+
this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name, this._cameras);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
this._buildPipeline();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Gets or sets a boolean indicating if the effect should be rendered in debug mode (default: false).
|
|
235
|
+
* In this mode, colors have this meaning:
|
|
236
|
+
* - blue: the ray hit the max distance (we reached maxDistance)
|
|
237
|
+
* - red: the ray ran out of steps (we reached maxSteps)
|
|
238
|
+
* - yellow: the ray went off screen
|
|
239
|
+
* - green: the ray hit a surface. The brightness of the green color is proportional to the distance between the ray origin and the intersection point: A brighter green means more computation than a darker green.
|
|
240
|
+
* In the first 3 cases, the final color is calculated by mixing the skybox color with the pixel color (if environmentTexture is defined), otherwise the pixel color is not modified
|
|
241
|
+
* You should try to get as few blue/red/yellow pixels as possible, as this means that the ray has gone further than if it had hit a surface.
|
|
242
|
+
*/
|
|
243
|
+
get debug() {
|
|
244
|
+
return this._debug;
|
|
245
|
+
}
|
|
246
|
+
set debug(value) {
|
|
247
|
+
if (this._debug === value) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this._debug = value;
|
|
251
|
+
this._buildPipeline();
|
|
252
|
+
}
|
|
253
|
+
get _geometryBufferRenderer() {
|
|
254
|
+
if (!this._forceGeometryBuffer) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
return this._scene.geometryBufferRenderer;
|
|
258
|
+
}
|
|
259
|
+
get _prePassRenderer() {
|
|
260
|
+
if (this._forceGeometryBuffer) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
return this._scene.prePassRenderer;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Gets active scene
|
|
267
|
+
*/
|
|
268
|
+
get scene() {
|
|
269
|
+
return this._scene;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Constructor of the SSR rendering pipeline
|
|
273
|
+
* @param name The rendering pipeline name
|
|
274
|
+
* @param scene The scene linked to this pipeline
|
|
275
|
+
* @param cameras The array of cameras that the rendering pipeline will be attached to (default: scene.cameras)
|
|
276
|
+
* @param forceGeometryBuffer Set to true if you want to use the legacy geometry buffer renderer (default: false)
|
|
277
|
+
* @param textureType The texture type used by the different post processes created by SSR (default: 0)
|
|
278
|
+
*/
|
|
279
|
+
constructor(name, scene, cameras, forceGeometryBuffer = false, textureType = 0) {
|
|
280
|
+
super(scene.getEngine(), name);
|
|
281
|
+
/**
|
|
282
|
+
* The SSR PostProcess effect id in the pipeline
|
|
283
|
+
*/
|
|
284
|
+
this.SSRRenderEffect = "SSRRenderEffect";
|
|
285
|
+
/**
|
|
286
|
+
* The blur PostProcess effect id in the pipeline
|
|
287
|
+
*/
|
|
288
|
+
this.SSRBlurRenderEffect = "SSRBlurRenderEffect";
|
|
289
|
+
/**
|
|
290
|
+
* The PostProcess effect id in the pipeline that combines the SSR-Blur output with the original scene color
|
|
291
|
+
*/
|
|
292
|
+
this.SSRCombineRenderEffect = "SSRCombineRenderEffect";
|
|
293
|
+
this._samples = 1;
|
|
294
|
+
/**
|
|
295
|
+
* Gets or sets the maxDistance used to define how far we look for reflection during the ray-marching on the reflected ray (default: 1000).
|
|
296
|
+
* Note that this value is a view (camera) space distance (not pixels!).
|
|
297
|
+
*/
|
|
298
|
+
this.maxDistance = 1000.0;
|
|
299
|
+
/**
|
|
300
|
+
* Gets or sets the step size used to iterate until the effect finds the color of the reflection's pixel. Should be an integer \>= 1 as it is the number of pixels we advance at each step (default: 1).
|
|
301
|
+
* Use higher values to improve performances (but at the expense of quality).
|
|
302
|
+
*/
|
|
303
|
+
this.step = 1.0;
|
|
304
|
+
/**
|
|
305
|
+
* Gets or sets the thickness value used as tolerance when computing the intersection between the reflected ray and the scene (default: 0.5).
|
|
306
|
+
* If setting "enableAutomaticThicknessComputation" to true, you can use lower values for "thickness" (even 0), as the geometry thickness
|
|
307
|
+
* is automatically computed thank to the regular depth buffer + the backface depth buffer
|
|
308
|
+
*/
|
|
309
|
+
this.thickness = 0.5;
|
|
310
|
+
/**
|
|
311
|
+
* Gets or sets the current reflection strength. 1.0 is an ideal value but can be increased/decreased for particular results (default: 1).
|
|
312
|
+
*/
|
|
313
|
+
this.strength = 1;
|
|
314
|
+
/**
|
|
315
|
+
* Gets or sets the falloff exponent used to compute the reflection strength. Higher values lead to fainter reflections (default: 1).
|
|
316
|
+
*/
|
|
317
|
+
this.reflectionSpecularFalloffExponent = 1;
|
|
318
|
+
/**
|
|
319
|
+
* Maximum number of steps during the ray marching process after which we consider an intersection could not be found (default: 1000)
|
|
320
|
+
*/
|
|
321
|
+
this.maxSteps = 1000.0;
|
|
322
|
+
/**
|
|
323
|
+
* Gets or sets the factor applied when computing roughness. Default value is 0.2.
|
|
324
|
+
* When blurring based on roughness is enabled (meaning blurDispersionStrength \> 0), roughnessFactor is used as a global roughness factor applied on all objects.
|
|
325
|
+
* If you want to disable this global roughness set it to 0.
|
|
326
|
+
*/
|
|
327
|
+
this.roughnessFactor = 0.2;
|
|
328
|
+
/**
|
|
329
|
+
* Number of steps to skip at start when marching the ray to avoid self collisions (default: 1)
|
|
330
|
+
* 1 should normally be a good value, depending on the scene you may need to use a higher value (2 or 3)
|
|
331
|
+
*/
|
|
332
|
+
this.selfCollisionNumSkip = 1;
|
|
333
|
+
this._blurDispersionStrength = 1 / 20;
|
|
334
|
+
/**
|
|
335
|
+
* Apply different weighting when blurring.
|
|
336
|
+
* Must be a value between 2 and 5
|
|
337
|
+
*/
|
|
338
|
+
this.blurQuality = 2;
|
|
339
|
+
this._enableSmoothReflections = false;
|
|
340
|
+
this._environmentTextureIsProbe = false;
|
|
341
|
+
this._attenuateScreenBorders = true;
|
|
342
|
+
this._attenuateIntersectionDistance = true;
|
|
343
|
+
this._attenuateFacingCamera = false;
|
|
344
|
+
this._attenuateBackfaceReflection = false;
|
|
345
|
+
this._clipToFrustum = true;
|
|
346
|
+
this._enableAutomaticThicknessComputation = false;
|
|
347
|
+
this._backfaceDepthTextureSizeFactor = 1;
|
|
348
|
+
this._isEnabled = true;
|
|
349
|
+
this._debug = false;
|
|
350
|
+
this._forceGeometryBuffer = false;
|
|
351
|
+
this._isDirty = false;
|
|
352
|
+
this._camerasToBeAttached = [];
|
|
353
|
+
this._cameras = cameras || scene.cameras;
|
|
354
|
+
this._cameras = this._cameras.slice();
|
|
355
|
+
this._camerasToBeAttached = this._cameras.slice();
|
|
356
|
+
this._scene = scene;
|
|
357
|
+
this._textureType = textureType;
|
|
358
|
+
this._forceGeometryBuffer = forceGeometryBuffer;
|
|
359
|
+
if (!this.isSupported) {
|
|
360
|
+
Logger.Error("The current engine does not support SSR.");
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
scene.postProcessRenderPipelineManager.addPipeline(this);
|
|
364
|
+
if (this._forceGeometryBuffer) {
|
|
365
|
+
const geometryBufferRenderer = scene.enableGeometryBufferRenderer();
|
|
366
|
+
if (geometryBufferRenderer) {
|
|
367
|
+
geometryBufferRenderer.enableReflectivity = true;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
const prePassRenderer = scene.enablePrePassRenderer();
|
|
372
|
+
prePassRenderer === null || prePassRenderer === void 0 ? void 0 : prePassRenderer.markAsDirty();
|
|
373
|
+
}
|
|
374
|
+
this._buildPipeline();
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Get the class name
|
|
378
|
+
* @returns "SSRRenderingPipeline"
|
|
379
|
+
*/
|
|
380
|
+
getClassName() {
|
|
381
|
+
return "SSRRenderingPipeline";
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Adds a camera to the pipeline
|
|
385
|
+
* @param camera the camera to be added
|
|
386
|
+
*/
|
|
387
|
+
addCamera(camera) {
|
|
388
|
+
this._camerasToBeAttached.push(camera);
|
|
389
|
+
this._buildPipeline();
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Removes a camera from the pipeline
|
|
393
|
+
* @param camera the camera to remove
|
|
394
|
+
*/
|
|
395
|
+
removeCamera(camera) {
|
|
396
|
+
const index = this._camerasToBeAttached.indexOf(camera);
|
|
397
|
+
this._camerasToBeAttached.splice(index, 1);
|
|
398
|
+
this._buildPipeline();
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Removes the internal pipeline assets and detaches the pipeline from the scene cameras
|
|
402
|
+
* @param disableGeometryBufferRenderer
|
|
403
|
+
*/
|
|
404
|
+
dispose(disableGeometryBufferRenderer = false) {
|
|
405
|
+
this._disposeDepthRenderer();
|
|
406
|
+
this._disposePostProcesses();
|
|
407
|
+
if (disableGeometryBufferRenderer) {
|
|
408
|
+
this._scene.disableGeometryBufferRenderer();
|
|
409
|
+
}
|
|
410
|
+
this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._cameras);
|
|
411
|
+
super.dispose();
|
|
412
|
+
}
|
|
413
|
+
_getTextureSize() {
|
|
414
|
+
const engine = this._scene.getEngine();
|
|
415
|
+
const geometryBufferRenderer = this._geometryBufferRenderer;
|
|
416
|
+
const prePassRenderer = this._prePassRenderer;
|
|
417
|
+
let textureSize = { width: engine.getRenderWidth(), height: engine.getRenderHeight() };
|
|
418
|
+
if (geometryBufferRenderer) {
|
|
419
|
+
textureSize = geometryBufferRenderer.getGBuffer().textures[0].getSize();
|
|
420
|
+
}
|
|
421
|
+
else if (prePassRenderer) {
|
|
422
|
+
const depthIndex = prePassRenderer.getIndex(5);
|
|
423
|
+
const renderTarget = prePassRenderer.getRenderTarget();
|
|
424
|
+
if (renderTarget && renderTarget.textures) {
|
|
425
|
+
textureSize = renderTarget.textures[depthIndex].getSize();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return textureSize;
|
|
429
|
+
}
|
|
430
|
+
_updateEffectDefines() {
|
|
431
|
+
var _a;
|
|
432
|
+
const defines = [];
|
|
433
|
+
if (this._geometryBufferRenderer || this._prePassRenderer) {
|
|
434
|
+
defines.push("#define SSR_SUPPORTED");
|
|
435
|
+
}
|
|
436
|
+
if (this._enableSmoothReflections) {
|
|
437
|
+
defines.push("#define SSRAYTRACE_ENABLE_REFINEMENT");
|
|
438
|
+
}
|
|
439
|
+
if (this._scene.useRightHandedSystem) {
|
|
440
|
+
defines.push("#define SSRAYTRACE_RIGHT_HANDED_SCENE");
|
|
441
|
+
}
|
|
442
|
+
if (this._environmentTexture) {
|
|
443
|
+
defines.push("#define SSR_USE_ENVIRONMENT_CUBE");
|
|
444
|
+
if (this._environmentTexture.boundingBoxSize) {
|
|
445
|
+
defines.push("#define SSR_USE_LOCAL_REFLECTIONMAP_CUBIC");
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (this._environmentTextureIsProbe) {
|
|
449
|
+
defines.push("#define SSR_INVERTCUBICMAP");
|
|
450
|
+
}
|
|
451
|
+
if (this._enableAutomaticThicknessComputation) {
|
|
452
|
+
defines.push("#define SSRAYTRACE_USE_BACK_DEPTHBUFFER");
|
|
453
|
+
}
|
|
454
|
+
if (this._attenuateScreenBorders) {
|
|
455
|
+
defines.push("#define SSR_ATTENUATE_SCREEN_BORDERS");
|
|
456
|
+
}
|
|
457
|
+
if (this._attenuateIntersectionDistance) {
|
|
458
|
+
defines.push("#define SSR_ATTENUATE_INTERSECTION_DISTANCE");
|
|
459
|
+
}
|
|
460
|
+
if (this._attenuateFacingCamera) {
|
|
461
|
+
defines.push("#define SSR_ATTENUATE_FACING_CAMERA");
|
|
462
|
+
}
|
|
463
|
+
if (this._attenuateBackfaceReflection) {
|
|
464
|
+
defines.push("#define SSR_ATTENUATE_BACKFACE_REFLECTION");
|
|
465
|
+
}
|
|
466
|
+
if (this._clipToFrustum) {
|
|
467
|
+
defines.push("#define SSRAYTRACE_CLIP_TO_FRUSTUM");
|
|
468
|
+
}
|
|
469
|
+
if (this._blurDispersionStrength > 0) {
|
|
470
|
+
defines.push("#define SSR_USE_BLUR");
|
|
471
|
+
}
|
|
472
|
+
if (this._debug) {
|
|
473
|
+
defines.push("#define SSRAYTRACE_DEBUG");
|
|
474
|
+
}
|
|
475
|
+
(_a = this._ssrPostProcess) === null || _a === void 0 ? void 0 : _a.updateEffect(defines.join("\n"));
|
|
476
|
+
}
|
|
477
|
+
_buildPipeline() {
|
|
478
|
+
var _a;
|
|
479
|
+
if (!this._isEnabled) {
|
|
480
|
+
this._isDirty = true;
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
this._isDirty = false;
|
|
484
|
+
const engine = this._scene.getEngine();
|
|
485
|
+
this._disposeDepthRenderer();
|
|
486
|
+
this._disposePostProcesses();
|
|
487
|
+
if (this._cameras !== null) {
|
|
488
|
+
this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._cameras);
|
|
489
|
+
// get back cameras to be used to reattach pipeline
|
|
490
|
+
this._cameras = this._camerasToBeAttached.slice();
|
|
491
|
+
}
|
|
492
|
+
this._reset();
|
|
493
|
+
if (this._enableAutomaticThicknessComputation) {
|
|
494
|
+
const camera = (_a = this._cameras) === null || _a === void 0 ? void 0 : _a[0];
|
|
495
|
+
if (camera) {
|
|
496
|
+
this._depthRendererCamera = camera;
|
|
497
|
+
this._depthRenderer = new DepthRenderer(this._scene, undefined, undefined, undefined, 1, true, "SSRBackDepth");
|
|
498
|
+
this._depthRenderer.clearColor.r = 1e8; // put a big value because we use the storeCameraSpaceZ mode
|
|
499
|
+
this._depthRenderer.reverseCulling = true; // we generate depth for the back faces
|
|
500
|
+
this._depthRenderer.getDepthMap().noPrePassRenderer = true; // we don't want the prepass renderer to attach to our depth buffer!
|
|
501
|
+
this._resizeDepthRenderer();
|
|
502
|
+
camera.customRenderTargets.push(this._depthRenderer.getDepthMap());
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
this._createSSRPostProcess();
|
|
506
|
+
this.addEffect(new PostProcessRenderEffect(engine, this.SSRRenderEffect, () => {
|
|
507
|
+
return this._ssrPostProcess;
|
|
508
|
+
}, true));
|
|
509
|
+
if (this._blurDispersionStrength > 0) {
|
|
510
|
+
this._createBlurAndCombinerPostProcesses();
|
|
511
|
+
this.addEffect(new PostProcessRenderEffect(engine, this.SSRBlurRenderEffect, () => {
|
|
512
|
+
return [this._blurPostProcessX, this._blurPostProcessY];
|
|
513
|
+
}, true));
|
|
514
|
+
this.addEffect(new PostProcessRenderEffect(engine, this.SSRCombineRenderEffect, () => {
|
|
515
|
+
return this._blurCombinerPostProcess;
|
|
516
|
+
}, true));
|
|
517
|
+
}
|
|
518
|
+
if (this._cameras !== null) {
|
|
519
|
+
this._scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this._name, this._cameras);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
_resizeDepthRenderer() {
|
|
523
|
+
if (!this._depthRenderer) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
const textureSize = this._getTextureSize();
|
|
527
|
+
const depthRendererSize = this._depthRenderer.getDepthMap().getSize();
|
|
528
|
+
const width = Math.floor(textureSize.width / this._backfaceDepthTextureSizeFactor);
|
|
529
|
+
const height = Math.floor(textureSize.height / this._backfaceDepthTextureSizeFactor);
|
|
530
|
+
if (depthRendererSize.width !== width || depthRendererSize.height !== height) {
|
|
531
|
+
this._depthRenderer.getDepthMap().resize({ width, height });
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
_disposeDepthRenderer() {
|
|
535
|
+
var _a;
|
|
536
|
+
if (this._depthRenderer) {
|
|
537
|
+
if (this._depthRendererCamera) {
|
|
538
|
+
const idx = (_a = this._depthRendererCamera.customRenderTargets.indexOf(this._depthRenderer.getDepthMap())) !== null && _a !== void 0 ? _a : -1;
|
|
539
|
+
if (idx !== -1) {
|
|
540
|
+
this._depthRendererCamera.customRenderTargets.splice(idx, 1);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
this._depthRendererCamera = null;
|
|
544
|
+
this._depthRenderer.getDepthMap().dispose();
|
|
545
|
+
}
|
|
546
|
+
this._depthRenderer = null;
|
|
547
|
+
}
|
|
548
|
+
_disposePostProcesses() {
|
|
549
|
+
var _a, _b, _c, _d;
|
|
550
|
+
for (let i = 0; i < this._cameras.length; i++) {
|
|
551
|
+
const camera = this._cameras[i];
|
|
552
|
+
(_a = this._ssrPostProcess) === null || _a === void 0 ? void 0 : _a.dispose(camera);
|
|
553
|
+
(_b = this._blurPostProcessX) === null || _b === void 0 ? void 0 : _b.dispose(camera);
|
|
554
|
+
(_c = this._blurPostProcessY) === null || _c === void 0 ? void 0 : _c.dispose(camera);
|
|
555
|
+
(_d = this._blurCombinerPostProcess) === null || _d === void 0 ? void 0 : _d.dispose(camera);
|
|
556
|
+
}
|
|
557
|
+
this._ssrPostProcess = null;
|
|
558
|
+
this._blurPostProcessX = null;
|
|
559
|
+
this._blurPostProcessY = null;
|
|
560
|
+
this._blurCombinerPostProcess = null;
|
|
561
|
+
}
|
|
562
|
+
_createSSRPostProcess() {
|
|
563
|
+
this._ssrPostProcess = new PostProcess("ssr", "screenSpaceReflection2", [
|
|
564
|
+
"projection",
|
|
565
|
+
"invProjectionMatrix",
|
|
566
|
+
"view",
|
|
567
|
+
"invView",
|
|
568
|
+
"thickness",
|
|
569
|
+
"reflectionSpecularFalloffExponent",
|
|
570
|
+
"strength",
|
|
571
|
+
"stepSize",
|
|
572
|
+
"maxSteps",
|
|
573
|
+
"roughnessFactor",
|
|
574
|
+
"projectionPixel",
|
|
575
|
+
"nearPlaneZ",
|
|
576
|
+
"maxDistance",
|
|
577
|
+
"selfCollisionNumSkip",
|
|
578
|
+
"vReflectionPosition",
|
|
579
|
+
"vReflectionSize",
|
|
580
|
+
"backSizeFactor",
|
|
581
|
+
], ["textureSampler", "normalSampler", "reflectivitySampler", "depthSampler", "envCubeSampler", "backDepthSampler"], 1.0, null, this._textureType, this._scene.getEngine(), false, "", this._textureType);
|
|
582
|
+
this._updateEffectDefines();
|
|
583
|
+
this._ssrPostProcess.onApply = (effect) => {
|
|
584
|
+
this._resizeDepthRenderer();
|
|
585
|
+
const geometryBufferRenderer = this._geometryBufferRenderer;
|
|
586
|
+
const prePassRenderer = this._prePassRenderer;
|
|
587
|
+
if (!prePassRenderer && !geometryBufferRenderer) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (geometryBufferRenderer) {
|
|
591
|
+
const roughnessIndex = geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE);
|
|
592
|
+
effect.setTexture("normalSampler", geometryBufferRenderer.getGBuffer().textures[1]);
|
|
593
|
+
effect.setTexture("reflectivitySampler", geometryBufferRenderer.getGBuffer().textures[roughnessIndex]);
|
|
594
|
+
effect.setTexture("depthSampler", geometryBufferRenderer.getGBuffer().textures[0]);
|
|
595
|
+
}
|
|
596
|
+
else if (prePassRenderer) {
|
|
597
|
+
const depthIndex = prePassRenderer.getIndex(5);
|
|
598
|
+
const roughnessIndex = prePassRenderer.getIndex(3);
|
|
599
|
+
const normalIndex = prePassRenderer.getIndex(6);
|
|
600
|
+
effect.setTexture("normalSampler", prePassRenderer.getRenderTarget().textures[normalIndex]);
|
|
601
|
+
effect.setTexture("depthSampler", prePassRenderer.getRenderTarget().textures[depthIndex]);
|
|
602
|
+
effect.setTexture("reflectivitySampler", prePassRenderer.getRenderTarget().textures[roughnessIndex]);
|
|
603
|
+
}
|
|
604
|
+
if (this._enableAutomaticThicknessComputation && this._depthRenderer) {
|
|
605
|
+
effect.setTexture("backDepthSampler", this._depthRenderer.getDepthMap());
|
|
606
|
+
effect.setFloat("backSizeFactor", this._backfaceDepthTextureSizeFactor);
|
|
607
|
+
}
|
|
608
|
+
const camera = this._scene.activeCamera;
|
|
609
|
+
if (!camera) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const viewMatrix = camera.getViewMatrix(true);
|
|
613
|
+
const projectionMatrix = camera.getProjectionMatrix(true);
|
|
614
|
+
projectionMatrix.invertToRef(TmpVectors.Matrix[0]);
|
|
615
|
+
viewMatrix.invertToRef(TmpVectors.Matrix[1]);
|
|
616
|
+
effect.setMatrix("projection", projectionMatrix);
|
|
617
|
+
effect.setMatrix("view", viewMatrix);
|
|
618
|
+
effect.setMatrix("invView", TmpVectors.Matrix[1]);
|
|
619
|
+
effect.setMatrix("invProjectionMatrix", TmpVectors.Matrix[0]);
|
|
620
|
+
effect.setFloat("thickness", this.thickness);
|
|
621
|
+
effect.setFloat("reflectionSpecularFalloffExponent", this.reflectionSpecularFalloffExponent);
|
|
622
|
+
effect.setFloat("strength", this.strength);
|
|
623
|
+
effect.setFloat("stepSize", this.step);
|
|
624
|
+
effect.setFloat("maxSteps", this.maxSteps);
|
|
625
|
+
effect.setFloat("roughnessFactor", this.roughnessFactor);
|
|
626
|
+
effect.setFloat("nearPlaneZ", camera.minZ);
|
|
627
|
+
effect.setFloat("maxDistance", this.maxDistance);
|
|
628
|
+
effect.setFloat("selfCollisionNumSkip", this.selfCollisionNumSkip);
|
|
629
|
+
const textureSize = this._getTextureSize();
|
|
630
|
+
Matrix.ScalingToRef(textureSize.width, textureSize.height, 1, TmpVectors.Matrix[2]);
|
|
631
|
+
projectionMatrix.multiplyToRef(this._scene.getEngine().isWebGPU ? trsWebGPU : trs, TmpVectors.Matrix[3]);
|
|
632
|
+
TmpVectors.Matrix[3].multiplyToRef(TmpVectors.Matrix[2], TmpVectors.Matrix[4]);
|
|
633
|
+
effect.setMatrix("projectionPixel", TmpVectors.Matrix[4]);
|
|
634
|
+
if (this._environmentTexture) {
|
|
635
|
+
effect.setTexture("envCubeSampler", this._environmentTexture);
|
|
636
|
+
if (this._environmentTexture.boundingBoxSize) {
|
|
637
|
+
effect.setVector3("vReflectionPosition", this._environmentTexture.boundingBoxPosition);
|
|
638
|
+
effect.setVector3("vReflectionSize", this._environmentTexture.boundingBoxSize);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
this._ssrPostProcess.samples = this.samples;
|
|
643
|
+
if (!this._forceGeometryBuffer) {
|
|
644
|
+
this._ssrPostProcess._prePassEffectConfiguration = new ScreenSpaceReflections2Configuration();
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
_createBlurAndCombinerPostProcesses() {
|
|
648
|
+
const engine = this._scene.getEngine();
|
|
649
|
+
this._blurPostProcessX = new PostProcess("SSRblurX", "screenSpaceReflection2Blur", ["blurQuality", "texelOffsetScale"], ["textureSampler"], 1, null, 2, engine, false, "", this._textureType);
|
|
650
|
+
this._blurPostProcessX.autoClear = false;
|
|
651
|
+
this._blurPostProcessX.onApplyObservable.add((effect) => {
|
|
652
|
+
var _a, _b;
|
|
653
|
+
let width = this._scene.getEngine().getRenderWidth();
|
|
654
|
+
if (this._prePassRenderer) {
|
|
655
|
+
const colorIndex = this._prePassRenderer.getIndex(4);
|
|
656
|
+
const renderTarget = this._prePassRenderer.getRenderTarget();
|
|
657
|
+
if (renderTarget && renderTarget.textures) {
|
|
658
|
+
width = renderTarget.textures[colorIndex].getSize().width;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
width = (_b = (_a = this._ssrPostProcess) === null || _a === void 0 ? void 0 : _a.inputTexture.width) !== null && _b !== void 0 ? _b : width;
|
|
663
|
+
}
|
|
664
|
+
effect.setFloat("blurQuality", this.blurQuality);
|
|
665
|
+
effect.setFloat2("texelOffsetScale", this._blurDispersionStrength / width, 0);
|
|
666
|
+
});
|
|
667
|
+
this._blurPostProcessY = new PostProcess("SSRblurY", "screenSpaceReflection2Blur", ["blurQuality", "texelOffsetScale"], ["textureSampler"], 1, null, 2, engine, false, "", this._textureType);
|
|
668
|
+
this._blurPostProcessY.autoClear = false;
|
|
669
|
+
this._blurPostProcessY.onApplyObservable.add((effect) => {
|
|
670
|
+
var _a, _b;
|
|
671
|
+
let height = this._scene.getEngine().getRenderHeight();
|
|
672
|
+
if (this._prePassRenderer) {
|
|
673
|
+
const colorIndex = this._prePassRenderer.getIndex(4);
|
|
674
|
+
const renderTarget = this._prePassRenderer.getRenderTarget();
|
|
675
|
+
if (renderTarget && renderTarget.textures) {
|
|
676
|
+
height = renderTarget.textures[colorIndex].getSize().height;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
height = (_b = (_a = this._ssrPostProcess) === null || _a === void 0 ? void 0 : _a.inputTexture.height) !== null && _b !== void 0 ? _b : height;
|
|
681
|
+
}
|
|
682
|
+
effect.setFloat("blurQuality", this.blurQuality);
|
|
683
|
+
effect.setFloat2("texelOffsetScale", 0, this._blurDispersionStrength / height);
|
|
684
|
+
});
|
|
685
|
+
this._blurCombinerPostProcess = new PostProcess("SSRblurCombiner", "screenSpaceReflection2BlurCombiner", ["strength", "reflectionSpecularFalloffExponent"], ["textureSampler", "mainSampler", "reflectivitySampler"], 1, null, 1, engine, false, "", this._textureType);
|
|
686
|
+
this._blurCombinerPostProcess.autoClear = false;
|
|
687
|
+
this._blurCombinerPostProcess.onApplyObservable.add((effect) => {
|
|
688
|
+
const geometryBufferRenderer = this._geometryBufferRenderer;
|
|
689
|
+
const prePassRenderer = this._prePassRenderer;
|
|
690
|
+
if (!prePassRenderer && !geometryBufferRenderer) {
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
if (prePassRenderer) {
|
|
694
|
+
const colorIndex = prePassRenderer.getIndex(4);
|
|
695
|
+
const renderTarget = prePassRenderer.getRenderTarget();
|
|
696
|
+
if (renderTarget && renderTarget.textures) {
|
|
697
|
+
effect.setTexture("mainSampler", renderTarget.textures[colorIndex]);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
effect._bindTexture("mainSampler", this._ssrPostProcess.inputTexture.texture);
|
|
702
|
+
}
|
|
703
|
+
if (geometryBufferRenderer) {
|
|
704
|
+
const roughnessIndex = geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.REFLECTIVITY_TEXTURE_TYPE);
|
|
705
|
+
effect.setTexture("reflectivitySampler", geometryBufferRenderer.getGBuffer().textures[roughnessIndex]);
|
|
706
|
+
}
|
|
707
|
+
else if (prePassRenderer) {
|
|
708
|
+
const roughnessIndex = prePassRenderer.getIndex(3);
|
|
709
|
+
effect.setTexture("reflectivitySampler", prePassRenderer.getRenderTarget().textures[roughnessIndex]);
|
|
710
|
+
}
|
|
711
|
+
effect.setFloat("strength", this.strength);
|
|
712
|
+
effect.setFloat("reflectionSpecularFalloffExponent", this.reflectionSpecularFalloffExponent);
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Serializes the rendering pipeline (Used when exporting)
|
|
717
|
+
* @returns the serialized object
|
|
718
|
+
*/
|
|
719
|
+
serialize() {
|
|
720
|
+
const serializationObject = SerializationHelper.Serialize(this);
|
|
721
|
+
serializationObject.customType = "SSRRenderingPipeline";
|
|
722
|
+
return serializationObject;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Parse the serialized pipeline
|
|
726
|
+
* @param source Source pipeline.
|
|
727
|
+
* @param scene The scene to load the pipeline to.
|
|
728
|
+
* @param rootUrl The URL of the serialized pipeline.
|
|
729
|
+
* @returns An instantiated pipeline from the serialized object.
|
|
730
|
+
*/
|
|
731
|
+
static Parse(source, scene, rootUrl) {
|
|
732
|
+
return SerializationHelper.Parse(() => new SSRRenderingPipeline(source._name, scene, source._ratio), source, scene, rootUrl);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
__decorate([
|
|
736
|
+
serialize()
|
|
737
|
+
], SSRRenderingPipeline.prototype, "samples", null);
|
|
738
|
+
__decorate([
|
|
739
|
+
serialize()
|
|
740
|
+
], SSRRenderingPipeline.prototype, "maxDistance", void 0);
|
|
741
|
+
__decorate([
|
|
742
|
+
serialize()
|
|
743
|
+
], SSRRenderingPipeline.prototype, "step", void 0);
|
|
744
|
+
__decorate([
|
|
745
|
+
serialize()
|
|
746
|
+
], SSRRenderingPipeline.prototype, "thickness", void 0);
|
|
747
|
+
__decorate([
|
|
748
|
+
serialize()
|
|
749
|
+
], SSRRenderingPipeline.prototype, "strength", void 0);
|
|
750
|
+
__decorate([
|
|
751
|
+
serialize()
|
|
752
|
+
], SSRRenderingPipeline.prototype, "reflectionSpecularFalloffExponent", void 0);
|
|
753
|
+
__decorate([
|
|
754
|
+
serialize()
|
|
755
|
+
], SSRRenderingPipeline.prototype, "maxSteps", void 0);
|
|
756
|
+
__decorate([
|
|
757
|
+
serialize()
|
|
758
|
+
], SSRRenderingPipeline.prototype, "roughnessFactor", void 0);
|
|
759
|
+
__decorate([
|
|
760
|
+
serialize()
|
|
761
|
+
], SSRRenderingPipeline.prototype, "selfCollisionNumSkip", void 0);
|
|
762
|
+
__decorate([
|
|
763
|
+
serialize("blurDispersionStrength")
|
|
764
|
+
], SSRRenderingPipeline.prototype, "_blurDispersionStrength", void 0);
|
|
765
|
+
__decorate([
|
|
766
|
+
serialize()
|
|
767
|
+
], SSRRenderingPipeline.prototype, "blurQuality", void 0);
|
|
768
|
+
__decorate([
|
|
769
|
+
serialize("enableSmoothReflections")
|
|
770
|
+
], SSRRenderingPipeline.prototype, "_enableSmoothReflections", void 0);
|
|
771
|
+
__decorate([
|
|
772
|
+
serialize("environmentTexture")
|
|
773
|
+
], SSRRenderingPipeline.prototype, "_environmentTexture", void 0);
|
|
774
|
+
__decorate([
|
|
775
|
+
serialize("environmentTextureIsProbe")
|
|
776
|
+
], SSRRenderingPipeline.prototype, "_environmentTextureIsProbe", void 0);
|
|
777
|
+
__decorate([
|
|
778
|
+
serialize("attenuateScreenBorders")
|
|
779
|
+
], SSRRenderingPipeline.prototype, "_attenuateScreenBorders", void 0);
|
|
780
|
+
__decorate([
|
|
781
|
+
serialize("attenuateIntersectionDistance")
|
|
782
|
+
], SSRRenderingPipeline.prototype, "_attenuateIntersectionDistance", void 0);
|
|
783
|
+
__decorate([
|
|
784
|
+
serialize("attenuateFacingCamera")
|
|
785
|
+
], SSRRenderingPipeline.prototype, "_attenuateFacingCamera", void 0);
|
|
786
|
+
__decorate([
|
|
787
|
+
serialize("attenuateBackfaceReflection")
|
|
788
|
+
], SSRRenderingPipeline.prototype, "_attenuateBackfaceReflection", void 0);
|
|
789
|
+
__decorate([
|
|
790
|
+
serialize("clipToFrustum")
|
|
791
|
+
], SSRRenderingPipeline.prototype, "_clipToFrustum", void 0);
|
|
792
|
+
__decorate([
|
|
793
|
+
serialize("enableAutomaticThicknessComputation")
|
|
794
|
+
], SSRRenderingPipeline.prototype, "_enableAutomaticThicknessComputation", void 0);
|
|
795
|
+
__decorate([
|
|
796
|
+
serialize("backfaceDepthTextureSizeFactor")
|
|
797
|
+
], SSRRenderingPipeline.prototype, "_backfaceDepthTextureSizeFactor", void 0);
|
|
798
|
+
__decorate([
|
|
799
|
+
serialize("isEnabled")
|
|
800
|
+
], SSRRenderingPipeline.prototype, "_isEnabled", void 0);
|
|
801
|
+
__decorate([
|
|
802
|
+
serialize("debug")
|
|
803
|
+
], SSRRenderingPipeline.prototype, "_debug", void 0);
|
|
804
|
+
RegisterClass("BABYLON.SSRRenderingPipeline", SSRRenderingPipeline);
|
|
805
|
+
//# sourceMappingURL=ssrRenderingPipeline.js.map
|