@babylonjs/core 7.32.3 → 7.32.5
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/Decorators/nodeDecorator.d.ts +4 -0
- package/Decorators/nodeDecorator.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Materials/Node/Blocks/Dual/sceneDepthBlock.js +1 -0
- package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +4 -4
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/clearCoatBlock.js +1 -1
- package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js +2 -2
- package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/refractionBlock.js +3 -3
- package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/sheenBlock.js +2 -2
- package/Materials/Node/Blocks/PBR/sheenBlock.js.map +1 -1
- package/Materials/Node/Blocks/clampBlock.js +2 -2
- package/Materials/Node/Blocks/clampBlock.js.map +1 -1
- package/Materials/Node/Blocks/cloudBlock.js +1 -1
- package/Materials/Node/Blocks/cloudBlock.js.map +1 -1
- package/Materials/Node/Blocks/conditionalBlock.js +19 -0
- package/Materials/Node/Blocks/conditionalBlock.js.map +1 -1
- package/Materials/Node/Blocks/curveBlock.js +37 -0
- package/Materials/Node/Blocks/curveBlock.js.map +1 -1
- package/Materials/Node/Blocks/loopBlock.js +1 -1
- package/Materials/Node/Blocks/loopBlock.js.map +1 -1
- package/Materials/Node/Blocks/meshAttributeExistsBlock.js +1 -0
- package/Materials/Node/Blocks/meshAttributeExistsBlock.js.map +1 -1
- package/Materials/Node/Blocks/transformBlock.d.ts +6 -0
- package/Materials/Node/Blocks/transformBlock.js +16 -1
- package/Materials/Node/Blocks/transformBlock.js.map +1 -1
- package/Materials/Node/Blocks/triPlanarBlock.js +1 -1
- package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
- package/Materials/Node/Blocks/trigonometryBlock.js +29 -0
- package/Materials/Node/Blocks/trigonometryBlock.js.map +1 -1
- package/Materials/Node/Blocks/waveBlock.js +13 -0
- package/Materials/Node/Blocks/waveBlock.js.map +1 -1
- package/Materials/Node/Blocks/worleyNoise3DBlock.js +1 -1
- package/Materials/Node/Blocks/worleyNoise3DBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Instances/instantiateBaseBlock.js +1 -1
- package/Meshes/Node/Blocks/Instances/instantiateBaseBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/aggregatorBlock.js +1 -0
- package/Meshes/Node/Blocks/Set/aggregatorBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/latticeBlock.js +4 -4
- package/Meshes/Node/Blocks/Set/latticeBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setColorsBlock.js +1 -1
- package/Meshes/Node/Blocks/Set/setColorsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setMaterialIDBlock.js +1 -1
- package/Meshes/Node/Blocks/Set/setMaterialIDBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setNormalsBlock.js +1 -1
- package/Meshes/Node/Blocks/Set/setNormalsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setPositionsBlock.js +1 -1
- package/Meshes/Node/Blocks/Set/setPositionsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setTangentsBlock.js +1 -1
- package/Meshes/Node/Blocks/Set/setTangentsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Set/setUVsBlock.js +2 -1
- package/Meshes/Node/Blocks/Set/setUVsBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/boxBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/boxBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/capsuleBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/capsuleBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/cylinderBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/cylinderBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/discBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/discBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/gridBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/gridBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/icoSphereBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/icoSphereBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/meshBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/meshBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/planeBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/planeBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/sphereBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/sphereBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/torusBlock.js +1 -1
- package/Meshes/Node/Blocks/Sources/torusBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js +1 -1
- package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js +1 -1
- package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js.map +1 -1
- package/Meshes/Node/Blocks/booleanGeometryBlock.d.ts +5 -0
- package/Meshes/Node/Blocks/booleanGeometryBlock.js +43 -13
- package/Meshes/Node/Blocks/booleanGeometryBlock.js.map +1 -1
- package/Meshes/Node/Blocks/cleanGeometryBlock.js +1 -1
- package/Meshes/Node/Blocks/cleanGeometryBlock.js.map +1 -1
- package/Meshes/Node/Blocks/conditionBlock.js +1 -0
- package/Meshes/Node/Blocks/conditionBlock.js.map +1 -1
- package/Meshes/Node/Blocks/geometryClampBlock.js +2 -2
- package/Meshes/Node/Blocks/geometryClampBlock.js.map +1 -1
- package/Meshes/Node/Blocks/geometryCollectionBlock.js +1 -1
- package/Meshes/Node/Blocks/geometryCollectionBlock.js.map +1 -1
- package/Meshes/Node/Blocks/geometryCurveBlock.js +1 -0
- package/Meshes/Node/Blocks/geometryCurveBlock.js.map +1 -1
- package/Meshes/Node/Blocks/geometryOptimizeBlock.js +3 -3
- package/Meshes/Node/Blocks/geometryOptimizeBlock.js.map +1 -1
- package/Meshes/Node/Blocks/geometryTransformBlock.js +1 -1
- package/Meshes/Node/Blocks/geometryTransformBlock.js.map +1 -1
- package/Meshes/Node/Blocks/geometryTrigonometryBlock.js +1 -0
- package/Meshes/Node/Blocks/geometryTrigonometryBlock.js.map +1 -1
- package/Meshes/Node/Blocks/mappingBlock.js +1 -0
- package/Meshes/Node/Blocks/mappingBlock.js.map +1 -1
- package/Meshes/Node/Blocks/mathBlock.js +1 -0
- package/Meshes/Node/Blocks/mathBlock.js.map +1 -1
- package/Meshes/Node/Blocks/mergeGeometryBlock.js +1 -1
- package/Meshes/Node/Blocks/mergeGeometryBlock.js.map +1 -1
- package/Meshes/Node/Blocks/randomBlock.js +1 -0
- package/Meshes/Node/Blocks/randomBlock.js.map +1 -1
- package/Misc/webRequest.d.ts +4 -0
- package/Misc/webRequest.js +6 -0
- package/Misc/webRequest.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.d.ts +35 -11
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js +131 -117
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js +0 -1
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsPluginMaterial.d.ts +60 -0
- package/Rendering/IBLShadows/iblShadowsPluginMaterial.js +166 -0
- package/Rendering/IBLShadows/iblShadowsPluginMaterial.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.d.ts +97 -56
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +356 -308
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.d.ts +20 -6
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js +67 -35
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.d.ts +9 -4
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +84 -66
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.d.ts +31 -6
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +108 -60
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
- package/Rendering/geometryBufferRenderer.d.ts +15 -0
- package/Rendering/geometryBufferRenderer.js +48 -5
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/instancesDeclaration.js +2 -4
- package/Shaders/ShadersInclude/instancesDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/instancesVertex.js +3 -6
- package/Shaders/ShadersInclude/instancesVertex.js.map +1 -1
- package/Shaders/geometry.fragment.js +5 -1
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/geometry.vertex.js +3 -3
- package/Shaders/geometry.vertex.js.map +1 -1
- package/Shaders/iblShadowAccumulation.fragment.js +7 -11
- package/Shaders/iblShadowAccumulation.fragment.js.map +1 -1
- package/Shaders/iblShadowGBufferDebug.fragment.js +2 -3
- package/Shaders/iblShadowGBufferDebug.fragment.js.map +1 -1
- package/Shaders/iblShadowSpatialBlur.fragment.js +5 -5
- package/Shaders/iblShadowSpatialBlur.fragment.js.map +1 -1
- package/Shaders/iblShadowVoxelTracing.fragment.js +31 -32
- package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -1
- package/Shaders/iblShadowsCombine.fragment.js +2 -2
- package/Shaders/iblShadowsCombine.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/instancesDeclaration.js +2 -4
- package/ShadersWGSL/ShadersInclude/instancesDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/instancesVertex.js +3 -6
- package/ShadersWGSL/ShadersInclude/instancesVertex.js.map +1 -1
- package/ShadersWGSL/geometry.fragment.js +7 -1
- package/ShadersWGSL/geometry.fragment.js.map +1 -1
- package/ShadersWGSL/geometry.vertex.js +3 -3
- package/ShadersWGSL/geometry.vertex.js.map +1 -1
- package/ShadersWGSL/iblShadowAccumulation.fragment.js +5 -10
- package/ShadersWGSL/iblShadowAccumulation.fragment.js.map +1 -1
- package/ShadersWGSL/iblShadowGBufferDebug.fragment.js +2 -3
- package/ShadersWGSL/iblShadowGBufferDebug.fragment.js.map +1 -1
- package/ShadersWGSL/iblShadowSpatialBlur.fragment.js +5 -5
- package/ShadersWGSL/iblShadowSpatialBlur.fragment.js.map +1 -1
- package/ShadersWGSL/iblShadowVoxelTracing.fragment.js +45 -33
- package/ShadersWGSL/iblShadowVoxelTracing.fragment.js.map +1 -1
- package/ShadersWGSL/iblShadowsCombine.fragment.js +6 -2
- package/ShadersWGSL/iblShadowsCombine.fragment.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { EngineStore } from "../../Engines/engineStore.js";
|
|
3
3
|
import { Matrix, Vector3, Vector4, Quaternion } from "../../Maths/math.vector.js";
|
|
4
|
-
import { Mesh } from "../../Meshes/mesh.js";
|
|
5
4
|
import { Texture } from "../../Materials/Textures/texture.js";
|
|
6
|
-
import { PrePassRenderer } from "../prePassRenderer.js";
|
|
7
5
|
import { Logger } from "../../Misc/logger.js";
|
|
8
6
|
import { _IblShadowsVoxelRenderer } from "./iblShadowsVoxelRenderer.js";
|
|
9
7
|
import { _IblShadowsVoxelTracingPass } from "./iblShadowsVoxelTracingPass.js";
|
|
@@ -11,61 +9,56 @@ import { PostProcess } from "../../PostProcesses/postProcess.js";
|
|
|
11
9
|
import { _IblShadowsImportanceSamplingRenderer } from "./iblShadowsImportanceSamplingRenderer.js";
|
|
12
10
|
import { _IblShadowsSpatialBlurPass } from "./iblShadowsSpatialBlurPass.js";
|
|
13
11
|
import { _IblShadowsAccumulationPass } from "./iblShadowsAccumulationPass.js";
|
|
14
|
-
import { ArcRotateCamera } from "../../Cameras/arcRotateCamera.js";
|
|
15
|
-
import { FreeCamera } from "../../Cameras/freeCamera.js";
|
|
16
12
|
import { PostProcessRenderPipeline } from "../../PostProcesses/RenderPipeline/postProcessRenderPipeline.js";
|
|
17
13
|
import { PostProcessRenderEffect } from "../../PostProcesses/RenderPipeline/postProcessRenderEffect.js";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
this.name = "iblShadows";
|
|
28
|
-
/**
|
|
29
|
-
* Textures that should be present in the MRT for this effect to work
|
|
30
|
-
*/
|
|
31
|
-
this.texturesRequired = [
|
|
32
|
-
5,
|
|
33
|
-
10,
|
|
34
|
-
8,
|
|
35
|
-
// 6, // TODO - don't need this for IBL shadows
|
|
36
|
-
11,
|
|
37
|
-
// Local positions used for shadow accumulation pass
|
|
38
|
-
1,
|
|
39
|
-
9,
|
|
40
|
-
];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
14
|
+
import { GeometryBufferRenderer } from "../geometryBufferRenderer.js";
|
|
15
|
+
import { RawTexture } from "../../Materials/Textures/rawTexture.js";
|
|
16
|
+
import { RawTexture3D } from "../../Materials/Textures/rawTexture3D.js";
|
|
17
|
+
import { Engine } from "../../Engines/engine.js";
|
|
18
|
+
import { IBLShadowsPluginMaterial } from "./iblShadowsPluginMaterial.js";
|
|
19
|
+
import { PBRBaseMaterial } from "../../Materials/PBR/pbrBaseMaterial.js";
|
|
20
|
+
import { StandardMaterial } from "../../Materials/standardMaterial.js";
|
|
21
|
+
import { Observable } from "../../Misc/observable.js";
|
|
43
22
|
/**
|
|
44
23
|
* Voxel-based shadow rendering for IBL's.
|
|
45
24
|
* This should not be instanciated directly, as it is part of a scene component
|
|
46
25
|
*/
|
|
47
26
|
export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
48
27
|
/**
|
|
49
|
-
*
|
|
28
|
+
* Reset the shadow accumulation.
|
|
50
29
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
resetAccumulation() {
|
|
31
|
+
this._accumulationPass.reset = true;
|
|
53
32
|
}
|
|
54
33
|
/**
|
|
55
34
|
* How dark the shadows appear. 1.0 is full opacity, 0.0 is no shadows.
|
|
56
35
|
*/
|
|
36
|
+
get shadowOpacity() {
|
|
37
|
+
return this._shadowOpacity;
|
|
38
|
+
}
|
|
57
39
|
set shadowOpacity(value) {
|
|
58
40
|
this._shadowOpacity = value;
|
|
41
|
+
this._setPluginParameters();
|
|
59
42
|
}
|
|
60
43
|
/**
|
|
61
|
-
*
|
|
44
|
+
* A multiplier for the render size of the shadows. Used for rendering lower-resolution shadows.
|
|
62
45
|
*/
|
|
63
|
-
get
|
|
64
|
-
return this.
|
|
46
|
+
get shadowRenderSizeFactor() {
|
|
47
|
+
return this._renderSizeFactor;
|
|
48
|
+
}
|
|
49
|
+
set shadowRenderSizeFactor(value) {
|
|
50
|
+
this._renderSizeFactor = Math.max(Math.min(value, 1.0), 0.0);
|
|
51
|
+
this._voxelTracingPass.resize(value);
|
|
52
|
+
this._spatialBlurPass.resize(value);
|
|
53
|
+
this._accumulationPass.resize(value);
|
|
54
|
+
this._setPluginParameters();
|
|
65
55
|
}
|
|
66
56
|
/**
|
|
67
57
|
* How dark the voxel shadows appear. 1.0 is full opacity, 0.0 is no shadows.
|
|
68
58
|
*/
|
|
59
|
+
get voxelShadowOpacity() {
|
|
60
|
+
return this._voxelTracingPass?.voxelShadowOpacity;
|
|
61
|
+
}
|
|
69
62
|
set voxelShadowOpacity(value) {
|
|
70
63
|
if (!this._voxelTracingPass)
|
|
71
64
|
return;
|
|
@@ -77,9 +70,6 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
77
70
|
get ssShadowOpacity() {
|
|
78
71
|
return this._voxelTracingPass?.ssShadowOpacity;
|
|
79
72
|
}
|
|
80
|
-
/**
|
|
81
|
-
* How dark the screen-space shadows appear. 1.0 is full opacity, 0.0 is no shadows.
|
|
82
|
-
*/
|
|
83
73
|
set ssShadowOpacity(value) {
|
|
84
74
|
if (!this._voxelTracingPass)
|
|
85
75
|
return;
|
|
@@ -91,9 +81,6 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
91
81
|
get ssShadowSamples() {
|
|
92
82
|
return this._voxelTracingPass?.sssSamples;
|
|
93
83
|
}
|
|
94
|
-
/**
|
|
95
|
-
* The number of samples used in the screen space shadow pass.
|
|
96
|
-
*/
|
|
97
84
|
set ssShadowSamples(value) {
|
|
98
85
|
if (!this._voxelTracingPass)
|
|
99
86
|
return;
|
|
@@ -105,43 +92,31 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
105
92
|
get ssShadowStride() {
|
|
106
93
|
return this._voxelTracingPass?.sssStride;
|
|
107
94
|
}
|
|
108
|
-
/**
|
|
109
|
-
* The stride of the screen-space shadow pass. This controls the distance between samples.
|
|
110
|
-
*/
|
|
111
95
|
set ssShadowStride(value) {
|
|
112
96
|
if (!this._voxelTracingPass)
|
|
113
97
|
return;
|
|
114
98
|
this._voxelTracingPass.sssStride = value;
|
|
115
99
|
}
|
|
116
100
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
101
|
+
* A scale for the maximum distance a shadow can be cast in screen space.
|
|
102
|
+
* The absolute distance for SS shadows is derived from the voxel size and this scalar.
|
|
119
103
|
*/
|
|
120
|
-
get
|
|
121
|
-
return this.
|
|
104
|
+
get ssShadowDistanceScale() {
|
|
105
|
+
return this._sssMaxDistScale;
|
|
122
106
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
*/
|
|
127
|
-
set ssShadowMaxDist(value) {
|
|
128
|
-
if (!this._voxelTracingPass)
|
|
129
|
-
return;
|
|
130
|
-
this._voxelTracingPass.sssMaxDist = value;
|
|
107
|
+
set ssShadowDistanceScale(value) {
|
|
108
|
+
this._sssMaxDistScale = value;
|
|
109
|
+
this._updateSSShadowParams();
|
|
131
110
|
}
|
|
132
111
|
/**
|
|
133
112
|
* Screen-space shadow thickness. This value controls the perceived thickness of the SS shadows.
|
|
134
113
|
*/
|
|
135
|
-
get
|
|
136
|
-
return this.
|
|
114
|
+
get ssShadowThicknessScale() {
|
|
115
|
+
return this._sssThicknessScale;
|
|
137
116
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
set ssShadowThickness(value) {
|
|
142
|
-
if (!this._voxelTracingPass)
|
|
143
|
-
return;
|
|
144
|
-
this._voxelTracingPass.sssThickness = value;
|
|
117
|
+
set ssShadowThicknessScale(value) {
|
|
118
|
+
this._sssThicknessScale = value;
|
|
119
|
+
this._updateSSShadowParams();
|
|
145
120
|
}
|
|
146
121
|
/**
|
|
147
122
|
* Set the IBL image to be used for shadowing. It can be either a cubemap
|
|
@@ -156,23 +131,86 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
156
131
|
/**
|
|
157
132
|
* Returns the texture containing the voxel grid data
|
|
158
133
|
* @returns The texture containing the voxel grid data
|
|
134
|
+
* @internal
|
|
159
135
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
136
|
+
_getVoxelGridTexture() {
|
|
137
|
+
const tex = this._voxelRenderer?.getVoxelGrid();
|
|
138
|
+
if (tex && tex.isReady()) {
|
|
139
|
+
return tex;
|
|
140
|
+
}
|
|
141
|
+
return this._dummyTexture3d;
|
|
162
142
|
}
|
|
163
143
|
/**
|
|
164
144
|
* Returns the texture containing the importance sampling CDF data for the IBL shadow pipeline
|
|
165
145
|
* @returns The texture containing the importance sampling CDF data for the IBL shadow pipeline
|
|
146
|
+
* @internal
|
|
166
147
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
148
|
+
_getIcdfyTexture() {
|
|
149
|
+
const tex = this._importanceSamplingRenderer.getIcdfyTexture();
|
|
150
|
+
if (tex && tex.isReady()) {
|
|
151
|
+
return tex;
|
|
152
|
+
}
|
|
153
|
+
return this._dummyTexture2d;
|
|
169
154
|
}
|
|
170
155
|
/**
|
|
171
156
|
* Returns the texture containing the importance sampling CDF data for the IBL shadow pipeline
|
|
172
157
|
* @returns The texture containing the importance sampling CDF data for the IBL shadow pipeline
|
|
158
|
+
* @internal
|
|
173
159
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
160
|
+
_getIcdfxTexture() {
|
|
161
|
+
const tex = this._importanceSamplingRenderer.getIcdfxTexture();
|
|
162
|
+
if (tex && tex.isReady()) {
|
|
163
|
+
return tex;
|
|
164
|
+
}
|
|
165
|
+
return this._dummyTexture2d;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Returns the noise texture.
|
|
169
|
+
* @returns The noise texture.
|
|
170
|
+
* @internal
|
|
171
|
+
*/
|
|
172
|
+
_getNoiseTexture() {
|
|
173
|
+
const tex = this._noiseTexture;
|
|
174
|
+
if (tex && tex.isReady()) {
|
|
175
|
+
return tex;
|
|
176
|
+
}
|
|
177
|
+
return this._dummyTexture2d;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Returns the voxel-tracing texture.
|
|
181
|
+
* @returns The voxel-tracing texture.
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
184
|
+
_getVoxelTracingTexture() {
|
|
185
|
+
const tex = this._voxelTracingPass?.getOutputTexture();
|
|
186
|
+
if (tex && tex.isReady()) {
|
|
187
|
+
return tex;
|
|
188
|
+
}
|
|
189
|
+
return this._dummyTexture2d;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Returns the spatial blur texture.
|
|
193
|
+
* @returns The spatial blur texture.
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
_getSpatialBlurTexture() {
|
|
197
|
+
const tex = this._spatialBlurPass.getOutputTexture();
|
|
198
|
+
if (tex && tex.isReady()) {
|
|
199
|
+
return tex;
|
|
200
|
+
}
|
|
201
|
+
return this._dummyTexture2d;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Returns the accumulated shadow texture.
|
|
205
|
+
* @returns The accumulated shadow texture.
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
208
|
+
_getAccumulatedTexture() {
|
|
209
|
+
const tex = this._accumulationPass?.getOutputTexture();
|
|
210
|
+
if (tex && tex.isReady()) {
|
|
211
|
+
return tex;
|
|
212
|
+
}
|
|
213
|
+
return this._dummyTexture2d;
|
|
176
214
|
}
|
|
177
215
|
/**
|
|
178
216
|
* Is the debug view of the G-Buffer enabled?
|
|
@@ -300,7 +338,7 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
300
338
|
* Display the debug view for the spatial blur pass
|
|
301
339
|
*/
|
|
302
340
|
get spatialBlurPassDebugEnabled() {
|
|
303
|
-
return this._spatialBlurPass
|
|
341
|
+
return this._spatialBlurPass.debugEnabled;
|
|
304
342
|
}
|
|
305
343
|
/**
|
|
306
344
|
* Display the debug view for the spatial blur pass
|
|
@@ -349,22 +387,41 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
349
387
|
}
|
|
350
388
|
}
|
|
351
389
|
/**
|
|
352
|
-
* Add a mesh
|
|
353
|
-
* @param mesh
|
|
390
|
+
* Add a mesh to be used for shadow casting in the IBL shadow pipeline
|
|
391
|
+
* @param mesh A mesh or list of meshes that you want to cast shadows
|
|
354
392
|
*/
|
|
355
|
-
|
|
356
|
-
if (
|
|
357
|
-
|
|
393
|
+
addShadowCastingMesh(mesh) {
|
|
394
|
+
if (Array.isArray(mesh)) {
|
|
395
|
+
for (const m of mesh) {
|
|
396
|
+
if (m && this._shadowCastingMeshes.indexOf(m) === -1) {
|
|
397
|
+
this._shadowCastingMeshes.push(m);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
if (mesh && this._shadowCastingMeshes.indexOf(mesh) === -1) {
|
|
403
|
+
this._shadowCastingMeshes.push(mesh);
|
|
404
|
+
}
|
|
358
405
|
}
|
|
359
406
|
}
|
|
360
407
|
/**
|
|
361
|
-
* Remove a mesh from the
|
|
362
|
-
* @param mesh The mesh to
|
|
408
|
+
* Remove a mesh from the shadow-casting list.
|
|
409
|
+
* @param mesh The mesh or list of meshes that you don't want to cast shadows.
|
|
363
410
|
*/
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
411
|
+
removeShadowCastingMesh(mesh) {
|
|
412
|
+
if (Array.isArray(mesh)) {
|
|
413
|
+
for (const m of mesh) {
|
|
414
|
+
const index = this._shadowCastingMeshes.indexOf(m);
|
|
415
|
+
if (index !== -1) {
|
|
416
|
+
this._shadowCastingMeshes.splice(index, 1);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
const index = this._shadowCastingMeshes.indexOf(mesh);
|
|
422
|
+
if (index !== -1) {
|
|
423
|
+
this._shadowCastingMeshes.splice(index, 1);
|
|
424
|
+
}
|
|
368
425
|
}
|
|
369
426
|
}
|
|
370
427
|
/**
|
|
@@ -388,7 +445,6 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
388
445
|
return;
|
|
389
446
|
}
|
|
390
447
|
this._voxelRenderer.voxelResolutionExp = newResolution;
|
|
391
|
-
this.updateVoxelization();
|
|
392
448
|
this._accumulationPass.reset = true;
|
|
393
449
|
}
|
|
394
450
|
/**
|
|
@@ -432,6 +488,7 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
432
488
|
if (!this._voxelTracingPass)
|
|
433
489
|
return;
|
|
434
490
|
this._voxelTracingPass.envRotation = value;
|
|
491
|
+
this._accumulationPass.reset = true;
|
|
435
492
|
}
|
|
436
493
|
/**
|
|
437
494
|
* Allow debug passes to be enabled. Default is false.
|
|
@@ -478,70 +535,93 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
478
535
|
*/
|
|
479
536
|
constructor(name, scene, options = {}, cameras) {
|
|
480
537
|
super(scene.getEngine(), name);
|
|
481
|
-
this._voxelizationDirty = true;
|
|
482
|
-
this._boundsNeedUpdate = true;
|
|
483
538
|
this._allowDebugPasses = false;
|
|
484
539
|
this._debugPasses = [];
|
|
485
|
-
this.
|
|
486
|
-
this._shadowOpacity = 0.
|
|
540
|
+
this._shadowCastingMeshes = [];
|
|
541
|
+
this._shadowOpacity = 0.8;
|
|
487
542
|
this._enabled = true;
|
|
543
|
+
this._materialsWithRenderPlugin = [];
|
|
544
|
+
/**
|
|
545
|
+
* Observable that triggers when the shadow renderer is ready
|
|
546
|
+
*/
|
|
547
|
+
this.onShadowTextureReadyObservable = new Observable();
|
|
548
|
+
/**
|
|
549
|
+
* Observable that triggers when a new IBL is set and the importance sampling is ready
|
|
550
|
+
*/
|
|
551
|
+
this.onNewIblReadyObservable = new Observable();
|
|
488
552
|
/**
|
|
489
553
|
* The current world-space size of that the voxel grid covers in the scene.
|
|
490
554
|
*/
|
|
491
555
|
this.voxelGridSize = 1.0;
|
|
556
|
+
this._renderSizeFactor = 1.0;
|
|
492
557
|
this._gbufferDebugEnabled = false;
|
|
493
558
|
this._gBufferDebugSizeParams = new Vector4(0.0, 0.0, 0.0, 0.0);
|
|
494
559
|
this.scene = scene;
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
560
|
+
this._cameras = cameras || [scene.activeCamera];
|
|
561
|
+
// Create the dummy textures to be used when the pipeline is not ready
|
|
562
|
+
const blackPixels = new Uint8Array([0, 0, 0, 255]);
|
|
563
|
+
this._dummyTexture2d = new RawTexture(blackPixels, 1, 1, Engine.TEXTUREFORMAT_RGBA, scene, false);
|
|
564
|
+
this._dummyTexture3d = new RawTexture3D(blackPixels, 1, 1, 1, Engine.TEXTUREFORMAT_RGBA, scene, false);
|
|
565
|
+
// Setup the geometry buffer target formats
|
|
566
|
+
const textureTypesAndFormats = {};
|
|
567
|
+
textureTypesAndFormats[GeometryBufferRenderer.SCREENSPACE_DEPTH_TEXTURE_TYPE] = {
|
|
568
|
+
textureFormat: 6,
|
|
569
|
+
textureType: 1,
|
|
570
|
+
};
|
|
571
|
+
textureTypesAndFormats[GeometryBufferRenderer.VELOCITY_LINEAR_TEXTURE_TYPE] = {
|
|
572
|
+
textureFormat: 7,
|
|
573
|
+
textureType: 2,
|
|
574
|
+
};
|
|
575
|
+
textureTypesAndFormats[GeometryBufferRenderer.POSITION_TEXTURE_TYPE] = {
|
|
576
|
+
textureFormat: 5,
|
|
577
|
+
textureType: 2,
|
|
578
|
+
};
|
|
579
|
+
textureTypesAndFormats[GeometryBufferRenderer.NORMAL_TEXTURE_TYPE] = {
|
|
580
|
+
textureFormat: 5,
|
|
581
|
+
textureType: 2,
|
|
582
|
+
};
|
|
583
|
+
const geometryBufferRenderer = scene.enableGeometryBufferRenderer(undefined, 14, textureTypesAndFormats);
|
|
584
|
+
if (!geometryBufferRenderer) {
|
|
585
|
+
Logger.Error("Geometry buffer renderer is required for IBL shadows to work.");
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
this._geometryBufferRenderer = geometryBufferRenderer;
|
|
589
|
+
this._geometryBufferRenderer.enableScreenspaceDepth = true;
|
|
590
|
+
this._geometryBufferRenderer.enableVelocityLinear = true;
|
|
591
|
+
this._geometryBufferRenderer.enablePosition = true;
|
|
592
|
+
this._geometryBufferRenderer.enableNormal = true;
|
|
593
|
+
this._geometryBufferRenderer.generateNormalsInWorldSpace = true;
|
|
594
|
+
this.shadowOpacity = options.shadowOpacity || 0.8;
|
|
502
595
|
this._voxelRenderer = new _IblShadowsVoxelRenderer(this.scene, this, options ? options.resolutionExp : 6, options.triPlanarVoxelization !== undefined ? options.triPlanarVoxelization : true);
|
|
503
596
|
this._importanceSamplingRenderer = new _IblShadowsImportanceSamplingRenderer(this.scene);
|
|
504
597
|
this._voxelTracingPass = new _IblShadowsVoxelTracingPass(this.scene, this);
|
|
598
|
+
this._spatialBlurPass = new _IblShadowsSpatialBlurPass(this.scene, this);
|
|
599
|
+
this._accumulationPass = new _IblShadowsAccumulationPass(this.scene, this);
|
|
600
|
+
this._accumulationPass.onReadyObservable.addOnce(() => {
|
|
601
|
+
this.onShadowTextureReadyObservable.notifyObservers();
|
|
602
|
+
});
|
|
505
603
|
this.sampleDirections = options.sampleDirections || 2;
|
|
506
|
-
this.voxelShadowOpacity = options.voxelShadowOpacity
|
|
604
|
+
this.voxelShadowOpacity = options.voxelShadowOpacity ?? 1.0;
|
|
605
|
+
this.shadowRenderSizeFactor = options.shadowRenderSizeFactor || 1.0;
|
|
507
606
|
this.ssShadowOpacity = options.ssShadowsEnabled === undefined || options.ssShadowsEnabled ? 1.0 : 0.0;
|
|
508
|
-
this.
|
|
607
|
+
this.ssShadowDistanceScale = options.ssShadowDistanceScale || 1.25;
|
|
509
608
|
this.ssShadowSamples = options.ssShadowSampleCount || 16;
|
|
510
609
|
this.ssShadowStride = options.ssShadowStride || 8;
|
|
511
|
-
this.
|
|
512
|
-
this.
|
|
513
|
-
this._accumulationPass = new _IblShadowsAccumulationPass(this.scene);
|
|
514
|
-
this.shadowRemenance = options.shadowRemenance || 0.75;
|
|
610
|
+
this.ssShadowThicknessScale = options.ssShadowThicknessScale || 1.0;
|
|
611
|
+
this.shadowRemenance = options.shadowRemenance ?? 0.75;
|
|
515
612
|
this._noiseTexture = new Texture("https://assets.babylonjs.com/textures/blue_noise/blue_noise_rgb.png", this.scene, false, true, 1);
|
|
516
613
|
if (this.scene.environmentTexture) {
|
|
517
614
|
this._importanceSamplingRenderer.iblSource = this.scene.environmentTexture;
|
|
518
615
|
}
|
|
519
|
-
// Create post process that applies the shadows to the scene
|
|
520
|
-
this._createShadowCombinePostProcess();
|
|
521
616
|
scene.postProcessRenderPipelineManager.addPipeline(this);
|
|
522
|
-
this.scene.onNewMeshAddedObservable.add(this.updateSceneBounds.bind(this));
|
|
523
|
-
this.scene.onMeshRemovedObservable.add(this.updateSceneBounds.bind(this));
|
|
524
617
|
this.scene.onActiveCameraChanged.add(this._listenForCameraChanges.bind(this));
|
|
525
618
|
this.scene.onBeforeRenderObservable.add(this._updateBeforeRender.bind(this));
|
|
526
619
|
this._listenForCameraChanges();
|
|
527
620
|
this.scene.getEngine().onResizeObservable.add(this._handleResize.bind(this));
|
|
528
|
-
//
|
|
529
|
-
this._importanceSamplingRenderer.onReadyObservable.
|
|
530
|
-
this.
|
|
531
|
-
|
|
532
|
-
if (this._voxelRenderer.isReady()) {
|
|
533
|
-
this.toggleShadow(this._enabled);
|
|
534
|
-
if (this._enabled) {
|
|
535
|
-
this._voxelizationDirty = true;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
else {
|
|
539
|
-
setTimeout(() => {
|
|
540
|
-
checkVoxelRendererReady();
|
|
541
|
-
}, 16);
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
checkVoxelRendererReady();
|
|
621
|
+
// Assigning the shadow texture to the materials needs to be done after the RT's are created.
|
|
622
|
+
this._importanceSamplingRenderer.onReadyObservable.add(() => {
|
|
623
|
+
this._setPluginParameters();
|
|
624
|
+
this.onNewIblReadyObservable.notifyObservers();
|
|
545
625
|
});
|
|
546
626
|
}
|
|
547
627
|
/**
|
|
@@ -550,85 +630,30 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
550
630
|
*/
|
|
551
631
|
toggleShadow(enabled) {
|
|
552
632
|
this._enabled = enabled;
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
this._disableEffect("IBLShadowCompositePass", null);
|
|
564
|
-
}
|
|
633
|
+
this._voxelTracingPass.enabled = enabled;
|
|
634
|
+
this._spatialBlurPass.enabled = enabled;
|
|
635
|
+
this._accumulationPass.enabled = enabled;
|
|
636
|
+
this._materialsWithRenderPlugin.forEach((mat) => {
|
|
637
|
+
if (mat.pluginManager) {
|
|
638
|
+
const plugin = mat.pluginManager.getPlugin(IBLShadowsPluginMaterial.Name);
|
|
639
|
+
plugin.isEnabled = enabled;
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
this._setPluginParameters();
|
|
565
643
|
}
|
|
566
644
|
_handleResize() {
|
|
567
645
|
this._voxelRenderer.resize();
|
|
568
|
-
this.
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const compositeOptions = {
|
|
573
|
-
width: this.scene.getEngine().getRenderWidth(),
|
|
574
|
-
height: this.scene.getEngine().getRenderHeight(),
|
|
575
|
-
uniforms: ["shadowOpacity"],
|
|
576
|
-
samplers: ["sceneTexture"],
|
|
577
|
-
samplingMode: 2,
|
|
578
|
-
engine: this.scene.getEngine(),
|
|
579
|
-
textureType: 0,
|
|
580
|
-
reusable: false,
|
|
581
|
-
shaderLanguage: isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
|
|
582
|
-
extraInitializations: (useWebGPU, list) => {
|
|
583
|
-
if (useWebGPU) {
|
|
584
|
-
list.push(import("../../ShadersWGSL/iblShadowsCombine.fragment.js"));
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
list.push(import("../../Shaders/iblShadowsCombine.fragment.js"));
|
|
588
|
-
}
|
|
589
|
-
},
|
|
590
|
-
};
|
|
591
|
-
this._shadowCompositePP = new PostProcess("iblShadowsCombine", "iblShadowsCombine", compositeOptions);
|
|
592
|
-
this._shadowCompositePP.autoClear = false;
|
|
593
|
-
this._shadowCompositePP.onApplyObservable.add((effect) => {
|
|
594
|
-
// Setting the input of the tracing pass because this is the scene RT that we want to apply the shadows to.
|
|
595
|
-
effect.setTextureFromPostProcess("sceneTexture", this._voxelTracingPass.getPassPP());
|
|
596
|
-
effect.setFloat("shadowOpacity", this._shadowOpacity);
|
|
597
|
-
if (this._importanceSamplingRenderer?.isReady() &&
|
|
598
|
-
this._voxelRenderer?.isReady() &&
|
|
599
|
-
this._voxelTracingPass?.isReady() &&
|
|
600
|
-
this._spatialBlurPass?.isReady() &&
|
|
601
|
-
this._accumulationPass?.isReady()) {
|
|
602
|
-
this.update();
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
this._shadowCompositePP._prePassEffectConfiguration = this._prePassEffectConfiguration;
|
|
606
|
-
}
|
|
607
|
-
_createEffectPasses(cameras) {
|
|
608
|
-
this.addEffect(new PostProcessRenderEffect(this.scene.getEngine(), "IBLShadowVoxelTracingPass", () => {
|
|
609
|
-
return this._voxelTracingPass.getPassPP();
|
|
610
|
-
}, true));
|
|
611
|
-
this.addEffect(new PostProcessRenderEffect(this.scene.getEngine(), "IBLShadowSpatialBlurPass", () => {
|
|
612
|
-
return this._spatialBlurPass.getPassPP();
|
|
613
|
-
}, true));
|
|
614
|
-
this.addEffect(new PostProcessRenderEffect(this.scene.getEngine(), "IBLShadowAccumulationBlurPass", () => {
|
|
615
|
-
return this._accumulationPass.getPassPP();
|
|
616
|
-
}, true));
|
|
617
|
-
this.addEffect(new PostProcessRenderEffect(this.scene.getEngine(), "IBLShadowCompositePass", () => {
|
|
618
|
-
return this._shadowCompositePP;
|
|
619
|
-
}, true));
|
|
620
|
-
if (cameras) {
|
|
621
|
-
this.scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this.name, cameras);
|
|
622
|
-
}
|
|
623
|
-
this.toggleShadow(false);
|
|
624
|
-
this._enabled = true;
|
|
646
|
+
this._voxelTracingPass.resize(this.shadowRenderSizeFactor);
|
|
647
|
+
this._spatialBlurPass.resize(this.shadowRenderSizeFactor);
|
|
648
|
+
this._accumulationPass.resize(this.shadowRenderSizeFactor);
|
|
649
|
+
this._setPluginParameters();
|
|
625
650
|
}
|
|
626
651
|
_getGBufferDebugPass() {
|
|
627
652
|
if (this._gbufferDebugPass) {
|
|
628
653
|
return this._gbufferDebugPass;
|
|
629
654
|
}
|
|
630
655
|
const isWebGPU = this.engine.isWebGPU;
|
|
631
|
-
const textureNames =
|
|
656
|
+
const textureNames = ["depthSampler", "normalSampler", "positionSampler", "velocitySampler"];
|
|
632
657
|
const options = {
|
|
633
658
|
width: this.scene.getEngine().getRenderWidth(),
|
|
634
659
|
height: this.scene.getEngine().getRenderHeight(),
|
|
@@ -652,16 +677,14 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
652
677
|
this._gbufferDebugPass = new PostProcess("iblShadowGBufferDebug", "iblShadowGBufferDebug", options);
|
|
653
678
|
this._gbufferDebugPass.autoClear = false;
|
|
654
679
|
this._gbufferDebugPass.onApplyObservable.add((effect) => {
|
|
655
|
-
this.
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
effect.setTexture(PrePassRenderer.TextureFormats[type].name, prePassRenderer.getRenderTarget().textures[index]);
|
|
664
|
-
});
|
|
680
|
+
const depthIndex = this._geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.SCREENSPACE_DEPTH_TEXTURE_TYPE);
|
|
681
|
+
effect.setTexture("depthSampler", this._geometryBufferRenderer.getGBuffer().textures[depthIndex]);
|
|
682
|
+
const normalIndex = this._geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.NORMAL_TEXTURE_TYPE);
|
|
683
|
+
effect.setTexture("normalSampler", this._geometryBufferRenderer.getGBuffer().textures[normalIndex]);
|
|
684
|
+
const positionIndex = this._geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.POSITION_TEXTURE_TYPE);
|
|
685
|
+
effect.setTexture("positionSampler", this._geometryBufferRenderer.getGBuffer().textures[positionIndex]);
|
|
686
|
+
const velocityIndex = this._geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.VELOCITY_LINEAR_TEXTURE_TYPE);
|
|
687
|
+
effect.setTexture("velocitySampler", this._geometryBufferRenderer.getGBuffer().textures[velocityIndex]);
|
|
665
688
|
effect.setVector4("sizeParams", this._gBufferDebugSizeParams);
|
|
666
689
|
if (this.scene.activeCamera) {
|
|
667
690
|
effect.setFloat("maxDepth", this.scene.activeCamera.maxZ);
|
|
@@ -671,11 +694,11 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
671
694
|
}
|
|
672
695
|
_createDebugPasses() {
|
|
673
696
|
this._debugPasses = [
|
|
674
|
-
{ pass: this._importanceSamplingRenderer
|
|
675
|
-
{ pass: this._voxelRenderer
|
|
676
|
-
{ pass: this._voxelTracingPass
|
|
677
|
-
{ pass: this._spatialBlurPass
|
|
678
|
-
{ pass: this._accumulationPass
|
|
697
|
+
{ pass: this._importanceSamplingRenderer.getDebugPassPP(), enabled: this.importanceSamplingDebugEnabled },
|
|
698
|
+
{ pass: this._voxelRenderer.getDebugPassPP(), enabled: this.voxelDebugEnabled },
|
|
699
|
+
{ pass: this._voxelTracingPass.getDebugPassPP(), enabled: this.voxelTracingDebugEnabled },
|
|
700
|
+
{ pass: this._spatialBlurPass.getDebugPassPP(), enabled: this.spatialBlurPassDebugEnabled },
|
|
701
|
+
{ pass: this._accumulationPass.getDebugPassPP(), enabled: this.accumulationPassDebugEnabled },
|
|
679
702
|
{ pass: this._getGBufferDebugPass(), enabled: this.gbufferDebugEnabled },
|
|
680
703
|
];
|
|
681
704
|
for (let i = 0; i < this._debugPasses.length; i++) {
|
|
@@ -701,10 +724,6 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
701
724
|
}
|
|
702
725
|
_disposeEffectPasses() {
|
|
703
726
|
this.scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this.name, this.cameras);
|
|
704
|
-
this._disableEffect("IBLShadowVoxelTracingPass", this.cameras);
|
|
705
|
-
this._disableEffect("IBLShadowSpatialBlurPass", this.cameras);
|
|
706
|
-
this._disableEffect("IBLShadowAccumulationBlurPass", this.cameras);
|
|
707
|
-
this._disableEffect("IBLShadowCompositePass", this.cameras);
|
|
708
727
|
this._disposeDebugPasses();
|
|
709
728
|
this._reset();
|
|
710
729
|
}
|
|
@@ -736,11 +755,6 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
736
755
|
let x = 0;
|
|
737
756
|
let y = 0;
|
|
738
757
|
if (this.gbufferDebugEnabled) {
|
|
739
|
-
const prePassRenderer = this.scene.prePassRenderer;
|
|
740
|
-
if (!prePassRenderer) {
|
|
741
|
-
Logger.Error("Can't enable G-Buffer debug rendering since prepassRenderer doesn't exist.");
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
758
|
this._gBufferDebugSizeParams.set(x, y, cols, rows);
|
|
745
759
|
x -= width;
|
|
746
760
|
if (x <= -1) {
|
|
@@ -793,60 +807,136 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
793
807
|
* Trigger the scene to be re-voxelized. This is useful when the scene has changed and the voxel grid needs to be updated.
|
|
794
808
|
*/
|
|
795
809
|
updateVoxelization() {
|
|
796
|
-
this.
|
|
810
|
+
if (this._shadowCastingMeshes.length === 0) {
|
|
811
|
+
Logger.Warn("IBL Shadows: updateVoxelization called with no shadow-casting meshes to voxelize.");
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
this._voxelRenderer.updateVoxelGrid(this._shadowCastingMeshes);
|
|
815
|
+
this._updateSSShadowParams();
|
|
797
816
|
}
|
|
798
817
|
/**
|
|
799
818
|
* Trigger the scene bounds of shadow-casters to be updated. This is useful when the scene has changed and the bounds need
|
|
800
819
|
* to be recalculated. This will also trigger a re-voxelization.
|
|
801
820
|
*/
|
|
802
821
|
updateSceneBounds() {
|
|
803
|
-
|
|
804
|
-
|
|
822
|
+
const bounds = {
|
|
823
|
+
min: new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE),
|
|
824
|
+
max: new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE),
|
|
825
|
+
};
|
|
826
|
+
this._shadowCastingMeshes.forEach((mesh) => {
|
|
827
|
+
const localBounds = mesh.getHierarchyBoundingVectors(true);
|
|
828
|
+
bounds.min = Vector3.Minimize(bounds.min, localBounds.min);
|
|
829
|
+
bounds.max = Vector3.Maximize(bounds.max, localBounds.max);
|
|
830
|
+
});
|
|
831
|
+
const size = bounds.max.subtract(bounds.min);
|
|
832
|
+
this.voxelGridSize = Math.max(size.x, size.y, size.z);
|
|
833
|
+
if (this._shadowCastingMeshes.length === 0 || !isFinite(this.voxelGridSize) || this.voxelGridSize === 0) {
|
|
834
|
+
Logger.Warn("IBL Shadows: Scene size is invalid. Can't update bounds.");
|
|
835
|
+
this.voxelGridSize = 1.0;
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
const halfSize = this.voxelGridSize / 2.0;
|
|
839
|
+
const centre = bounds.max.add(bounds.min).multiplyByFloats(-0.5, -0.5, -0.5);
|
|
840
|
+
const invWorldScaleMatrix = Matrix.Compose(new Vector3(1.0 / halfSize, 1.0 / halfSize, 1.0 / halfSize), new Quaternion(), new Vector3(0, 0, 0));
|
|
841
|
+
const invTranslationMatrix = Matrix.Compose(new Vector3(1.0, 1.0, 1.0), new Quaternion(), centre);
|
|
842
|
+
invTranslationMatrix.multiplyToRef(invWorldScaleMatrix, invWorldScaleMatrix);
|
|
843
|
+
this._voxelTracingPass.setWorldScaleMatrix(invWorldScaleMatrix);
|
|
844
|
+
this._voxelRenderer.setWorldScaleMatrix(invWorldScaleMatrix);
|
|
845
|
+
// Set world scale for spatial blur.
|
|
846
|
+
this._spatialBlurPass.setWorldScale(halfSize * 2.0);
|
|
847
|
+
this._updateSSShadowParams();
|
|
805
848
|
}
|
|
806
|
-
|
|
807
|
-
|
|
849
|
+
/**
|
|
850
|
+
* Update the SS shadow max distance and thickness based on the voxel grid size and resolution.
|
|
851
|
+
* The max distance should be just a little larger than the world size of a single voxel.
|
|
852
|
+
*/
|
|
853
|
+
_updateSSShadowParams() {
|
|
854
|
+
this._voxelTracingPass.sssMaxDist = (this._sssMaxDistScale * this.voxelGridSize) / (1 << this.resolutionExp);
|
|
855
|
+
this._voxelTracingPass.sssThickness = this._sssThicknessScale * 0.005 * this.voxelGridSize;
|
|
808
856
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
camera.cameraRotation.x !== 0 ||
|
|
828
|
-
camera.cameraRotation.y !== 0;
|
|
829
|
-
}
|
|
830
|
-
if (this._accumulationPass) {
|
|
831
|
-
if (isMoving) {
|
|
832
|
-
// this._accumulationPass.reset = true;
|
|
833
|
-
// this._accumulationPass.remenance = 1.0;
|
|
834
|
-
}
|
|
835
|
-
else {
|
|
836
|
-
// this._accumulationPass.reset = false;
|
|
837
|
-
// this._accumulationPass.remenance = 0.9;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
857
|
+
/**
|
|
858
|
+
* Apply the shadows to a material or array of materials.
|
|
859
|
+
* @param material Material that will be affected by the shadows. If not provided, all materials of the scene will be affected.
|
|
860
|
+
*/
|
|
861
|
+
addShadowReceivingMaterial(material) {
|
|
862
|
+
if (material) {
|
|
863
|
+
if (Array.isArray(material)) {
|
|
864
|
+
material.forEach((m) => {
|
|
865
|
+
this._addShadowSupportToMaterial(m);
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
else {
|
|
869
|
+
this._addShadowSupportToMaterial(material);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
this.scene.materials.forEach((mat) => {
|
|
874
|
+
this._addShadowSupportToMaterial(mat);
|
|
840
875
|
});
|
|
841
876
|
}
|
|
842
877
|
}
|
|
843
878
|
/**
|
|
844
|
-
*
|
|
845
|
-
* @param
|
|
846
|
-
* @returns true if the pre pass is setup
|
|
879
|
+
* Remove a material from receiving shadows
|
|
880
|
+
* @param material The material that will no longer receive shadows
|
|
847
881
|
*/
|
|
848
|
-
|
|
849
|
-
|
|
882
|
+
removeShadowReceivingMaterial(material) {
|
|
883
|
+
if (Array.isArray(material)) {
|
|
884
|
+
material.forEach((m) => {
|
|
885
|
+
const matIndex = this._materialsWithRenderPlugin.indexOf(m);
|
|
886
|
+
if (matIndex !== -1) {
|
|
887
|
+
this._materialsWithRenderPlugin.splice(matIndex, 1);
|
|
888
|
+
const plugin = m.pluginManager?.getPlugin(IBLShadowsPluginMaterial.Name);
|
|
889
|
+
plugin.isEnabled = false;
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
else {
|
|
894
|
+
const matIndex = this._materialsWithRenderPlugin.indexOf(material);
|
|
895
|
+
if (matIndex !== -1) {
|
|
896
|
+
this._materialsWithRenderPlugin.splice(matIndex, 1);
|
|
897
|
+
const plugin = material.pluginManager.getPlugin(IBLShadowsPluginMaterial.Name);
|
|
898
|
+
plugin.isEnabled = false;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
_addShadowSupportToMaterial(material) {
|
|
903
|
+
if (!(material instanceof PBRBaseMaterial) && !(material instanceof StandardMaterial)) {
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
let plugin = material.pluginManager?.getPlugin(IBLShadowsPluginMaterial.Name);
|
|
907
|
+
if (!plugin) {
|
|
908
|
+
plugin = new IBLShadowsPluginMaterial(material);
|
|
909
|
+
}
|
|
910
|
+
if (this._materialsWithRenderPlugin.indexOf(material) !== -1) {
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
if (this._enabled) {
|
|
914
|
+
plugin.iblShadowsTexture = this._getAccumulatedTexture().getInternalTexture();
|
|
915
|
+
plugin.shadowOpacity = this.shadowOpacity;
|
|
916
|
+
}
|
|
917
|
+
plugin.isEnabled = this._enabled;
|
|
918
|
+
this._materialsWithRenderPlugin.push(material);
|
|
919
|
+
}
|
|
920
|
+
_setPluginParameters() {
|
|
921
|
+
if (!this._enabled) {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
this._materialsWithRenderPlugin.forEach((mat) => {
|
|
925
|
+
if (mat.pluginManager) {
|
|
926
|
+
const plugin = mat.pluginManager.getPlugin(IBLShadowsPluginMaterial.Name);
|
|
927
|
+
plugin.iblShadowsTexture = this._getAccumulatedTexture().getInternalTexture();
|
|
928
|
+
plugin.shadowOpacity = this.shadowOpacity;
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
_updateBeforeRender() {
|
|
933
|
+
this._updateDebugPasses();
|
|
934
|
+
}
|
|
935
|
+
_listenForCameraChanges() {
|
|
936
|
+
// We want to listen for camera changes and change settings while the camera is moving.
|
|
937
|
+
this.scene.activeCamera?.onViewMatrixChangedObservable.add(() => {
|
|
938
|
+
this._accumulationPass.isMoving = true;
|
|
939
|
+
});
|
|
850
940
|
}
|
|
851
941
|
/**
|
|
852
942
|
* Checks if the IBL shadow pipeline is ready to render shadows
|
|
@@ -860,54 +950,6 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
860
950
|
(!this._spatialBlurPass || this._spatialBlurPass.isReady()) &&
|
|
861
951
|
(!this._accumulationPass || this._accumulationPass.isReady()));
|
|
862
952
|
}
|
|
863
|
-
/**
|
|
864
|
-
* Renders accumulated shadows for IBL
|
|
865
|
-
*/
|
|
866
|
-
update() {
|
|
867
|
-
// This is called for every MRT in the customRenderTargets structure during voxelization. That doesn't make
|
|
868
|
-
// sense. We only want this to run after voxelization so we should put in some state logic here to return
|
|
869
|
-
// if voxelization is happening.
|
|
870
|
-
if (this._voxelRenderer.isVoxelizationInProgress()) {
|
|
871
|
-
return;
|
|
872
|
-
}
|
|
873
|
-
if (this._boundsNeedUpdate) {
|
|
874
|
-
const bounds = this.scene.getWorldExtends((mesh) => {
|
|
875
|
-
return mesh instanceof Mesh && this._excludedMeshes.indexOf(mesh.uniqueId) === -1;
|
|
876
|
-
});
|
|
877
|
-
const size = bounds.max.subtract(bounds.min);
|
|
878
|
-
this.voxelGridSize = Math.max(size.x, Math.max(size.y, size.z));
|
|
879
|
-
if (!isFinite(this.voxelGridSize) || this.voxelGridSize === 0) {
|
|
880
|
-
Logger.Warn("IBL Shadows: Scene size is invalid. Can't update bounds.");
|
|
881
|
-
this._boundsNeedUpdate = false;
|
|
882
|
-
this.voxelGridSize = 1.0;
|
|
883
|
-
return;
|
|
884
|
-
}
|
|
885
|
-
const halfSize = this.voxelGridSize / 2.0;
|
|
886
|
-
const centre = bounds.max.add(bounds.min).multiplyByFloats(-0.5, -0.5, -0.5);
|
|
887
|
-
const invWorldScaleMatrix = Matrix.Compose(new Vector3(1.0 / halfSize, 1.0 / halfSize, 1.0 / halfSize), new Quaternion(), new Vector3(0, 0, 0));
|
|
888
|
-
const invTranslationMatrix = Matrix.Compose(new Vector3(1.0, 1.0, 1.0), new Quaternion(), centre);
|
|
889
|
-
invTranslationMatrix.multiplyToRef(invWorldScaleMatrix, invWorldScaleMatrix);
|
|
890
|
-
this._voxelTracingPass?.setWorldScaleMatrix(invWorldScaleMatrix);
|
|
891
|
-
this._voxelRenderer.setWorldScaleMatrix(invWorldScaleMatrix);
|
|
892
|
-
// Set world scale for spatial blur.
|
|
893
|
-
this._spatialBlurPass?.setWorldScale(halfSize * 2.0);
|
|
894
|
-
this._boundsNeedUpdate = false;
|
|
895
|
-
// Logger.Log("IBL Shadows: Scene size: " + size);
|
|
896
|
-
// Logger.Log("Half size: " + halfSize);
|
|
897
|
-
// Logger.Log("Centre translation: " + centre);
|
|
898
|
-
// Update the SS shadow max distance based on the voxel grid size and resolution.
|
|
899
|
-
// The max distance should be just a little larger than the world size of a single voxel.
|
|
900
|
-
this.ssShadowMaxDist = (1.1 * this.voxelGridSize) / (1 << this.resolutionExp);
|
|
901
|
-
}
|
|
902
|
-
// If update is needed, render voxels
|
|
903
|
-
if (this._voxelizationDirty) {
|
|
904
|
-
this._voxelRenderer.updateVoxelGrid(this._excludedMeshes);
|
|
905
|
-
this._voxelizationDirty = false;
|
|
906
|
-
// Update the SS shadow max distance based on the voxel grid size and resolution.
|
|
907
|
-
// The max distance should be just a little larger than the world size of a single voxel.
|
|
908
|
-
this.ssShadowMaxDist = (1.1 * this.voxelGridSize) / (1 << this.resolutionExp);
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
953
|
/**
|
|
912
954
|
* Get the class name
|
|
913
955
|
* @returns "IBLShadowsRenderPipeline"
|
|
@@ -919,13 +961,19 @@ export class IblShadowsRenderPipeline extends PostProcessRenderPipeline {
|
|
|
919
961
|
* Disposes the IBL shadow pipeline and associated resources
|
|
920
962
|
*/
|
|
921
963
|
dispose() {
|
|
964
|
+
const materials = this._materialsWithRenderPlugin.splice(0);
|
|
965
|
+
materials.forEach((mat) => {
|
|
966
|
+
this.removeShadowReceivingMaterial(mat);
|
|
967
|
+
});
|
|
922
968
|
this._disposeEffectPasses();
|
|
923
969
|
this._noiseTexture.dispose();
|
|
924
970
|
this._voxelRenderer.dispose();
|
|
925
971
|
this._importanceSamplingRenderer.dispose();
|
|
926
|
-
this._voxelTracingPass
|
|
927
|
-
this._spatialBlurPass
|
|
928
|
-
this._accumulationPass
|
|
972
|
+
this._voxelTracingPass.dispose();
|
|
973
|
+
this._spatialBlurPass.dispose();
|
|
974
|
+
this._accumulationPass.dispose();
|
|
975
|
+
this._dummyTexture2d.dispose();
|
|
976
|
+
this._dummyTexture3d.dispose();
|
|
929
977
|
super.dispose();
|
|
930
978
|
}
|
|
931
979
|
}
|