@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,18 +1,20 @@
|
|
|
1
1
|
|
|
2
2
|
import { Vector4 } from "../../Maths/math.vector.js";
|
|
3
3
|
import { PostProcess } from "../../PostProcesses/postProcess.js";
|
|
4
|
-
import {
|
|
4
|
+
import { GeometryBufferRenderer } from "../../Rendering/geometryBufferRenderer.js";
|
|
5
|
+
import { ProceduralTexture } from "../../Materials/Textures/Procedurals/proceduralTexture.js";
|
|
6
|
+
import { Observable } from "../../Misc/observable.js";
|
|
5
7
|
/**
|
|
6
8
|
* This should not be instanciated directly, as it is part of a scene component
|
|
7
9
|
* @internal
|
|
8
10
|
*/
|
|
9
11
|
export class _IblShadowsAccumulationPass {
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @returns The
|
|
13
|
+
* Returns the output texture of the pass.
|
|
14
|
+
* @returns The output texture.
|
|
13
15
|
*/
|
|
14
|
-
|
|
15
|
-
return this.
|
|
16
|
+
getOutputTexture() {
|
|
17
|
+
return this._outputTexture;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Gets the debug pass post process
|
|
@@ -57,6 +59,13 @@ export class _IblShadowsAccumulationPass {
|
|
|
57
59
|
set reset(value) {
|
|
58
60
|
this._reset = value;
|
|
59
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Tell the pass that the camera is moving. This will cause the accumulation
|
|
64
|
+
* rate to change.
|
|
65
|
+
*/
|
|
66
|
+
set isMoving(value) {
|
|
67
|
+
this._isMoving = value;
|
|
68
|
+
}
|
|
60
69
|
/**
|
|
61
70
|
* Sets params that control the position and scaling of the debug display on the screen.
|
|
62
71
|
* @param x Screen X offset of the debug display (0-1)
|
|
@@ -76,7 +85,7 @@ export class _IblShadowsAccumulationPass {
|
|
|
76
85
|
const debugOptions = {
|
|
77
86
|
width: this._engine.getRenderWidth(),
|
|
78
87
|
height: this._engine.getRenderHeight(),
|
|
79
|
-
textureFormat:
|
|
88
|
+
textureFormat: 5,
|
|
80
89
|
textureType: 0,
|
|
81
90
|
samplingMode: 1,
|
|
82
91
|
uniforms: ["sizeParams"],
|
|
@@ -97,7 +106,7 @@ export class _IblShadowsAccumulationPass {
|
|
|
97
106
|
this._debugPassPP.autoClear = false;
|
|
98
107
|
this._debugPassPP.onApplyObservable.add((effect) => {
|
|
99
108
|
// update the caustic texture with what we just rendered.
|
|
100
|
-
effect.
|
|
109
|
+
effect.setTexture("debugSampler", this._outputTexture);
|
|
101
110
|
effect.setVector4("sizeParams", this._debugSizeParams);
|
|
102
111
|
});
|
|
103
112
|
}
|
|
@@ -105,168 +114,174 @@ export class _IblShadowsAccumulationPass {
|
|
|
105
114
|
/**
|
|
106
115
|
* Instantiates the accumulation pass
|
|
107
116
|
* @param scene Scene to attach to
|
|
117
|
+
* @param iblShadowsRenderPipeline The IBL shadows render pipeline
|
|
108
118
|
* @returns The accumulation pass
|
|
109
119
|
*/
|
|
110
|
-
constructor(scene) {
|
|
120
|
+
constructor(scene, iblShadowsRenderPipeline) {
|
|
121
|
+
this._accumulationParams = new Vector4(0.0, 0.0, 0.0, 0.0);
|
|
111
122
|
/** Enable the debug view for this pass */
|
|
112
123
|
this.debugEnabled = false;
|
|
124
|
+
/**
|
|
125
|
+
* Is the effect enabled
|
|
126
|
+
*/
|
|
127
|
+
this.enabled = true;
|
|
128
|
+
/**
|
|
129
|
+
* Observable that triggers when the accumulation texture is ready
|
|
130
|
+
*/
|
|
131
|
+
this.onReadyObservable = new Observable();
|
|
113
132
|
this._debugPassName = "Shadow Accumulation Debug Pass";
|
|
114
133
|
this._remenance = 0.9;
|
|
115
134
|
this._reset = true;
|
|
135
|
+
this._isMoving = false;
|
|
116
136
|
this._debugSizeParams = new Vector4(0.0, 0.0, 0.0, 0.0);
|
|
117
137
|
this._scene = scene;
|
|
118
138
|
this._engine = scene.getEngine();
|
|
139
|
+
this._renderPipeline = iblShadowsRenderPipeline;
|
|
119
140
|
this._createTextures();
|
|
120
141
|
}
|
|
121
142
|
_createTextures() {
|
|
122
143
|
const isWebGPU = this._engine.isWebGPU;
|
|
123
|
-
|
|
124
|
-
// We'll copy the previous local position texture to this texture at the start of every frame.
|
|
125
|
-
const localPositionOptions = {
|
|
126
|
-
generateDepthBuffer: false,
|
|
127
|
-
generateMipMaps: false,
|
|
128
|
-
format: 5,
|
|
144
|
+
const outputTextureOptions = {
|
|
129
145
|
type: 2,
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
this._oldLocalPositionRT = new RenderTargetTexture("oldLocalPositionRT", { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, this._scene, localPositionOptions);
|
|
133
|
-
const localPositionCopyOptions = {
|
|
134
|
-
width: this._engine.getRenderWidth(),
|
|
135
|
-
height: this._engine.getRenderHeight(),
|
|
136
|
-
textureFormat: 5,
|
|
137
|
-
textureType: 2,
|
|
146
|
+
format: 5,
|
|
138
147
|
samplingMode: 1,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
defines: "#define PASS_SAMPLER sampler",
|
|
148
|
+
generateDepthBuffer: false,
|
|
149
|
+
generateMipMaps: false,
|
|
142
150
|
shaderLanguage: isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
|
|
151
|
+
extraInitializationsAsync: async () => {
|
|
152
|
+
if (isWebGPU) {
|
|
153
|
+
await Promise.all([import("../../ShadersWGSL/iblShadowAccumulation.fragment.js")]);
|
|
146
154
|
}
|
|
147
155
|
else {
|
|
148
|
-
|
|
156
|
+
await Promise.all([import("../../Shaders/iblShadowAccumulation.fragment.js")]);
|
|
149
157
|
}
|
|
150
158
|
},
|
|
151
159
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
160
|
+
this._outputTexture = new ProceduralTexture("shadowAccumulationPass", {
|
|
161
|
+
width: this._engine.getRenderWidth(),
|
|
162
|
+
height: this._engine.getRenderHeight(),
|
|
163
|
+
}, "iblShadowAccumulation", this._scene, outputTextureOptions);
|
|
164
|
+
this._outputTexture.refreshRate = -1;
|
|
165
|
+
this._outputTexture.autoClear = false;
|
|
166
|
+
this._outputTexture.onGeneratedObservable.addOnce(() => {
|
|
167
|
+
this.onReadyObservable.notifyObservers();
|
|
168
|
+
});
|
|
169
|
+
// Need to set all the textures first so that the effect gets created with the proper uniforms.
|
|
170
|
+
this._setOutputTextureBindings();
|
|
171
|
+
let counter = 0;
|
|
172
|
+
this._scene.onBeforeRenderObservable.add(() => {
|
|
173
|
+
counter = 0;
|
|
174
|
+
});
|
|
175
|
+
this._scene.onAfterRenderTargetsRenderObservable.add(() => {
|
|
176
|
+
if (++counter == 2) {
|
|
177
|
+
if (this.enabled && this._outputTexture.isReady()) {
|
|
178
|
+
this._setOutputTextureBindings();
|
|
179
|
+
this._outputTexture.render();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
159
182
|
});
|
|
160
|
-
this._oldLocalPositionRT.addPostProcess(localPositionCopyPP);
|
|
161
|
-
this._oldLocalPositionRT.skipInitialClear = true;
|
|
162
|
-
this._oldLocalPositionRT.noPrePassRenderer = true;
|
|
163
|
-
this._scene.customRenderTargets.push(this._oldLocalPositionRT);
|
|
164
183
|
// Create the accumulation texture for the previous frame.
|
|
165
184
|
// We'll copy the output of the accumulation pass to this texture at the start of every frame.
|
|
166
185
|
const accumulationOptions = {
|
|
167
|
-
generateDepthBuffer: false,
|
|
168
|
-
generateMipMaps: false,
|
|
169
|
-
format: 7,
|
|
170
186
|
type: 2,
|
|
187
|
+
format: 5,
|
|
171
188
|
samplingMode: 1,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const accumulationCopyOptions = {
|
|
175
|
-
width: this._engine.getRenderWidth(),
|
|
176
|
-
height: this._engine.getRenderHeight(),
|
|
177
|
-
textureFormat: 7,
|
|
178
|
-
textureType: 2,
|
|
179
|
-
samplingMode: 1,
|
|
180
|
-
engine: this._engine,
|
|
181
|
-
reusable: false,
|
|
182
|
-
defines: "#define PASS_SAMPLER sampler",
|
|
189
|
+
generateDepthBuffer: false,
|
|
190
|
+
generateMipMaps: false,
|
|
183
191
|
shaderLanguage: isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
|
|
184
|
-
|
|
185
|
-
if (
|
|
186
|
-
|
|
192
|
+
extraInitializationsAsync: async () => {
|
|
193
|
+
if (isWebGPU) {
|
|
194
|
+
await Promise.all([import("../../ShadersWGSL/pass.fragment.js")]);
|
|
187
195
|
}
|
|
188
196
|
else {
|
|
189
|
-
|
|
197
|
+
await Promise.all([import("../../Shaders/pass.fragment.js")]);
|
|
190
198
|
}
|
|
191
199
|
},
|
|
192
200
|
};
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
});
|
|
204
|
-
this._oldAccumulationRT.addPostProcess(accumulationCopyPP);
|
|
205
|
-
this._oldAccumulationRT.skipInitialClear = true;
|
|
206
|
-
this._oldAccumulationRT.noPrePassRenderer = true;
|
|
207
|
-
this._scene.customRenderTargets.push(this._oldAccumulationRT);
|
|
208
|
-
// Now, create the accumulation pass
|
|
209
|
-
const ppOptions = {
|
|
210
|
-
width: this._engine.getRenderWidth(),
|
|
211
|
-
height: this._engine.getRenderHeight(),
|
|
212
|
-
textureFormat: 7,
|
|
213
|
-
textureType: 2,
|
|
201
|
+
this._oldAccumulationCopy = new ProceduralTexture("oldAccumulationRT", { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, "pass", this._scene, accumulationOptions, false);
|
|
202
|
+
this._oldAccumulationCopy.autoClear = false;
|
|
203
|
+
this._oldAccumulationCopy.refreshRate = 1;
|
|
204
|
+
this._oldAccumulationCopy.onBeforeGenerationObservable.add(this._setAccumulationCopyBindings.bind(this));
|
|
205
|
+
this._setAccumulationCopyBindings();
|
|
206
|
+
// Create the local position texture for the previous frame.
|
|
207
|
+
// We'll copy the previous local position texture to this texture at the start of every frame.
|
|
208
|
+
const localPositionOptions = {
|
|
209
|
+
type: 2,
|
|
210
|
+
format: 5,
|
|
214
211
|
samplingMode: 1,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
engine: this._engine,
|
|
218
|
-
reusable: false,
|
|
212
|
+
generateDepthBuffer: false,
|
|
213
|
+
generateMipMaps: false,
|
|
219
214
|
shaderLanguage: isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
|
|
220
|
-
|
|
221
|
-
if (
|
|
222
|
-
|
|
215
|
+
extraInitializationsAsync: async () => {
|
|
216
|
+
if (isWebGPU) {
|
|
217
|
+
await Promise.all([import("../../ShadersWGSL/pass.fragment.js")]);
|
|
223
218
|
}
|
|
224
219
|
else {
|
|
225
|
-
|
|
220
|
+
await Promise.all([import("../../Shaders/pass.fragment.js")]);
|
|
226
221
|
}
|
|
227
222
|
},
|
|
228
223
|
};
|
|
229
|
-
this.
|
|
230
|
-
this.
|
|
231
|
-
this.
|
|
232
|
-
this.
|
|
233
|
-
|
|
234
|
-
});
|
|
224
|
+
this._oldPositionCopy = new ProceduralTexture("oldLocalPositionRT", { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, "pass", this._scene, localPositionOptions, false);
|
|
225
|
+
this._updatePositionCopy();
|
|
226
|
+
this._oldPositionCopy.autoClear = false;
|
|
227
|
+
this._oldPositionCopy.refreshRate = 1;
|
|
228
|
+
this._oldPositionCopy.onBeforeGenerationObservable.add(this._updatePositionCopy.bind(this));
|
|
235
229
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (velocityIndex >= 0)
|
|
247
|
-
effect.setTexture("motionSampler", prePassRenderer.getRenderTarget().textures[velocityIndex]);
|
|
230
|
+
_setOutputTextureBindings() {
|
|
231
|
+
const remenance = this._isMoving ? this.remenance : 0.99;
|
|
232
|
+
this._accumulationParams.set(remenance, this.reset ? 1.0 : 0.0, 0.0, 0.0);
|
|
233
|
+
this._outputTexture.setTexture("spatialBlurSampler", this._renderPipeline._getSpatialBlurTexture());
|
|
234
|
+
this._outputTexture.setVector4("accumulationParameters", this._accumulationParams);
|
|
235
|
+
this._outputTexture.setTexture("oldAccumulationSampler", this._oldAccumulationCopy ? this._oldAccumulationCopy : this._renderPipeline._dummyTexture2d);
|
|
236
|
+
this._outputTexture.setTexture("prevPositionSampler", this._oldPositionCopy ? this._oldPositionCopy : this._renderPipeline._dummyTexture2d);
|
|
237
|
+
const geometryBufferRenderer = this._scene.geometryBufferRenderer;
|
|
238
|
+
if (!geometryBufferRenderer) {
|
|
239
|
+
return;
|
|
248
240
|
}
|
|
241
|
+
const velocityIndex = geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.VELOCITY_LINEAR_TEXTURE_TYPE);
|
|
242
|
+
this._outputTexture.setTexture("motionSampler", geometryBufferRenderer.getGBuffer().textures[velocityIndex]);
|
|
243
|
+
const wPositionIndex = geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.POSITION_TEXTURE_TYPE);
|
|
244
|
+
this._outputTexture.setTexture("positionSampler", geometryBufferRenderer.getGBuffer().textures[wPositionIndex]);
|
|
249
245
|
this.reset = false;
|
|
246
|
+
this._isMoving = false;
|
|
247
|
+
}
|
|
248
|
+
_updatePositionCopy() {
|
|
249
|
+
const geometryBufferRenderer = this._scene.geometryBufferRenderer;
|
|
250
|
+
const index = geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.POSITION_TEXTURE_TYPE);
|
|
251
|
+
this._oldPositionCopy.setTexture("textureSampler", geometryBufferRenderer.getGBuffer().textures[index]);
|
|
252
|
+
}
|
|
253
|
+
_setAccumulationCopyBindings() {
|
|
254
|
+
this._oldAccumulationCopy.setTexture("textureSampler", this._outputTexture);
|
|
250
255
|
}
|
|
251
|
-
/**
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
256
|
+
/**
|
|
257
|
+
* Called by render pipeline when canvas resized.
|
|
258
|
+
* @param scaleFactor The factor by which to scale the canvas size.
|
|
259
|
+
*/
|
|
260
|
+
resize(scaleFactor = 1.0) {
|
|
261
|
+
const newSize = {
|
|
262
|
+
width: Math.max(1.0, Math.floor(this._engine.getRenderWidth() * scaleFactor)),
|
|
263
|
+
height: Math.max(1.0, Math.floor(this._engine.getRenderHeight() * scaleFactor)),
|
|
264
|
+
};
|
|
265
|
+
this._outputTexture.resize(newSize, false);
|
|
266
|
+
this._oldAccumulationCopy.resize(newSize, false);
|
|
267
|
+
this._oldPositionCopy.resize({ width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, false);
|
|
268
|
+
this.reset = true;
|
|
255
269
|
}
|
|
256
270
|
_disposeTextures() {
|
|
257
|
-
this.
|
|
258
|
-
this.
|
|
271
|
+
this._oldAccumulationCopy.dispose();
|
|
272
|
+
this._oldPositionCopy.dispose();
|
|
273
|
+
this._outputTexture.dispose();
|
|
259
274
|
}
|
|
260
275
|
/**
|
|
261
276
|
* Checks if the pass is ready
|
|
262
277
|
* @returns true if the pass is ready
|
|
263
278
|
*/
|
|
264
279
|
isReady() {
|
|
265
|
-
return (this.
|
|
266
|
-
this.
|
|
267
|
-
this.
|
|
268
|
-
this.
|
|
269
|
-
this.
|
|
280
|
+
return (this._oldAccumulationCopy &&
|
|
281
|
+
this._oldAccumulationCopy.isReady() &&
|
|
282
|
+
this._oldPositionCopy &&
|
|
283
|
+
this._oldPositionCopy.isReady() &&
|
|
284
|
+
this._outputTexture.isReady() &&
|
|
270
285
|
!(this._debugPassPP && !this._debugPassPP.isReady()));
|
|
271
286
|
}
|
|
272
287
|
/**
|
|
@@ -274,7 +289,6 @@ export class _IblShadowsAccumulationPass {
|
|
|
274
289
|
*/
|
|
275
290
|
dispose() {
|
|
276
291
|
this._disposeTextures();
|
|
277
|
-
this._outputPP.dispose();
|
|
278
292
|
if (this._debugPassPP) {
|
|
279
293
|
this._debugPassPP.dispose();
|
|
280
294
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iblShadowsAccumulationPass.js","sourceRoot":"","sources":["../../../../../dev/core/src/Rendering/IBLShadows/iblShadowsAccumulationPass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,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CAAC;SAC/B;IACL,CAAC;CACJ","sourcesContent":["import { Constants } from \"../../Engines/constants\";\r\nimport type { AbstractEngine } from \"../../Engines/abstractEngine\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Vector4 } from \"../../Maths/math.vector\";\r\nimport { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport type { PostProcessOptions } from \"../../PostProcesses/postProcess\";\r\nimport type { Effect } from \"../../Materials/effect\";\r\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\r\nimport type { RenderTargetCreationOptions } from \"../../Materials/Textures/textureCreationOptions\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\n\r\n/**\r\n * This should not be instanciated directly, as it is part of a scene component\r\n * @internal\r\n */\r\nexport class _IblShadowsAccumulationPass {\r\n private _scene: Scene;\r\n private _engine: AbstractEngine;\r\n\r\n // First, render the accumulation pass with both position buffers, motion buffer, shadow buffer, and the previous accumulation buffer\r\n private _outputPP: PostProcess;\r\n private _oldAccumulationRT: RenderTargetTexture;\r\n private _oldLocalPositionRT: RenderTargetTexture;\r\n\r\n /** Enable the debug view for this pass */\r\n public debugEnabled: boolean = false;\r\n\r\n /**\r\n * Gets the pass post process\r\n * @returns The post process\r\n */\r\n public getPassPP(): PostProcess {\r\n return this._outputPP;\r\n }\r\n\r\n /**\r\n * Gets the debug pass post process\r\n * @returns The post process\r\n */\r\n public getDebugPassPP(): PostProcess {\r\n if (!this._debugPassPP) {\r\n this._createDebugPass();\r\n }\r\n return this._debugPassPP;\r\n }\r\n\r\n private _debugPassName: string = \"Shadow Accumulation Debug Pass\";\r\n\r\n /**\r\n * Gets the name of the debug pass\r\n * @returns The name of the debug pass\r\n */\r\n public get debugPassName(): string {\r\n return this._debugPassName;\r\n }\r\n\r\n /**\r\n * A value that controls how much of the previous frame's accumulation to keep.\r\n * The higher the value, the faster the shadows accumulate but the more potential ghosting you'll see.\r\n */\r\n public get remenance(): number {\r\n return this._remenance;\r\n }\r\n\r\n /**\r\n * A value that controls how much of the previous frame's accumulation to keep.\r\n * The higher the value, the faster the shadows accumulate but the more potential ghosting you'll see.\r\n */\r\n public set remenance(value: number) {\r\n this._remenance = value;\r\n }\r\n private _remenance: number = 0.9;\r\n\r\n /**\r\n * Reset the accumulation.\r\n */\r\n public get reset(): boolean {\r\n return this._reset;\r\n }\r\n /**\r\n * Reset the accumulation.\r\n */\r\n public set reset(value: boolean) {\r\n this._reset = value;\r\n }\r\n private _reset: boolean = true;\r\n private _debugPassPP: PostProcess;\r\n private _debugSizeParams: Vector4 = new Vector4(0.0, 0.0, 0.0, 0.0);\r\n\r\n /**\r\n * Sets params that control the position and scaling of the debug display on the screen.\r\n * @param x Screen X offset of the debug display (0-1)\r\n * @param y Screen Y offset of the debug display (0-1)\r\n * @param widthScale X scale of the debug display (0-1)\r\n * @param heightScale Y scale of the debug display (0-1)\r\n */\r\n public setDebugDisplayParams(x: number, y: number, widthScale: number, heightScale: number) {\r\n this._debugSizeParams.set(x, y, widthScale, heightScale);\r\n }\r\n\r\n /**\r\n * Creates the debug post process effect for this pass\r\n */\r\n private _createDebugPass() {\r\n if (!this._debugPassPP) {\r\n const isWebGPU = this._engine.isWebGPU;\r\n const debugOptions: PostProcessOptions = {\r\n width: this._engine.getRenderWidth(),\r\n height: this._engine.getRenderHeight(),\r\n textureFormat: Constants.TEXTUREFORMAT_RG,\r\n textureType: Constants.TEXTURETYPE_UNSIGNED_BYTE,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n uniforms: [\"sizeParams\"],\r\n samplers: [\"debugSampler\"],\r\n engine: this._engine,\r\n reusable: false,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializations: (useWebGPU: boolean, list: Promise<any>[]) => {\r\n if (useWebGPU) {\r\n list.push(import(\"../../ShadersWGSL/iblShadowDebug.fragment\"));\r\n } else {\r\n list.push(import(\"../../Shaders/iblShadowDebug.fragment\"));\r\n }\r\n },\r\n };\r\n this._debugPassPP = new PostProcess(this.debugPassName, \"iblShadowDebug\", debugOptions);\r\n this._debugPassPP.autoClear = false;\r\n this._debugPassPP.onApplyObservable.add((effect) => {\r\n // update the caustic texture with what we just rendered.\r\n effect.setTextureFromPostProcessOutput(\"debugSampler\", this._outputPP);\r\n effect.setVector4(\"sizeParams\", this._debugSizeParams);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Instantiates the accumulation pass\r\n * @param scene Scene to attach to\r\n * @returns The accumulation pass\r\n */\r\n constructor(scene: Scene) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n this._createTextures();\r\n }\r\n\r\n private _createTextures() {\r\n const isWebGPU = this._engine.isWebGPU;\r\n // Create the local position texture for the previous frame.\r\n // We'll copy the previous local position texture to this texture at the start of every frame.\r\n const localPositionOptions: RenderTargetCreationOptions = {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n samplingMode: Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n };\r\n\r\n this._oldLocalPositionRT = new RenderTargetTexture(\r\n \"oldLocalPositionRT\",\r\n { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() },\r\n this._scene,\r\n localPositionOptions\r\n );\r\n\r\n const localPositionCopyOptions: PostProcessOptions = {\r\n width: this._engine.getRenderWidth(),\r\n height: this._engine.getRenderHeight(),\r\n textureFormat: Constants.TEXTUREFORMAT_RGBA,\r\n textureType: Constants.TEXTURETYPE_HALF_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n engine: this._engine,\r\n reusable: false,\r\n defines: \"#define PASS_SAMPLER sampler\",\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializations: (useWebGPU: boolean, list: Promise<any>[]) => {\r\n if (useWebGPU) {\r\n list.push(import(\"../../ShadersWGSL/pass.fragment\"));\r\n } else {\r\n list.push(import(\"../../Shaders/pass.fragment\"));\r\n }\r\n },\r\n };\r\n const localPositionCopyPP = new PostProcess(\"Copy Local Position Texture\", \"pass\", localPositionCopyOptions);\r\n localPositionCopyPP.autoClear = false;\r\n localPositionCopyPP.onApplyObservable.add((effect) => {\r\n const prePassRenderer = this._scene!.prePassRenderer;\r\n const index = prePassRenderer!.getIndex(Constants.PREPASS_POSITION_TEXTURE_TYPE);\r\n if (index >= 0) effect.setTexture(\"textureSampler\", prePassRenderer!.getRenderTarget().textures[index]);\r\n });\r\n this._oldLocalPositionRT.addPostProcess(localPositionCopyPP);\r\n this._oldLocalPositionRT.skipInitialClear = true;\r\n this._oldLocalPositionRT.noPrePassRenderer = true;\r\n\r\n this._scene.customRenderTargets.push(this._oldLocalPositionRT);\r\n\r\n // Create the accumulation texture for the previous frame.\r\n // We'll copy the output of the accumulation pass to this texture at the start of every frame.\r\n const accumulationOptions: RenderTargetCreationOptions = {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n format: Constants.TEXTUREFORMAT_RG,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n };\r\n\r\n this._oldAccumulationRT = new RenderTargetTexture(\r\n \"oldAccumulationRT\",\r\n { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() },\r\n this._scene,\r\n accumulationOptions\r\n );\r\n const accumulationCopyOptions: PostProcessOptions = {\r\n width: this._engine.getRenderWidth(),\r\n height: this._engine.getRenderHeight(),\r\n textureFormat: Constants.TEXTUREFORMAT_RG,\r\n textureType: Constants.TEXTURETYPE_HALF_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n engine: this._engine,\r\n reusable: false,\r\n defines: \"#define PASS_SAMPLER sampler\",\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializations: (useWebGPU: boolean, list: Promise<any>[]) => {\r\n if (useWebGPU) {\r\n list.push(import(\"../../ShadersWGSL/pass.fragment\"));\r\n } else {\r\n list.push(import(\"../../Shaders/pass.fragment\"));\r\n }\r\n },\r\n };\r\n const accumulationCopyPP = new PostProcess(\"Copy Accumulation Texture\", \"pass\", accumulationCopyOptions);\r\n accumulationCopyPP.autoClear = false;\r\n accumulationCopyPP.onApplyObservable.add((effect) => {\r\n if (this._outputPP._outputTexture?.texture) {\r\n effect.setTextureFromPostProcessOutput(\"textureSampler\", this._outputPP);\r\n } else {\r\n // We must set a texture. It's not the right one, but we must set something before the right one is available (see above), probably on next frame.\r\n effect._bindTexture(\"textureSampler\", this._outputPP.inputTexture.texture);\r\n }\r\n });\r\n this._oldAccumulationRT.addPostProcess(accumulationCopyPP);\r\n this._oldAccumulationRT.skipInitialClear = true;\r\n this._oldAccumulationRT.noPrePassRenderer = true;\r\n this._scene.customRenderTargets.push(this._oldAccumulationRT);\r\n\r\n // Now, create the accumulation pass\r\n const ppOptions: PostProcessOptions = {\r\n width: this._engine.getRenderWidth(),\r\n height: this._engine.getRenderHeight(),\r\n textureFormat: Constants.TEXTUREFORMAT_RG,\r\n textureType: Constants.TEXTURETYPE_HALF_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n uniforms: [\"accumulationParameters\"],\r\n samplers: [\"oldAccumulationSampler\", \"prevLocalPositionSampler\", \"localPositionSampler\", \"motionSampler\"],\r\n engine: this._engine,\r\n reusable: false,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializations: (useWebGPU: boolean, list: Promise<any>[]) => {\r\n if (useWebGPU) {\r\n list.push(import(\"../../ShadersWGSL/iblShadowAccumulation.fragment\"));\r\n } else {\r\n list.push(import(\"../../Shaders/iblShadowAccumulation.fragment\"));\r\n }\r\n },\r\n };\r\n this._outputPP = new PostProcess(\"accumulationPassPP\", \"iblShadowAccumulation\", ppOptions);\r\n this._outputPP.autoClear = false;\r\n this._outputPP.resize(this._engine.getRenderWidth(), this._engine.getRenderHeight()); // make sure that _outputPP.inputTexture.texture is created right away\r\n this._outputPP.onApplyObservable.add((effect) => {\r\n this._updatePostProcess(effect);\r\n });\r\n }\r\n\r\n public _updatePostProcess(effect: Effect) {\r\n effect.setVector4(\"accumulationParameters\", new Vector4(this.remenance, this.reset ? 1.0 : 0.0, 0.0, 0.0));\r\n effect.setTexture(\"oldAccumulationSampler\", this._oldAccumulationRT);\r\n effect.setTexture(\"prevLocalPositionSampler\", this._oldLocalPositionRT);\r\n\r\n const prePassRenderer = this._scene.prePassRenderer;\r\n if (prePassRenderer) {\r\n const localPositionIndex = prePassRenderer.getIndex(Constants.PREPASS_POSITION_TEXTURE_TYPE);\r\n if (localPositionIndex >= 0) effect.setTexture(\"localPositionSampler\", prePassRenderer.getRenderTarget().textures[localPositionIndex]);\r\n const velocityIndex = prePassRenderer.getIndex(Constants.PREPASS_VELOCITY_LINEAR_TEXTURE_TYPE);\r\n if (velocityIndex >= 0) effect.setTexture(\"motionSampler\", prePassRenderer.getRenderTarget().textures[velocityIndex]);\r\n }\r\n\r\n this.reset = false;\r\n }\r\n\r\n /** Called by render pipeline when canvas resized. */\r\n public resize() {\r\n this._oldAccumulationRT.resize({ width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() });\r\n this._oldLocalPositionRT.resize({ width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() });\r\n }\r\n\r\n private _disposeTextures() {\r\n this._oldAccumulationRT.dispose();\r\n this._oldLocalPositionRT.dispose();\r\n }\r\n\r\n /**\r\n * Checks if the pass is ready\r\n * @returns true if the pass is ready\r\n */\r\n public isReady() {\r\n return (\r\n this._oldAccumulationRT &&\r\n this._oldAccumulationRT.isReadyForRendering() &&\r\n this._oldLocalPositionRT &&\r\n this._oldLocalPositionRT.isReadyForRendering() &&\r\n this._outputPP.isReady() &&\r\n !(this._debugPassPP && !this._debugPassPP.isReady())\r\n );\r\n }\r\n\r\n /**\r\n * Disposes the associated resources\r\n */\r\n public dispose() {\r\n this._disposeTextures();\r\n this._outputPP.dispose();\r\n if (this._debugPassPP) {\r\n this._debugPassPP.dispose();\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"iblShadowsAccumulationPass.js","sourceRoot":"","sources":["../../../../../dev/core/src/Rendering/IBLShadows/iblShadowsAccumulationPass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,kEAA8D;AAG1F,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,2BAA2B;IAmBpC;;;OAGG;IACI,gBAAgB;QACnB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAOD;;;OAGG;IACI,cAAc;QACjB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACpB,IAAI,CAAC,gBAAgB,EAAE,CAAC;SAC3B;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAID;;;OAGG;IACH,IAAW,aAAa;QACpB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,IAAW,SAAS,CAAC,KAAa;QAC9B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC5B,CAAC;IAGD;;OAEG;IACH,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IACD;;OAEG;IACH,IAAW,KAAK,CAAC,KAA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IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;QACtH,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;IAEO,gBAAgB;QACpB,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC;QACpC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;IAED;;;OAGG;IACI,OAAO;QACV,OAAO,CACH,IAAI,CAAC,oBAAoB;YACzB,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE;YACnC,IAAI,CAAC,gBAAgB;YACrB,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE;YAC/B,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;YAC7B,CAAC,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,CACvD,CAAC;IACN,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;SAC/B;IACL,CAAC;CACJ","sourcesContent":["import { Constants } from \"../../Engines/constants\";\r\nimport type { AbstractEngine } from \"../../Engines/abstractEngine\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Vector4 } from \"../../Maths/math.vector\";\r\nimport { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport type { PostProcessOptions } from \"../../PostProcesses/postProcess\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { GeometryBufferRenderer } from \"../../Rendering/geometryBufferRenderer\";\r\nimport { ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { IProceduralTextureCreationOptions } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { IblShadowsRenderPipeline } from \"./iblShadowsRenderPipeline\";\r\nimport { Observable } from \"../../Misc/observable\";\r\n\r\n/**\r\n * This should not be instanciated directly, as it is part of a scene component\r\n * @internal\r\n */\r\nexport class _IblShadowsAccumulationPass {\r\n private _scene: Scene;\r\n private _engine: AbstractEngine;\r\n private _renderPipeline: IblShadowsRenderPipeline;\r\n\r\n // First, render the accumulation pass with both position buffers, motion buffer, shadow buffer, and the previous accumulation buffer\r\n private _outputTexture: ProceduralTexture;\r\n private _oldAccumulationCopy: ProceduralTexture;\r\n private _oldPositionCopy: ProceduralTexture;\r\n private _accumulationParams: Vector4 = new Vector4(0.0, 0.0, 0.0, 0.0);\r\n\r\n /** Enable the debug view for this pass */\r\n public debugEnabled: boolean = false;\r\n\r\n /**\r\n * Is the effect enabled\r\n */\r\n public enabled: boolean = true;\r\n\r\n /**\r\n * Returns the output texture of the pass.\r\n * @returns The output texture.\r\n */\r\n public getOutputTexture(): ProceduralTexture {\r\n return this._outputTexture;\r\n }\r\n\r\n /**\r\n * Observable that triggers when the accumulation texture is ready\r\n */\r\n public onReadyObservable: Observable<void> = new Observable<void>();\r\n\r\n /**\r\n * Gets the debug pass post process\r\n * @returns The post process\r\n */\r\n public getDebugPassPP(): PostProcess {\r\n if (!this._debugPassPP) {\r\n this._createDebugPass();\r\n }\r\n return this._debugPassPP;\r\n }\r\n\r\n private _debugPassName: string = \"Shadow Accumulation Debug Pass\";\r\n\r\n /**\r\n * Gets the name of the debug pass\r\n * @returns The name of the debug pass\r\n */\r\n public get debugPassName(): string {\r\n return this._debugPassName;\r\n }\r\n\r\n /**\r\n * A value that controls how much of the previous frame's accumulation to keep.\r\n * The higher the value, the faster the shadows accumulate but the more potential ghosting you'll see.\r\n */\r\n public get remenance(): number {\r\n return this._remenance;\r\n }\r\n\r\n /**\r\n * A value that controls how much of the previous frame's accumulation to keep.\r\n * The higher the value, the faster the shadows accumulate but the more potential ghosting you'll see.\r\n */\r\n public set remenance(value: number) {\r\n this._remenance = value;\r\n }\r\n private _remenance: number = 0.9;\r\n\r\n /**\r\n * Reset the accumulation.\r\n */\r\n public get reset(): boolean {\r\n return this._reset;\r\n }\r\n /**\r\n * Reset the accumulation.\r\n */\r\n public set reset(value: boolean) {\r\n this._reset = value;\r\n }\r\n private _reset: boolean = true;\r\n\r\n /**\r\n * Tell the pass that the camera is moving. This will cause the accumulation\r\n * rate to change.\r\n */\r\n public set isMoving(value: boolean) {\r\n this._isMoving = value;\r\n }\r\n private _isMoving: boolean = false;\r\n\r\n private _debugPassPP: PostProcess;\r\n private _debugSizeParams: Vector4 = new Vector4(0.0, 0.0, 0.0, 0.0);\r\n\r\n /**\r\n * Sets params that control the position and scaling of the debug display on the screen.\r\n * @param x Screen X offset of the debug display (0-1)\r\n * @param y Screen Y offset of the debug display (0-1)\r\n * @param widthScale X scale of the debug display (0-1)\r\n * @param heightScale Y scale of the debug display (0-1)\r\n */\r\n public setDebugDisplayParams(x: number, y: number, widthScale: number, heightScale: number) {\r\n this._debugSizeParams.set(x, y, widthScale, heightScale);\r\n }\r\n\r\n /**\r\n * Creates the debug post process effect for this pass\r\n */\r\n private _createDebugPass() {\r\n if (!this._debugPassPP) {\r\n const isWebGPU = this._engine.isWebGPU;\r\n const debugOptions: PostProcessOptions = {\r\n width: this._engine.getRenderWidth(),\r\n height: this._engine.getRenderHeight(),\r\n textureFormat: Constants.TEXTUREFORMAT_RGBA,\r\n textureType: Constants.TEXTURETYPE_UNSIGNED_BYTE,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n uniforms: [\"sizeParams\"],\r\n samplers: [\"debugSampler\"],\r\n engine: this._engine,\r\n reusable: false,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializations: (useWebGPU: boolean, list: Promise<any>[]) => {\r\n if (useWebGPU) {\r\n list.push(import(\"../../ShadersWGSL/iblShadowDebug.fragment\"));\r\n } else {\r\n list.push(import(\"../../Shaders/iblShadowDebug.fragment\"));\r\n }\r\n },\r\n };\r\n this._debugPassPP = new PostProcess(this.debugPassName, \"iblShadowDebug\", debugOptions);\r\n this._debugPassPP.autoClear = false;\r\n this._debugPassPP.onApplyObservable.add((effect) => {\r\n // update the caustic texture with what we just rendered.\r\n effect.setTexture(\"debugSampler\", this._outputTexture);\r\n effect.setVector4(\"sizeParams\", this._debugSizeParams);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Instantiates the accumulation pass\r\n * @param scene Scene to attach to\r\n * @param iblShadowsRenderPipeline The IBL shadows render pipeline\r\n * @returns The accumulation pass\r\n */\r\n constructor(scene: Scene, iblShadowsRenderPipeline: IblShadowsRenderPipeline) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n this._renderPipeline = iblShadowsRenderPipeline;\r\n this._createTextures();\r\n }\r\n\r\n private _createTextures() {\r\n const isWebGPU = this._engine.isWebGPU;\r\n\r\n const outputTextureOptions: IProceduralTextureCreationOptions = {\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializationsAsync: async () => {\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../../ShadersWGSL/iblShadowAccumulation.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../../Shaders/iblShadowAccumulation.fragment\")]);\r\n }\r\n },\r\n };\r\n this._outputTexture = new ProceduralTexture(\r\n \"shadowAccumulationPass\",\r\n {\r\n width: this._engine.getRenderWidth(),\r\n height: this._engine.getRenderHeight(),\r\n },\r\n \"iblShadowAccumulation\",\r\n this._scene,\r\n outputTextureOptions\r\n );\r\n this._outputTexture.refreshRate = -1;\r\n this._outputTexture.autoClear = false;\r\n this._outputTexture.onGeneratedObservable.addOnce(() => {\r\n this.onReadyObservable.notifyObservers();\r\n });\r\n\r\n // Need to set all the textures first so that the effect gets created with the proper uniforms.\r\n this._setOutputTextureBindings();\r\n\r\n let counter = 0;\r\n this._scene.onBeforeRenderObservable.add(() => {\r\n counter = 0;\r\n });\r\n this._scene.onAfterRenderTargetsRenderObservable.add(() => {\r\n if (++counter == 2) {\r\n if (this.enabled && this._outputTexture.isReady()) {\r\n this._setOutputTextureBindings();\r\n this._outputTexture.render();\r\n }\r\n }\r\n });\r\n\r\n // Create the accumulation texture for the previous frame.\r\n // We'll copy the output of the accumulation pass to this texture at the start of every frame.\r\n const accumulationOptions: IProceduralTextureCreationOptions = {\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializationsAsync: async () => {\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../../ShadersWGSL/pass.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../../Shaders/pass.fragment\")]);\r\n }\r\n },\r\n };\r\n\r\n this._oldAccumulationCopy = new ProceduralTexture(\r\n \"oldAccumulationRT\",\r\n { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() },\r\n \"pass\",\r\n this._scene,\r\n accumulationOptions,\r\n false\r\n );\r\n\r\n this._oldAccumulationCopy.autoClear = false;\r\n this._oldAccumulationCopy.refreshRate = 1;\r\n this._oldAccumulationCopy.onBeforeGenerationObservable.add(this._setAccumulationCopyBindings.bind(this));\r\n this._setAccumulationCopyBindings();\r\n\r\n // Create the local position texture for the previous frame.\r\n // We'll copy the previous local position texture to this texture at the start of every frame.\r\n const localPositionOptions: IProceduralTextureCreationOptions = {\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializationsAsync: async () => {\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../../ShadersWGSL/pass.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../../Shaders/pass.fragment\")]);\r\n }\r\n },\r\n };\r\n\r\n this._oldPositionCopy = new ProceduralTexture(\r\n \"oldLocalPositionRT\",\r\n { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() },\r\n \"pass\",\r\n this._scene,\r\n localPositionOptions,\r\n false\r\n );\r\n this._updatePositionCopy();\r\n this._oldPositionCopy.autoClear = false;\r\n this._oldPositionCopy.refreshRate = 1;\r\n this._oldPositionCopy.onBeforeGenerationObservable.add(this._updatePositionCopy.bind(this));\r\n }\r\n\r\n private _setOutputTextureBindings() {\r\n const remenance = this._isMoving ? this.remenance : 0.99;\r\n this._accumulationParams.set(remenance, this.reset ? 1.0 : 0.0, 0.0, 0.0);\r\n this._outputTexture.setTexture(\"spatialBlurSampler\", this._renderPipeline._getSpatialBlurTexture());\r\n this._outputTexture.setVector4(\"accumulationParameters\", this._accumulationParams);\r\n this._outputTexture.setTexture(\"oldAccumulationSampler\", this._oldAccumulationCopy ? this._oldAccumulationCopy : this._renderPipeline._dummyTexture2d);\r\n this._outputTexture.setTexture(\"prevPositionSampler\", this._oldPositionCopy ? this._oldPositionCopy : this._renderPipeline._dummyTexture2d);\r\n\r\n const geometryBufferRenderer = this._scene.geometryBufferRenderer;\r\n if (!geometryBufferRenderer) {\r\n return;\r\n }\r\n const velocityIndex = geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.VELOCITY_LINEAR_TEXTURE_TYPE);\r\n this._outputTexture.setTexture(\"motionSampler\", geometryBufferRenderer.getGBuffer().textures[velocityIndex]);\r\n const wPositionIndex = geometryBufferRenderer.getTextureIndex(GeometryBufferRenderer.POSITION_TEXTURE_TYPE);\r\n this._outputTexture.setTexture(\"positionSampler\", geometryBufferRenderer.getGBuffer().textures[wPositionIndex]);\r\n\r\n this.reset = false;\r\n this._isMoving = false;\r\n }\r\n\r\n private _updatePositionCopy() {\r\n const geometryBufferRenderer = this._scene.geometryBufferRenderer;\r\n const index = geometryBufferRenderer!.getTextureIndex(GeometryBufferRenderer.POSITION_TEXTURE_TYPE);\r\n this._oldPositionCopy.setTexture(\"textureSampler\", geometryBufferRenderer!.getGBuffer().textures[index]);\r\n }\r\n\r\n private _setAccumulationCopyBindings() {\r\n this._oldAccumulationCopy.setTexture(\"textureSampler\", this._outputTexture);\r\n }\r\n\r\n /**\r\n * Called by render pipeline when canvas resized.\r\n * @param scaleFactor The factor by which to scale the canvas size.\r\n */\r\n public resize(scaleFactor: number = 1.0) {\r\n const newSize = {\r\n width: Math.max(1.0, Math.floor(this._engine.getRenderWidth() * scaleFactor)),\r\n height: Math.max(1.0, Math.floor(this._engine.getRenderHeight() * scaleFactor)),\r\n };\r\n this._outputTexture.resize(newSize, false);\r\n this._oldAccumulationCopy.resize(newSize, false);\r\n this._oldPositionCopy.resize({ width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, false);\r\n this.reset = true;\r\n }\r\n\r\n private _disposeTextures() {\r\n this._oldAccumulationCopy.dispose();\r\n this._oldPositionCopy.dispose();\r\n this._outputTexture.dispose();\r\n }\r\n\r\n /**\r\n * Checks if the pass is ready\r\n * @returns true if the pass is ready\r\n */\r\n public isReady() {\r\n return (\r\n this._oldAccumulationCopy &&\r\n this._oldAccumulationCopy.isReady() &&\r\n this._oldPositionCopy &&\r\n this._oldPositionCopy.isReady() &&\r\n this._outputTexture.isReady() &&\r\n !(this._debugPassPP && !this._debugPassPP.isReady())\r\n );\r\n }\r\n\r\n /**\r\n * Disposes the associated resources\r\n */\r\n public dispose() {\r\n this._disposeTextures();\r\n if (this._debugPassPP) {\r\n this._debugPassPP.dispose();\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iblShadowsImportanceSamplingRenderer.js","sourceRoot":"","sources":["../../../../../dev/core/src/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAIpD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAE3F,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAInD;;;;GAIG;AACH,MAAM,OAAO,qCAAqC;IAU9C;;OAEG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,IAAW,SAAS,CAAC,MAAmB;QACpC,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE;YAC5B,OAAO;SACV;QACD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QACzB,IAAI,MAAM,CAAC,MAAM,EAAE;YACf,IAAI,MAAM,CAAC,oBAAoB,EAAE,EAAE;gBAC/B,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;aAC1C;iBAAM;gBACF,MAAsB,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;aACvG;SACJ;aAAM;YAC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AAQ,CAAC,CAAC;YAC1C,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1C,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAChD,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QACvI,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACI,OAAO;QACV,OAAO,CACH,IAAI,CAAC,UAAU;YACf,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,wBAAwB;YACjD,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACzB,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACtB,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACvB,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACtB,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAC1B,CAAC;IACN,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC7B;IACL,CAAC;CACJ","sourcesContent":["import { Constants } from \"../../Engines/constants\";\r\nimport type { AbstractEngine } from \"../../Engines/abstractEngine\";\r\n\r\nimport type { Scene } from \"../../scene\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport type { TextureSize } from \"../../Materials/Textures/textureCreationOptions\";\r\nimport { ProceduralTexture } from \"../../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { IProceduralTextureCreationOptions } from \"../../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport type { PostProcessOptions } from \"../../PostProcesses/postProcess\";\r\nimport { Vector4 } from \"../../Maths/math.vector\";\r\nimport { RawTexture } from \"../../Materials/Textures/rawTexture\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { CubeTexture } from \"../../Materials/Textures/cubeTexture\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\n\r\n/**\r\n * Build cdf maps for IBL importance sampling during IBL shadow computation.\r\n * This should not be instanciated directly, as it is part of a scene component\r\n * @internal\r\n */\r\nexport class _IblShadowsImportanceSamplingRenderer {\r\n private _scene: Scene;\r\n private _engine: AbstractEngine;\r\n\r\n private _cdfyPT: ProceduralTexture;\r\n private _icdfyPT: ProceduralTexture;\r\n private _cdfxPT: ProceduralTexture;\r\n private _icdfxPT: ProceduralTexture;\r\n private _iblSource: BaseTexture;\r\n\r\n /**\r\n * Gets the IBL source texture being used by the importance sampling renderer\r\n */\r\n public get iblSource(): BaseTexture {\r\n return this._iblSource;\r\n }\r\n\r\n /**\r\n * Sets the IBL source texture to be used by the importance sampling renderer.\r\n * This will trigger recreation of the importance sampling assets.\r\n */\r\n public set iblSource(source: BaseTexture) {\r\n if (this._iblSource === source) {\r\n return;\r\n }\r\n this._disposeTextures();\r\n this._iblSource = source;\r\n if (source.isCube) {\r\n if (source.isReadyOrNotBlocking()) {\r\n this._recreateAssetsFromNewIbl(source);\r\n } else {\r\n (source as CubeTexture).onLoadObservable.addOnce(this._recreateAssetsFromNewIbl.bind(this, source));\r\n }\r\n } else {\r\n if (source.isReadyOrNotBlocking()) {\r\n this._recreateAssetsFromNewIbl(source);\r\n } else {\r\n (source as Texture).onLoadObservable.addOnce(this._recreateAssetsFromNewIbl.bind(this, source));\r\n }\r\n }\r\n }\r\n\r\n private _recreateAssetsFromNewIbl(source: BaseTexture) {\r\n if (this._debugPass) {\r\n this._debugPass.dispose();\r\n }\r\n\r\n this._createTextures();\r\n\r\n if (this._debugPass) {\r\n // Recreate the debug pass because of the new textures\r\n this._createDebugPass();\r\n }\r\n\r\n // Once the textures are generated, notify that they are ready to use.\r\n this._icdfxPT.onGeneratedObservable.addOnce(() => {\r\n this.onReadyObservable.notifyObservers();\r\n });\r\n }\r\n\r\n /**\r\n * Return the cumulative distribution function (CDF) Y texture\r\n * @returns Return the cumulative distribution function (CDF) Y texture\r\n */\r\n public getIcdfyTexture(): ProceduralTexture {\r\n return this._icdfyPT;\r\n }\r\n\r\n /**\r\n * Return the cumulative distribution function (CDF) X texture\r\n * @returns Return the cumulative distribution function (CDF) X texture\r\n */\r\n public getIcdfxTexture(): ProceduralTexture {\r\n return this._icdfxPT;\r\n }\r\n\r\n /** Enable the debug view for this pass */\r\n public debugEnabled: boolean = false;\r\n private _debugPass: PostProcess;\r\n private _debugSizeParams: Vector4 = new Vector4(0.0, 0.0, 0.0, 0.0);\r\n\r\n /**\r\n * Sets params that control the position and scaling of the debug display on the screen.\r\n * @param x Screen X offset of the debug display (0-1)\r\n * @param y Screen Y offset of the debug display (0-1)\r\n * @param widthScale X scale of the debug display (0-1)\r\n * @param heightScale Y scale of the debug display (0-1)\r\n */\r\n public setDebugDisplayParams(x: number, y: number, widthScale: number, heightScale: number) {\r\n this._debugSizeParams.set(x, y, widthScale, heightScale);\r\n }\r\n\r\n /**\r\n * The name of the debug pass post process\r\n */\r\n public get debugPassName(): string {\r\n return this._debugPassName;\r\n }\r\n private _debugPassName: string = \"Importance Sample Debug\";\r\n\r\n /**\r\n * Gets the debug pass post process\r\n * @returns The post process\r\n */\r\n public getDebugPassPP(): PostProcess {\r\n if (!this._debugPass) {\r\n this._createDebugPass();\r\n }\r\n return this._debugPass;\r\n }\r\n\r\n /**\r\n * Instanciates the importance sampling renderer\r\n * @param scene Scene to attach to\r\n * @returns The importance sampling renderer\r\n */\r\n constructor(scene: Scene) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n }\r\n\r\n /**\r\n * Observable that triggers when the importance sampling renderer is ready\r\n */\r\n public onReadyObservable: Observable<void> = new Observable<void>();\r\n\r\n private _createTextures() {\r\n const size: TextureSize = this._iblSource ? this._iblSource.getSize() : { width: 1, height: 1 };\r\n if (!this._iblSource) {\r\n this._iblSource = RawTexture.CreateRTexture(\r\n new Uint8Array([255]),\r\n 1,\r\n 1,\r\n this._scene,\r\n false,\r\n false,\r\n Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n );\r\n this._iblSource.name = \"Placeholder IBL Source\";\r\n }\r\n\r\n if (this._iblSource!.isCube) {\r\n size.width *= 4;\r\n size.height *= 2;\r\n }\r\n\r\n const isWebGPU = this._engine.isWebGPU;\r\n // Create CDF maps (Cumulative Distribution Function) to assist in importance sampling\r\n const cdfOptions: IProceduralTextureCreationOptions = {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n format: Constants.TEXTUREFORMAT_R,\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializationsAsync: async () => {\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../../ShadersWGSL/iblShadowsCdfx.fragment\"), import(\"../../ShadersWGSL/iblShadowsCdfy.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../../Shaders/iblShadowsCdfx.fragment\"), import(\"../../Shaders/iblShadowsCdfy.fragment\")]);\r\n }\r\n },\r\n };\r\n const icdfOptions: IProceduralTextureCreationOptions = {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n format: Constants.TEXTUREFORMAT_R,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializationsAsync: async () => {\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../../ShadersWGSL/iblShadowsIcdfx.fragment\"), import(\"../../ShadersWGSL/iblShadowsIcdfy.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../../Shaders/iblShadowsIcdfx.fragment\"), import(\"../../Shaders/iblShadowsIcdfy.fragment\")]);\r\n }\r\n },\r\n };\r\n this._cdfyPT = new ProceduralTexture(\"cdfyTexture\", { width: size.width, height: size.height + 1 }, \"iblShadowsCdfy\", this._scene, cdfOptions, false, false);\r\n this._cdfyPT.autoClear = false;\r\n this._cdfyPT.setTexture(\"iblSource\", this._iblSource as Texture);\r\n this._cdfyPT.setInt(\"iblHeight\", size.height);\r\n if (this._iblSource.isCube) {\r\n this._cdfyPT.defines = \"#define IBL_USE_CUBE_MAP\\n\";\r\n }\r\n this._cdfyPT.refreshRate = 0;\r\n this._icdfyPT = new ProceduralTexture(\"icdfyTexture\", { width: size.width, height: size.height }, \"iblShadowsIcdfy\", this._scene, icdfOptions, false, false);\r\n this._icdfyPT.autoClear = false;\r\n this._icdfyPT.setTexture(\"cdfy\", this._cdfyPT);\r\n this._icdfyPT.refreshRate = 0;\r\n this._cdfxPT = new ProceduralTexture(\"cdfxTexture\", { width: size.width + 1, height: 1 }, \"iblShadowsCdfx\", this._scene, cdfOptions, false, false);\r\n this._cdfxPT.autoClear = false;\r\n this._cdfxPT.setTexture(\"cdfy\", this._cdfyPT);\r\n this._cdfxPT.refreshRate = 0;\r\n this._icdfxPT = new ProceduralTexture(\"icdfxTexture\", { width: size.width, height: 1 }, \"iblShadowsIcdfx\", this._scene, icdfOptions, false, false);\r\n this._icdfxPT.autoClear = false;\r\n this._icdfxPT.setTexture(\"cdfx\", this._cdfxPT);\r\n this._icdfxPT.refreshRate = 0;\r\n }\r\n\r\n private _disposeTextures() {\r\n this._cdfyPT?.dispose();\r\n this._icdfyPT?.dispose();\r\n this._cdfxPT?.dispose();\r\n this._icdfxPT?.dispose();\r\n this._iblSource?.dispose();\r\n }\r\n\r\n private _createDebugPass() {\r\n if (this._debugPass) {\r\n this._debugPass.dispose();\r\n }\r\n const isWebGPU = this._engine.isWebGPU;\r\n const debugOptions: PostProcessOptions = {\r\n width: this._scene.getEngine().getRenderWidth(),\r\n height: this._scene.getEngine().getRenderHeight(),\r\n samplingMode: Texture.BILINEAR_SAMPLINGMODE,\r\n engine: this._engine,\r\n textureType: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n uniforms: [\"sizeParams\"],\r\n samplers: [\"cdfy\", \"icdfy\", \"cdfx\", \"icdfx\", \"iblSource\"],\r\n defines: this._iblSource?.isCube ? \"#define IBL_USE_CUBE_MAP\\n\" : \"\",\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializations: (useWebGPU: boolean, list: Promise<any>[]) => {\r\n if (useWebGPU) {\r\n list.push(import(\"../../ShadersWGSL/iblShadowsImportanceSamplingDebug.fragment\"));\r\n } else {\r\n list.push(import(\"../../Shaders/iblShadowsImportanceSamplingDebug.fragment\"));\r\n }\r\n },\r\n };\r\n this._debugPass = new PostProcess(this._debugPassName, \"iblShadowsImportanceSamplingDebug\", debugOptions);\r\n const debugEffect = this._debugPass.getEffect();\r\n if (debugEffect) {\r\n debugEffect.defines = this._iblSource?.isCube ? \"#define IBL_USE_CUBE_MAP\\n\" : \"\";\r\n }\r\n if (this._iblSource?.isCube) {\r\n this._debugPass.updateEffect(\"#define IBL_USE_CUBE_MAP\\n\");\r\n }\r\n this._debugPass.onApplyObservable.add((effect) => {\r\n effect.setTexture(\"cdfy\", this._cdfyPT);\r\n effect.setTexture(\"icdfy\", this._icdfyPT);\r\n effect.setTexture(\"cdfx\", this._cdfxPT);\r\n effect.setTexture(\"icdfx\", this._icdfxPT);\r\n effect.setTexture(\"iblSource\", this._iblSource);\r\n effect.setFloat4(\"sizeParams\", this._debugSizeParams.x, this._debugSizeParams.y, this._debugSizeParams.z, this._debugSizeParams.w);\r\n });\r\n }\r\n\r\n /**\r\n * Checks if the importance sampling renderer is ready\r\n * @returns true if the importance sampling renderer is ready\r\n */\r\n public isReady() {\r\n return (\r\n this._iblSource &&\r\n this._iblSource.name !== \"Placeholder IBL Source\" &&\r\n this._iblSource.isReady() &&\r\n this._cdfyPT &&\r\n this._cdfyPT.isReady() &&\r\n this._icdfyPT &&\r\n this._icdfyPT.isReady() &&\r\n this._cdfxPT &&\r\n this._cdfxPT.isReady() &&\r\n this._icdfxPT &&\r\n this._icdfxPT.isReady()\r\n );\r\n }\r\n\r\n /**\r\n * Disposes the importance sampling renderer and associated resources\r\n */\r\n public dispose() {\r\n this._disposeTextures();\r\n if (this._debugPass) {\r\n this._debugPass.dispose();\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"iblShadowsImportanceSamplingRenderer.js","sourceRoot":"","sources":["../../../../../dev/core/src/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAIpD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAE3F,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAInD;;;;GAIG;AACH,MAAM,OAAO,qCAAqC;IAU9C;;OAEG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAA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IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACtB,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAC1B,CAAC;IACN,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC7B;IACL,CAAC;CACJ","sourcesContent":["import { Constants } from \"../../Engines/constants\";\r\nimport type { AbstractEngine } from \"../../Engines/abstractEngine\";\r\n\r\nimport type { Scene } from \"../../scene\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport type { TextureSize } from \"../../Materials/Textures/textureCreationOptions\";\r\nimport { ProceduralTexture } from \"../../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { IProceduralTextureCreationOptions } from \"../../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport type { PostProcessOptions } from \"../../PostProcesses/postProcess\";\r\nimport { Vector4 } from \"../../Maths/math.vector\";\r\nimport { RawTexture } from \"../../Materials/Textures/rawTexture\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { CubeTexture } from \"../../Materials/Textures/cubeTexture\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\n\r\n/**\r\n * Build cdf maps for IBL importance sampling during IBL shadow computation.\r\n * This should not be instanciated directly, as it is part of a scene component\r\n * @internal\r\n */\r\nexport class _IblShadowsImportanceSamplingRenderer {\r\n private _scene: Scene;\r\n private _engine: AbstractEngine;\r\n\r\n private _cdfyPT: ProceduralTexture;\r\n private _icdfyPT: ProceduralTexture;\r\n private _cdfxPT: ProceduralTexture;\r\n private _icdfxPT: ProceduralTexture;\r\n private _iblSource: BaseTexture;\r\n\r\n /**\r\n * Gets the IBL source texture being used by the importance sampling renderer\r\n */\r\n public get iblSource(): BaseTexture {\r\n return this._iblSource;\r\n }\r\n\r\n /**\r\n * Sets the IBL source texture to be used by the importance sampling renderer.\r\n * This will trigger recreation of the importance sampling assets.\r\n */\r\n public set iblSource(source: BaseTexture) {\r\n if (this._iblSource === source) {\r\n return;\r\n }\r\n this._disposeTextures();\r\n this._iblSource = source;\r\n if (source.isCube) {\r\n if (source.isReadyOrNotBlocking()) {\r\n this._recreateAssetsFromNewIbl(source);\r\n } else {\r\n (source as CubeTexture).onLoadObservable.addOnce(this._recreateAssetsFromNewIbl.bind(this, source));\r\n }\r\n } else {\r\n if (source.isReadyOrNotBlocking()) {\r\n this._recreateAssetsFromNewIbl(source);\r\n } else {\r\n (source as Texture).onLoadObservable.addOnce(this._recreateAssetsFromNewIbl.bind(this, source));\r\n }\r\n }\r\n }\r\n\r\n private _recreateAssetsFromNewIbl(source: BaseTexture) {\r\n if (this._debugPass) {\r\n this._debugPass.dispose();\r\n }\r\n\r\n this._createTextures();\r\n\r\n if (this._debugPass) {\r\n // Recreate the debug pass because of the new textures\r\n this._createDebugPass();\r\n }\r\n\r\n // Once the textures are generated, notify that they are ready to use.\r\n this._icdfxPT.onGeneratedObservable.addOnce(() => {\r\n this.onReadyObservable.notifyObservers();\r\n });\r\n }\r\n\r\n /**\r\n * Return the cumulative distribution function (CDF) Y texture\r\n * @returns Return the cumulative distribution function (CDF) Y texture\r\n */\r\n public getIcdfyTexture(): ProceduralTexture {\r\n return this._icdfyPT;\r\n }\r\n\r\n /**\r\n * Return the cumulative distribution function (CDF) X texture\r\n * @returns Return the cumulative distribution function (CDF) X texture\r\n */\r\n public getIcdfxTexture(): ProceduralTexture {\r\n return this._icdfxPT;\r\n }\r\n\r\n /** Enable the debug view for this pass */\r\n public debugEnabled: boolean = false;\r\n private _debugPass: PostProcess;\r\n private _debugSizeParams: Vector4 = new Vector4(0.0, 0.0, 0.0, 0.0);\r\n\r\n /**\r\n * Sets params that control the position and scaling of the debug display on the screen.\r\n * @param x Screen X offset of the debug display (0-1)\r\n * @param y Screen Y offset of the debug display (0-1)\r\n * @param widthScale X scale of the debug display (0-1)\r\n * @param heightScale Y scale of the debug display (0-1)\r\n */\r\n public setDebugDisplayParams(x: number, y: number, widthScale: number, heightScale: number) {\r\n this._debugSizeParams.set(x, y, widthScale, heightScale);\r\n }\r\n\r\n /**\r\n * The name of the debug pass post process\r\n */\r\n public get debugPassName(): string {\r\n return this._debugPassName;\r\n }\r\n private _debugPassName: string = \"Importance Sample Debug\";\r\n\r\n /**\r\n * Gets the debug pass post process\r\n * @returns The post process\r\n */\r\n public getDebugPassPP(): PostProcess {\r\n if (!this._debugPass) {\r\n this._createDebugPass();\r\n }\r\n return this._debugPass;\r\n }\r\n\r\n /**\r\n * Instanciates the importance sampling renderer\r\n * @param scene Scene to attach to\r\n * @returns The importance sampling renderer\r\n */\r\n constructor(scene: Scene) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n }\r\n\r\n /**\r\n * Observable that triggers when the importance sampling renderer is ready\r\n */\r\n public onReadyObservable: Observable<void> = new Observable<void>();\r\n\r\n private _createTextures() {\r\n const size: TextureSize = this._iblSource ? this._iblSource.getSize() : { width: 1, height: 1 };\r\n if (!this._iblSource) {\r\n this._iblSource = RawTexture.CreateRTexture(\r\n new Uint8Array([255]),\r\n 1,\r\n 1,\r\n this._scene,\r\n false,\r\n false,\r\n Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n );\r\n this._iblSource.name = \"Placeholder IBL Source\";\r\n }\r\n\r\n if (this._iblSource!.isCube) {\r\n size.width *= 4;\r\n size.height *= 2;\r\n }\r\n\r\n const isWebGPU = this._engine.isWebGPU;\r\n // Create CDF maps (Cumulative Distribution Function) to assist in importance sampling\r\n const cdfOptions: IProceduralTextureCreationOptions = {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n format: Constants.TEXTUREFORMAT_R,\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializationsAsync: async () => {\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../../ShadersWGSL/iblShadowsCdfx.fragment\"), import(\"../../ShadersWGSL/iblShadowsCdfy.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../../Shaders/iblShadowsCdfx.fragment\"), import(\"../../Shaders/iblShadowsCdfy.fragment\")]);\r\n }\r\n },\r\n };\r\n const icdfOptions: IProceduralTextureCreationOptions = {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n format: Constants.TEXTUREFORMAT_R,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializationsAsync: async () => {\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../../ShadersWGSL/iblShadowsIcdfx.fragment\"), import(\"../../ShadersWGSL/iblShadowsIcdfy.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../../Shaders/iblShadowsIcdfx.fragment\"), import(\"../../Shaders/iblShadowsIcdfy.fragment\")]);\r\n }\r\n },\r\n };\r\n this._cdfyPT = new ProceduralTexture(\"cdfyTexture\", { width: size.width, height: size.height + 1 }, \"iblShadowsCdfy\", this._scene, cdfOptions, false, false);\r\n this._cdfyPT.autoClear = false;\r\n this._cdfyPT.setTexture(\"iblSource\", this._iblSource as Texture);\r\n this._cdfyPT.setInt(\"iblHeight\", size.height);\r\n if (this._iblSource.isCube) {\r\n this._cdfyPT.defines = \"#define IBL_USE_CUBE_MAP\\n\";\r\n }\r\n this._cdfyPT.refreshRate = 0;\r\n this._icdfyPT = new ProceduralTexture(\"icdfyTexture\", { width: size.width, height: size.height }, \"iblShadowsIcdfy\", this._scene, icdfOptions, false, false);\r\n this._icdfyPT.autoClear = false;\r\n this._icdfyPT.setTexture(\"cdfy\", this._cdfyPT);\r\n this._icdfyPT.refreshRate = 0;\r\n this._cdfxPT = new ProceduralTexture(\"cdfxTexture\", { width: size.width + 1, height: 1 }, \"iblShadowsCdfx\", this._scene, cdfOptions, false, false);\r\n this._cdfxPT.autoClear = false;\r\n this._cdfxPT.setTexture(\"cdfy\", this._cdfyPT);\r\n this._cdfxPT.refreshRate = 0;\r\n this._icdfxPT = new ProceduralTexture(\"icdfxTexture\", { width: size.width, height: 1 }, \"iblShadowsIcdfx\", this._scene, icdfOptions, false, false);\r\n this._icdfxPT.autoClear = false;\r\n this._icdfxPT.setTexture(\"cdfx\", this._cdfxPT);\r\n this._icdfxPT.refreshRate = 0;\r\n }\r\n\r\n private _disposeTextures() {\r\n this._cdfyPT?.dispose();\r\n this._icdfyPT?.dispose();\r\n this._cdfxPT?.dispose();\r\n this._icdfxPT?.dispose();\r\n }\r\n\r\n private _createDebugPass() {\r\n if (this._debugPass) {\r\n this._debugPass.dispose();\r\n }\r\n const isWebGPU = this._engine.isWebGPU;\r\n const debugOptions: PostProcessOptions = {\r\n width: this._scene.getEngine().getRenderWidth(),\r\n height: this._scene.getEngine().getRenderHeight(),\r\n samplingMode: Texture.BILINEAR_SAMPLINGMODE,\r\n engine: this._engine,\r\n textureType: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n uniforms: [\"sizeParams\"],\r\n samplers: [\"cdfy\", \"icdfy\", \"cdfx\", \"icdfx\", \"iblSource\"],\r\n defines: this._iblSource?.isCube ? \"#define IBL_USE_CUBE_MAP\\n\" : \"\",\r\n shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n extraInitializations: (useWebGPU: boolean, list: Promise<any>[]) => {\r\n if (useWebGPU) {\r\n list.push(import(\"../../ShadersWGSL/iblShadowsImportanceSamplingDebug.fragment\"));\r\n } else {\r\n list.push(import(\"../../Shaders/iblShadowsImportanceSamplingDebug.fragment\"));\r\n }\r\n },\r\n };\r\n this._debugPass = new PostProcess(this._debugPassName, \"iblShadowsImportanceSamplingDebug\", debugOptions);\r\n const debugEffect = this._debugPass.getEffect();\r\n if (debugEffect) {\r\n debugEffect.defines = this._iblSource?.isCube ? \"#define IBL_USE_CUBE_MAP\\n\" : \"\";\r\n }\r\n if (this._iblSource?.isCube) {\r\n this._debugPass.updateEffect(\"#define IBL_USE_CUBE_MAP\\n\");\r\n }\r\n this._debugPass.onApplyObservable.add((effect) => {\r\n effect.setTexture(\"cdfy\", this._cdfyPT);\r\n effect.setTexture(\"icdfy\", this._icdfyPT);\r\n effect.setTexture(\"cdfx\", this._cdfxPT);\r\n effect.setTexture(\"icdfx\", this._icdfxPT);\r\n effect.setTexture(\"iblSource\", this._iblSource);\r\n effect.setFloat4(\"sizeParams\", this._debugSizeParams.x, this._debugSizeParams.y, this._debugSizeParams.z, this._debugSizeParams.w);\r\n });\r\n }\r\n\r\n /**\r\n * Checks if the importance sampling renderer is ready\r\n * @returns true if the importance sampling renderer is ready\r\n */\r\n public isReady() {\r\n return (\r\n this._iblSource &&\r\n this._iblSource.name !== \"Placeholder IBL Source\" &&\r\n this._iblSource.isReady() &&\r\n this._cdfyPT &&\r\n this._cdfyPT.isReady() &&\r\n this._icdfyPT &&\r\n this._icdfyPT.isReady() &&\r\n this._cdfxPT &&\r\n this._cdfxPT.isReady() &&\r\n this._icdfxPT &&\r\n this._icdfxPT.isReady()\r\n );\r\n }\r\n\r\n /**\r\n * Disposes the importance sampling renderer and associated resources\r\n */\r\n public dispose() {\r\n this._disposeTextures();\r\n if (this._debugPass) {\r\n this._debugPass.dispose();\r\n }\r\n }\r\n}\r\n"]}
|