@babylonjs/core 9.2.0 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cameras/Inputs/geospatialCameraPointersInput.js +10 -8
- package/Cameras/Inputs/geospatialCameraPointersInput.js.map +1 -1
- package/Cameras/geospatialCameraMovement.js +2 -2
- package/Cameras/geospatialCameraMovement.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +2 -0
- package/Engines/webgpuEngine.js.map +1 -1
- package/FrameGraph/Node/Blocks/Rendering/iblShadowsRendererBlock.d.ts +105 -0
- package/FrameGraph/Node/Blocks/Rendering/iblShadowsRendererBlock.js +318 -0
- package/FrameGraph/Node/Blocks/Rendering/iblShadowsRendererBlock.js.map +1 -0
- package/FrameGraph/Node/Blocks/index.d.ts +1 -0
- package/FrameGraph/Node/Blocks/index.js +1 -0
- package/FrameGraph/Node/Blocks/index.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.d.ts +34 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js +144 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js.map +1 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.d.ts +26 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.js +82 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.js.map +1 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.d.ts +61 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.js +207 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.js.map +1 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsVoxelizationTask.d.ts +104 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsVoxelizationTask.js +218 -0
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsVoxelizationTask.js.map +1 -0
- package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.d.ts +217 -0
- package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.js +640 -0
- package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.js.map +1 -0
- package/FrameGraph/frameGraph.js +1 -0
- package/FrameGraph/frameGraph.js.map +1 -1
- package/FrameGraph/index.d.ts +1 -0
- package/FrameGraph/index.js +1 -0
- package/FrameGraph/index.js.map +1 -1
- package/Gizmos/boundingBoxGizmo.js +4 -0
- package/Gizmos/boundingBoxGizmo.js.map +1 -1
- package/Lights/Clustered/clusteredLightContainer.js +8 -5
- package/Lights/Clustered/clusteredLightContainer.js.map +1 -1
- package/Materials/PBR/openpbrMaterial.d.ts +13 -2
- package/Materials/PBR/openpbrMaterial.js +47 -16
- package/Materials/PBR/openpbrMaterial.js.map +1 -1
- package/Materials/PBR/pbrBRDFConfiguration.js +1 -1
- package/Materials/PBR/pbrBRDFConfiguration.js.map +1 -1
- package/Materials/Textures/Filtering/hdrFiltering.js +6 -0
- package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
- package/Materials/Textures/envCubeTexture.js +13 -13
- package/Materials/Textures/envCubeTexture.js.map +1 -1
- package/Materials/materialHelper.functions.js +1 -1
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +101 -62
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.js +39 -25
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.js.map +1 -1
- package/Misc/textureTools.d.ts +3 -1
- package/Misc/textureTools.js +74 -13
- package/Misc/textureTools.js.map +1 -1
- package/Misc/tools.js +1 -1
- package/Misc/tools.js.map +1 -1
- package/Particles/baseParticleSystem.d.ts +33 -1
- package/Particles/baseParticleSystem.js +65 -0
- package/Particles/baseParticleSystem.js.map +1 -1
- package/Particles/computeShaderParticleSystem.js +6 -0
- package/Particles/computeShaderParticleSystem.js.map +1 -1
- package/Particles/gpuParticleSystem.d.ts +24 -6
- package/Particles/gpuParticleSystem.js +85 -36
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particleSystem.d.ts +0 -6
- package/Particles/particleSystem.js +3 -14
- package/Particles/particleSystem.js.map +1 -1
- package/Particles/thinParticleSystem.d.ts +1 -3
- package/Particles/thinParticleSystem.js +1 -27
- package/Particles/thinParticleSystem.js.map +1 -1
- package/Particles/webgl2ParticleSystem.js +7 -0
- package/Particles/webgl2ParticleSystem.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js +1 -1
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsPluginMaterial.d.ts +3 -1
- package/Rendering/IBLShadows/iblShadowsPluginMaterial.js +11 -1
- package/Rendering/IBLShadows/iblShadowsPluginMaterial.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.d.ts +0 -19
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +21 -65
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.d.ts +15 -52
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +129 -220
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +3 -0
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
- package/Rendering/depthRenderer.js +6 -0
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.d.ts +14 -5
- package/Rendering/geometryBufferRenderer.js +6 -2
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/geometryBufferRendererSceneComponent.d.ts +4 -6
- package/Rendering/geometryBufferRendererSceneComponent.js.map +1 -1
- package/Rendering/iblCdfGenerator.d.ts +10 -0
- package/Rendering/iblCdfGenerator.js +52 -17
- package/Rendering/iblCdfGenerator.js.map +1 -1
- package/Rendering/index.d.ts +0 -6
- package/Rendering/index.js +0 -6
- package/Rendering/index.js.map +1 -1
- package/Shaders/ShadersInclude/openpbrDirectLighting.js +6 -1
- package/Shaders/ShadersInclude/openpbrDirectLighting.js.map +1 -1
- package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js +1 -1
- package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
- package/Shaders/gpuUpdateParticles.vertex.js +12 -6
- package/Shaders/gpuUpdateParticles.vertex.js.map +1 -1
- package/Shaders/iblShadowVoxelTracing.fragment.js +5 -1
- package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -1
- package/Shaders/iblVoxelGrid.fragment.d.ts +1 -0
- package/Shaders/iblVoxelGrid.fragment.js +33 -5
- package/Shaders/iblVoxelGrid.fragment.js.map +1 -1
- package/Shaders/{iblVoxelSlabDebug.fragment.d.ts → lod3D.fragment.d.ts} +1 -1
- package/Shaders/lod3D.fragment.js +13 -0
- package/Shaders/lod3D.fragment.js.map +1 -0
- package/Shaders/openpbr.fragment.js +5 -0
- package/Shaders/openpbr.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js +6 -1
- package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js +1 -1
- package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
- package/ShadersWGSL/gpuUpdateParticles.compute.js +14 -7
- package/ShadersWGSL/gpuUpdateParticles.compute.js.map +1 -1
- package/ShadersWGSL/iblShadowVoxelTracing.fragment.js +5 -1
- package/ShadersWGSL/iblShadowVoxelTracing.fragment.js.map +1 -1
- package/ShadersWGSL/iblVoxelGrid.fragment.js +1 -1
- package/ShadersWGSL/iblVoxelGrid.fragment.js.map +1 -1
- package/{Shaders/iblVoxelSlabDebug.vertex.d.ts → ShadersWGSL/lod3D.fragment.d.ts} +1 -1
- package/ShadersWGSL/lod3D.fragment.js +13 -0
- package/ShadersWGSL/lod3D.fragment.js.map +1 -0
- package/ShadersWGSL/openpbr.fragment.js +5 -0
- package/ShadersWGSL/openpbr.fragment.js.map +1 -1
- package/package.json +1 -1
- package/Shaders/iblVoxelGrid3dDebug.fragment.d.ts +0 -5
- package/Shaders/iblVoxelGrid3dDebug.fragment.js +0 -24
- package/Shaders/iblVoxelGrid3dDebug.fragment.js.map +0 -1
- package/Shaders/iblVoxelSlabDebug.fragment.js +0 -13
- package/Shaders/iblVoxelSlabDebug.fragment.js.map +0 -1
- package/Shaders/iblVoxelSlabDebug.vertex.js +0 -11
- package/Shaders/iblVoxelSlabDebug.vertex.js.map +0 -1
- package/ShadersWGSL/iblVoxelGrid3dDebug.fragment.d.ts +0 -5
- package/ShadersWGSL/iblVoxelGrid3dDebug.fragment.js +0 -23
- package/ShadersWGSL/iblVoxelGrid3dDebug.fragment.js.map +0 -1
- package/ShadersWGSL/iblVoxelSlabDebug.fragment.d.ts +0 -5
- package/ShadersWGSL/iblVoxelSlabDebug.fragment.js +0 -14
- package/ShadersWGSL/iblVoxelSlabDebug.fragment.js.map +0 -1
- package/ShadersWGSL/iblVoxelSlabDebug.vertex.d.ts +0 -5
- package/ShadersWGSL/iblVoxelSlabDebug.vertex.js +0 -12
- package/ShadersWGSL/iblVoxelSlabDebug.vertex.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
|
|
2
|
+
import { Vector4 } from "../../../../Maths/math.vector.js";
|
|
3
|
+
import { ThinCustomPostProcess } from "../../../../PostProcesses/thinCustomPostProcess.js";
|
|
4
|
+
import { FrameGraphTask } from "../../../frameGraphTask.js";
|
|
5
|
+
/**
|
|
6
|
+
* Task used to temporally accumulate IBL shadows.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class FrameGraphIblShadowsAccumulationTask extends FrameGraphTask {
|
|
10
|
+
get remanence() {
|
|
11
|
+
return this._remanence;
|
|
12
|
+
}
|
|
13
|
+
set remanence(value) {
|
|
14
|
+
this._remanence = Math.max(0, Math.min(value, 1));
|
|
15
|
+
}
|
|
16
|
+
constructor(name, frameGraph) {
|
|
17
|
+
super(name, frameGraph);
|
|
18
|
+
this._remanence = 0.75;
|
|
19
|
+
this.reset = true;
|
|
20
|
+
this.isMoving = false;
|
|
21
|
+
this.voxelGridSize = 1;
|
|
22
|
+
this._accumulationParams = new Vector4(0, 0, 0, 0);
|
|
23
|
+
this.postProcess = new ThinCustomPostProcess(name, frameGraph.engine, {
|
|
24
|
+
fragmentShader: "iblShadowAccumulation",
|
|
25
|
+
uniforms: ["accumulationParameters"],
|
|
26
|
+
samplers: ["spatialBlurSampler", "oldAccumulationSampler", "prevPositionSampler", "motionSampler", "positionSampler"],
|
|
27
|
+
shaderLanguage: frameGraph.engine.isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
|
|
28
|
+
});
|
|
29
|
+
this._postProcessDrawWrapper = this.postProcess.drawWrapper;
|
|
30
|
+
this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();
|
|
31
|
+
}
|
|
32
|
+
getClassName() {
|
|
33
|
+
return "FrameGraphIblShadowsAccumulationTask";
|
|
34
|
+
}
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
|
|
36
|
+
initAsync() {
|
|
37
|
+
if (this._frameGraph.engine.isWebGPU) {
|
|
38
|
+
return import("../../../../ShadersWGSL/iblShadowAccumulation.fragment.js");
|
|
39
|
+
}
|
|
40
|
+
return import("../../../../Shaders/iblShadowAccumulation.fragment.js");
|
|
41
|
+
}
|
|
42
|
+
isReady() {
|
|
43
|
+
return this.postProcess.isReady();
|
|
44
|
+
}
|
|
45
|
+
record() {
|
|
46
|
+
if (this.sourceTexture === undefined || this.velocityTexture === undefined || this.positionTexture === undefined) {
|
|
47
|
+
throw new Error(`FrameGraphIblShadowsAccumulationTask ${this.name}: sourceTexture, velocityTexture and positionTexture are required`);
|
|
48
|
+
}
|
|
49
|
+
const textureManager = this._frameGraph.textureManager;
|
|
50
|
+
const outputSize = textureManager.getTextureAbsoluteDimensions(this.sourceTexture);
|
|
51
|
+
const positionSize = textureManager.getTextureAbsoluteDimensions(this.positionTexture);
|
|
52
|
+
const outputCreationOptions = {
|
|
53
|
+
size: outputSize,
|
|
54
|
+
sizeIsPercentage: false,
|
|
55
|
+
isHistoryTexture: false,
|
|
56
|
+
options: {
|
|
57
|
+
createMipMaps: false,
|
|
58
|
+
samples: 1,
|
|
59
|
+
types: [2],
|
|
60
|
+
formats: [5],
|
|
61
|
+
useSRGBBuffers: [false],
|
|
62
|
+
creationFlags: [0],
|
|
63
|
+
labels: [`${this.name} Output`],
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
textureManager.resolveDanglingHandle(this.outputTexture, undefined, `${this.name} Output`, outputCreationOptions);
|
|
67
|
+
const accumulationHistoryCreationOptions = {
|
|
68
|
+
size: outputSize,
|
|
69
|
+
sizeIsPercentage: false,
|
|
70
|
+
isHistoryTexture: true,
|
|
71
|
+
options: {
|
|
72
|
+
createMipMaps: false,
|
|
73
|
+
samples: 1,
|
|
74
|
+
types: [2],
|
|
75
|
+
formats: [5],
|
|
76
|
+
useSRGBBuffers: [false],
|
|
77
|
+
creationFlags: [0],
|
|
78
|
+
labels: [`${this.name} History`],
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
const positionHistoryCreationOptions = {
|
|
82
|
+
size: positionSize,
|
|
83
|
+
sizeIsPercentage: false,
|
|
84
|
+
isHistoryTexture: true,
|
|
85
|
+
options: {
|
|
86
|
+
createMipMaps: false,
|
|
87
|
+
samples: 1,
|
|
88
|
+
types: [2],
|
|
89
|
+
formats: [5],
|
|
90
|
+
useSRGBBuffers: [false],
|
|
91
|
+
creationFlags: [0],
|
|
92
|
+
labels: [`${this.name} Position History`],
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
this._accumulationHistoryTexture = textureManager.createRenderTargetTexture(`${this.name} Accumulation History`, accumulationHistoryCreationOptions, this._accumulationHistoryTexture);
|
|
96
|
+
this._positionHistoryTexture = textureManager.createRenderTargetTexture(`${this.name} Position History`, positionHistoryCreationOptions, this._positionHistoryTexture);
|
|
97
|
+
const pass = this._frameGraph.addRenderPass(this.name);
|
|
98
|
+
pass.addDependencies(this.sourceTexture);
|
|
99
|
+
pass.addDependencies(this.velocityTexture);
|
|
100
|
+
pass.addDependencies(this.positionTexture);
|
|
101
|
+
pass.addDependencies(this._accumulationHistoryTexture);
|
|
102
|
+
pass.addDependencies(this._positionHistoryTexture);
|
|
103
|
+
// Accumulation writes directly to the history handle (current frame write side)
|
|
104
|
+
// so oldAccumulationSampler reads previous-frame data automatically.
|
|
105
|
+
// A dedicated copy pass then exposes a stable current-frame outputTexture.
|
|
106
|
+
pass.setRenderTarget(this._accumulationHistoryTexture);
|
|
107
|
+
pass.setExecuteFunc((context) => {
|
|
108
|
+
context.setTextureSamplingMode(this.sourceTexture, 1);
|
|
109
|
+
context.setTextureSamplingMode(this.velocityTexture, 1);
|
|
110
|
+
context.setTextureSamplingMode(this.positionTexture, 1);
|
|
111
|
+
const remanence = this.isMoving ? this.remanence : 0.99;
|
|
112
|
+
this._accumulationParams.set(remanence, this.reset ? 1.0 : 0.0, this.voxelizationTask?.voxelGridSize ?? this.voxelGridSize, 0.0);
|
|
113
|
+
context.applyFullScreenEffect(this._postProcessDrawWrapper, () => {
|
|
114
|
+
const effect = this._postProcessDrawWrapper.effect;
|
|
115
|
+
context.bindTextureHandle(effect, "spatialBlurSampler", this.sourceTexture);
|
|
116
|
+
context.bindTextureHandle(effect, "oldAccumulationSampler", this._accumulationHistoryTexture);
|
|
117
|
+
context.bindTextureHandle(effect, "prevPositionSampler", this._positionHistoryTexture);
|
|
118
|
+
context.bindTextureHandle(effect, "motionSampler", this.velocityTexture);
|
|
119
|
+
context.bindTextureHandle(effect, "positionSampler", this.positionTexture);
|
|
120
|
+
effect.setVector4("accumulationParameters", this._accumulationParams);
|
|
121
|
+
this.postProcess.bind();
|
|
122
|
+
}, undefined, false, false, true);
|
|
123
|
+
this.reset = false;
|
|
124
|
+
this.isMoving = false;
|
|
125
|
+
});
|
|
126
|
+
const copyPositionToHistoryPass = this._frameGraph.addRenderPass(`${this.name} CopyPositionToHistory`);
|
|
127
|
+
copyPositionToHistoryPass.addDependencies(this.positionTexture);
|
|
128
|
+
copyPositionToHistoryPass.setRenderTarget(this._positionHistoryTexture);
|
|
129
|
+
copyPositionToHistoryPass.setExecuteFunc((context) => {
|
|
130
|
+
context.copyTexture(this.positionTexture);
|
|
131
|
+
});
|
|
132
|
+
const copyAccumulationToOutputPass = this._frameGraph.addRenderPass(`${this.name} CopyAccumulationToOutput`);
|
|
133
|
+
copyAccumulationToOutputPass.addDependencies(this._accumulationHistoryTexture);
|
|
134
|
+
copyAccumulationToOutputPass.setRenderTarget(this.outputTexture);
|
|
135
|
+
copyAccumulationToOutputPass.setExecuteFunc((context) => {
|
|
136
|
+
context.copyTexture(this._accumulationHistoryTexture);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
dispose() {
|
|
140
|
+
this.postProcess.dispose();
|
|
141
|
+
super.dispose();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=iblShadowsAccumulationTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iblShadowsAccumulationTask.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,qBAAqB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AAC,aAAa,CAAC,GAAG,IAAI,CAAC,IAAI,2BAA2B,CAAC,CAAC;QAE7G,4BAA4B,CAAC,eAAe,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC/E,4BAA4B,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACjE,4BAA4B,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE;YACpD,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,2BAA4B,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACP,CAAC;IAEe,OAAO;QACnB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC3B,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ","sourcesContent":["import { type DrawWrapper, type FrameGraph, type FrameGraphTextureCreationOptions, type FrameGraphTextureHandle } from \"core/index\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { type FrameGraphIblShadowsVoxelizationTask } from \"./iblShadowsVoxelizationTask\";\r\nimport { Vector4 } from \"core/Maths/math.vector\";\r\nimport { ThinCustomPostProcess } from \"core/PostProcesses/thinCustomPostProcess\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { FrameGraphTask } from \"../../../frameGraphTask\";\r\n\r\n/**\r\n * Task used to temporally accumulate IBL shadows.\r\n * @internal\r\n */\r\nexport class FrameGraphIblShadowsAccumulationTask extends FrameGraphTask {\r\n public sourceTexture?: FrameGraphTextureHandle;\r\n public velocityTexture?: FrameGraphTextureHandle;\r\n public positionTexture?: FrameGraphTextureHandle;\r\n\r\n private _remanence = 0.75;\r\n\r\n public get remanence(): number {\r\n return this._remanence;\r\n }\r\n\r\n public set remanence(value: number) {\r\n this._remanence = Math.max(0, Math.min(value, 1));\r\n }\r\n public reset = true;\r\n public isMoving = false;\r\n public voxelGridSize = 1;\r\n /** Voxelization task providing the runtime voxelGridSize used by the accumulation shader. */\r\n public voxelizationTask?: FrameGraphIblShadowsVoxelizationTask;\r\n\r\n protected _accumulationHistoryTexture?: FrameGraphTextureHandle;\r\n protected _positionHistoryTexture?: FrameGraphTextureHandle;\r\n\r\n public readonly outputTexture: FrameGraphTextureHandle;\r\n\r\n public readonly postProcess: ThinCustomPostProcess;\r\n protected readonly _postProcessDrawWrapper: DrawWrapper;\r\n protected readonly _accumulationParams = new Vector4(0, 0, 0, 0);\r\n\r\n constructor(name: string, frameGraph: FrameGraph) {\r\n super(name, frameGraph);\r\n\r\n this.postProcess = new ThinCustomPostProcess(name, frameGraph.engine, {\r\n fragmentShader: \"iblShadowAccumulation\",\r\n uniforms: [\"accumulationParameters\"],\r\n samplers: [\"spatialBlurSampler\", \"oldAccumulationSampler\", \"prevPositionSampler\", \"motionSampler\", \"positionSampler\"],\r\n shaderLanguage: frameGraph.engine.isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n });\r\n this._postProcessDrawWrapper = this.postProcess.drawWrapper;\r\n\r\n this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();\r\n }\r\n\r\n public override getClassName(): string {\r\n return \"FrameGraphIblShadowsAccumulationTask\";\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public override initAsync(): Promise<unknown> {\r\n if (this._frameGraph.engine.isWebGPU) {\r\n return import(\"../../../../ShadersWGSL/iblShadowAccumulation.fragment\");\r\n }\r\n\r\n return import(\"../../../../Shaders/iblShadowAccumulation.fragment\");\r\n }\r\n\r\n public override isReady(): boolean {\r\n return this.postProcess.isReady();\r\n }\r\n\r\n public override record() {\r\n if (this.sourceTexture === undefined || this.velocityTexture === undefined || this.positionTexture === undefined) {\r\n throw new Error(`FrameGraphIblShadowsAccumulationTask ${this.name}: sourceTexture, velocityTexture and positionTexture are required`);\r\n }\r\n\r\n const textureManager = this._frameGraph.textureManager;\r\n const outputSize = textureManager.getTextureAbsoluteDimensions(this.sourceTexture);\r\n const positionSize = textureManager.getTextureAbsoluteDimensions(this.positionTexture);\r\n\r\n const outputCreationOptions: FrameGraphTextureCreationOptions = {\r\n size: outputSize,\r\n sizeIsPercentage: false,\r\n isHistoryTexture: false,\r\n options: {\r\n createMipMaps: false,\r\n samples: 1,\r\n types: [Constants.TEXTURETYPE_HALF_FLOAT],\r\n formats: [Constants.TEXTUREFORMAT_RGBA],\r\n useSRGBBuffers: [false],\r\n creationFlags: [0],\r\n labels: [`${this.name} Output`],\r\n },\r\n };\r\n\r\n textureManager.resolveDanglingHandle(this.outputTexture, undefined, `${this.name} Output`, outputCreationOptions);\r\n\r\n const accumulationHistoryCreationOptions: FrameGraphTextureCreationOptions = {\r\n size: outputSize,\r\n sizeIsPercentage: false,\r\n isHistoryTexture: true,\r\n options: {\r\n createMipMaps: false,\r\n samples: 1,\r\n types: [Constants.TEXTURETYPE_HALF_FLOAT],\r\n formats: [Constants.TEXTUREFORMAT_RGBA],\r\n useSRGBBuffers: [false],\r\n creationFlags: [0],\r\n labels: [`${this.name} History`],\r\n },\r\n };\r\n\r\n const positionHistoryCreationOptions: FrameGraphTextureCreationOptions = {\r\n size: positionSize,\r\n sizeIsPercentage: false,\r\n isHistoryTexture: true,\r\n options: {\r\n createMipMaps: false,\r\n samples: 1,\r\n types: [Constants.TEXTURETYPE_HALF_FLOAT],\r\n formats: [Constants.TEXTUREFORMAT_RGBA],\r\n useSRGBBuffers: [false],\r\n creationFlags: [0],\r\n labels: [`${this.name} Position History`],\r\n },\r\n };\r\n\r\n this._accumulationHistoryTexture = textureManager.createRenderTargetTexture(\r\n `${this.name} Accumulation History`,\r\n accumulationHistoryCreationOptions,\r\n this._accumulationHistoryTexture\r\n );\r\n this._positionHistoryTexture = textureManager.createRenderTargetTexture(`${this.name} Position History`, positionHistoryCreationOptions, this._positionHistoryTexture);\r\n\r\n const pass = this._frameGraph.addRenderPass(this.name);\r\n\r\n pass.addDependencies(this.sourceTexture);\r\n pass.addDependencies(this.velocityTexture);\r\n pass.addDependencies(this.positionTexture);\r\n pass.addDependencies(this._accumulationHistoryTexture);\r\n pass.addDependencies(this._positionHistoryTexture);\r\n // Accumulation writes directly to the history handle (current frame write side)\r\n // so oldAccumulationSampler reads previous-frame data automatically.\r\n // A dedicated copy pass then exposes a stable current-frame outputTexture.\r\n pass.setRenderTarget(this._accumulationHistoryTexture);\r\n pass.setExecuteFunc((context) => {\r\n context.setTextureSamplingMode(this.sourceTexture!, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n context.setTextureSamplingMode(this.velocityTexture!, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n context.setTextureSamplingMode(this.positionTexture!, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n\r\n const remanence = this.isMoving ? this.remanence : 0.99;\r\n this._accumulationParams.set(remanence, this.reset ? 1.0 : 0.0, this.voxelizationTask?.voxelGridSize ?? this.voxelGridSize, 0.0);\r\n\r\n context.applyFullScreenEffect(\r\n this._postProcessDrawWrapper,\r\n () => {\r\n const effect = this._postProcessDrawWrapper.effect!;\r\n\r\n context.bindTextureHandle(effect, \"spatialBlurSampler\", this.sourceTexture!);\r\n context.bindTextureHandle(effect, \"oldAccumulationSampler\", this._accumulationHistoryTexture!);\r\n context.bindTextureHandle(effect, \"prevPositionSampler\", this._positionHistoryTexture!);\r\n context.bindTextureHandle(effect, \"motionSampler\", this.velocityTexture!);\r\n context.bindTextureHandle(effect, \"positionSampler\", this.positionTexture!);\r\n\r\n effect.setVector4(\"accumulationParameters\", this._accumulationParams);\r\n this.postProcess.bind();\r\n },\r\n undefined,\r\n false,\r\n false,\r\n true\r\n );\r\n\r\n this.reset = false;\r\n this.isMoving = false;\r\n });\r\n\r\n const copyPositionToHistoryPass = this._frameGraph.addRenderPass(`${this.name} CopyPositionToHistory`);\r\n\r\n copyPositionToHistoryPass.addDependencies(this.positionTexture);\r\n copyPositionToHistoryPass.setRenderTarget(this._positionHistoryTexture);\r\n copyPositionToHistoryPass.setExecuteFunc((context) => {\r\n context.copyTexture(this.positionTexture!);\r\n });\r\n\r\n const copyAccumulationToOutputPass = this._frameGraph.addRenderPass(`${this.name} CopyAccumulationToOutput`);\r\n\r\n copyAccumulationToOutputPass.addDependencies(this._accumulationHistoryTexture);\r\n copyAccumulationToOutputPass.setRenderTarget(this.outputTexture);\r\n copyAccumulationToOutputPass.setExecuteFunc((context) => {\r\n context.copyTexture(this._accumulationHistoryTexture!);\r\n });\r\n }\r\n\r\n public override dispose(): void {\r\n this.postProcess.dispose();\r\n super.dispose();\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type DrawWrapper, type FrameGraph, type FrameGraphTextureHandle } from "../../../../index.js";
|
|
2
|
+
import { type FrameGraphIblShadowsVoxelizationTask } from "./iblShadowsVoxelizationTask.js";
|
|
3
|
+
import { Vector4 } from "../../../../Maths/math.vector.js";
|
|
4
|
+
import { ThinCustomPostProcess } from "../../../../PostProcesses/thinCustomPostProcess.js";
|
|
5
|
+
import { FrameGraphTask } from "../../../frameGraphTask.js";
|
|
6
|
+
/**
|
|
7
|
+
* Task used to spatially blur IBL shadows.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare class FrameGraphIblShadowsSpatialBlurTask extends FrameGraphTask {
|
|
11
|
+
sourceTexture?: FrameGraphTextureHandle;
|
|
12
|
+
depthTexture?: FrameGraphTextureHandle;
|
|
13
|
+
normalTexture?: FrameGraphTextureHandle;
|
|
14
|
+
/** Voxelization task providing the dynamic voxelGridSize used as worldScale. */
|
|
15
|
+
voxelizationTask?: FrameGraphIblShadowsVoxelizationTask;
|
|
16
|
+
readonly outputTexture: FrameGraphTextureHandle;
|
|
17
|
+
readonly postProcess: ThinCustomPostProcess;
|
|
18
|
+
protected readonly _postProcessDrawWrapper: DrawWrapper;
|
|
19
|
+
protected readonly _blurParameters: Vector4;
|
|
20
|
+
constructor(name: string, frameGraph: FrameGraph);
|
|
21
|
+
getClassName(): string;
|
|
22
|
+
initAsync(): Promise<unknown>;
|
|
23
|
+
isReady(): boolean;
|
|
24
|
+
record(): void;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
import { Vector4 } from "../../../../Maths/math.vector.js";
|
|
3
|
+
import { ThinCustomPostProcess } from "../../../../PostProcesses/thinCustomPostProcess.js";
|
|
4
|
+
import { FrameGraphTask } from "../../../frameGraphTask.js";
|
|
5
|
+
/**
|
|
6
|
+
* Task used to spatially blur IBL shadows.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class FrameGraphIblShadowsSpatialBlurTask extends FrameGraphTask {
|
|
10
|
+
constructor(name, frameGraph) {
|
|
11
|
+
super(name, frameGraph);
|
|
12
|
+
this._blurParameters = new Vector4(0, 0, 0, 0);
|
|
13
|
+
this.postProcess = new ThinCustomPostProcess(name, frameGraph.engine, {
|
|
14
|
+
fragmentShader: "iblShadowSpatialBlur",
|
|
15
|
+
uniforms: ["blurParameters"],
|
|
16
|
+
samplers: ["voxelTracingSampler", "depthSampler", "worldNormalSampler"],
|
|
17
|
+
shaderLanguage: frameGraph.engine.isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
|
|
18
|
+
});
|
|
19
|
+
this._postProcessDrawWrapper = this.postProcess.drawWrapper;
|
|
20
|
+
this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();
|
|
21
|
+
}
|
|
22
|
+
getClassName() {
|
|
23
|
+
return "FrameGraphIblShadowsSpatialBlurTask";
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
|
|
26
|
+
initAsync() {
|
|
27
|
+
if (this._frameGraph.engine.isWebGPU) {
|
|
28
|
+
return import("../../../../ShadersWGSL/iblShadowSpatialBlur.fragment.js");
|
|
29
|
+
}
|
|
30
|
+
return import("../../../../Shaders/iblShadowSpatialBlur.fragment.js");
|
|
31
|
+
}
|
|
32
|
+
isReady() {
|
|
33
|
+
return this.postProcess.isReady();
|
|
34
|
+
}
|
|
35
|
+
record() {
|
|
36
|
+
if (this.sourceTexture === undefined || this.depthTexture === undefined || this.normalTexture === undefined) {
|
|
37
|
+
throw new Error(`FrameGraphIblShadowsSpatialBlurTask ${this.name}: sourceTexture, depthTexture and normalTexture are required`);
|
|
38
|
+
}
|
|
39
|
+
const textureManager = this._frameGraph.textureManager;
|
|
40
|
+
const size = textureManager.getTextureAbsoluteDimensions(this.sourceTexture);
|
|
41
|
+
const creationOptions = {
|
|
42
|
+
size,
|
|
43
|
+
sizeIsPercentage: false,
|
|
44
|
+
isHistoryTexture: false,
|
|
45
|
+
options: {
|
|
46
|
+
createMipMaps: false,
|
|
47
|
+
samples: 1,
|
|
48
|
+
types: [0],
|
|
49
|
+
formats: [5],
|
|
50
|
+
useSRGBBuffers: [false],
|
|
51
|
+
creationFlags: [0],
|
|
52
|
+
labels: [`${this.name} Output`],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
textureManager.resolveDanglingHandle(this.outputTexture, undefined, `${this.name} Output`, creationOptions);
|
|
56
|
+
const pass = this._frameGraph.addRenderPass(this.name);
|
|
57
|
+
pass.addDependencies(this.sourceTexture);
|
|
58
|
+
pass.addDependencies(this.depthTexture);
|
|
59
|
+
pass.addDependencies(this.normalTexture);
|
|
60
|
+
pass.setRenderTarget(this.outputTexture);
|
|
61
|
+
pass.setExecuteFunc((context) => {
|
|
62
|
+
context.setTextureSamplingMode(this.sourceTexture, 1);
|
|
63
|
+
context.setTextureSamplingMode(this.depthTexture, 1);
|
|
64
|
+
context.setTextureSamplingMode(this.normalTexture, 1);
|
|
65
|
+
const iterationCount = 1;
|
|
66
|
+
this._blurParameters.set(iterationCount, this.voxelizationTask?.voxelGridSize ?? 1.0, 0.0, 0.0);
|
|
67
|
+
context.applyFullScreenEffect(this._postProcessDrawWrapper, () => {
|
|
68
|
+
const effect = this._postProcessDrawWrapper.effect;
|
|
69
|
+
context.bindTextureHandle(effect, "voxelTracingSampler", this.sourceTexture);
|
|
70
|
+
context.bindTextureHandle(effect, "depthSampler", this.depthTexture);
|
|
71
|
+
context.bindTextureHandle(effect, "worldNormalSampler", this.normalTexture);
|
|
72
|
+
effect.setVector4("blurParameters", this._blurParameters);
|
|
73
|
+
this.postProcess.bind();
|
|
74
|
+
}, undefined, false, false, true);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
dispose() {
|
|
78
|
+
this.postProcess.dispose();
|
|
79
|
+
super.dispose();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=iblShadowsSpatialBlurTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iblShadowsSpatialBlurTask.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;;GAGG;AACH,MAAM,OAAO,mCAAoC,SAAQ,cAAc;IAcnE,YAAY,IAAY,EAAE,UAAsB;QAC5C,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAHT,oBAAe,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAKzD,IAAI,CAAC,WAAW,GAAG,IAAI,qBAAqB,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,EAAE;YAClE,cAAc,EAAE,sBAAsB;YACtC,QAAQ,EAAE,CAAC,gBAAgB,CAAC;YAC5B,QAAQ,EAAE,CAAC,qBAAqB,EAAE,cAAc,EAAE,oBAAoB,CAAC;YACvE,cAAc,EAAE,UAAU,C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AO,CAAC,iBAAiB,CAAC,MAAM,EAAE,qBAAqB,EAAE,IAAI,CAAC,aAAc,CAAC,CAAC;gBAC9E,OAAO,CAAC,iBAAiB,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,CAAC,YAAa,CAAC,CAAC;gBACtE,OAAO,CAAC,iBAAiB,CAAC,MAAM,EAAE,oBAAoB,EAAE,IAAI,CAAC,aAAc,CAAC,CAAC;gBAC7E,MAAM,CAAC,UAAU,CAAC,gBAAgB,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;gBAE1D,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAC5B,CAAC,EACD,SAAS,EACT,KAAK,EACL,KAAK,EACL,IAAI,CACP,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;IAEe,OAAO;QACnB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC3B,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ","sourcesContent":["import { type DrawWrapper, type FrameGraph, type FrameGraphTextureCreationOptions, type FrameGraphTextureHandle } from \"core/index\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { type FrameGraphIblShadowsVoxelizationTask } from \"./iblShadowsVoxelizationTask\";\r\nimport { Vector4 } from \"core/Maths/math.vector\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { ThinCustomPostProcess } from \"core/PostProcesses/thinCustomPostProcess\";\r\nimport { FrameGraphTask } from \"../../../frameGraphTask\";\r\n\r\n/**\r\n * Task used to spatially blur IBL shadows.\r\n * @internal\r\n */\r\nexport class FrameGraphIblShadowsSpatialBlurTask extends FrameGraphTask {\r\n public sourceTexture?: FrameGraphTextureHandle;\r\n public depthTexture?: FrameGraphTextureHandle;\r\n public normalTexture?: FrameGraphTextureHandle;\r\n\r\n /** Voxelization task providing the dynamic voxelGridSize used as worldScale. */\r\n public voxelizationTask?: FrameGraphIblShadowsVoxelizationTask;\r\n\r\n public readonly outputTexture: FrameGraphTextureHandle;\r\n\r\n public readonly postProcess: ThinCustomPostProcess;\r\n protected readonly _postProcessDrawWrapper: DrawWrapper;\r\n protected readonly _blurParameters = new Vector4(0, 0, 0, 0);\r\n\r\n constructor(name: string, frameGraph: FrameGraph) {\r\n super(name, frameGraph);\r\n\r\n this.postProcess = new ThinCustomPostProcess(name, frameGraph.engine, {\r\n fragmentShader: \"iblShadowSpatialBlur\",\r\n uniforms: [\"blurParameters\"],\r\n samplers: [\"voxelTracingSampler\", \"depthSampler\", \"worldNormalSampler\"],\r\n shaderLanguage: frameGraph.engine.isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n });\r\n this._postProcessDrawWrapper = this.postProcess.drawWrapper;\r\n\r\n this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();\r\n }\r\n\r\n public override getClassName(): string {\r\n return \"FrameGraphIblShadowsSpatialBlurTask\";\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public override initAsync(): Promise<unknown> {\r\n if (this._frameGraph.engine.isWebGPU) {\r\n return import(\"../../../../ShadersWGSL/iblShadowSpatialBlur.fragment\");\r\n }\r\n\r\n return import(\"../../../../Shaders/iblShadowSpatialBlur.fragment\");\r\n }\r\n\r\n public override isReady(): boolean {\r\n return this.postProcess.isReady();\r\n }\r\n\r\n public override record() {\r\n if (this.sourceTexture === undefined || this.depthTexture === undefined || this.normalTexture === undefined) {\r\n throw new Error(`FrameGraphIblShadowsSpatialBlurTask ${this.name}: sourceTexture, depthTexture and normalTexture are required`);\r\n }\r\n\r\n const textureManager = this._frameGraph.textureManager;\r\n const size = textureManager.getTextureAbsoluteDimensions(this.sourceTexture);\r\n const creationOptions: FrameGraphTextureCreationOptions = {\r\n size,\r\n sizeIsPercentage: false,\r\n isHistoryTexture: false,\r\n options: {\r\n createMipMaps: false,\r\n samples: 1,\r\n types: [Constants.TEXTURETYPE_UNSIGNED_BYTE],\r\n formats: [Constants.TEXTUREFORMAT_RGBA],\r\n useSRGBBuffers: [false],\r\n creationFlags: [0],\r\n labels: [`${this.name} Output`],\r\n },\r\n };\r\n\r\n textureManager.resolveDanglingHandle(this.outputTexture, undefined, `${this.name} Output`, creationOptions);\r\n\r\n const pass = this._frameGraph.addRenderPass(this.name);\r\n\r\n pass.addDependencies(this.sourceTexture);\r\n pass.addDependencies(this.depthTexture);\r\n pass.addDependencies(this.normalTexture);\r\n pass.setRenderTarget(this.outputTexture);\r\n pass.setExecuteFunc((context) => {\r\n context.setTextureSamplingMode(this.sourceTexture!, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n context.setTextureSamplingMode(this.depthTexture!, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n context.setTextureSamplingMode(this.normalTexture!, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n\r\n const iterationCount = 1;\r\n this._blurParameters.set(iterationCount, this.voxelizationTask?.voxelGridSize ?? 1.0, 0.0, 0.0);\r\n\r\n context.applyFullScreenEffect(\r\n this._postProcessDrawWrapper,\r\n () => {\r\n const effect = this._postProcessDrawWrapper.effect!;\r\n\r\n context.bindTextureHandle(effect, \"voxelTracingSampler\", this.sourceTexture!);\r\n context.bindTextureHandle(effect, \"depthSampler\", this.depthTexture!);\r\n context.bindTextureHandle(effect, \"worldNormalSampler\", this.normalTexture!);\r\n effect.setVector4(\"blurParameters\", this._blurParameters);\r\n\r\n this.postProcess.bind();\r\n },\r\n undefined,\r\n false,\r\n false,\r\n true\r\n );\r\n });\r\n }\r\n\r\n public override dispose(): void {\r\n this.postProcess.dispose();\r\n super.dispose();\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type Camera, type DrawWrapper, type FrameGraph, type FrameGraphTextureHandle } from "../../../../index.js";
|
|
2
|
+
import { type FrameGraphIblShadowsVoxelizationTask } from "./iblShadowsVoxelizationTask.js";
|
|
3
|
+
import { Matrix, Vector4 } from "../../../../Maths/math.vector.js";
|
|
4
|
+
import { ThinCustomPostProcess } from "../../../../PostProcesses/thinCustomPostProcess.js";
|
|
5
|
+
import { FrameGraphTask } from "../../../frameGraphTask.js";
|
|
6
|
+
/**
|
|
7
|
+
* Task used to trace IBL shadows from a voxel grid.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare class FrameGraphIblShadowsTracingTask extends FrameGraphTask {
|
|
11
|
+
camera?: Camera;
|
|
12
|
+
voxelGridTexture?: FrameGraphTextureHandle;
|
|
13
|
+
depthTexture?: FrameGraphTextureHandle;
|
|
14
|
+
normalTexture?: FrameGraphTextureHandle;
|
|
15
|
+
icdfTexture?: FrameGraphTextureHandle;
|
|
16
|
+
environmentTexture?: FrameGraphTextureHandle;
|
|
17
|
+
blueNoiseTexture?: FrameGraphTextureHandle;
|
|
18
|
+
private _sampleDirections;
|
|
19
|
+
get sampleDirections(): number;
|
|
20
|
+
set sampleDirections(value: number);
|
|
21
|
+
voxelShadowOpacity: number;
|
|
22
|
+
ssShadowOpacity: number;
|
|
23
|
+
private _ssShadowSampleCount;
|
|
24
|
+
get ssShadowSampleCount(): number;
|
|
25
|
+
set ssShadowSampleCount(value: number);
|
|
26
|
+
private _ssShadowStride;
|
|
27
|
+
get ssShadowStride(): number;
|
|
28
|
+
set ssShadowStride(value: number);
|
|
29
|
+
/** Scale factor applied to voxelGridSize / 2^resolutionExp to get the max SSS ray distance. */
|
|
30
|
+
ssShadowDistanceScale: number;
|
|
31
|
+
/** Scale factor applied to voxelGridSize to get the SSS surface thickness. */
|
|
32
|
+
ssShadowThicknessScale: number;
|
|
33
|
+
/** Voxelization task providing dynamic voxelGridSize and resolutionExp for SSS parameter derivation. */
|
|
34
|
+
voxelizationTask?: FrameGraphIblShadowsVoxelizationTask;
|
|
35
|
+
envRotation: number;
|
|
36
|
+
voxelNormalBias: number;
|
|
37
|
+
voxelDirectionBias: number;
|
|
38
|
+
worldScaleMatrix: Matrix;
|
|
39
|
+
readonly outputTexture: FrameGraphTextureHandle;
|
|
40
|
+
readonly postProcess: ThinCustomPostProcess;
|
|
41
|
+
protected readonly _postProcessDrawWrapper: DrawWrapper;
|
|
42
|
+
protected readonly _shadowParameters: Vector4;
|
|
43
|
+
protected readonly _sssParameters: Vector4;
|
|
44
|
+
protected readonly _opacityParameters: Vector4;
|
|
45
|
+
protected readonly _voxelBiasParameters: Vector4;
|
|
46
|
+
protected readonly _cameraInvView: Matrix;
|
|
47
|
+
protected readonly _cameraInvProj: Matrix;
|
|
48
|
+
protected readonly _cameraInvViewProjection: Matrix;
|
|
49
|
+
protected _frameId: number;
|
|
50
|
+
protected _coloredShadows: boolean;
|
|
51
|
+
protected _currentDefines: string;
|
|
52
|
+
constructor(name: string, frameGraph: FrameGraph);
|
|
53
|
+
getClassName(): string;
|
|
54
|
+
initAsync(): Promise<unknown>;
|
|
55
|
+
get coloredShadows(): boolean;
|
|
56
|
+
set coloredShadows(value: boolean);
|
|
57
|
+
isReady(): boolean;
|
|
58
|
+
record(): void;
|
|
59
|
+
dispose(): void;
|
|
60
|
+
protected _updateDefines(): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
|
|
2
|
+
import { Matrix, Vector4 } from "../../../../Maths/math.vector.js";
|
|
3
|
+
import { ThinCustomPostProcess } from "../../../../PostProcesses/thinCustomPostProcess.js";
|
|
4
|
+
import { FrameGraphTask } from "../../../frameGraphTask.js";
|
|
5
|
+
import { Color4 } from "../../../../Maths/math.color.js";
|
|
6
|
+
/**
|
|
7
|
+
* Task used to trace IBL shadows from a voxel grid.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class FrameGraphIblShadowsTracingTask extends FrameGraphTask {
|
|
11
|
+
get sampleDirections() {
|
|
12
|
+
return this._sampleDirections;
|
|
13
|
+
}
|
|
14
|
+
set sampleDirections(value) {
|
|
15
|
+
this._sampleDirections = Math.max(1, Math.round(value));
|
|
16
|
+
}
|
|
17
|
+
get ssShadowSampleCount() {
|
|
18
|
+
return this._ssShadowSampleCount;
|
|
19
|
+
}
|
|
20
|
+
set ssShadowSampleCount(value) {
|
|
21
|
+
this._ssShadowSampleCount = Math.max(1, Math.round(value));
|
|
22
|
+
}
|
|
23
|
+
get ssShadowStride() {
|
|
24
|
+
return this._ssShadowStride;
|
|
25
|
+
}
|
|
26
|
+
set ssShadowStride(value) {
|
|
27
|
+
this._ssShadowStride = Math.max(1, Math.round(value));
|
|
28
|
+
}
|
|
29
|
+
constructor(name, frameGraph) {
|
|
30
|
+
super(name, frameGraph);
|
|
31
|
+
this._sampleDirections = 2;
|
|
32
|
+
this.voxelShadowOpacity = 1;
|
|
33
|
+
this.ssShadowOpacity = 1;
|
|
34
|
+
this._ssShadowSampleCount = 16;
|
|
35
|
+
this._ssShadowStride = 8;
|
|
36
|
+
/** Scale factor applied to voxelGridSize / 2^resolutionExp to get the max SSS ray distance. */
|
|
37
|
+
this.ssShadowDistanceScale = 1.25;
|
|
38
|
+
/** Scale factor applied to voxelGridSize to get the SSS surface thickness. */
|
|
39
|
+
this.ssShadowThicknessScale = 1.0;
|
|
40
|
+
this.envRotation = 0;
|
|
41
|
+
this.voxelNormalBias = 1.4;
|
|
42
|
+
this.voxelDirectionBias = 1.75;
|
|
43
|
+
this.worldScaleMatrix = Matrix.Identity();
|
|
44
|
+
this._shadowParameters = new Vector4(0, 0, 0, 0);
|
|
45
|
+
this._sssParameters = new Vector4(0, 0, 0, 0);
|
|
46
|
+
this._opacityParameters = new Vector4(0, 0, 0, 0);
|
|
47
|
+
this._voxelBiasParameters = new Vector4(0, 0, 0, 0);
|
|
48
|
+
this._cameraInvView = Matrix.Identity();
|
|
49
|
+
this._cameraInvProj = Matrix.Identity();
|
|
50
|
+
this._cameraInvViewProjection = Matrix.Identity();
|
|
51
|
+
this._frameId = 0;
|
|
52
|
+
this._coloredShadows = false;
|
|
53
|
+
this._currentDefines = "";
|
|
54
|
+
this.postProcess = new ThinCustomPostProcess(name, frameGraph.engine, {
|
|
55
|
+
fragmentShader: "iblShadowVoxelTracing",
|
|
56
|
+
uniforms: [
|
|
57
|
+
"viewMtx",
|
|
58
|
+
"projMtx",
|
|
59
|
+
"invProjMtx",
|
|
60
|
+
"invViewMtx",
|
|
61
|
+
"invVPMtx",
|
|
62
|
+
"wsNormalizationMtx",
|
|
63
|
+
"shadowParameters",
|
|
64
|
+
"voxelBiasParameters",
|
|
65
|
+
"sssParameters",
|
|
66
|
+
"shadowOpacity",
|
|
67
|
+
],
|
|
68
|
+
samplers: ["depthSampler", "worldNormalSampler", "blueNoiseSampler", "icdfSampler", "voxelGridSampler", "iblSampler"],
|
|
69
|
+
shaderLanguage: frameGraph.engine.isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
|
|
70
|
+
});
|
|
71
|
+
this._postProcessDrawWrapper = this.postProcess.drawWrapper;
|
|
72
|
+
this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();
|
|
73
|
+
}
|
|
74
|
+
getClassName() {
|
|
75
|
+
return "FrameGraphIblShadowsTracingTask";
|
|
76
|
+
}
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
|
|
78
|
+
initAsync() {
|
|
79
|
+
if (this._frameGraph.engine.isWebGPU) {
|
|
80
|
+
return import("../../../../ShadersWGSL/iblShadowVoxelTracing.fragment.js");
|
|
81
|
+
}
|
|
82
|
+
return import("../../../../Shaders/iblShadowVoxelTracing.fragment.js");
|
|
83
|
+
}
|
|
84
|
+
get coloredShadows() {
|
|
85
|
+
return this._coloredShadows;
|
|
86
|
+
}
|
|
87
|
+
set coloredShadows(value) {
|
|
88
|
+
if (this._coloredShadows === value) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this._coloredShadows = value;
|
|
92
|
+
this._updateDefines();
|
|
93
|
+
}
|
|
94
|
+
isReady() {
|
|
95
|
+
return this.postProcess.isReady();
|
|
96
|
+
}
|
|
97
|
+
record() {
|
|
98
|
+
if (this.camera === undefined ||
|
|
99
|
+
this.voxelGridTexture === undefined ||
|
|
100
|
+
this.depthTexture === undefined ||
|
|
101
|
+
this.normalTexture === undefined ||
|
|
102
|
+
this.icdfTexture === undefined) {
|
|
103
|
+
throw new Error(`FrameGraphIblShadowsTracingTask ${this.name}: camera, voxelGridTexture, depthTexture, normalTexture and icdfTexture are required`);
|
|
104
|
+
}
|
|
105
|
+
const textureManager = this._frameGraph.textureManager;
|
|
106
|
+
const size = textureManager.getTextureAbsoluteDimensions(this.depthTexture);
|
|
107
|
+
const creationOptions = {
|
|
108
|
+
size,
|
|
109
|
+
sizeIsPercentage: false,
|
|
110
|
+
isHistoryTexture: false,
|
|
111
|
+
options: {
|
|
112
|
+
createMipMaps: false,
|
|
113
|
+
samples: 1,
|
|
114
|
+
types: [0],
|
|
115
|
+
formats: [5],
|
|
116
|
+
useSRGBBuffers: [false],
|
|
117
|
+
creationFlags: [0],
|
|
118
|
+
labels: [`${this.name} Output`],
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
textureManager.resolveDanglingHandle(this.outputTexture, undefined, `${this.name} Output`, creationOptions);
|
|
122
|
+
this._updateDefines();
|
|
123
|
+
const pass = this._frameGraph.addRenderPass(this.name);
|
|
124
|
+
const dependencies = [this.voxelGridTexture, this.depthTexture, this.normalTexture, this.icdfTexture];
|
|
125
|
+
if (this.environmentTexture !== undefined) {
|
|
126
|
+
dependencies.push(this.environmentTexture);
|
|
127
|
+
}
|
|
128
|
+
if (this.blueNoiseTexture !== undefined) {
|
|
129
|
+
dependencies.push(this.blueNoiseTexture);
|
|
130
|
+
}
|
|
131
|
+
pass.addDependencies(dependencies);
|
|
132
|
+
pass.setRenderTarget(this.outputTexture);
|
|
133
|
+
pass.setExecuteFunc((context) => {
|
|
134
|
+
if (this.icdfTexture === undefined || this.blueNoiseTexture === undefined || (this.coloredShadows && this.environmentTexture === undefined)) {
|
|
135
|
+
context.clear(new Color4(1, 1, 1, 1), true, false, false);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
context.setTextureSamplingMode(this.depthTexture, 1);
|
|
139
|
+
context.setTextureSamplingMode(this.normalTexture, 1);
|
|
140
|
+
context.setTextureSamplingMode(this.icdfTexture, 1);
|
|
141
|
+
context.setTextureSamplingMode(this.blueNoiseTexture, 1);
|
|
142
|
+
const view = this.camera.getViewMatrix();
|
|
143
|
+
const projection = this.camera.getProjectionMatrix();
|
|
144
|
+
projection.invertToRef(this._cameraInvProj);
|
|
145
|
+
view.invertToRef(this._cameraInvView);
|
|
146
|
+
this.camera.getTransformationMatrix().invertToRef(this._cameraInvViewProjection);
|
|
147
|
+
const voxelGridSize = textureManager.getTextureAbsoluteDimensions(this.voxelGridTexture);
|
|
148
|
+
const highestMip = Math.floor(Math.log2(Math.max(1, voxelGridSize.width)));
|
|
149
|
+
this._frameId++;
|
|
150
|
+
let rotation = 0.0;
|
|
151
|
+
if (this.environmentTexture) {
|
|
152
|
+
rotation = this._frameGraph.scene.environmentTexture.rotationY ?? 0;
|
|
153
|
+
}
|
|
154
|
+
rotation = this._frameGraph.scene.useRightHandedSystem ? -(rotation + 0.5 * Math.PI) : rotation - 0.5 * Math.PI;
|
|
155
|
+
rotation = rotation % (2.0 * Math.PI);
|
|
156
|
+
this._shadowParameters.set(this.sampleDirections, this._frameId, 1.0, rotation);
|
|
157
|
+
this._voxelBiasParameters.set(this.voxelNormalBias, this.voxelDirectionBias, highestMip, 0.0);
|
|
158
|
+
const gridSize = this.voxelizationTask?.voxelGridSize ?? 1.0;
|
|
159
|
+
const resExp = this.voxelizationTask?.resolutionExp ?? 6;
|
|
160
|
+
const sssMaxDist = (this.ssShadowDistanceScale * gridSize) / (1 << resExp);
|
|
161
|
+
const sssThickness = this.ssShadowThicknessScale * 0.005 * gridSize;
|
|
162
|
+
this._sssParameters.set(this.ssShadowSampleCount, this.ssShadowStride, sssMaxDist, sssThickness);
|
|
163
|
+
this._opacityParameters.set(this.voxelShadowOpacity, this.ssShadowOpacity, 0.0, 0.0);
|
|
164
|
+
context.applyFullScreenEffect(this._postProcessDrawWrapper, () => {
|
|
165
|
+
const effect = this._postProcessDrawWrapper.effect;
|
|
166
|
+
context.bindTextureHandle(effect, "voxelGridSampler", this.voxelGridTexture);
|
|
167
|
+
context.bindTextureHandle(effect, "depthSampler", this.depthTexture);
|
|
168
|
+
context.bindTextureHandle(effect, "worldNormalSampler", this.normalTexture);
|
|
169
|
+
context.bindTextureHandle(effect, "icdfSampler", this.icdfTexture);
|
|
170
|
+
context.bindTextureHandle(effect, "blueNoiseSampler", this.blueNoiseTexture);
|
|
171
|
+
if (this.coloredShadows && this.environmentTexture !== undefined) {
|
|
172
|
+
context.bindTextureHandle(effect, "iblSampler", this.environmentTexture);
|
|
173
|
+
}
|
|
174
|
+
effect.setMatrix("viewMtx", view);
|
|
175
|
+
effect.setMatrix("projMtx", projection);
|
|
176
|
+
effect.setMatrix("invProjMtx", this._cameraInvProj);
|
|
177
|
+
effect.setMatrix("invViewMtx", this._cameraInvView);
|
|
178
|
+
effect.setMatrix("invVPMtx", this._cameraInvViewProjection);
|
|
179
|
+
effect.setMatrix("wsNormalizationMtx", this.worldScaleMatrix);
|
|
180
|
+
effect.setVector4("shadowParameters", this._shadowParameters);
|
|
181
|
+
effect.setVector4("voxelBiasParameters", this._voxelBiasParameters);
|
|
182
|
+
effect.setVector4("sssParameters", this._sssParameters);
|
|
183
|
+
effect.setVector4("shadowOpacity", this._opacityParameters);
|
|
184
|
+
this.postProcess.bind();
|
|
185
|
+
}, undefined, false, false, true);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
dispose() {
|
|
189
|
+
this.postProcess.dispose();
|
|
190
|
+
super.dispose();
|
|
191
|
+
}
|
|
192
|
+
_updateDefines() {
|
|
193
|
+
const defines = ["#define WORLD_NORMAL_UNSIGNED"];
|
|
194
|
+
if (this._frameGraph.scene.useRightHandedSystem) {
|
|
195
|
+
defines.push("#define RIGHT_HANDED");
|
|
196
|
+
}
|
|
197
|
+
if (this.coloredShadows) {
|
|
198
|
+
defines.push("#define COLOR_SHADOWS 1u");
|
|
199
|
+
}
|
|
200
|
+
const defineString = defines.join("\n");
|
|
201
|
+
if (defineString !== this._currentDefines) {
|
|
202
|
+
this._currentDefines = defineString;
|
|
203
|
+
this.postProcess.updateEffect(this._currentDefines);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=iblShadowsTracingTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iblShadowsTracingTask.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C;;;GAGG;AACH,MAAM,OAAO,+BAAgC,SAAQ,cAAc;IAW/D,IAAW,gBAAgB;QACvB,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAClC,CAAC;IAED,IAAW,gBAAgB,CAAC,KAAa;QACrC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5D,CAAC;IAOD,IAAW,mBAAmB;QAC1B,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACrC,CAAC;IAED,IAAW,mBAAmB,CAAC,KAAa;QACxC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,CAAC;IAID,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KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;IAES,cAAc;QACpB,MAAM,OAAO,GAAa,CAAC,+BAA+B,CAAC,CAAC;QAE5D,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACzC,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,OAAO,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,YAAY,KAAK,IAAI,CAAC,eAAe,EAAE,CAAC;YACxC,IAAI,CAAC,eAAe,GAAG,YAAY,CAAC;YACpC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxD,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { type Camera, type DrawWrapper, type FrameGraph, type FrameGraphTextureCreationOptions, type FrameGraphTextureHandle } from \"core/index\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { type FrameGraphIblShadowsVoxelizationTask } from \"./iblShadowsVoxelizationTask\";\r\nimport { Matrix, Vector4 } from \"core/Maths/math.vector\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { ThinCustomPostProcess } from \"core/PostProcesses/thinCustomPostProcess\";\r\nimport { FrameGraphTask } from \"../../../frameGraphTask\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\nimport { type CubeTexture } from \"core/Materials/Textures/cubeTexture\";\r\n\r\n/**\r\n * Task used to trace IBL shadows from a voxel grid.\r\n * @internal\r\n */\r\nexport class FrameGraphIblShadowsTracingTask extends FrameGraphTask {\r\n public camera?: Camera;\r\n public voxelGridTexture?: FrameGraphTextureHandle;\r\n public depthTexture?: FrameGraphTextureHandle;\r\n public normalTexture?: FrameGraphTextureHandle;\r\n public icdfTexture?: FrameGraphTextureHandle;\r\n public environmentTexture?: FrameGraphTextureHandle;\r\n public blueNoiseTexture?: FrameGraphTextureHandle;\r\n\r\n private _sampleDirections = 2;\r\n\r\n public get sampleDirections(): number {\r\n return this._sampleDirections;\r\n }\r\n\r\n public set sampleDirections(value: number) {\r\n this._sampleDirections = Math.max(1, Math.round(value));\r\n }\r\n\r\n public voxelShadowOpacity = 1;\r\n public ssShadowOpacity = 1;\r\n\r\n private _ssShadowSampleCount = 16;\r\n\r\n public get ssShadowSampleCount(): number {\r\n return this._ssShadowSampleCount;\r\n }\r\n\r\n public set ssShadowSampleCount(value: number) {\r\n this._ssShadowSampleCount = Math.max(1, Math.round(value));\r\n }\r\n\r\n private _ssShadowStride = 8;\r\n\r\n public get ssShadowStride(): number {\r\n return this._ssShadowStride;\r\n }\r\n\r\n public set ssShadowStride(value: number) {\r\n this._ssShadowStride = Math.max(1, Math.round(value));\r\n }\r\n /** Scale factor applied to voxelGridSize / 2^resolutionExp to get the max SSS ray distance. */\r\n public ssShadowDistanceScale = 1.25;\r\n /** Scale factor applied to voxelGridSize to get the SSS surface thickness. */\r\n public ssShadowThicknessScale = 1.0;\r\n /** Voxelization task providing dynamic voxelGridSize and resolutionExp for SSS parameter derivation. */\r\n public voxelizationTask?: FrameGraphIblShadowsVoxelizationTask;\r\n public envRotation = 0;\r\n public voxelNormalBias = 1.4;\r\n public voxelDirectionBias = 1.75;\r\n public worldScaleMatrix = Matrix.Identity();\r\n\r\n public readonly outputTexture: FrameGraphTextureHandle;\r\n\r\n public readonly postProcess: ThinCustomPostProcess;\r\n protected readonly _postProcessDrawWrapper: DrawWrapper;\r\n protected readonly _shadowParameters = new Vector4(0, 0, 0, 0);\r\n protected readonly _sssParameters = new Vector4(0, 0, 0, 0);\r\n protected readonly _opacityParameters = new Vector4(0, 0, 0, 0);\r\n protected readonly _voxelBiasParameters = new Vector4(0, 0, 0, 0);\r\n protected readonly _cameraInvView = Matrix.Identity();\r\n protected readonly _cameraInvProj = Matrix.Identity();\r\n protected readonly _cameraInvViewProjection = Matrix.Identity();\r\n protected _frameId = 0;\r\n protected _coloredShadows = false;\r\n protected _currentDefines = \"\";\r\n\r\n constructor(name: string, frameGraph: FrameGraph) {\r\n super(name, frameGraph);\r\n\r\n this.postProcess = new ThinCustomPostProcess(name, frameGraph.engine, {\r\n fragmentShader: \"iblShadowVoxelTracing\",\r\n uniforms: [\r\n \"viewMtx\",\r\n \"projMtx\",\r\n \"invProjMtx\",\r\n \"invViewMtx\",\r\n \"invVPMtx\",\r\n \"wsNormalizationMtx\",\r\n \"shadowParameters\",\r\n \"voxelBiasParameters\",\r\n \"sssParameters\",\r\n \"shadowOpacity\",\r\n ],\r\n samplers: [\"depthSampler\", \"worldNormalSampler\", \"blueNoiseSampler\", \"icdfSampler\", \"voxelGridSampler\", \"iblSampler\"],\r\n shaderLanguage: frameGraph.engine.isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n });\r\n this._postProcessDrawWrapper = this.postProcess.drawWrapper;\r\n\r\n this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();\r\n }\r\n\r\n public override getClassName(): string {\r\n return \"FrameGraphIblShadowsTracingTask\";\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public override initAsync(): Promise<unknown> {\r\n if (this._frameGraph.engine.isWebGPU) {\r\n return import(\"../../../../ShadersWGSL/iblShadowVoxelTracing.fragment\");\r\n }\r\n\r\n return import(\"../../../../Shaders/iblShadowVoxelTracing.fragment\");\r\n }\r\n\r\n public get coloredShadows(): boolean {\r\n return this._coloredShadows;\r\n }\r\n\r\n public set coloredShadows(value: boolean) {\r\n if (this._coloredShadows === value) {\r\n return;\r\n }\r\n\r\n this._coloredShadows = value;\r\n this._updateDefines();\r\n }\r\n\r\n public override isReady(): boolean {\r\n return this.postProcess.isReady();\r\n }\r\n\r\n public override record() {\r\n if (\r\n this.camera === undefined ||\r\n this.voxelGridTexture === undefined ||\r\n this.depthTexture === undefined ||\r\n this.normalTexture === undefined ||\r\n this.icdfTexture === undefined\r\n ) {\r\n throw new Error(`FrameGraphIblShadowsTracingTask ${this.name}: camera, voxelGridTexture, depthTexture, normalTexture and icdfTexture are required`);\r\n }\r\n\r\n const textureManager = this._frameGraph.textureManager;\r\n const size = textureManager.getTextureAbsoluteDimensions(this.depthTexture);\r\n const creationOptions: FrameGraphTextureCreationOptions = {\r\n size,\r\n sizeIsPercentage: false,\r\n isHistoryTexture: false,\r\n options: {\r\n createMipMaps: false,\r\n samples: 1,\r\n types: [Constants.TEXTURETYPE_UNSIGNED_BYTE],\r\n formats: [Constants.TEXTUREFORMAT_RGBA],\r\n useSRGBBuffers: [false],\r\n creationFlags: [0],\r\n labels: [`${this.name} Output`],\r\n },\r\n };\r\n\r\n textureManager.resolveDanglingHandle(this.outputTexture, undefined, `${this.name} Output`, creationOptions);\r\n\r\n this._updateDefines();\r\n\r\n const pass = this._frameGraph.addRenderPass(this.name);\r\n\r\n const dependencies: FrameGraphTextureHandle[] = [this.voxelGridTexture, this.depthTexture, this.normalTexture, this.icdfTexture];\r\n if (this.environmentTexture !== undefined) {\r\n dependencies.push(this.environmentTexture);\r\n }\r\n if (this.blueNoiseTexture !== undefined) {\r\n dependencies.push(this.blueNoiseTexture);\r\n }\r\n pass.addDependencies(dependencies);\r\n pass.setRenderTarget(this.outputTexture);\r\n pass.setExecuteFunc((context) => {\r\n if (this.icdfTexture === undefined || this.blueNoiseTexture === undefined || (this.coloredShadows && this.environmentTexture === undefined)) {\r\n context.clear(new Color4(1, 1, 1, 1), true, false, false);\r\n return;\r\n }\r\n\r\n context.setTextureSamplingMode(this.depthTexture!, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n context.setTextureSamplingMode(this.normalTexture!, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n context.setTextureSamplingMode(this.icdfTexture!, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n context.setTextureSamplingMode(this.blueNoiseTexture, Constants.TEXTURE_NEAREST_SAMPLINGMODE);\r\n\r\n const view = this.camera!.getViewMatrix();\r\n const projection = this.camera!.getProjectionMatrix();\r\n projection.invertToRef(this._cameraInvProj);\r\n view.invertToRef(this._cameraInvView);\r\n this.camera!.getTransformationMatrix().invertToRef(this._cameraInvViewProjection);\r\n\r\n const voxelGridSize = textureManager.getTextureAbsoluteDimensions(this.voxelGridTexture!);\r\n const highestMip = Math.floor(Math.log2(Math.max(1, voxelGridSize.width)));\r\n\r\n this._frameId++;\r\n let rotation = 0.0;\r\n if (this.environmentTexture) {\r\n rotation = (this._frameGraph.scene.environmentTexture as CubeTexture).rotationY ?? 0;\r\n }\r\n rotation = this._frameGraph.scene.useRightHandedSystem ? -(rotation + 0.5 * Math.PI) : rotation - 0.5 * Math.PI;\r\n rotation = rotation % (2.0 * Math.PI);\r\n this._shadowParameters.set(this.sampleDirections, this._frameId, 1.0, rotation);\r\n this._voxelBiasParameters.set(this.voxelNormalBias, this.voxelDirectionBias, highestMip, 0.0);\r\n const gridSize = this.voxelizationTask?.voxelGridSize ?? 1.0;\r\n const resExp = this.voxelizationTask?.resolutionExp ?? 6;\r\n const sssMaxDist = (this.ssShadowDistanceScale * gridSize) / (1 << resExp);\r\n const sssThickness = this.ssShadowThicknessScale * 0.005 * gridSize;\r\n this._sssParameters.set(this.ssShadowSampleCount, this.ssShadowStride, sssMaxDist, sssThickness);\r\n this._opacityParameters.set(this.voxelShadowOpacity, this.ssShadowOpacity, 0.0, 0.0);\r\n\r\n context.applyFullScreenEffect(\r\n this._postProcessDrawWrapper,\r\n () => {\r\n const effect = this._postProcessDrawWrapper.effect!;\r\n\r\n context.bindTextureHandle(effect, \"voxelGridSampler\", this.voxelGridTexture!);\r\n context.bindTextureHandle(effect, \"depthSampler\", this.depthTexture!);\r\n context.bindTextureHandle(effect, \"worldNormalSampler\", this.normalTexture!);\r\n context.bindTextureHandle(effect, \"icdfSampler\", this.icdfTexture!);\r\n context.bindTextureHandle(effect, \"blueNoiseSampler\", this.blueNoiseTexture!);\r\n if (this.coloredShadows && this.environmentTexture !== undefined) {\r\n context.bindTextureHandle(effect, \"iblSampler\", this.environmentTexture);\r\n }\r\n\r\n effect.setMatrix(\"viewMtx\", view);\r\n effect.setMatrix(\"projMtx\", projection);\r\n effect.setMatrix(\"invProjMtx\", this._cameraInvProj);\r\n effect.setMatrix(\"invViewMtx\", this._cameraInvView);\r\n effect.setMatrix(\"invVPMtx\", this._cameraInvViewProjection);\r\n effect.setMatrix(\"wsNormalizationMtx\", this.worldScaleMatrix);\r\n effect.setVector4(\"shadowParameters\", this._shadowParameters);\r\n effect.setVector4(\"voxelBiasParameters\", this._voxelBiasParameters);\r\n effect.setVector4(\"sssParameters\", this._sssParameters);\r\n effect.setVector4(\"shadowOpacity\", this._opacityParameters);\r\n\r\n this.postProcess.bind();\r\n },\r\n undefined,\r\n false,\r\n false,\r\n true\r\n );\r\n });\r\n }\r\n\r\n public override dispose(): void {\r\n this.postProcess.dispose();\r\n super.dispose();\r\n }\r\n\r\n protected _updateDefines(): void {\r\n const defines: string[] = [\"#define WORLD_NORMAL_UNSIGNED\"];\r\n\r\n if (this._frameGraph.scene.useRightHandedSystem) {\r\n defines.push(\"#define RIGHT_HANDED\");\r\n }\r\n if (this.coloredShadows) {\r\n defines.push(\"#define COLOR_SHADOWS 1u\");\r\n }\r\n\r\n const defineString = defines.join(\"\\n\");\r\n if (defineString !== this._currentDefines) {\r\n this._currentDefines = defineString;\r\n this.postProcess.updateEffect(this._currentDefines);\r\n }\r\n }\r\n}\r\n"]}
|