@babylonjs/core 7.22.2 → 7.22.4
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/Animations/animationGroup.js +1 -1
- package/Animations/animationGroup.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/constants.d.ts +21 -1
- package/Engines/constants.js +21 -1
- package/Engines/constants.js.map +1 -1
- package/Engines/engineFeatures.d.ts +2 -0
- package/Engines/engineFeatures.js.map +1 -1
- package/Engines/nativeEngine.js +7 -1
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/nullEngine.js +1 -0
- package/Engines/nullEngine.js.map +1 -1
- package/Engines/thinEngine.js +2 -0
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +1 -0
- package/Engines/webgpuEngine.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/prePassOutputBlock.d.ts +12 -0
- package/Materials/Node/Blocks/Fragment/prePassOutputBlock.js +51 -0
- package/Materials/Node/Blocks/Fragment/prePassOutputBlock.js.map +1 -1
- package/Materials/Node/Blocks/Input/prePassTextureBlock.d.ts +27 -0
- package/Materials/Node/Blocks/Input/prePassTextureBlock.js +69 -0
- package/Materials/Node/Blocks/Input/prePassTextureBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +12 -0
- package/Materials/Node/nodeMaterial.js +24 -0
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.d.ts +8 -0
- package/Materials/PBR/pbrBaseMaterial.js +8 -0
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.d.ts +4 -0
- package/Materials/Textures/Procedurals/proceduralTexture.js +19 -5
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/materialHelper.functions.js +20 -0
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Materials/prePassConfiguration.js +2 -1
- package/Materials/prePassConfiguration.js.map +1 -1
- package/Materials/standardMaterial.d.ts +8 -0
- package/Materials/standardMaterial.js +8 -0
- package/Materials/standardMaterial.js.map +1 -1
- package/Misc/fileTools.js +1 -1
- package/Misc/fileTools.js.map +1 -1
- package/PostProcesses/postProcessManager.d.ts +2 -0
- package/PostProcesses/postProcessManager.js +3 -0
- package/PostProcesses/postProcessManager.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js +79 -8
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.d.ts +88 -0
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js +240 -0
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.d.ts +88 -0
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js +231 -0
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.d.ts +340 -0
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +884 -0
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.d.ts +67 -0
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js +139 -0
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.d.ts +168 -0
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +597 -0
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.d.ts +151 -0
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +291 -0
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -0
- package/Rendering/depthRenderer.js +44 -23
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/index.d.ts +1 -0
- package/Rendering/index.js +1 -0
- package/Rendering/index.js.map +1 -1
- package/Rendering/outlineRenderer.js +3 -3
- package/Rendering/outlineRenderer.js.map +1 -1
- package/Rendering/prePassRenderer.js +25 -1
- package/Rendering/prePassRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/instancesDeclaration.js +4 -2
- package/Shaders/ShadersInclude/instancesDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/instancesVertex.js +8 -4
- package/Shaders/ShadersInclude/instancesVertex.js.map +1 -1
- package/Shaders/ShadersInclude/prePassDeclaration.js +4 -1
- package/Shaders/ShadersInclude/prePassDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/prePassVertex.js +5 -1
- package/Shaders/ShadersInclude/prePassVertex.js.map +1 -1
- package/Shaders/ShadersInclude/prePassVertexDeclaration.js +4 -1
- package/Shaders/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
- package/Shaders/combineVoxelGrids.fragment.d.ts +5 -0
- package/Shaders/combineVoxelGrids.fragment.js +9 -0
- package/Shaders/combineVoxelGrids.fragment.js.map +1 -0
- package/Shaders/copyTexture3DLayerToTexture.fragment.d.ts +5 -0
- package/Shaders/copyTexture3DLayerToTexture.fragment.js +10 -0
- package/Shaders/copyTexture3DLayerToTexture.fragment.js.map +1 -0
- package/Shaders/default.fragment.js +31 -6
- package/Shaders/default.fragment.js.map +1 -1
- package/Shaders/default.vertex.js +6 -2
- package/Shaders/default.vertex.js.map +1 -1
- package/Shaders/generateVoxelMip.fragment.d.ts +5 -0
- package/Shaders/generateVoxelMip.fragment.js +25 -0
- package/Shaders/generateVoxelMip.fragment.js.map +1 -0
- package/Shaders/geometry.fragment.js +1 -1
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/iblShadowAccumulation.fragment.d.ts +5 -0
- package/Shaders/iblShadowAccumulation.fragment.js +27 -0
- package/Shaders/iblShadowAccumulation.fragment.js.map +1 -0
- package/Shaders/iblShadowDebug.fragment.d.ts +5 -0
- package/Shaders/iblShadowDebug.fragment.js +18 -0
- package/Shaders/iblShadowDebug.fragment.js.map +1 -0
- package/Shaders/iblShadowGBufferDebug.fragment.d.ts +5 -0
- package/Shaders/iblShadowGBufferDebug.fragment.js +19 -0
- package/Shaders/iblShadowGBufferDebug.fragment.js.map +1 -0
- package/Shaders/iblShadowSpatialBlur.fragment.d.ts +5 -0
- package/Shaders/iblShadowSpatialBlur.fragment.js +21 -0
- package/Shaders/iblShadowSpatialBlur.fragment.js.map +1 -0
- package/Shaders/iblShadowVoxelTracing.fragment.d.ts +5 -0
- package/Shaders/iblShadowVoxelTracing.fragment.js +152 -0
- package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -0
- package/Shaders/iblShadowsCdfx.fragment.d.ts +5 -0
- package/Shaders/iblShadowsCdfx.fragment.js +12 -0
- package/Shaders/iblShadowsCdfx.fragment.js.map +1 -0
- package/Shaders/iblShadowsCdfy.fragment.d.ts +5 -0
- package/Shaders/iblShadowsCdfy.fragment.js +33 -0
- package/Shaders/iblShadowsCdfy.fragment.js.map +1 -0
- package/Shaders/iblShadowsCombine.fragment.d.ts +5 -0
- package/Shaders/iblShadowsCombine.fragment.js +10 -0
- package/Shaders/iblShadowsCombine.fragment.js.map +1 -0
- package/Shaders/iblShadowsIcdfx.fragment.d.ts +5 -0
- package/Shaders/iblShadowsIcdfx.fragment.js +19 -0
- package/Shaders/iblShadowsIcdfx.fragment.js.map +1 -0
- package/Shaders/iblShadowsIcdfy.fragment.d.ts +5 -0
- package/Shaders/iblShadowsIcdfy.fragment.js +19 -0
- package/Shaders/iblShadowsIcdfy.fragment.js.map +1 -0
- package/Shaders/iblShadowsImportanceSamplingDebug.fragment.d.ts +5 -0
- package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js +48 -0
- package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js.map +1 -0
- package/Shaders/pbr.fragment.js +32 -7
- package/Shaders/pbr.fragment.js.map +1 -1
- package/Shaders/pbr.vertex.js +3 -1
- package/Shaders/pbr.vertex.js.map +1 -1
- package/Shaders/voxelGrid.fragment.d.ts +5 -0
- package/Shaders/voxelGrid.fragment.js +14 -0
- package/Shaders/voxelGrid.fragment.js.map +1 -0
- package/Shaders/voxelGrid.vertex.d.ts +5 -0
- package/Shaders/voxelGrid.vertex.js +9 -0
- package/Shaders/voxelGrid.vertex.js.map +1 -0
- package/Shaders/voxelGrid2dArrayDebug.fragment.d.ts +5 -0
- package/Shaders/voxelGrid2dArrayDebug.fragment.js +9 -0
- package/Shaders/voxelGrid2dArrayDebug.fragment.js.map +1 -0
- package/Shaders/voxelGrid3dDebug.fragment.d.ts +5 -0
- package/Shaders/voxelGrid3dDebug.fragment.js +22 -0
- package/Shaders/voxelGrid3dDebug.fragment.js.map +1 -0
- package/Shaders/voxelSlabDebug.fragment.d.ts +5 -0
- package/Shaders/voxelSlabDebug.fragment.js +11 -0
- package/Shaders/voxelSlabDebug.fragment.js.map +1 -0
- package/Shaders/voxelSlabDebug.vertex.d.ts +5 -0
- package/Shaders/voxelSlabDebug.vertex.js +9 -0
- package/Shaders/voxelSlabDebug.vertex.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/instancesDeclaration.js +4 -2
- package/ShadersWGSL/ShadersInclude/instancesDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/instancesVertex.js +9 -4
- package/ShadersWGSL/ShadersInclude/instancesVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/prePassDeclaration.js +4 -1
- package/ShadersWGSL/ShadersInclude/prePassDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/prePassVertex.js +5 -1
- package/ShadersWGSL/ShadersInclude/prePassVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js +4 -1
- package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
- package/ShadersWGSL/default.fragment.js +42 -16
- package/ShadersWGSL/default.fragment.js.map +1 -1
- package/ShadersWGSL/default.vertex.js +5 -2
- package/ShadersWGSL/default.vertex.js.map +1 -1
- package/ShadersWGSL/geometry.fragment.js +1 -1
- package/ShadersWGSL/geometry.fragment.js.map +1 -1
- package/ShadersWGSL/pbr.fragment.js +37 -20
- package/ShadersWGSL/pbr.fragment.js.map +1 -1
- package/ShadersWGSL/pbr.vertex.js +1 -1
- package/ShadersWGSL/pbr.vertex.js.map +1 -1
- package/package.json +1 -1
- package/sceneComponent.d.ts +1 -0
- package/sceneComponent.js +1 -0
- package/sceneComponent.js.map +1 -1
|
@@ -0,0 +1,884 @@
|
|
|
1
|
+
|
|
2
|
+
import { EngineStore } from "../../Engines/engineStore.js";
|
|
3
|
+
import { Matrix, Vector3, Vector4, Quaternion } from "../../Maths/math.vector.js";
|
|
4
|
+
import { Mesh } from "../../Meshes/mesh.js";
|
|
5
|
+
import { Texture } from "../../Materials/Textures/texture.js";
|
|
6
|
+
import { PrePassRenderer } from "../prePassRenderer.js";
|
|
7
|
+
import { Logger } from "../../Misc/logger.js";
|
|
8
|
+
import { _IblShadowsVoxelRenderer } from "./iblShadowsVoxelRenderer.js";
|
|
9
|
+
import { _IblShadowsVoxelTracingPass } from "./iblShadowsVoxelTracingPass.js";
|
|
10
|
+
import "../../Shaders/postprocess.vertex.js";
|
|
11
|
+
import "../../Shaders/iblShadowGBufferDebug.fragment.js";
|
|
12
|
+
import "../../Shaders/iblShadowsCombine.fragment.js";
|
|
13
|
+
import { PostProcess } from "../../PostProcesses/postProcess.js";
|
|
14
|
+
import { _IblShadowsImportanceSamplingRenderer } from "./iblShadowsImportanceSamplingRenderer.js";
|
|
15
|
+
import { _IblShadowsSpatialBlurPass } from "./iblShadowsSpatialBlurPass.js";
|
|
16
|
+
import { _IblShadowsAccumulationPass } from "./iblShadowsAccumulationPass.js";
|
|
17
|
+
import { ArcRotateCamera } from "../../Cameras/arcRotateCamera.js";
|
|
18
|
+
import { FreeCamera } from "../../Cameras/freeCamera.js";
|
|
19
|
+
import { PostProcessRenderPipeline } from "../../PostProcesses/RenderPipeline/postProcessRenderPipeline.js";
|
|
20
|
+
import { PostProcessRenderEffect } from "../../PostProcesses/RenderPipeline/postProcessRenderEffect.js";
|
|
21
|
+
class IblShadowsPrepassConfiguration {
|
|
22
|
+
constructor() {
|
|
23
|
+
/**
|
|
24
|
+
* Is this effect enabled
|
|
25
|
+
*/
|
|
26
|
+
this.enabled = true;
|
|
27
|
+
/**
|
|
28
|
+
* Name of the configuration
|
|
29
|
+
*/
|
|
30
|
+
this.name = "iblShadows";
|
|
31
|
+
/**
|
|
32
|
+
* Textures that should be present in the MRT for this effect to work
|
|
33
|
+
*/
|
|
34
|
+
this.texturesRequired = [
|
|
35
|
+
5,
|
|
36
|
+
10,
|
|
37
|
+
8,
|
|
38
|
+
// 6, // TODO - don't need this for IBL shadows
|
|
39
|
+
11,
|
|
40
|
+
// Local positions used for shadow accumulation pass
|
|
41
|
+
1,
|
|
42
|
+
9,
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Voxel-based shadow rendering for IBL's.
|
|
48
|
+
* This should not be instanciated directly, as it is part of a scene component
|
|
49
|
+
*/
|
|
50
|
+
export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
51
|
+
/**
|
|
52
|
+
* How dark the shadows appear. 1.0 is full opacity, 0.0 is no shadows.
|
|
53
|
+
*/
|
|
54
|
+
get shadowOpacity() {
|
|
55
|
+
return this._shadowOpacity;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* How dark the shadows appear. 1.0 is full opacity, 0.0 is no shadows.
|
|
59
|
+
*/
|
|
60
|
+
set shadowOpacity(value) {
|
|
61
|
+
this._shadowOpacity = value;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* How dark the voxel shadows appear. 1.0 is full opacity, 0.0 is no shadows.
|
|
65
|
+
*/
|
|
66
|
+
get voxelShadowOpacity() {
|
|
67
|
+
return this._voxelTracingPass?.voxelShadowOpacity;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* How dark the voxel shadows appear. 1.0 is full opacity, 0.0 is no shadows.
|
|
71
|
+
*/
|
|
72
|
+
set voxelShadowOpacity(value) {
|
|
73
|
+
if (!this._voxelTracingPass)
|
|
74
|
+
return;
|
|
75
|
+
this._voxelTracingPass.voxelShadowOpacity = value;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* How dark the screen-space shadows appear. 1.0 is full opacity, 0.0 is no shadows.
|
|
79
|
+
*/
|
|
80
|
+
get ssShadowOpacity() {
|
|
81
|
+
return this._voxelTracingPass?.ssShadowOpacity;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* How dark the screen-space shadows appear. 1.0 is full opacity, 0.0 is no shadows.
|
|
85
|
+
*/
|
|
86
|
+
set ssShadowOpacity(value) {
|
|
87
|
+
if (!this._voxelTracingPass)
|
|
88
|
+
return;
|
|
89
|
+
this._voxelTracingPass.ssShadowOpacity = value;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The number of samples used in the screen space shadow pass.
|
|
93
|
+
*/
|
|
94
|
+
get ssShadowSamples() {
|
|
95
|
+
return this._voxelTracingPass?.sssSamples;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The number of samples used in the screen space shadow pass.
|
|
99
|
+
*/
|
|
100
|
+
set ssShadowSamples(value) {
|
|
101
|
+
if (!this._voxelTracingPass)
|
|
102
|
+
return;
|
|
103
|
+
this._voxelTracingPass.sssSamples = value;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The stride of the screen-space shadow pass. This controls the distance between samples.
|
|
107
|
+
*/
|
|
108
|
+
get ssShadowStride() {
|
|
109
|
+
return this._voxelTracingPass?.sssStride;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The stride of the screen-space shadow pass. This controls the distance between samples.
|
|
113
|
+
*/
|
|
114
|
+
set ssShadowStride(value) {
|
|
115
|
+
if (!this._voxelTracingPass)
|
|
116
|
+
return;
|
|
117
|
+
this._voxelTracingPass.sssStride = value;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The maximum distance a shadow can be cast in screen space. This should usually be kept small
|
|
121
|
+
* as screenspace shadows are mostly useful for small details.
|
|
122
|
+
*/
|
|
123
|
+
get ssShadowMaxDist() {
|
|
124
|
+
return this._voxelTracingPass?.sssMaxDist;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The maximum distance a shadow can be cast in screen space. This should usually be kept small
|
|
128
|
+
* as screenspace shadows are mostly useful for small details.
|
|
129
|
+
*/
|
|
130
|
+
set ssShadowMaxDist(value) {
|
|
131
|
+
if (!this._voxelTracingPass)
|
|
132
|
+
return;
|
|
133
|
+
this._voxelTracingPass.sssMaxDist = value;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Screen-space shadow thickness. This value controls the perceived thickness of the SS shadows.
|
|
137
|
+
*/
|
|
138
|
+
get ssShadowThickness() {
|
|
139
|
+
return this._voxelTracingPass?.sssThickness;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Screen-space shadow thickness. This value controls the perceived thickness of the SS shadows.
|
|
143
|
+
*/
|
|
144
|
+
set ssShadowThickness(value) {
|
|
145
|
+
if (!this._voxelTracingPass)
|
|
146
|
+
return;
|
|
147
|
+
this._voxelTracingPass.sssThickness = value;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Set the IBL image to be used for shadowing. It can be either a cubemap
|
|
151
|
+
* or a 2D equirectangular texture.
|
|
152
|
+
* @param iblSource The texture to use for IBL shadowing
|
|
153
|
+
*/
|
|
154
|
+
setIblTexture(iblSource) {
|
|
155
|
+
if (!this._importanceSamplingRenderer)
|
|
156
|
+
return;
|
|
157
|
+
this._importanceSamplingRenderer.iblSource = iblSource;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns the texture containing the voxel grid data
|
|
161
|
+
* @returns The texture containing the voxel grid data
|
|
162
|
+
*/
|
|
163
|
+
getVoxelGridTexture() {
|
|
164
|
+
return this._voxelRenderer?.getVoxelGrid();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Returns the texture containing the importance sampling CDF data for the IBL shadow pipeline
|
|
168
|
+
* @returns The texture containing the importance sampling CDF data for the IBL shadow pipeline
|
|
169
|
+
*/
|
|
170
|
+
getIcdfyTexture() {
|
|
171
|
+
return this._importanceSamplingRenderer.getIcdfyTexture();
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Returns the texture containing the importance sampling CDF data for the IBL shadow pipeline
|
|
175
|
+
* @returns The texture containing the importance sampling CDF data for the IBL shadow pipeline
|
|
176
|
+
*/
|
|
177
|
+
getIcdfxTexture() {
|
|
178
|
+
return this._importanceSamplingRenderer.getIcdfxTexture();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Is the debug view of the G-Buffer enabled?
|
|
182
|
+
*/
|
|
183
|
+
get gbufferDebugEnabled() {
|
|
184
|
+
return this._gbufferDebugEnabled;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Turn on or off the debug view of the G-Buffer
|
|
188
|
+
*/
|
|
189
|
+
set gbufferDebugEnabled(enabled) {
|
|
190
|
+
if (enabled && !this.allowDebugPasses) {
|
|
191
|
+
Logger.Warn("Can't enable G-Buffer debug view without setting allowDebugPasses to true.");
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
this._gbufferDebugEnabled = enabled;
|
|
195
|
+
if (enabled) {
|
|
196
|
+
this._enableEffect(this._getGBufferDebugPass().name, this.cameras);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
this._disableEffect(this._getGBufferDebugPass().name, this.cameras);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Turn on or off the debug view of the CDF importance sampling data
|
|
204
|
+
*/
|
|
205
|
+
get importanceSamplingDebugEnabled() {
|
|
206
|
+
return this._importanceSamplingRenderer?.debugEnabled;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Turn on or off the debug view of the CDF importance sampling data
|
|
210
|
+
*/
|
|
211
|
+
set importanceSamplingDebugEnabled(enabled) {
|
|
212
|
+
if (!this._importanceSamplingRenderer)
|
|
213
|
+
return;
|
|
214
|
+
if (enabled && !this.allowDebugPasses) {
|
|
215
|
+
Logger.Warn("Can't enable importance sampling debug view without setting allowDebugPasses to true.");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (enabled === this._importanceSamplingRenderer.debugEnabled)
|
|
219
|
+
return;
|
|
220
|
+
this._importanceSamplingRenderer.debugEnabled = enabled;
|
|
221
|
+
if (enabled) {
|
|
222
|
+
this._enableEffect(this._importanceSamplingRenderer.debugPassName, this.cameras);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
this._disableEffect(this._importanceSamplingRenderer.debugPassName, this.cameras);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Turn on or off the debug view of the voxel grid
|
|
230
|
+
*/
|
|
231
|
+
get voxelDebugEnabled() {
|
|
232
|
+
return this._voxelRenderer?.voxelDebugEnabled;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Turn on or off the debug view of the voxel grid
|
|
236
|
+
*/
|
|
237
|
+
set voxelDebugEnabled(enabled) {
|
|
238
|
+
if (!this._voxelRenderer)
|
|
239
|
+
return;
|
|
240
|
+
if (enabled && !this.allowDebugPasses) {
|
|
241
|
+
Logger.Warn("Can't enable voxel debug view without setting allowDebugPasses to true.");
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
this._voxelRenderer.voxelDebugEnabled = enabled;
|
|
245
|
+
if (enabled) {
|
|
246
|
+
this._enableEffect(this._voxelRenderer.debugPassName, this.cameras);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
this._disableEffect(this._voxelRenderer.debugPassName, this.cameras);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Set the axis to display for the voxel grid debug view
|
|
254
|
+
* When using tri-axis voxelization, this will display the voxel grid for the specified axis
|
|
255
|
+
*/
|
|
256
|
+
get voxelDebugAxis() {
|
|
257
|
+
return this._voxelRenderer?.voxelDebugAxis;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Set the axis to display for the voxel grid debug view
|
|
261
|
+
* When using tri-axis voxelization, this will display the voxel grid for the specified axis
|
|
262
|
+
*/
|
|
263
|
+
set voxelDebugAxis(axisNum) {
|
|
264
|
+
if (!this._voxelRenderer)
|
|
265
|
+
return;
|
|
266
|
+
this._voxelRenderer.voxelDebugAxis = axisNum;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Set the mip level to display for the voxel grid debug view
|
|
270
|
+
*/
|
|
271
|
+
set voxelDebugDisplayMip(mipNum) {
|
|
272
|
+
if (!this._voxelRenderer)
|
|
273
|
+
return;
|
|
274
|
+
this._voxelRenderer.setDebugMipNumber(mipNum);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Display the debug view for the voxel tracing pass
|
|
278
|
+
*/
|
|
279
|
+
get voxelTracingDebugEnabled() {
|
|
280
|
+
return this._voxelTracingPass?.debugEnabled;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Display the debug view for the voxel tracing pass
|
|
284
|
+
*/
|
|
285
|
+
set voxelTracingDebugEnabled(enabled) {
|
|
286
|
+
if (!this._voxelTracingPass)
|
|
287
|
+
return;
|
|
288
|
+
if (enabled && !this.allowDebugPasses) {
|
|
289
|
+
Logger.Warn("Can't enable voxel tracing debug view without setting allowDebugPasses to true.");
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (enabled === this._voxelTracingPass.debugEnabled)
|
|
293
|
+
return;
|
|
294
|
+
this._voxelTracingPass.debugEnabled = enabled;
|
|
295
|
+
if (enabled) {
|
|
296
|
+
this._enableEffect(this._voxelTracingPass.debugPassName, this.cameras);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
this._disableEffect(this._voxelTracingPass.debugPassName, this.cameras);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Display the debug view for the spatial blur pass
|
|
304
|
+
*/
|
|
305
|
+
get spatialBlurPassDebugEnabled() {
|
|
306
|
+
return this._spatialBlurPass?.debugEnabled;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Display the debug view for the spatial blur pass
|
|
310
|
+
*/
|
|
311
|
+
set spatialBlurPassDebugEnabled(enabled) {
|
|
312
|
+
if (!this._spatialBlurPass)
|
|
313
|
+
return;
|
|
314
|
+
if (enabled && !this.allowDebugPasses) {
|
|
315
|
+
Logger.Warn("Can't enable spatial blur debug view without setting allowDebugPasses to true.");
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (enabled === this._spatialBlurPass.debugEnabled)
|
|
319
|
+
return;
|
|
320
|
+
this._spatialBlurPass.debugEnabled = enabled;
|
|
321
|
+
if (enabled) {
|
|
322
|
+
this._enableEffect(this._spatialBlurPass.debugPassName, this.cameras);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
this._disableEffect(this._spatialBlurPass.debugPassName, this.cameras);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Display the debug view for the accumulation pass
|
|
330
|
+
*/
|
|
331
|
+
get accumulationPassDebugEnabled() {
|
|
332
|
+
return this._accumulationPass?.debugEnabled;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Display the debug view for the accumulation pass
|
|
336
|
+
*/
|
|
337
|
+
set accumulationPassDebugEnabled(enabled) {
|
|
338
|
+
if (!this._accumulationPass)
|
|
339
|
+
return;
|
|
340
|
+
if (enabled && !this.allowDebugPasses) {
|
|
341
|
+
Logger.Warn("Can't enable accumulation pass debug view without setting allowDebugPasses to true.");
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (enabled === this._accumulationPass.debugEnabled)
|
|
345
|
+
return;
|
|
346
|
+
this._accumulationPass.debugEnabled = enabled;
|
|
347
|
+
if (enabled) {
|
|
348
|
+
this._enableEffect(this._accumulationPass.debugPassName, this.cameras);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
this._disableEffect(this._accumulationPass.debugPassName, this.cameras);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Add a mesh in the exclusion list to prevent it to be handled by the IBL shadow pipeline
|
|
356
|
+
* @param mesh The mesh to exclude from the IBL shadow pipeline
|
|
357
|
+
*/
|
|
358
|
+
addExcludedMesh(mesh) {
|
|
359
|
+
if (this._excludedMeshes.indexOf(mesh.uniqueId) === -1) {
|
|
360
|
+
this._excludedMeshes.push(mesh.uniqueId);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Remove a mesh from the exclusion list of the IBL shadow pipeline
|
|
365
|
+
* @param mesh The mesh to remove
|
|
366
|
+
*/
|
|
367
|
+
removeExcludedMesh(mesh) {
|
|
368
|
+
const index = this._excludedMeshes.indexOf(mesh.uniqueId);
|
|
369
|
+
if (index !== -1) {
|
|
370
|
+
this._excludedMeshes.splice(index, 1);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* The exponent of the resolution of the voxel shadow grid. Higher resolutions will result in sharper
|
|
375
|
+
* shadows but are more expensive to compute and require more memory.
|
|
376
|
+
* The resolution is calculated as 2 to the power of this number.
|
|
377
|
+
*/
|
|
378
|
+
get resolutionExp() {
|
|
379
|
+
return this._voxelRenderer.voxelResolutionExp;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* The exponent of the resolution of the voxel shadow grid. Higher resolutions will result in sharper
|
|
383
|
+
* shadows but are more expensive to compute and require more memory.
|
|
384
|
+
* The resolution is calculated as 2 to the power of this number.
|
|
385
|
+
*/
|
|
386
|
+
set resolutionExp(newResolution) {
|
|
387
|
+
if (newResolution === this._voxelRenderer.voxelResolutionExp)
|
|
388
|
+
return;
|
|
389
|
+
if (this._voxelRenderer.isVoxelizationInProgress()) {
|
|
390
|
+
Logger.Warn("Can't change the resolution of the voxel grid while voxelization is in progress.");
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
this._voxelRenderer.voxelResolutionExp = newResolution;
|
|
394
|
+
this.updateVoxelization();
|
|
395
|
+
setTimeout(() => {
|
|
396
|
+
// TODO - why do we need to run this a second time to get the voxel grid to update?
|
|
397
|
+
this.updateVoxelization();
|
|
398
|
+
}, 0);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* The number of different directions to sample during the voxel tracing pass
|
|
402
|
+
*/
|
|
403
|
+
get sampleDirections() {
|
|
404
|
+
return this._voxelTracingPass?.sampleDirections;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* The number of different directions to sample during the voxel tracing pass
|
|
408
|
+
*/
|
|
409
|
+
set sampleDirections(value) {
|
|
410
|
+
if (!this._voxelTracingPass)
|
|
411
|
+
return;
|
|
412
|
+
this._voxelTracingPass.sampleDirections = value;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* The decree to which the shadows persist between frames. 0.0 is no persistence, 1.0 is full persistence.
|
|
416
|
+
**/
|
|
417
|
+
get shadowRemenance() {
|
|
418
|
+
return this._accumulationPass?.remenance;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* The decree to which the shadows persist between frames. 0.0 is no persistence, 1.0 is full persistence.
|
|
422
|
+
**/
|
|
423
|
+
set shadowRemenance(value) {
|
|
424
|
+
if (!this._accumulationPass)
|
|
425
|
+
return;
|
|
426
|
+
this._accumulationPass.remenance = value;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* The global rotation of the IBL for shadows
|
|
430
|
+
*/
|
|
431
|
+
get envRotation() {
|
|
432
|
+
return this._voxelTracingPass?.envRotation;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* The global rotation of the IBL for shadows
|
|
436
|
+
*/
|
|
437
|
+
set envRotation(value) {
|
|
438
|
+
if (!this._voxelTracingPass)
|
|
439
|
+
return;
|
|
440
|
+
this._voxelTracingPass.envRotation = value;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Allow debug passes to be enabled. Default is false.
|
|
444
|
+
*/
|
|
445
|
+
get allowDebugPasses() {
|
|
446
|
+
return this._allowDebugPasses;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Allow debug passes to be enabled. Default is false.
|
|
450
|
+
*/
|
|
451
|
+
set allowDebugPasses(value) {
|
|
452
|
+
if (this._allowDebugPasses === value)
|
|
453
|
+
return;
|
|
454
|
+
this._allowDebugPasses = value;
|
|
455
|
+
if (value) {
|
|
456
|
+
this._createDebugPasses();
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
this._disposeDebugPasses();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Support test.
|
|
464
|
+
*/
|
|
465
|
+
static get IsSupported() {
|
|
466
|
+
const engine = EngineStore.LastCreatedEngine;
|
|
467
|
+
if (!engine) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
return engine._features.supportIBLShadows;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* @param name The rendering pipeline name
|
|
474
|
+
* @param scene The scene linked to this pipeline
|
|
475
|
+
* @param options Options to configure the pipeline
|
|
476
|
+
* @param cameras Cameras to apply the pipeline to.
|
|
477
|
+
*/
|
|
478
|
+
constructor(name, scene, options = {}, cameras) {
|
|
479
|
+
super(scene.getEngine(), name);
|
|
480
|
+
this._voxelizationDirty = true;
|
|
481
|
+
this._boundsNeedUpdate = true;
|
|
482
|
+
this._allowDebugPasses = false;
|
|
483
|
+
this._debugPasses = [];
|
|
484
|
+
this._excludedMeshes = [];
|
|
485
|
+
this._shadowOpacity = 1.0;
|
|
486
|
+
this._gbufferDebugEnabled = false;
|
|
487
|
+
this._gBufferDebugSizeParams = new Vector4(0.0, 0.0, 0.0, 0.0);
|
|
488
|
+
this.scene = scene;
|
|
489
|
+
// We need a depth texture for opaque
|
|
490
|
+
if (!scene.enablePrePassRenderer()) {
|
|
491
|
+
Logger.Warn("IBL Shadows Render Pipeline could not enable PrePass, aborting.");
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
this.shadowOpacity = options.shadowOpacity || 1.0;
|
|
495
|
+
this._prePassEffectConfiguration = new IblShadowsPrepassConfiguration();
|
|
496
|
+
this._voxelRenderer = new _IblShadowsVoxelRenderer(this.scene, this, options ? options.resolutionExp : 6, options.triPlanarVoxelization !== undefined ? options.triPlanarVoxelization : true);
|
|
497
|
+
this._importanceSamplingRenderer = new _IblShadowsImportanceSamplingRenderer(this.scene);
|
|
498
|
+
this._voxelTracingPass = new _IblShadowsVoxelTracingPass(this.scene, this);
|
|
499
|
+
this.sampleDirections = options.sampleDirections || 2;
|
|
500
|
+
this.ssShadowOpacity = options.ssShadowsEnabled === undefined || options.ssShadowsEnabled ? 1.0 : 0.0;
|
|
501
|
+
this.ssShadowMaxDist = options.ssShadowMaxDist || 0.05;
|
|
502
|
+
this.ssShadowSamples = options.ssShadowSampleCount || 16;
|
|
503
|
+
this.ssShadowStride = options.ssShadowStride || 8;
|
|
504
|
+
this.ssShadowThickness = options.ssShadowThickness || 0.01;
|
|
505
|
+
this._spatialBlurPass = new _IblShadowsSpatialBlurPass(this.scene);
|
|
506
|
+
this._accumulationPass = new _IblShadowsAccumulationPass(this.scene);
|
|
507
|
+
this.shadowRemenance = options.shadowRemenance || 0.75;
|
|
508
|
+
this._noiseTexture = new Texture("https://assets.babylonjs.com/textures/blue_noise/blue_noise_rgb.png", this.scene, false, true, 1);
|
|
509
|
+
if (this.scene.environmentTexture) {
|
|
510
|
+
this._importanceSamplingRenderer.iblSource = this.scene.environmentTexture;
|
|
511
|
+
}
|
|
512
|
+
// Create post process that applies the shadows to the scene
|
|
513
|
+
this._createShadowCombinePostProcess();
|
|
514
|
+
scene.postProcessRenderPipelineManager.addPipeline(this);
|
|
515
|
+
this._createEffectPasses(cameras);
|
|
516
|
+
this.scene.onNewMeshAddedObservable.add(this.updateSceneBounds.bind(this));
|
|
517
|
+
this.scene.onMeshRemovedObservable.add(this.updateSceneBounds.bind(this));
|
|
518
|
+
this.scene.onActiveCameraChanged.add(this._listenForCameraChanges.bind(this));
|
|
519
|
+
this.scene.onBeforeRenderObservable.add(this._updateBeforeRender.bind(this));
|
|
520
|
+
this._listenForCameraChanges();
|
|
521
|
+
this.scene.getEngine().onResizeObservable.add(this._handleResize.bind(this));
|
|
522
|
+
this._importanceSamplingRenderer.onReadyObservable.addOnce(() => {
|
|
523
|
+
if (this._voxelRenderer.isReady()) {
|
|
524
|
+
this.toggleShadow(true);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
this._voxelRenderer.onReadyObservable.addOnce(() => {
|
|
528
|
+
this.toggleShadow(true);
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Toggle the shadow tracing on or off
|
|
535
|
+
* @param enabled Toggle the shadow tracing on or off
|
|
536
|
+
*/
|
|
537
|
+
toggleShadow(enabled) {
|
|
538
|
+
if (enabled) {
|
|
539
|
+
this._enableEffect("IBLShadowVoxelTracingPass", this.cameras);
|
|
540
|
+
this._enableEffect("IBLShadowSpatialBlurPass", this.cameras);
|
|
541
|
+
this._enableEffect("IBLShadowAccumulationBlurPass", this.cameras);
|
|
542
|
+
this._enableEffect("IBLShadowCompositePass", this.cameras);
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
this._disableEffect("IBLShadowVoxelTracingPass", null);
|
|
546
|
+
this._disableEffect("IBLShadowSpatialBlurPass", null);
|
|
547
|
+
this._disableEffect("IBLShadowAccumulationBlurPass", null);
|
|
548
|
+
this._disableEffect("IBLShadowCompositePass", null);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
_handleResize() {
|
|
552
|
+
this._voxelRenderer.resize();
|
|
553
|
+
this._accumulationPass?.resize();
|
|
554
|
+
}
|
|
555
|
+
_createShadowCombinePostProcess() {
|
|
556
|
+
const compositeOptions = {
|
|
557
|
+
width: this.scene.getEngine().getRenderWidth(),
|
|
558
|
+
height: this.scene.getEngine().getRenderHeight(),
|
|
559
|
+
uniforms: ["shadowOpacity"],
|
|
560
|
+
samplers: ["sceneTexture"],
|
|
561
|
+
samplingMode: 2,
|
|
562
|
+
engine: this.scene.getEngine(),
|
|
563
|
+
textureType: 0,
|
|
564
|
+
reusable: false,
|
|
565
|
+
};
|
|
566
|
+
this._shadowCompositePP = new PostProcess("iblShadowsCombine", "iblShadowsCombine", compositeOptions);
|
|
567
|
+
this._shadowCompositePP.autoClear = false;
|
|
568
|
+
this._shadowCompositePP.onApplyObservable.add((effect) => {
|
|
569
|
+
// Setting the input of the tracing pass because this is the scene RT that we want to apply the shadows to.
|
|
570
|
+
effect.setTextureFromPostProcess("sceneTexture", this._voxelTracingPass.getPassPP());
|
|
571
|
+
effect.setFloat("shadowOpacity", this._shadowOpacity);
|
|
572
|
+
if (this._importanceSamplingRenderer?.isReady() &&
|
|
573
|
+
this._voxelRenderer?.isReady() &&
|
|
574
|
+
this._voxelTracingPass?.isReady() &&
|
|
575
|
+
this._spatialBlurPass?.isReady() &&
|
|
576
|
+
this._accumulationPass?.isReady()) {
|
|
577
|
+
this.update();
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
this._shadowCompositePP._prePassEffectConfiguration = this._prePassEffectConfiguration;
|
|
581
|
+
setTimeout(() => {
|
|
582
|
+
this._voxelizationDirty = true;
|
|
583
|
+
}, 500);
|
|
584
|
+
}
|
|
585
|
+
_createEffectPasses(cameras) {
|
|
586
|
+
this.addEffect(new PostProcessRenderEffect(this.scene.getEngine(), "IBLShadowVoxelTracingPass", () => {
|
|
587
|
+
return this._voxelTracingPass.getPassPP();
|
|
588
|
+
}, true));
|
|
589
|
+
this.addEffect(new PostProcessRenderEffect(this.scene.getEngine(), "IBLShadowSpatialBlurPass", () => {
|
|
590
|
+
return this._spatialBlurPass.getPassPP();
|
|
591
|
+
}, true));
|
|
592
|
+
this.addEffect(new PostProcessRenderEffect(this.scene.getEngine(), "IBLShadowAccumulationBlurPass", () => {
|
|
593
|
+
return this._accumulationPass.getPassPP();
|
|
594
|
+
}, true));
|
|
595
|
+
this.addEffect(new PostProcessRenderEffect(this.scene.getEngine(), "IBLShadowCompositePass", () => {
|
|
596
|
+
return this._shadowCompositePP;
|
|
597
|
+
}, true));
|
|
598
|
+
if (cameras) {
|
|
599
|
+
this.scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this.name, cameras);
|
|
600
|
+
}
|
|
601
|
+
this.toggleShadow(false);
|
|
602
|
+
if (this.allowDebugPasses) {
|
|
603
|
+
this._createDebugPasses();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
_getGBufferDebugPass() {
|
|
607
|
+
if (this._gbufferDebugPass) {
|
|
608
|
+
return this._gbufferDebugPass;
|
|
609
|
+
}
|
|
610
|
+
const textureNames = this._prePassEffectConfiguration.texturesRequired.map((type) => PrePassRenderer.TextureFormats[type].name.toString());
|
|
611
|
+
const options = {
|
|
612
|
+
width: this.scene.getEngine().getRenderWidth(),
|
|
613
|
+
height: this.scene.getEngine().getRenderHeight(),
|
|
614
|
+
samplingMode: 1,
|
|
615
|
+
engine: this.scene.getEngine(),
|
|
616
|
+
textureType: 0,
|
|
617
|
+
textureFormat: 5,
|
|
618
|
+
uniforms: ["sizeParams"],
|
|
619
|
+
samplers: textureNames,
|
|
620
|
+
reusable: false,
|
|
621
|
+
};
|
|
622
|
+
this._gbufferDebugPass = new PostProcess("iblShadowGBufferDebug", "iblShadowGBufferDebug", options);
|
|
623
|
+
this._gbufferDebugPass.autoClear = false;
|
|
624
|
+
this._gbufferDebugPass.onApplyObservable.add((effect) => {
|
|
625
|
+
this._prePassEffectConfiguration.texturesRequired.forEach((type) => {
|
|
626
|
+
const prePassRenderer = this.scene.prePassRenderer;
|
|
627
|
+
if (!prePassRenderer) {
|
|
628
|
+
Logger.Error("Can't enable G-Buffer debug rendering since prepassRenderer doesn't exist.");
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const index = prePassRenderer.getIndex(type);
|
|
632
|
+
if (index >= 0)
|
|
633
|
+
effect.setTexture(PrePassRenderer.TextureFormats[type].name, prePassRenderer.getRenderTarget().textures[index]);
|
|
634
|
+
});
|
|
635
|
+
effect.setVector4("sizeParams", this._gBufferDebugSizeParams);
|
|
636
|
+
if (this.scene.activeCamera) {
|
|
637
|
+
effect.setFloat("maxDepth", this.scene.activeCamera.maxZ);
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
return this._gbufferDebugPass;
|
|
641
|
+
}
|
|
642
|
+
_createDebugPasses() {
|
|
643
|
+
this._debugPasses = [
|
|
644
|
+
this._importanceSamplingRenderer?.getDebugPassPP(),
|
|
645
|
+
this._voxelRenderer?.getDebugPassPP(),
|
|
646
|
+
this._voxelTracingPass?.getDebugPassPP(),
|
|
647
|
+
this._spatialBlurPass?.getDebugPassPP(),
|
|
648
|
+
this._accumulationPass?.getDebugPassPP(),
|
|
649
|
+
this._getGBufferDebugPass(),
|
|
650
|
+
];
|
|
651
|
+
for (let i = 0; i < this._debugPasses.length; i++) {
|
|
652
|
+
if (!this._debugPasses[i])
|
|
653
|
+
continue;
|
|
654
|
+
this.addEffect(new PostProcessRenderEffect(this.scene.getEngine(), this._debugPasses[i].name, () => {
|
|
655
|
+
return this._debugPasses[i];
|
|
656
|
+
}, true));
|
|
657
|
+
}
|
|
658
|
+
const cameras = this.cameras.slice();
|
|
659
|
+
this.scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this.name, this.cameras);
|
|
660
|
+
this.scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this.name, cameras);
|
|
661
|
+
for (let i = 0; i < this._debugPasses.length; i++) {
|
|
662
|
+
if (!this._debugPasses[i])
|
|
663
|
+
continue;
|
|
664
|
+
this._disableEffect(this._debugPasses[i].name, this.cameras);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
_disposeEffectPasses() {
|
|
668
|
+
this.scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this.name, this.cameras);
|
|
669
|
+
this._disableEffect("IBLShadowVoxelTracingPass", this.cameras);
|
|
670
|
+
this._disableEffect("IBLShadowSpatialBlurPass", this.cameras);
|
|
671
|
+
this._disableEffect("IBLShadowAccumulationBlurPass", this.cameras);
|
|
672
|
+
this._disableEffect("IBLShadowCompositePass", this.cameras);
|
|
673
|
+
this._disposeDebugPasses();
|
|
674
|
+
this._reset();
|
|
675
|
+
}
|
|
676
|
+
_disposeDebugPasses() {
|
|
677
|
+
for (let i = 0; i < this._debugPasses.length; i++) {
|
|
678
|
+
this._disableEffect(this._debugPasses[i].name, this.cameras);
|
|
679
|
+
this._debugPasses[i].dispose();
|
|
680
|
+
}
|
|
681
|
+
this._debugPasses = [];
|
|
682
|
+
}
|
|
683
|
+
_updateDebugPasses() {
|
|
684
|
+
let count = 0;
|
|
685
|
+
if (this._gbufferDebugEnabled)
|
|
686
|
+
count++;
|
|
687
|
+
if (this.importanceSamplingDebugEnabled)
|
|
688
|
+
count++;
|
|
689
|
+
if (this.voxelDebugEnabled)
|
|
690
|
+
count++;
|
|
691
|
+
if (this.voxelTracingDebugEnabled)
|
|
692
|
+
count++;
|
|
693
|
+
if (this.spatialBlurPassDebugEnabled)
|
|
694
|
+
count++;
|
|
695
|
+
if (this.accumulationPassDebugEnabled)
|
|
696
|
+
count++;
|
|
697
|
+
const rows = Math.ceil(Math.sqrt(count));
|
|
698
|
+
const cols = Math.ceil(count / rows);
|
|
699
|
+
const width = 1.0 / cols;
|
|
700
|
+
const height = 1.0 / rows;
|
|
701
|
+
let x = 0;
|
|
702
|
+
let y = 0;
|
|
703
|
+
if (this.gbufferDebugEnabled) {
|
|
704
|
+
const prePassRenderer = this.scene.prePassRenderer;
|
|
705
|
+
if (!prePassRenderer) {
|
|
706
|
+
Logger.Error("Can't enable G-Buffer debug rendering since prepassRenderer doesn't exist.");
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
this._gBufferDebugSizeParams.set(x, y, cols, rows);
|
|
710
|
+
x -= width;
|
|
711
|
+
if (x <= -1) {
|
|
712
|
+
x = 0;
|
|
713
|
+
y -= height;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
if (this.importanceSamplingDebugEnabled) {
|
|
717
|
+
this._importanceSamplingRenderer.setDebugDisplayParams(x, y, cols, rows);
|
|
718
|
+
x -= width;
|
|
719
|
+
if (x <= -1) {
|
|
720
|
+
x = 0;
|
|
721
|
+
y -= height;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (this.voxelDebugEnabled) {
|
|
725
|
+
this._voxelRenderer.setDebugDisplayParams(x, y, cols, rows);
|
|
726
|
+
x -= width;
|
|
727
|
+
if (x <= -1) {
|
|
728
|
+
x = 0;
|
|
729
|
+
y -= height;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
if (this.voxelTracingDebugEnabled) {
|
|
733
|
+
this._voxelTracingPass.setDebugDisplayParams(x, y, cols, rows);
|
|
734
|
+
x -= width;
|
|
735
|
+
if (x <= -1) {
|
|
736
|
+
x = 0;
|
|
737
|
+
y -= height;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
if (this.spatialBlurPassDebugEnabled) {
|
|
741
|
+
this._spatialBlurPass.setDebugDisplayParams(x, y, cols, rows);
|
|
742
|
+
x -= width;
|
|
743
|
+
if (x <= -1) {
|
|
744
|
+
x = 0;
|
|
745
|
+
y -= height;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
if (this.accumulationPassDebugEnabled) {
|
|
749
|
+
this._accumulationPass.setDebugDisplayParams(x, y, cols, rows);
|
|
750
|
+
x -= width;
|
|
751
|
+
if (x <= -1) {
|
|
752
|
+
x = 0;
|
|
753
|
+
y -= height;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Trigger the scene to be re-voxelized. This is useful when the scene has changed and the voxel grid needs to be updated.
|
|
759
|
+
*/
|
|
760
|
+
updateVoxelization() {
|
|
761
|
+
this._voxelizationDirty = true;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Trigger the scene bounds of shadow-casters to be updated. This is useful when the scene has changed and the bounds need
|
|
765
|
+
* to be recalculated. This will also trigger a re-voxelization.
|
|
766
|
+
*/
|
|
767
|
+
updateSceneBounds() {
|
|
768
|
+
this._voxelizationDirty = true;
|
|
769
|
+
this._boundsNeedUpdate = true;
|
|
770
|
+
}
|
|
771
|
+
_updateBeforeRender() {
|
|
772
|
+
this._updateDebugPasses();
|
|
773
|
+
}
|
|
774
|
+
_listenForCameraChanges() {
|
|
775
|
+
// We want to listen for camera changes and change settings while the camera is moving.
|
|
776
|
+
if (this.scene.activeCamera instanceof ArcRotateCamera) {
|
|
777
|
+
this.scene.onBeforeCameraRenderObservable.add((camera) => {
|
|
778
|
+
let isMoving = false;
|
|
779
|
+
if (camera instanceof ArcRotateCamera) {
|
|
780
|
+
isMoving =
|
|
781
|
+
camera.inertialAlphaOffset !== 0 ||
|
|
782
|
+
camera.inertialBetaOffset !== 0 ||
|
|
783
|
+
camera.inertialRadiusOffset !== 0 ||
|
|
784
|
+
camera.inertialPanningX !== 0 ||
|
|
785
|
+
camera.inertialPanningY !== 0;
|
|
786
|
+
}
|
|
787
|
+
else if (camera instanceof FreeCamera) {
|
|
788
|
+
isMoving =
|
|
789
|
+
camera.cameraDirection.x !== 0 ||
|
|
790
|
+
camera.cameraDirection.y !== 0 ||
|
|
791
|
+
camera.cameraDirection.z !== 0 ||
|
|
792
|
+
camera.cameraRotation.x !== 0 ||
|
|
793
|
+
camera.cameraRotation.y !== 0;
|
|
794
|
+
}
|
|
795
|
+
if (this._accumulationPass) {
|
|
796
|
+
if (isMoving) {
|
|
797
|
+
// this._accumulationPass.reset = true;
|
|
798
|
+
// this._accumulationPass.remenance = 1.0;
|
|
799
|
+
}
|
|
800
|
+
else {
|
|
801
|
+
// this._accumulationPass.reset = false;
|
|
802
|
+
// this._accumulationPass.remenance = 0.9;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Links to the prepass renderer
|
|
810
|
+
* @param prePassRenderer The scene PrePassRenderer
|
|
811
|
+
* @returns true if the pre pass is setup
|
|
812
|
+
*/
|
|
813
|
+
setPrePassRenderer(prePassRenderer) {
|
|
814
|
+
return !!prePassRenderer.addEffectConfiguration(this._prePassEffectConfiguration);
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Checks if the IBL shadow pipeline is ready to render shadows
|
|
818
|
+
* @returns true if the IBL shadow pipeline is ready to render the shadows
|
|
819
|
+
*/
|
|
820
|
+
isReady() {
|
|
821
|
+
return (this._noiseTexture.isReady() &&
|
|
822
|
+
this._voxelRenderer.isReady() &&
|
|
823
|
+
this._importanceSamplingRenderer.isReady() &&
|
|
824
|
+
(!this._voxelTracingPass || this._voxelTracingPass.isReady()) &&
|
|
825
|
+
(!this._spatialBlurPass || this._spatialBlurPass.isReady()) &&
|
|
826
|
+
(!this._accumulationPass || this._accumulationPass.isReady()));
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Renders accumulated shadows for IBL
|
|
830
|
+
*/
|
|
831
|
+
update() {
|
|
832
|
+
// This is called for every MRT in the customRenderTargets structure during voxelization. That doesn't make
|
|
833
|
+
// sense. We only want this to run after voxelization so we should put in some state logic here to return
|
|
834
|
+
// if voxelization is happening.
|
|
835
|
+
if (this._voxelRenderer.isVoxelizationInProgress()) {
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
if (this._boundsNeedUpdate) {
|
|
839
|
+
const bounds = this.scene.getWorldExtends((mesh) => {
|
|
840
|
+
return mesh instanceof Mesh && this._excludedMeshes.indexOf(mesh.uniqueId) === -1;
|
|
841
|
+
});
|
|
842
|
+
const size = bounds.max.subtract(bounds.min);
|
|
843
|
+
const halfSize = Math.max(size.x, Math.max(size.y, size.z)) * 0.5;
|
|
844
|
+
const centre = bounds.max.add(bounds.min).multiplyByFloats(-0.5, -0.5, -0.5);
|
|
845
|
+
const invWorldScaleMatrix = Matrix.Compose(new Vector3(1.0 / halfSize, 1.0 / halfSize, 1.0 / halfSize), new Quaternion(), new Vector3(0, 0, 0));
|
|
846
|
+
const invTranslationMatrix = Matrix.Compose(new Vector3(1.0, 1.0, 1.0), new Quaternion(), centre);
|
|
847
|
+
invTranslationMatrix.multiplyToRef(invWorldScaleMatrix, invWorldScaleMatrix);
|
|
848
|
+
this._voxelTracingPass?.setWorldScaleMatrix(invWorldScaleMatrix);
|
|
849
|
+
this._voxelRenderer.setWorldScaleMatrix(invWorldScaleMatrix);
|
|
850
|
+
// Set world scale for spatial blur.
|
|
851
|
+
this._spatialBlurPass?.setWorldScale(halfSize * 2.0);
|
|
852
|
+
this._boundsNeedUpdate = false;
|
|
853
|
+
Logger.Log("IBL Shadows: Scene size: " + size);
|
|
854
|
+
Logger.Log("Half size: " + halfSize);
|
|
855
|
+
Logger.Log("Centre translation: " + centre);
|
|
856
|
+
}
|
|
857
|
+
// If update is needed, render voxels
|
|
858
|
+
if (this._voxelizationDirty) {
|
|
859
|
+
this._voxelRenderer.updateVoxelGrid(this._excludedMeshes);
|
|
860
|
+
this._voxelizationDirty = false;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Get the class name
|
|
865
|
+
* @returns "IBLShadowsRenderPipeline"
|
|
866
|
+
*/
|
|
867
|
+
getClassName() {
|
|
868
|
+
return "IBLShadowsRenderPipeline";
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Disposes the IBL shadow pipeline and associated resources
|
|
872
|
+
*/
|
|
873
|
+
dispose() {
|
|
874
|
+
this._disposeEffectPasses();
|
|
875
|
+
this._noiseTexture.dispose();
|
|
876
|
+
this._voxelRenderer.dispose();
|
|
877
|
+
this._importanceSamplingRenderer.dispose();
|
|
878
|
+
this._voxelTracingPass?.dispose();
|
|
879
|
+
this._spatialBlurPass?.dispose();
|
|
880
|
+
this._accumulationPass?.dispose();
|
|
881
|
+
super.dispose();
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
//# sourceMappingURL=iblShadowsRenderPipeline.js.map
|