@babylonjs/core 7.22.3 → 7.22.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/Animations/animationGroup.js +1 -1
- package/Animations/animationGroup.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/constants.d.ts +21 -1
- package/Engines/constants.js +21 -1
- package/Engines/constants.js.map +1 -1
- package/Engines/engineFeatures.d.ts +2 -0
- package/Engines/engineFeatures.js.map +1 -1
- package/Engines/nativeEngine.js +1 -0
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/nullEngine.js +1 -0
- package/Engines/nullEngine.js.map +1 -1
- package/Engines/thinEngine.js +2 -0
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +1 -0
- package/Engines/webgpuEngine.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/prePassOutputBlock.d.ts +12 -0
- package/Materials/Node/Blocks/Fragment/prePassOutputBlock.js +51 -0
- package/Materials/Node/Blocks/Fragment/prePassOutputBlock.js.map +1 -1
- package/Materials/Node/Blocks/Input/prePassTextureBlock.d.ts +27 -0
- package/Materials/Node/Blocks/Input/prePassTextureBlock.js +69 -0
- package/Materials/Node/Blocks/Input/prePassTextureBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +12 -0
- package/Materials/Node/nodeMaterial.js +24 -0
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.d.ts +8 -0
- package/Materials/PBR/pbrBaseMaterial.js +8 -0
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.d.ts +4 -0
- package/Materials/Textures/Procedurals/proceduralTexture.js +19 -5
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/effectRenderer.d.ts +4 -0
- package/Materials/effectRenderer.js +10 -10
- package/Materials/effectRenderer.js.map +1 -1
- package/Materials/materialHelper.functions.js +20 -0
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Materials/prePassConfiguration.js +2 -1
- package/Materials/prePassConfiguration.js.map +1 -1
- package/Materials/standardMaterial.d.ts +8 -0
- package/Materials/standardMaterial.js +8 -0
- package/Materials/standardMaterial.js.map +1 -1
- package/Misc/fileTools.js +1 -1
- package/Misc/fileTools.js.map +1 -1
- package/PostProcesses/postProcessManager.d.ts +2 -0
- package/PostProcesses/postProcessManager.js +3 -0
- package/PostProcesses/postProcessManager.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js +79 -8
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.d.ts +88 -0
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js +240 -0
- package/Rendering/IBLShadows/iblShadowsAccumulationPass.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.d.ts +88 -0
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js +231 -0
- package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.d.ts +340 -0
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +884 -0
- package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.d.ts +67 -0
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js +139 -0
- package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.d.ts +168 -0
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +597 -0
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.d.ts +151 -0
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +291 -0
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -0
- package/Rendering/depthRenderer.js +44 -23
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/index.d.ts +1 -0
- package/Rendering/index.js +1 -0
- package/Rendering/index.js.map +1 -1
- package/Rendering/outlineRenderer.js +3 -3
- package/Rendering/outlineRenderer.js.map +1 -1
- package/Rendering/prePassRenderer.js +25 -1
- package/Rendering/prePassRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/instancesDeclaration.js +4 -2
- package/Shaders/ShadersInclude/instancesDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/instancesVertex.js +8 -4
- package/Shaders/ShadersInclude/instancesVertex.js.map +1 -1
- package/Shaders/ShadersInclude/prePassDeclaration.js +4 -1
- package/Shaders/ShadersInclude/prePassDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/prePassVertex.js +5 -1
- package/Shaders/ShadersInclude/prePassVertex.js.map +1 -1
- package/Shaders/ShadersInclude/prePassVertexDeclaration.js +4 -1
- package/Shaders/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
- package/Shaders/combineVoxelGrids.fragment.d.ts +5 -0
- package/Shaders/combineVoxelGrids.fragment.js +9 -0
- package/Shaders/combineVoxelGrids.fragment.js.map +1 -0
- package/Shaders/copyTexture3DLayerToTexture.fragment.d.ts +5 -0
- package/Shaders/copyTexture3DLayerToTexture.fragment.js +10 -0
- package/Shaders/copyTexture3DLayerToTexture.fragment.js.map +1 -0
- package/Shaders/default.fragment.js +31 -6
- package/Shaders/default.fragment.js.map +1 -1
- package/Shaders/default.vertex.js +6 -2
- package/Shaders/default.vertex.js.map +1 -1
- package/Shaders/generateVoxelMip.fragment.d.ts +5 -0
- package/Shaders/generateVoxelMip.fragment.js +25 -0
- package/Shaders/generateVoxelMip.fragment.js.map +1 -0
- package/Shaders/geometry.fragment.js +1 -1
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/iblShadowAccumulation.fragment.d.ts +5 -0
- package/Shaders/iblShadowAccumulation.fragment.js +27 -0
- package/Shaders/iblShadowAccumulation.fragment.js.map +1 -0
- package/Shaders/iblShadowDebug.fragment.d.ts +5 -0
- package/Shaders/iblShadowDebug.fragment.js +18 -0
- package/Shaders/iblShadowDebug.fragment.js.map +1 -0
- package/Shaders/iblShadowGBufferDebug.fragment.d.ts +5 -0
- package/Shaders/iblShadowGBufferDebug.fragment.js +19 -0
- package/Shaders/iblShadowGBufferDebug.fragment.js.map +1 -0
- package/Shaders/iblShadowSpatialBlur.fragment.d.ts +5 -0
- package/Shaders/iblShadowSpatialBlur.fragment.js +21 -0
- package/Shaders/iblShadowSpatialBlur.fragment.js.map +1 -0
- package/Shaders/iblShadowVoxelTracing.fragment.d.ts +5 -0
- package/Shaders/iblShadowVoxelTracing.fragment.js +152 -0
- package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -0
- package/Shaders/iblShadowsCdfx.fragment.d.ts +5 -0
- package/Shaders/iblShadowsCdfx.fragment.js +12 -0
- package/Shaders/iblShadowsCdfx.fragment.js.map +1 -0
- package/Shaders/iblShadowsCdfy.fragment.d.ts +5 -0
- package/Shaders/iblShadowsCdfy.fragment.js +33 -0
- package/Shaders/iblShadowsCdfy.fragment.js.map +1 -0
- package/Shaders/iblShadowsCombine.fragment.d.ts +5 -0
- package/Shaders/iblShadowsCombine.fragment.js +10 -0
- package/Shaders/iblShadowsCombine.fragment.js.map +1 -0
- package/Shaders/iblShadowsIcdfx.fragment.d.ts +5 -0
- package/Shaders/iblShadowsIcdfx.fragment.js +19 -0
- package/Shaders/iblShadowsIcdfx.fragment.js.map +1 -0
- package/Shaders/iblShadowsIcdfy.fragment.d.ts +5 -0
- package/Shaders/iblShadowsIcdfy.fragment.js +19 -0
- package/Shaders/iblShadowsIcdfy.fragment.js.map +1 -0
- package/Shaders/iblShadowsImportanceSamplingDebug.fragment.d.ts +5 -0
- package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js +48 -0
- package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js.map +1 -0
- package/Shaders/pbr.fragment.js +32 -7
- package/Shaders/pbr.fragment.js.map +1 -1
- package/Shaders/pbr.vertex.js +3 -1
- package/Shaders/pbr.vertex.js.map +1 -1
- package/Shaders/voxelGrid.fragment.d.ts +5 -0
- package/Shaders/voxelGrid.fragment.js +14 -0
- package/Shaders/voxelGrid.fragment.js.map +1 -0
- package/Shaders/voxelGrid.vertex.d.ts +5 -0
- package/Shaders/voxelGrid.vertex.js +9 -0
- package/Shaders/voxelGrid.vertex.js.map +1 -0
- package/Shaders/voxelGrid2dArrayDebug.fragment.d.ts +5 -0
- package/Shaders/voxelGrid2dArrayDebug.fragment.js +9 -0
- package/Shaders/voxelGrid2dArrayDebug.fragment.js.map +1 -0
- package/Shaders/voxelGrid3dDebug.fragment.d.ts +5 -0
- package/Shaders/voxelGrid3dDebug.fragment.js +22 -0
- package/Shaders/voxelGrid3dDebug.fragment.js.map +1 -0
- package/Shaders/voxelSlabDebug.fragment.d.ts +5 -0
- package/Shaders/voxelSlabDebug.fragment.js +11 -0
- package/Shaders/voxelSlabDebug.fragment.js.map +1 -0
- package/Shaders/voxelSlabDebug.vertex.d.ts +5 -0
- package/Shaders/voxelSlabDebug.vertex.js +9 -0
- package/Shaders/voxelSlabDebug.vertex.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/instancesDeclaration.js +4 -2
- package/ShadersWGSL/ShadersInclude/instancesDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/instancesVertex.js +9 -4
- package/ShadersWGSL/ShadersInclude/instancesVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/prePassDeclaration.js +4 -1
- package/ShadersWGSL/ShadersInclude/prePassDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/prePassVertex.js +5 -1
- package/ShadersWGSL/ShadersInclude/prePassVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js +4 -1
- package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
- package/ShadersWGSL/default.fragment.js +42 -16
- package/ShadersWGSL/default.fragment.js.map +1 -1
- package/ShadersWGSL/default.vertex.js +5 -2
- package/ShadersWGSL/default.vertex.js.map +1 -1
- package/ShadersWGSL/geometry.fragment.js +1 -1
- package/ShadersWGSL/geometry.fragment.js.map +1 -1
- package/ShadersWGSL/pbr.fragment.js +37 -20
- package/ShadersWGSL/pbr.fragment.js.map +1 -1
- package/ShadersWGSL/pbr.vertex.js +1 -1
- package/ShadersWGSL/pbr.vertex.js.map +1 -1
- package/package.json +1 -1
- package/sceneComponent.d.ts +1 -0
- package/sceneComponent.js +1 -0
- package/sceneComponent.js.map +1 -1
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
|
|
2
|
+
import { Engine } from "../../Engines/engine.js";
|
|
3
|
+
import { WebGPUEngine } from "../../Engines/webgpuEngine.js";
|
|
4
|
+
import { ShaderMaterial } from "../../Materials/shaderMaterial.js";
|
|
5
|
+
import { MultiRenderTarget } from "../../Materials/Textures/multiRenderTarget.js";
|
|
6
|
+
import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.js";
|
|
7
|
+
import { Color4 } from "../../Maths/math.color.js";
|
|
8
|
+
import { Matrix, Vector3, Vector4 } from "../../Maths/math.vector.js";
|
|
9
|
+
import { Mesh } from "../../Meshes/mesh.js";
|
|
10
|
+
import { Texture } from "../../Materials/Textures/texture.js";
|
|
11
|
+
import { Logger } from "../../Misc/logger.js";
|
|
12
|
+
import "../../Shaders/voxelGrid.fragment.js";
|
|
13
|
+
import "../../Shaders/voxelGrid.vertex.js";
|
|
14
|
+
import "../../Shaders/voxelGrid2dArrayDebug.fragment.js";
|
|
15
|
+
import "../../Shaders/voxelGrid3dDebug.fragment.js";
|
|
16
|
+
import "../../Shaders/voxelSlabDebug.vertex.js";
|
|
17
|
+
import "../../Shaders/voxelSlabDebug.fragment.js";
|
|
18
|
+
import "../../Shaders/combineVoxelGrids.fragment.js";
|
|
19
|
+
import "../../Shaders/generateVoxelMip.fragment.js";
|
|
20
|
+
import "../../Shaders/copyTexture3DLayerToTexture.fragment.js";
|
|
21
|
+
import { PostProcess } from "../../PostProcesses/postProcess.js";
|
|
22
|
+
import { ProceduralTexture } from "../../Materials/Textures/Procedurals/proceduralTexture.js";
|
|
23
|
+
import { EffectRenderer, EffectWrapper } from "../../Materials/effectRenderer.js";
|
|
24
|
+
import { Observable } from "../../Misc/observable.js";
|
|
25
|
+
/**
|
|
26
|
+
* Voxel-based shadow rendering for IBL's.
|
|
27
|
+
* This should not be instanciated directly, as it is part of a scene component
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export class _IblShadowsVoxelRenderer {
|
|
31
|
+
/**
|
|
32
|
+
* Return the voxel grid texture.
|
|
33
|
+
* @returns The voxel grid texture.
|
|
34
|
+
*/
|
|
35
|
+
getVoxelGrid() {
|
|
36
|
+
if (this._triPlanarVoxelization) {
|
|
37
|
+
return this._voxelGridRT;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return this._voxelGridZaxis;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The debug pass post process
|
|
45
|
+
* @returns The debug pass post process
|
|
46
|
+
*/
|
|
47
|
+
getDebugPassPP() {
|
|
48
|
+
if (!this._voxelDebugPass) {
|
|
49
|
+
this._createDebugPass();
|
|
50
|
+
}
|
|
51
|
+
return this._voxelDebugPass;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Whether to use tri-planar voxelization. More expensive, but can help with artifacts.
|
|
55
|
+
*/
|
|
56
|
+
get triPlanarVoxelization() {
|
|
57
|
+
return this._triPlanarVoxelization;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether to use tri-planar voxelization. More expensive, but can help with artifacts.
|
|
61
|
+
*/
|
|
62
|
+
set triPlanarVoxelization(enabled) {
|
|
63
|
+
if (this._triPlanarVoxelization === enabled) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this._triPlanarVoxelization = enabled;
|
|
67
|
+
this._disposeVoxelTextures();
|
|
68
|
+
this._createTextures();
|
|
69
|
+
this._renderPipeline.updateVoxelization();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Set the matrix to use for scaling the world space to voxel space
|
|
73
|
+
* @param matrix The matrix to use for scaling the world space to voxel space
|
|
74
|
+
*/
|
|
75
|
+
setWorldScaleMatrix(matrix) {
|
|
76
|
+
this._invWorldScaleMatrix = matrix;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @returns Whether voxelization is currently happening.
|
|
80
|
+
*/
|
|
81
|
+
isVoxelizationInProgress() {
|
|
82
|
+
return this._voxelizationInProgress;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Resolution of the voxel grid. The final resolution will be 2^resolutionExp.
|
|
86
|
+
*/
|
|
87
|
+
get voxelResolutionExp() {
|
|
88
|
+
return this._voxelResolutionExp;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolution of the voxel grid. The final resolution will be 2^resolutionExp.
|
|
92
|
+
*/
|
|
93
|
+
set voxelResolutionExp(resolutionExp) {
|
|
94
|
+
if (this._voxelResolutionExp === resolutionExp && this._voxelGridZaxis) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this._voxelResolutionExp = Math.round(Math.min(Math.max(resolutionExp, 3), 9));
|
|
98
|
+
this._voxelResolution = Math.pow(2.0, this._voxelResolutionExp);
|
|
99
|
+
this._disposeVoxelTextures();
|
|
100
|
+
this._createTextures();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Shows only the voxels that were rendered along a particular axis (while using triPlanarVoxelization).
|
|
104
|
+
* If not set, the combined voxel grid will be shown.
|
|
105
|
+
* Note: This only works when the debugMipNumber is set to 0 because we don't generate mips for each axis.
|
|
106
|
+
* @param axis The axis to show (0 = x, 1 = y, 2 = z)
|
|
107
|
+
*/
|
|
108
|
+
set voxelDebugAxis(axis) {
|
|
109
|
+
this._voxelDebugAxis = axis;
|
|
110
|
+
}
|
|
111
|
+
get voxelDebugAxis() {
|
|
112
|
+
return this._voxelDebugAxis;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Sets params that control the position and scaling of the debug display on the screen.
|
|
116
|
+
* @param x Screen X offset of the debug display (0-1)
|
|
117
|
+
* @param y Screen Y offset of the debug display (0-1)
|
|
118
|
+
* @param widthScale X scale of the debug display (0-1)
|
|
119
|
+
* @param heightScale Y scale of the debug display (0-1)
|
|
120
|
+
*/
|
|
121
|
+
setDebugDisplayParams(x, y, widthScale, heightScale) {
|
|
122
|
+
this._debugSizeParams.set(x, y, widthScale, heightScale);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The mip level to show in the debug display
|
|
126
|
+
* @param mipNum The mip level to show in the debug display
|
|
127
|
+
*/
|
|
128
|
+
setDebugMipNumber(mipNum) {
|
|
129
|
+
this._debugMipNumber = mipNum;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Sets the name of the debug pass
|
|
133
|
+
*/
|
|
134
|
+
get debugPassName() {
|
|
135
|
+
return this._debugPassName;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Enable or disable the debug view for this pass
|
|
139
|
+
*/
|
|
140
|
+
get voxelDebugEnabled() {
|
|
141
|
+
return this._voxelDebugEnabled;
|
|
142
|
+
}
|
|
143
|
+
set voxelDebugEnabled(enabled) {
|
|
144
|
+
if (this._voxelDebugEnabled === enabled) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
this._voxelDebugEnabled = enabled;
|
|
148
|
+
if (enabled) {
|
|
149
|
+
this._voxelSlabDebugRT = new RenderTargetTexture("voxelSlabDebug", { ratio: 1 }, this._scene, {
|
|
150
|
+
generateDepthBuffer: true,
|
|
151
|
+
generateMipMaps: false,
|
|
152
|
+
type: 0,
|
|
153
|
+
format: 6,
|
|
154
|
+
samplingMode: 1,
|
|
155
|
+
});
|
|
156
|
+
this._voxelSlabDebugRT.noPrePassRenderer = true;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (this._voxelSlabDebugRT) {
|
|
160
|
+
this._removeVoxelRTs([this._voxelSlabDebugRT]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Creates the debug post process effect for this pass
|
|
166
|
+
*/
|
|
167
|
+
_createDebugPass() {
|
|
168
|
+
if (!this._voxelDebugPass) {
|
|
169
|
+
const debugOptions = {
|
|
170
|
+
width: this._engine.getRenderWidth(),
|
|
171
|
+
height: this._engine.getRenderHeight(),
|
|
172
|
+
textureFormat: 6,
|
|
173
|
+
textureType: 0,
|
|
174
|
+
samplingMode: 1,
|
|
175
|
+
uniforms: ["sizeParams", "mipNumber"],
|
|
176
|
+
samplers: ["voxelTexture", "voxelSlabTexture"],
|
|
177
|
+
engine: this._engine,
|
|
178
|
+
reusable: false,
|
|
179
|
+
};
|
|
180
|
+
this._voxelDebugPass = new PostProcess(this.debugPassName, this._isVoxelGrid3D ? "voxelGrid3dDebug" : "voxelGrid2dArrayDebug", debugOptions);
|
|
181
|
+
this._voxelDebugPass.onApplyObservable.add((effect) => {
|
|
182
|
+
if (this._voxelDebugAxis === 0) {
|
|
183
|
+
effect.setTexture("voxelTexture", this._voxelGridXaxis);
|
|
184
|
+
}
|
|
185
|
+
else if (this._voxelDebugAxis === 1) {
|
|
186
|
+
effect.setTexture("voxelTexture", this._voxelGridYaxis);
|
|
187
|
+
}
|
|
188
|
+
else if (this._voxelDebugAxis === 2) {
|
|
189
|
+
effect.setTexture("voxelTexture", this._voxelGridZaxis);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
effect.setTexture("voxelTexture", this.getVoxelGrid());
|
|
193
|
+
}
|
|
194
|
+
effect.setTexture("voxelSlabTexture", this._voxelSlabDebugRT);
|
|
195
|
+
effect.setVector4("sizeParams", this._debugSizeParams);
|
|
196
|
+
effect.setFloat("mipNumber", this._debugMipNumber);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Instanciates the voxel renderer
|
|
202
|
+
* @param scene Scene to attach to
|
|
203
|
+
* @param iblShadowsRenderPipeline The render pipeline this pass is associated with
|
|
204
|
+
* @param resolutionExp Resolution of the voxel grid. The final resolution will be 2^resolutionExp.
|
|
205
|
+
* @param triPlanarVoxelization Whether to use tri-planar voxelization. More expensive, but can help with artifacts.
|
|
206
|
+
* @returns The voxel renderer
|
|
207
|
+
*/
|
|
208
|
+
constructor(scene, iblShadowsRenderPipeline, resolutionExp = 6, triPlanarVoxelization = true) {
|
|
209
|
+
this._voxelMrtsXaxis = [];
|
|
210
|
+
this._voxelMrtsYaxis = [];
|
|
211
|
+
this._voxelMrtsZaxis = [];
|
|
212
|
+
this._isVoxelGrid3D = true;
|
|
213
|
+
this._renderTargets = [];
|
|
214
|
+
this._triPlanarVoxelization = true;
|
|
215
|
+
this._voxelizationInProgress = false;
|
|
216
|
+
this._voxelResolution = 64;
|
|
217
|
+
this._voxelResolutionExp = 6;
|
|
218
|
+
/**
|
|
219
|
+
* Observable that will be triggered when the voxel grid is ready to be used
|
|
220
|
+
*/
|
|
221
|
+
this.onReadyObservable = new Observable();
|
|
222
|
+
this._mipArray = [];
|
|
223
|
+
this._voxelDebugEnabled = false;
|
|
224
|
+
this._voxelDebugAxis = -1;
|
|
225
|
+
this._debugSizeParams = new Vector4(0.0, 0.0, 0.0, 0.0);
|
|
226
|
+
this._debugMipNumber = 0;
|
|
227
|
+
this._debugPassName = "Voxelization Debug Pass";
|
|
228
|
+
this._scene = scene;
|
|
229
|
+
this._engine = scene.getEngine();
|
|
230
|
+
this._triPlanarVoxelization = triPlanarVoxelization;
|
|
231
|
+
this._renderPipeline = iblShadowsRenderPipeline;
|
|
232
|
+
if (!this._engine.getCaps().drawBuffersExtension) {
|
|
233
|
+
Logger.Error("Can't do voxel rendering without the draw buffers extension.");
|
|
234
|
+
}
|
|
235
|
+
if (this._engine instanceof WebGPUEngine) {
|
|
236
|
+
this._maxDrawBuffers = 8; // TODO - get this from the WebGPU engine?
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
this._maxDrawBuffers = this._engine._gl.getParameter(this._engine._gl.MAX_DRAW_BUFFERS);
|
|
240
|
+
}
|
|
241
|
+
this._copyMipEffectRenderer = new EffectRenderer(this._engine);
|
|
242
|
+
this._copyMipEffectWrapper = new EffectWrapper({
|
|
243
|
+
engine: this._engine,
|
|
244
|
+
fragmentShader: "copyTexture3DLayerToTexture",
|
|
245
|
+
useShaderStore: true,
|
|
246
|
+
uniformNames: ["layerNum"],
|
|
247
|
+
samplerNames: ["textureSampler"],
|
|
248
|
+
});
|
|
249
|
+
this.voxelResolutionExp = resolutionExp;
|
|
250
|
+
}
|
|
251
|
+
_generateMipMaps() {
|
|
252
|
+
const iterations = Math.ceil(Math.log2(this._voxelResolution));
|
|
253
|
+
for (let i = 1; i < iterations + 1; i++) {
|
|
254
|
+
this._generateMipMap(i);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
_generateMipMap(lodLevel) {
|
|
258
|
+
// Generate a mip map for the given level by triggering the render of the procedural mip texture.
|
|
259
|
+
const mipTarget = this._mipArray[lodLevel - 1];
|
|
260
|
+
if (!mipTarget) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
mipTarget.setTexture("srcMip", lodLevel === 1 ? this.getVoxelGrid() : this._mipArray[lodLevel - 2]);
|
|
264
|
+
mipTarget.render();
|
|
265
|
+
}
|
|
266
|
+
_copyMipMaps() {
|
|
267
|
+
const iterations = Math.ceil(Math.log2(this._voxelResolution));
|
|
268
|
+
for (let i = 1; i < iterations + 1; i++) {
|
|
269
|
+
this._copyMipMap(i);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
_copyMipMap(lodLevel) {
|
|
273
|
+
// Now, copy this mip into the mip chain of the voxel grid.
|
|
274
|
+
// TODO - this currently isn't working. "textureSampler" isn't being properly set to mipTarget.
|
|
275
|
+
const mipTarget = this._mipArray[lodLevel - 1];
|
|
276
|
+
if (!mipTarget) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const voxelGrid = this.getVoxelGrid();
|
|
280
|
+
let rt;
|
|
281
|
+
if (voxelGrid instanceof RenderTargetTexture && voxelGrid.renderTarget) {
|
|
282
|
+
rt = voxelGrid.renderTarget;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
rt = voxelGrid._rtWrapper;
|
|
286
|
+
}
|
|
287
|
+
if (rt) {
|
|
288
|
+
this._copyMipEffectRenderer.saveStates();
|
|
289
|
+
const bindSize = mipTarget.getSize().width;
|
|
290
|
+
// Render to each layer of the voxel grid.
|
|
291
|
+
for (let layer = 0; layer < bindSize; layer++) {
|
|
292
|
+
this._engine.bindFramebuffer(rt, 0, bindSize, bindSize, true, lodLevel, layer);
|
|
293
|
+
this._copyMipEffectRenderer.applyEffectWrapper(this._copyMipEffectWrapper);
|
|
294
|
+
this._copyMipEffectWrapper.effect.setTexture("textureSampler", mipTarget);
|
|
295
|
+
this._copyMipEffectWrapper.effect.setInt("layerNum", layer);
|
|
296
|
+
this._copyMipEffectRenderer.draw();
|
|
297
|
+
this._engine.unBindFramebuffer(rt, true);
|
|
298
|
+
}
|
|
299
|
+
this._copyMipEffectRenderer.restoreStates();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
_computeNumberOfSlabs() {
|
|
303
|
+
return Math.ceil(this._voxelResolution / this._maxDrawBuffers);
|
|
304
|
+
}
|
|
305
|
+
_createTextures() {
|
|
306
|
+
const size = {
|
|
307
|
+
width: this._voxelResolution,
|
|
308
|
+
height: this._voxelResolution,
|
|
309
|
+
layers: this._isVoxelGrid3D ? undefined : this._voxelResolution,
|
|
310
|
+
depth: this._isVoxelGrid3D ? this._voxelResolution : undefined,
|
|
311
|
+
};
|
|
312
|
+
const voxelAxisOptions = {
|
|
313
|
+
generateDepthBuffer: false,
|
|
314
|
+
generateMipMaps: false,
|
|
315
|
+
type: 0,
|
|
316
|
+
format: 6,
|
|
317
|
+
samplingMode: 1,
|
|
318
|
+
};
|
|
319
|
+
// We can render up to maxDrawBuffers voxel slices of the grid per render.
|
|
320
|
+
// We call this a slab.
|
|
321
|
+
const numSlabs = this._computeNumberOfSlabs();
|
|
322
|
+
const voxelCombinedOptions = {
|
|
323
|
+
generateDepthBuffer: false,
|
|
324
|
+
generateMipMaps: true,
|
|
325
|
+
type: 0,
|
|
326
|
+
format: 6,
|
|
327
|
+
samplingMode: 4,
|
|
328
|
+
};
|
|
329
|
+
if (this._triPlanarVoxelization) {
|
|
330
|
+
this._voxelGridXaxis = new RenderTargetTexture("voxelGridXaxis", size, this._scene, voxelAxisOptions);
|
|
331
|
+
this._voxelGridYaxis = new RenderTargetTexture("voxelGridYaxis", size, this._scene, voxelAxisOptions);
|
|
332
|
+
this._voxelGridZaxis = new RenderTargetTexture("voxelGridZaxis", size, this._scene, voxelAxisOptions);
|
|
333
|
+
this._voxelMrtsXaxis = this._createVoxelMRTs("x_axis_", this._voxelGridXaxis, numSlabs);
|
|
334
|
+
this._voxelMrtsYaxis = this._createVoxelMRTs("y_axis_", this._voxelGridYaxis, numSlabs);
|
|
335
|
+
this._voxelMrtsZaxis = this._createVoxelMRTs("z_axis_", this._voxelGridZaxis, numSlabs);
|
|
336
|
+
this._voxelGridRT = new ProceduralTexture("combinedVoxelGrid", size, "combineVoxelGrids", this._scene, voxelCombinedOptions, true);
|
|
337
|
+
this._voxelGridRT.isRenderTarget = true;
|
|
338
|
+
this._voxelGridRT.setFloat("layer", 0.0);
|
|
339
|
+
this._voxelGridRT.setTexture("voxelXaxisSampler", this._voxelGridXaxis);
|
|
340
|
+
this._voxelGridRT.setTexture("voxelYaxisSampler", this._voxelGridYaxis);
|
|
341
|
+
this._voxelGridRT.setTexture("voxelZaxisSampler", this._voxelGridZaxis);
|
|
342
|
+
// We will render this only after voxelization is completed for the 3 axes.
|
|
343
|
+
this._voxelGridRT.autoClear = false;
|
|
344
|
+
this._voxelGridRT.refreshRate = 0;
|
|
345
|
+
this._voxelGridRT.wrapU = Texture.CLAMP_ADDRESSMODE;
|
|
346
|
+
this._voxelGridRT.wrapV = Texture.CLAMP_ADDRESSMODE;
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
this._voxelGridZaxis = new RenderTargetTexture("voxelGridZaxis", size, this._scene, voxelCombinedOptions);
|
|
350
|
+
this._voxelMrtsZaxis = this._createVoxelMRTs("z_axis_", this._voxelGridZaxis, numSlabs);
|
|
351
|
+
}
|
|
352
|
+
this._mipArray = new Array(Math.ceil(Math.log2(this._voxelResolution)));
|
|
353
|
+
for (let mipIdx = 1; mipIdx <= this._mipArray.length; mipIdx++) {
|
|
354
|
+
const mipDim = this._voxelResolution >> mipIdx;
|
|
355
|
+
const mipSize = { width: mipDim, height: mipDim, depth: mipDim };
|
|
356
|
+
this._mipArray[mipIdx - 1] = new ProceduralTexture("voxelMip" + mipIdx, mipSize, "generateVoxelMip", this._scene, voxelAxisOptions);
|
|
357
|
+
const mipTarget = this._mipArray[mipIdx - 1];
|
|
358
|
+
mipTarget._noMipmap = true;
|
|
359
|
+
mipTarget.refreshRate = 0;
|
|
360
|
+
mipTarget.autoClear = false;
|
|
361
|
+
mipTarget.wrapU = Texture.CLAMP_ADDRESSMODE;
|
|
362
|
+
mipTarget.wrapV = Texture.CLAMP_ADDRESSMODE;
|
|
363
|
+
mipTarget.setTexture("srcMip", mipIdx > 1 ? this._mipArray[mipIdx - 2] : this.getVoxelGrid());
|
|
364
|
+
mipTarget.setInt("layerNum", 0);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
_createVoxelMRTs(name, voxelRT, numSlabs) {
|
|
368
|
+
voxelRT.noPrePassRenderer = true;
|
|
369
|
+
const mrtArray = [];
|
|
370
|
+
const targetTypes = new Array(this._maxDrawBuffers).fill(this._isVoxelGrid3D ? 32879 : 35866);
|
|
371
|
+
for (let mrt_index = 0; mrt_index < numSlabs; mrt_index++) {
|
|
372
|
+
let layerIndices = new Array(this._maxDrawBuffers).fill(0);
|
|
373
|
+
layerIndices = layerIndices.map((value, index) => mrt_index * this._maxDrawBuffers + index);
|
|
374
|
+
let textureNames = new Array(this._maxDrawBuffers).fill("");
|
|
375
|
+
textureNames = textureNames.map((value, index) => "voxel_grid_" + name + (mrt_index * this._maxDrawBuffers + index));
|
|
376
|
+
const mrt = new MultiRenderTarget("mrt_" + name + mrt_index, { width: this._voxelResolution, height: this._voxelResolution, depth: this._isVoxelGrid3D ? this._voxelResolution : undefined }, this._maxDrawBuffers, // number of draw buffers
|
|
377
|
+
this._scene, {
|
|
378
|
+
types: new Array(this._maxDrawBuffers).fill(0),
|
|
379
|
+
samplingModes: new Array(this._maxDrawBuffers).fill(3),
|
|
380
|
+
generateMipMaps: false,
|
|
381
|
+
targetTypes,
|
|
382
|
+
formats: new Array(this._maxDrawBuffers).fill(6),
|
|
383
|
+
faceIndex: new Array(this._maxDrawBuffers).fill(0),
|
|
384
|
+
layerIndex: layerIndices,
|
|
385
|
+
layerCounts: new Array(this._maxDrawBuffers).fill(this._voxelResolution),
|
|
386
|
+
generateDepthBuffer: false,
|
|
387
|
+
generateStencilBuffer: false,
|
|
388
|
+
}, textureNames);
|
|
389
|
+
mrt.clearColor = new Color4(0, 0, 0, 1);
|
|
390
|
+
mrt.noPrePassRenderer = true;
|
|
391
|
+
for (let i = 0; i < this._maxDrawBuffers; i++) {
|
|
392
|
+
mrt.setInternalTexture(voxelRT.getInternalTexture(), i);
|
|
393
|
+
}
|
|
394
|
+
mrtArray.push(mrt);
|
|
395
|
+
}
|
|
396
|
+
return mrtArray;
|
|
397
|
+
}
|
|
398
|
+
_disposeVoxelTextures() {
|
|
399
|
+
this._stopVoxelization();
|
|
400
|
+
for (let i = 0; i < this._voxelMrtsZaxis.length; i++) {
|
|
401
|
+
if (this._triPlanarVoxelization) {
|
|
402
|
+
this._voxelMrtsXaxis[i].dispose(true);
|
|
403
|
+
this._voxelMrtsYaxis[i].dispose(true);
|
|
404
|
+
}
|
|
405
|
+
this._voxelMrtsZaxis[i].dispose(true);
|
|
406
|
+
}
|
|
407
|
+
if (this._triPlanarVoxelization) {
|
|
408
|
+
this._voxelGridXaxis?.dispose();
|
|
409
|
+
this._voxelGridYaxis?.dispose();
|
|
410
|
+
this._voxelGridRT?.dispose();
|
|
411
|
+
}
|
|
412
|
+
this._voxelGridZaxis?.dispose();
|
|
413
|
+
this._mipArray.forEach((mip) => {
|
|
414
|
+
mip.dispose();
|
|
415
|
+
});
|
|
416
|
+
this._mipArray = [];
|
|
417
|
+
this._voxelMrtsXaxis = [];
|
|
418
|
+
this._voxelMrtsYaxis = [];
|
|
419
|
+
this._voxelMrtsZaxis = [];
|
|
420
|
+
}
|
|
421
|
+
_createVoxelMaterial() {
|
|
422
|
+
const voxelMaterial = new ShaderMaterial("voxelization", this._scene, "voxelGrid", {
|
|
423
|
+
uniforms: ["world", "viewMatrix", "invWorldScale", "nearPlane", "farPlane", "stepSize"],
|
|
424
|
+
defines: ["MAX_DRAW_BUFFERS " + this._maxDrawBuffers],
|
|
425
|
+
});
|
|
426
|
+
voxelMaterial.cullBackFaces = false;
|
|
427
|
+
voxelMaterial.backFaceCulling = false;
|
|
428
|
+
voxelMaterial.depthFunction = Engine.ALWAYS;
|
|
429
|
+
return voxelMaterial;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Checks if the voxel renderer is ready to voxelize scene
|
|
433
|
+
* @returns true if the voxel renderer is ready to voxelize scene
|
|
434
|
+
*/
|
|
435
|
+
isReady() {
|
|
436
|
+
if (!this.getVoxelGrid().isReady() || this._voxelizationInProgress) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* If the MRT's are already in the list of render targets, this will
|
|
443
|
+
* remove them so that they don't get rendered again.
|
|
444
|
+
*/
|
|
445
|
+
_stopVoxelization() {
|
|
446
|
+
// If the MRT's are already in the list of render targets, remove them.
|
|
447
|
+
this._removeVoxelRTs(this._voxelMrtsXaxis);
|
|
448
|
+
this._removeVoxelRTs(this._voxelMrtsYaxis);
|
|
449
|
+
this._removeVoxelRTs(this._voxelMrtsZaxis);
|
|
450
|
+
}
|
|
451
|
+
_removeVoxelRTs(rts) {
|
|
452
|
+
// const currentRTs = this._scene.customRenderTargets;
|
|
453
|
+
const rtIdx = this._renderTargets.findIndex((rt) => {
|
|
454
|
+
if (rt === rts[0])
|
|
455
|
+
return true;
|
|
456
|
+
return false;
|
|
457
|
+
});
|
|
458
|
+
if (rtIdx >= 0) {
|
|
459
|
+
this._renderTargets.splice(rtIdx, rts.length);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
const rtIdx = this._scene.customRenderTargets.findIndex((rt) => {
|
|
463
|
+
if (rt === rts[0])
|
|
464
|
+
return true;
|
|
465
|
+
return false;
|
|
466
|
+
});
|
|
467
|
+
if (rtIdx >= 0) {
|
|
468
|
+
this._scene.customRenderTargets.splice(rtIdx, rts.length);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Renders voxel grid of scene for IBL shadows
|
|
474
|
+
* @param excludedMeshes
|
|
475
|
+
*/
|
|
476
|
+
updateVoxelGrid(excludedMeshes) {
|
|
477
|
+
this._stopVoxelization();
|
|
478
|
+
this._voxelizationInProgress = true;
|
|
479
|
+
if (this._triPlanarVoxelization) {
|
|
480
|
+
this._addRTsForRender(this._voxelMrtsXaxis, excludedMeshes, 0);
|
|
481
|
+
this._addRTsForRender(this._voxelMrtsYaxis, excludedMeshes, 1);
|
|
482
|
+
this._addRTsForRender(this._voxelMrtsZaxis, excludedMeshes, 2);
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
this._addRTsForRender(this._voxelMrtsZaxis, excludedMeshes, 2);
|
|
486
|
+
}
|
|
487
|
+
// Add the slab debug RT if needed.
|
|
488
|
+
if (this._voxelDebugEnabled) {
|
|
489
|
+
this._removeVoxelRTs([this._voxelSlabDebugRT]);
|
|
490
|
+
this._addRTsForRender([this._voxelSlabDebugRT], [], this._voxelDebugAxis, 1, true);
|
|
491
|
+
}
|
|
492
|
+
this.boundVoxelGridRenderFn = this._renderVoxelGrid.bind(this);
|
|
493
|
+
this._scene.onAfterRenderTargetsRenderObservable.add(this.boundVoxelGridRenderFn);
|
|
494
|
+
}
|
|
495
|
+
_renderVoxelGrid() {
|
|
496
|
+
if (this._voxelizationInProgress) {
|
|
497
|
+
const allRTsReady = this._renderTargets.every((rt) => rt.isReadyForRendering());
|
|
498
|
+
if (allRTsReady) {
|
|
499
|
+
this._scene.prePassRenderer._setEnabled(false);
|
|
500
|
+
this._renderTargets.forEach((rt) => {
|
|
501
|
+
rt.render();
|
|
502
|
+
});
|
|
503
|
+
this._stopVoxelization();
|
|
504
|
+
if (this._triPlanarVoxelization) {
|
|
505
|
+
// This hack is to prevent the procedural texture from auto-generating mips while unbinding the framebuffer.
|
|
506
|
+
this._voxelGridRT._generateMipMaps = false;
|
|
507
|
+
this._voxelGridRT.render();
|
|
508
|
+
}
|
|
509
|
+
this._generateMipMaps();
|
|
510
|
+
this._copyMipMaps();
|
|
511
|
+
this._voxelizationInProgress = false;
|
|
512
|
+
this._scene.onAfterRenderTargetsRenderObservable.removeCallback(this.boundVoxelGridRenderFn);
|
|
513
|
+
this.onReadyObservable.notifyObservers();
|
|
514
|
+
this._scene.prePassRenderer._setEnabled(true);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
_addRTsForRender(mrts, excludedMeshes, axis, shaderType = 0, continuousRender = false) {
|
|
519
|
+
const slabSize = 1.0 / this._computeNumberOfSlabs();
|
|
520
|
+
const meshes = this._scene.meshes;
|
|
521
|
+
// We need to update the world scale uniform for every mesh being rendered to the voxel grid.
|
|
522
|
+
mrts.forEach((mrt, mrtIndex) => {
|
|
523
|
+
mrt.renderList = [];
|
|
524
|
+
const nearPlane = mrtIndex * slabSize;
|
|
525
|
+
const farPlane = (mrtIndex + 1) * slabSize;
|
|
526
|
+
const stepSize = slabSize / this._maxDrawBuffers;
|
|
527
|
+
let voxelMaterial;
|
|
528
|
+
if (shaderType === 0) {
|
|
529
|
+
voxelMaterial = this._createVoxelMaterial();
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
voxelMaterial = new ShaderMaterial("voxelSlabDebug", this._scene, "voxelSlabDebug", {
|
|
533
|
+
uniforms: ["world", "viewMatrix", "cameraViewMatrix", "projection", "invWorldScale", "nearPlane", "farPlane", "stepSize"],
|
|
534
|
+
defines: ["MAX_DRAW_BUFFERS " + this._maxDrawBuffers],
|
|
535
|
+
});
|
|
536
|
+
this._scene.onBeforeRenderObservable.add(() => {
|
|
537
|
+
voxelMaterial.setMatrix("projection", this._scene.activeCamera.getProjectionMatrix());
|
|
538
|
+
voxelMaterial.setMatrix("cameraViewMatrix", this._scene.activeCamera.getViewMatrix());
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
const cameraPosition = new Vector3(0, 0, 0);
|
|
542
|
+
let targetPosition = new Vector3(0, 0, 1);
|
|
543
|
+
if (axis === 0) {
|
|
544
|
+
targetPosition = new Vector3(1, 0, 0);
|
|
545
|
+
}
|
|
546
|
+
else if (axis === 1) {
|
|
547
|
+
targetPosition = new Vector3(0, 1, 0);
|
|
548
|
+
}
|
|
549
|
+
let upDirection = new Vector3(0, 1, 0);
|
|
550
|
+
if (axis === 1) {
|
|
551
|
+
upDirection = new Vector3(1, 0, 0);
|
|
552
|
+
}
|
|
553
|
+
voxelMaterial.setMatrix("viewMatrix", Matrix.LookAtLH(cameraPosition, targetPosition, upDirection));
|
|
554
|
+
voxelMaterial.setMatrix("invWorldScale", this._invWorldScaleMatrix);
|
|
555
|
+
voxelMaterial.setFloat("nearPlane", nearPlane);
|
|
556
|
+
voxelMaterial.setFloat("farPlane", farPlane);
|
|
557
|
+
voxelMaterial.setFloat("stepSize", stepSize);
|
|
558
|
+
// Set this material on every mesh in the scene (for this RT)
|
|
559
|
+
meshes.forEach((mesh) => {
|
|
560
|
+
if (mesh instanceof Mesh && mesh.material && excludedMeshes.indexOf(mesh.uniqueId) === -1) {
|
|
561
|
+
mrt.renderList?.push(mesh);
|
|
562
|
+
// TODO - if the mesh already has a voxel material applied, don't create a new one.
|
|
563
|
+
// mesh.getMaterialForRenderPass(mrt.renderPassIds)
|
|
564
|
+
mrt.setMaterialForRendering(mesh, voxelMaterial);
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
// Add the MRT's to render.
|
|
569
|
+
if (continuousRender) {
|
|
570
|
+
this._scene.customRenderTargets = this._scene.customRenderTargets.concat(mrts);
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
this._renderTargets = this._renderTargets.concat(mrts);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Called by the pipeline to resize resources.
|
|
578
|
+
*/
|
|
579
|
+
resize() {
|
|
580
|
+
this._voxelSlabDebugRT?.resize({ width: this._scene.getEngine().getRenderWidth(), height: this._scene.getEngine().getRenderHeight() });
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Disposes the voxel renderer and associated resources
|
|
584
|
+
*/
|
|
585
|
+
dispose() {
|
|
586
|
+
this._disposeVoxelTextures();
|
|
587
|
+
if (this._voxelSlabDebugRT) {
|
|
588
|
+
this._removeVoxelRTs([this._voxelSlabDebugRT]);
|
|
589
|
+
this._voxelSlabDebugRT.dispose();
|
|
590
|
+
}
|
|
591
|
+
if (this._voxelDebugPass) {
|
|
592
|
+
this._voxelDebugPass.dispose();
|
|
593
|
+
}
|
|
594
|
+
// TODO - dispose all created voxel materials.
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
//# sourceMappingURL=iblShadowsVoxelRenderer.js.map
|