@onerjs/core 8.48.4 → 8.48.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/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/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/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/Misc/textureTools.d.ts +3 -1
- package/Misc/textureTools.js +74 -13
- package/Misc/textureTools.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 -7
- package/Particles/particleSystem.js +3 -15
- 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/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/lod3D.fragment.d.ts +5 -0
- 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/ShadersWGSL/lod3D.fragment.d.ts +5 -0
- 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
|
@@ -3,13 +3,13 @@ import { ShaderMaterial } from "../../Materials/shaderMaterial.js";
|
|
|
3
3
|
import { MultiRenderTarget } from "../../Materials/Textures/multiRenderTarget.js";
|
|
4
4
|
import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.js";
|
|
5
5
|
import { Color4 } from "../../Maths/math.color.js";
|
|
6
|
-
import { Matrix, Vector3
|
|
6
|
+
import { Matrix, Vector3 } from "../../Maths/math.vector.js";
|
|
7
7
|
import { Texture } from "../../Materials/Textures/texture.js";
|
|
8
8
|
import { Logger } from "../../Misc/logger.js";
|
|
9
9
|
import { Observable } from "../../Misc/observable.js";
|
|
10
|
-
import { PostProcess } from "../../PostProcesses/postProcess.js";
|
|
11
10
|
import { ProceduralTexture } from "../../Materials/Textures/Procedurals/proceduralTexture.js";
|
|
12
11
|
import { EffectRenderer, EffectWrapper } from "../../Materials/effectRenderer.js";
|
|
12
|
+
import "../../Engines/Extensions/engine.multiRender.js";
|
|
13
13
|
/**
|
|
14
14
|
* Voxel-based shadow rendering for IBL's.
|
|
15
15
|
* This should not be instanciated directly, as it is part of a scene component
|
|
@@ -33,14 +33,19 @@ export class _IblShadowsVoxelRenderer {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @returns The
|
|
36
|
+
* Return the voxel render target used during voxelization.
|
|
37
|
+
* @returns The voxel render target.
|
|
38
38
|
*/
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
this.
|
|
39
|
+
getRT() {
|
|
40
|
+
if (this._engine.isWebGPU) {
|
|
41
|
+
return this._voxelGridRT;
|
|
42
|
+
}
|
|
43
|
+
else if (this._triPlanarVoxelization) {
|
|
44
|
+
return this._combinedVoxelGridPT;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return this._voxelGridZaxis;
|
|
42
48
|
}
|
|
43
|
-
return this._voxelDebugPass;
|
|
44
49
|
}
|
|
45
50
|
/**
|
|
46
51
|
* Whether to use tri-planar voxelization. More expensive, but can help with artifacts.
|
|
@@ -95,121 +100,6 @@ export class _IblShadowsVoxelRenderer {
|
|
|
95
100
|
this._disposeVoxelTextures();
|
|
96
101
|
this._createTextures();
|
|
97
102
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Shows only the voxels that were rendered along a particular axis (while using triPlanarVoxelization).
|
|
100
|
-
* If not set, the combined voxel grid will be shown.
|
|
101
|
-
* Note: This only works when the debugMipNumber is set to 0 because we don't generate mips for each axis.
|
|
102
|
-
* @param axis The axis to show (0 = x, 1 = y, 2 = z)
|
|
103
|
-
*/
|
|
104
|
-
set voxelDebugAxis(axis) {
|
|
105
|
-
this._voxelDebugAxis = axis;
|
|
106
|
-
}
|
|
107
|
-
get voxelDebugAxis() {
|
|
108
|
-
return this._voxelDebugAxis;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Sets params that control the position and scaling of the debug display on the screen.
|
|
112
|
-
* @param x Screen X offset of the debug display (0-1)
|
|
113
|
-
* @param y Screen Y offset of the debug display (0-1)
|
|
114
|
-
* @param widthScale X scale of the debug display (0-1)
|
|
115
|
-
* @param heightScale Y scale of the debug display (0-1)
|
|
116
|
-
*/
|
|
117
|
-
setDebugDisplayParams(x, y, widthScale, heightScale) {
|
|
118
|
-
this._debugSizeParams.set(x, y, widthScale, heightScale);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* The mip level to show in the debug display
|
|
122
|
-
* @param mipNum The mip level to show in the debug display
|
|
123
|
-
*/
|
|
124
|
-
setDebugMipNumber(mipNum) {
|
|
125
|
-
this._debugMipNumber = mipNum;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Sets the name of the debug pass
|
|
129
|
-
*/
|
|
130
|
-
get debugPassName() {
|
|
131
|
-
return this._debugPassName;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Enable or disable the debug view for this pass
|
|
135
|
-
*/
|
|
136
|
-
get voxelDebugEnabled() {
|
|
137
|
-
return this._voxelDebugEnabled;
|
|
138
|
-
}
|
|
139
|
-
set voxelDebugEnabled(enabled) {
|
|
140
|
-
if (this._voxelDebugEnabled === enabled) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
this._voxelDebugEnabled = enabled;
|
|
144
|
-
if (enabled) {
|
|
145
|
-
this._voxelSlabDebugRT = new RenderTargetTexture("voxelSlabDebug", { width: this._engine.getRenderWidth(), height: this._engine.getRenderHeight() }, this._scene, {
|
|
146
|
-
generateDepthBuffer: true,
|
|
147
|
-
generateMipMaps: false,
|
|
148
|
-
type: 0,
|
|
149
|
-
format: 5,
|
|
150
|
-
samplingMode: 1,
|
|
151
|
-
});
|
|
152
|
-
this._voxelSlabDebugRT.noPrePassRenderer = true;
|
|
153
|
-
}
|
|
154
|
-
if (this._voxelSlabDebugRT) {
|
|
155
|
-
this._removeVoxelRTs([this._voxelSlabDebugRT]);
|
|
156
|
-
}
|
|
157
|
-
// Add the slab debug RT if needed.
|
|
158
|
-
if (this._voxelDebugEnabled) {
|
|
159
|
-
this._addRTsForRender([this._voxelSlabDebugRT], this._includedMeshes, this._voxelDebugAxis, 1, true);
|
|
160
|
-
this._setDebugBindingsBound = this._setDebugBindings.bind(this);
|
|
161
|
-
this._scene.onBeforeRenderObservable.add(this._setDebugBindingsBound);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
this._scene.onBeforeRenderObservable.removeCallback(this._setDebugBindingsBound);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Creates the debug post process effect for this pass
|
|
169
|
-
*/
|
|
170
|
-
_createDebugPass() {
|
|
171
|
-
const isWebGPU = this._engine.isWebGPU;
|
|
172
|
-
if (!this._voxelDebugPass) {
|
|
173
|
-
const debugOptions = {
|
|
174
|
-
width: this._engine.getRenderWidth(),
|
|
175
|
-
height: this._engine.getRenderHeight(),
|
|
176
|
-
textureFormat: 5,
|
|
177
|
-
textureType: 0,
|
|
178
|
-
samplingMode: 1,
|
|
179
|
-
uniforms: ["sizeParams", "mipNumber"],
|
|
180
|
-
samplers: ["voxelTexture", "voxelSlabTexture"],
|
|
181
|
-
engine: this._engine,
|
|
182
|
-
reusable: false,
|
|
183
|
-
shaderLanguage: isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
|
|
184
|
-
extraInitializations: (useWebGPU, list) => {
|
|
185
|
-
if (useWebGPU) {
|
|
186
|
-
list.push(import("../../ShadersWGSL/iblVoxelGrid3dDebug.fragment.js"));
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
list.push(import("../../Shaders/iblVoxelGrid3dDebug.fragment.js"));
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
this._voxelDebugPass = new PostProcess(this.debugPassName, "iblVoxelGrid3dDebug", debugOptions);
|
|
194
|
-
this._voxelDebugPass.onApplyObservable.add((effect) => {
|
|
195
|
-
if (this._voxelDebugAxis === 0) {
|
|
196
|
-
effect.setTexture("voxelTexture", this._voxelGridXaxis);
|
|
197
|
-
}
|
|
198
|
-
else if (this._voxelDebugAxis === 1) {
|
|
199
|
-
effect.setTexture("voxelTexture", this._voxelGridYaxis);
|
|
200
|
-
}
|
|
201
|
-
else if (this._voxelDebugAxis === 2) {
|
|
202
|
-
effect.setTexture("voxelTexture", this._voxelGridZaxis);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
effect.setTexture("voxelTexture", this.getVoxelGrid());
|
|
206
|
-
}
|
|
207
|
-
effect.setTexture("voxelSlabTexture", this._voxelSlabDebugRT);
|
|
208
|
-
effect.setVector4("sizeParams", this._debugSizeParams);
|
|
209
|
-
effect.setFloat("mipNumber", this._debugMipNumber);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
103
|
/**
|
|
214
104
|
* Instanciates the voxel renderer
|
|
215
105
|
* @param scene Scene to attach to
|
|
@@ -233,13 +123,8 @@ export class _IblShadowsVoxelRenderer {
|
|
|
233
123
|
this._invWorldScaleMatrix = Matrix.Identity();
|
|
234
124
|
this._voxelResolution = 64;
|
|
235
125
|
this._voxelResolutionExp = 6;
|
|
126
|
+
this._copyMipLayer = 0;
|
|
236
127
|
this._mipArray = [];
|
|
237
|
-
this._voxelDebugEnabled = false;
|
|
238
|
-
this._voxelDebugAxis = -1;
|
|
239
|
-
this._debugSizeParams = new Vector4(0.0, 0.0, 0.0, 0.0);
|
|
240
|
-
this._includedMeshes = [];
|
|
241
|
-
this._debugMipNumber = 0;
|
|
242
|
-
this._debugPassName = "Voxelization Debug Pass";
|
|
243
128
|
this._scene = scene;
|
|
244
129
|
this._engine = scene.getEngine();
|
|
245
130
|
this._triPlanarVoxelization = this._engine.isWebGPU || triPlanarVoxelization;
|
|
@@ -249,8 +134,11 @@ export class _IblShadowsVoxelRenderer {
|
|
|
249
134
|
const isWebGPU = this._engine.isWebGPU;
|
|
250
135
|
// Round down to a power of 2 so it evenly divides the power-of-2 voxel resolution,
|
|
251
136
|
// preventing out-of-bounds layer indices in the last MRT slab.
|
|
137
|
+
// This shader implementation writes up to 16 MRT outputs, so clamp to 16 to keep
|
|
138
|
+
// active draw buffers aligned with declared/written fragment outputs.
|
|
252
139
|
const rawMaxDrawBuffers = this._engine.getCaps().maxDrawBuffers || 0;
|
|
253
|
-
|
|
140
|
+
const cappedMaxDrawBuffers = Math.min(rawMaxDrawBuffers, 16);
|
|
141
|
+
this._maxDrawBuffers = cappedMaxDrawBuffers >= 1 ? 1 << Math.floor(Math.log2(cappedMaxDrawBuffers)) : 0;
|
|
254
142
|
this._copyMipEffectRenderer = new EffectRenderer(this._engine);
|
|
255
143
|
this._copyMipEffectWrapper = new EffectWrapper({
|
|
256
144
|
engine: this._engine,
|
|
@@ -268,6 +156,14 @@ export class _IblShadowsVoxelRenderer {
|
|
|
268
156
|
}
|
|
269
157
|
},
|
|
270
158
|
});
|
|
159
|
+
this._copyMipEffectWrapper.onApplyObservable.add(() => {
|
|
160
|
+
const effect = this._copyMipEffectWrapper.effect;
|
|
161
|
+
if (!effect || !this._copyMipSourceTexture) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
effect.setTexture("textureSampler", this._copyMipSourceTexture);
|
|
165
|
+
effect.setInt("layerNum", this._copyMipLayer);
|
|
166
|
+
});
|
|
271
167
|
this.voxelResolutionExp = resolutionExp;
|
|
272
168
|
}
|
|
273
169
|
_generateMipMaps() {
|
|
@@ -293,7 +189,6 @@ export class _IblShadowsVoxelRenderer {
|
|
|
293
189
|
}
|
|
294
190
|
_copyMipMap(lodLevel) {
|
|
295
191
|
// Now, copy this mip into the mip chain of the voxel grid.
|
|
296
|
-
// TODO - this currently isn't working. "textureSampler" isn't being properly set to mipTarget.
|
|
297
192
|
const mipTarget = this._mipArray[lodLevel - 1];
|
|
298
193
|
if (!mipTarget) {
|
|
299
194
|
return;
|
|
@@ -308,16 +203,48 @@ export class _IblShadowsVoxelRenderer {
|
|
|
308
203
|
}
|
|
309
204
|
if (rt) {
|
|
310
205
|
this._copyMipEffectRenderer.saveStates();
|
|
206
|
+
const previousColorWrite = this._engine.getColorWrite();
|
|
207
|
+
const previousDepthBuffer = this._engine.getDepthBuffer();
|
|
208
|
+
const previousDepthWrite = this._engine.getDepthWrite();
|
|
209
|
+
const previousAlphaMode = this._engine.getAlphaMode();
|
|
210
|
+
this._engine.setColorWrite(true);
|
|
211
|
+
this._engine.setDepthBuffer(false);
|
|
212
|
+
this._engine.setDepthWrite(false);
|
|
213
|
+
this._engine.setAlphaMode(0);
|
|
311
214
|
const bindSize = mipTarget.getSize().width;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
215
|
+
let sourceDepth = mipTarget.getInternalTexture()?.depth;
|
|
216
|
+
sourceDepth = Math.max(1, sourceDepth || bindSize);
|
|
217
|
+
const destinationMipDepth = Math.max(1, this._voxelResolution >> lodLevel);
|
|
218
|
+
const layersToCopy = Math.min(sourceDepth, destinationMipDepth);
|
|
219
|
+
const destinationTexture = rt.texture;
|
|
220
|
+
const previousGenerateMipMaps = destinationTexture?.generateMipMaps;
|
|
221
|
+
if (destinationTexture) {
|
|
222
|
+
destinationTexture.generateMipMaps = false;
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
// Render to each layer of the voxel grid.
|
|
226
|
+
for (let layer = 0; layer < layersToCopy; layer++) {
|
|
227
|
+
this._engine.bindFramebuffer(rt, 0, bindSize, bindSize, true, lodLevel, layer);
|
|
228
|
+
this._copyMipSourceTexture = mipTarget;
|
|
229
|
+
this._copyMipLayer = layer;
|
|
230
|
+
this._copyMipEffectRenderer.applyEffectWrapper(this._copyMipEffectWrapper);
|
|
231
|
+
this._copyMipEffectRenderer.draw();
|
|
232
|
+
this._engine.unBindFramebuffer(rt, true);
|
|
233
|
+
}
|
|
234
|
+
if (!this._engine.isWebGPU) {
|
|
235
|
+
this._engine.unbindAllTextures();
|
|
236
|
+
}
|
|
320
237
|
}
|
|
238
|
+
finally {
|
|
239
|
+
if (destinationTexture && previousGenerateMipMaps !== undefined) {
|
|
240
|
+
destinationTexture.generateMipMaps = previousGenerateMipMaps;
|
|
241
|
+
}
|
|
242
|
+
this._engine.setAlphaMode(previousAlphaMode);
|
|
243
|
+
this._engine.setDepthWrite(previousDepthWrite);
|
|
244
|
+
this._engine.setDepthBuffer(previousDepthBuffer);
|
|
245
|
+
this._engine.setColorWrite(previousColorWrite);
|
|
246
|
+
}
|
|
247
|
+
this._copyMipSourceTexture = undefined;
|
|
321
248
|
this._copyMipEffectRenderer.restoreStates();
|
|
322
249
|
}
|
|
323
250
|
}
|
|
@@ -335,7 +262,7 @@ export class _IblShadowsVoxelRenderer {
|
|
|
335
262
|
generateDepthBuffer: false,
|
|
336
263
|
generateMipMaps: false,
|
|
337
264
|
type: 0,
|
|
338
|
-
format:
|
|
265
|
+
format: 6,
|
|
339
266
|
samplingMode: 1,
|
|
340
267
|
};
|
|
341
268
|
// We can render up to maxDrawBuffers voxel slices of the grid per render.
|
|
@@ -360,7 +287,7 @@ export class _IblShadowsVoxelRenderer {
|
|
|
360
287
|
if (this._engine.isWebGPU) {
|
|
361
288
|
this._voxelGrid = new RenderTargetTexture("voxelGrid", size, this._scene, {
|
|
362
289
|
...voxelCombinedOptions,
|
|
363
|
-
format:
|
|
290
|
+
format: 6,
|
|
364
291
|
creationFlags: 1,
|
|
365
292
|
});
|
|
366
293
|
this._voxelGridRT = new RenderTargetTexture("voxelGridRT", { width: Math.min(size.width * 2.0, 2048), height: Math.min(size.height * 2.0, 2048) }, this._scene, voxelAxisOptions);
|
|
@@ -470,7 +397,6 @@ export class _IblShadowsVoxelRenderer {
|
|
|
470
397
|
mip.dispose();
|
|
471
398
|
}
|
|
472
399
|
this._voxelMaterial?.dispose();
|
|
473
|
-
this._voxelSlabDebugMaterial?.dispose();
|
|
474
400
|
this._mipArray = [];
|
|
475
401
|
this._voxelMrtsXaxis = [];
|
|
476
402
|
this._voxelMrtsYaxis = [];
|
|
@@ -494,23 +420,6 @@ export class _IblShadowsVoxelRenderer {
|
|
|
494
420
|
this._voxelMaterial.cullBackFaces = false;
|
|
495
421
|
this._voxelMaterial.backFaceCulling = false;
|
|
496
422
|
this._voxelMaterial.depthFunction = 519;
|
|
497
|
-
this._voxelSlabDebugMaterial = new ShaderMaterial("voxelSlabDebug", this._scene, "iblVoxelSlabDebug", {
|
|
498
|
-
uniforms: ["world", "viewMatrix", "cameraViewMatrix", "projection", "invWorldScale", "nearPlane", "farPlane", "stepSize"],
|
|
499
|
-
defines: ["MAX_DRAW_BUFFERS " + this._maxDrawBuffers],
|
|
500
|
-
shaderLanguage: isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
|
|
501
|
-
extraInitializationsAsync: async () => {
|
|
502
|
-
if (isWebGPU) {
|
|
503
|
-
await Promise.all([import("../../ShadersWGSL/iblVoxelSlabDebug.fragment.js"), import("../../ShadersWGSL/iblVoxelSlabDebug.vertex.js")]);
|
|
504
|
-
}
|
|
505
|
-
else {
|
|
506
|
-
await Promise.all([import("../../Shaders/iblVoxelSlabDebug.fragment.js"), import("../../Shaders/iblVoxelSlabDebug.vertex.js")]);
|
|
507
|
-
}
|
|
508
|
-
},
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
_setDebugBindings() {
|
|
512
|
-
this._voxelSlabDebugMaterial.setMatrix("projection", this._scene.activeCamera.getProjectionMatrix());
|
|
513
|
-
this._voxelSlabDebugMaterial.setMatrix("cameraViewMatrix", this._scene.activeCamera.getViewMatrix());
|
|
514
423
|
}
|
|
515
424
|
/**
|
|
516
425
|
* Checks if the voxel renderer is ready to voxelize scene
|
|
@@ -564,13 +473,13 @@ export class _IblShadowsVoxelRenderer {
|
|
|
564
473
|
/**
|
|
565
474
|
* Renders voxel grid of scene for IBL shadows
|
|
566
475
|
* @param includedMeshes
|
|
476
|
+
* @param registerAfterRenderObservable Whether to register scene onAfterRender callback (legacy path).
|
|
567
477
|
*/
|
|
568
|
-
updateVoxelGrid(includedMeshes) {
|
|
478
|
+
updateVoxelGrid(includedMeshes, registerAfterRenderObservable = true) {
|
|
569
479
|
if (this._voxelizationInProgress) {
|
|
570
480
|
return;
|
|
571
481
|
}
|
|
572
482
|
this._stopVoxelization();
|
|
573
|
-
this._includedMeshes = includedMeshes;
|
|
574
483
|
this._voxelizationInProgress = true;
|
|
575
484
|
if (this._engine.isWebGPU) {
|
|
576
485
|
this._voxelGridRT.renderList = includedMeshes;
|
|
@@ -584,11 +493,17 @@ export class _IblShadowsVoxelRenderer {
|
|
|
584
493
|
else {
|
|
585
494
|
this._addRTsForRender(this._voxelMrtsZaxis, includedMeshes, 2);
|
|
586
495
|
}
|
|
587
|
-
if (
|
|
588
|
-
this.
|
|
496
|
+
if (registerAfterRenderObservable) {
|
|
497
|
+
this._renderVoxelGridBound = this._renderVoxelGrid.bind(this);
|
|
498
|
+
this._scene.onAfterRenderObservable.add(this._renderVoxelGridBound);
|
|
589
499
|
}
|
|
590
|
-
|
|
591
|
-
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Advances voxelization work when running in custom render loops (for example FrameGraph tasks)
|
|
503
|
+
* where scene onAfterRender timing may differ from classic pipeline flow.
|
|
504
|
+
*/
|
|
505
|
+
processVoxelization() {
|
|
506
|
+
this._renderVoxelGrid();
|
|
592
507
|
}
|
|
593
508
|
_renderVoxelGrid() {
|
|
594
509
|
if (this._voxelizationInProgress) {
|
|
@@ -601,49 +516,62 @@ export class _IblShadowsVoxelRenderer {
|
|
|
601
516
|
const rttReady = this._renderTargets[i].isReadyForRendering();
|
|
602
517
|
allReady && (allReady = rttReady);
|
|
603
518
|
}
|
|
604
|
-
if (allReady) {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
519
|
+
if (!allReady) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
const copyMipEffect = this._copyMipEffectWrapper.effect;
|
|
523
|
+
if (!copyMipEffect.isReady()) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
if (this._engine.isWebGPU) {
|
|
527
|
+
// Clear the voxel grid storage texture.
|
|
528
|
+
// Need to clear each layer individually.
|
|
529
|
+
// Would a compute shader be faster here to clear all layers in one go?
|
|
530
|
+
if (this._voxelGrid && this._voxelGrid.renderTarget) {
|
|
531
|
+
for (let layer = 0; layer < this._voxelResolution; layer++) {
|
|
532
|
+
this._engine.bindFramebuffer(this._voxelGrid.renderTarget, 0, undefined, undefined, true, 0, layer);
|
|
533
|
+
this._engine.clear(this._voxelClearColor, true, false, false);
|
|
534
|
+
this._engine.unBindFramebuffer(this._voxelGrid.renderTarget, true);
|
|
615
535
|
}
|
|
616
536
|
}
|
|
617
|
-
for (const rt of this._renderTargets) {
|
|
618
|
-
rt.render();
|
|
619
|
-
}
|
|
620
|
-
this._stopVoxelization();
|
|
621
|
-
if (this._triPlanarVoxelization && !this._engine.isWebGPU) {
|
|
622
|
-
this._combinedVoxelGridPT.render();
|
|
623
|
-
}
|
|
624
|
-
this._generateMipMaps();
|
|
625
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises, github/no-then
|
|
626
|
-
this._copyMipEffectWrapper.effect.whenCompiledAsync().then(() => {
|
|
627
|
-
this._copyMipMaps();
|
|
628
|
-
this._scene.onAfterRenderObservable.removeCallback(this._renderVoxelGridBound);
|
|
629
|
-
this._voxelizationInProgress = false;
|
|
630
|
-
this.onVoxelizationCompleteObservable.notifyObservers();
|
|
631
|
-
});
|
|
632
537
|
}
|
|
538
|
+
for (const rt of this._renderTargets) {
|
|
539
|
+
rt.render();
|
|
540
|
+
}
|
|
541
|
+
this._stopVoxelization();
|
|
542
|
+
if (this._triPlanarVoxelization && !this._engine.isWebGPU) {
|
|
543
|
+
this._combinedVoxelGridPT.render();
|
|
544
|
+
}
|
|
545
|
+
this._generateMipMaps();
|
|
546
|
+
this._copyMipMaps();
|
|
547
|
+
this._scene.onAfterRenderObservable.removeCallback(this._renderVoxelGridBound);
|
|
548
|
+
this._voxelizationInProgress = false;
|
|
549
|
+
this.onVoxelizationCompleteObservable.notifyObservers();
|
|
633
550
|
}
|
|
634
551
|
}
|
|
635
|
-
_addRTsForRender(mrts, includedMeshes, axis
|
|
552
|
+
_addRTsForRender(mrts, includedMeshes, axis) {
|
|
636
553
|
const slabSize = 1.0 / this._computeNumberOfSlabs();
|
|
637
|
-
|
|
638
|
-
if (shaderType === 0) {
|
|
639
|
-
voxelMaterial = this._voxelMaterial;
|
|
640
|
-
}
|
|
641
|
-
else {
|
|
642
|
-
voxelMaterial = this._voxelSlabDebugMaterial;
|
|
643
|
-
}
|
|
554
|
+
const voxelMaterial = this._voxelMaterial;
|
|
644
555
|
// We need to update the world scale uniform for every mesh being rendered to the voxel grid.
|
|
645
556
|
for (let mrtIndex = 0; mrtIndex < mrts.length; mrtIndex++) {
|
|
646
557
|
const mrt = mrts[mrtIndex];
|
|
558
|
+
mrt._disableEngineStages = true;
|
|
559
|
+
mrt.useCameraPostProcesses = false;
|
|
560
|
+
mrt.renderParticles = false;
|
|
561
|
+
mrt.renderSprites = false;
|
|
562
|
+
mrt.enableOutlineRendering = false;
|
|
563
|
+
mrt.customRenderFunction = (opaqueSubMeshes, alphaTestSubMeshes, transparentSubMeshes, depthOnlySubMeshes) => {
|
|
564
|
+
const buckets = [depthOnlySubMeshes, opaqueSubMeshes, alphaTestSubMeshes, transparentSubMeshes];
|
|
565
|
+
for (const bucket of buckets) {
|
|
566
|
+
for (let index = 0; index < bucket.length; index++) {
|
|
567
|
+
const subMesh = bucket.data[index];
|
|
568
|
+
if (subMesh.getMaterial() !== voxelMaterial) {
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
subMesh.render(false);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
};
|
|
647
575
|
mrt.renderList = [];
|
|
648
576
|
const nearPlane = mrtIndex * slabSize;
|
|
649
577
|
const farPlane = (mrtIndex + 1) * slabSize;
|
|
@@ -692,36 +620,17 @@ export class _IblShadowsVoxelRenderer {
|
|
|
692
620
|
}
|
|
693
621
|
}
|
|
694
622
|
}
|
|
695
|
-
|
|
696
|
-
if (continuousRender) {
|
|
697
|
-
for (const mrt of mrts) {
|
|
698
|
-
if (this._scene.customRenderTargets.indexOf(mrt) === -1) {
|
|
699
|
-
this._scene.customRenderTargets.push(mrt);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
else {
|
|
704
|
-
this._renderTargets = this._renderTargets.concat(mrts);
|
|
705
|
-
}
|
|
623
|
+
this._renderTargets = this._renderTargets.concat(mrts);
|
|
706
624
|
}
|
|
707
625
|
/**
|
|
708
626
|
* Called by the pipeline to resize resources.
|
|
709
627
|
*/
|
|
710
|
-
resize() {
|
|
711
|
-
this._voxelSlabDebugRT?.resize({ width: this._scene.getEngine().getRenderWidth(), height: this._scene.getEngine().getRenderHeight() });
|
|
712
|
-
}
|
|
628
|
+
resize() { }
|
|
713
629
|
/**
|
|
714
630
|
* Disposes the voxel renderer and associated resources
|
|
715
631
|
*/
|
|
716
632
|
dispose() {
|
|
717
633
|
this._disposeVoxelTextures();
|
|
718
|
-
if (this._voxelSlabDebugRT) {
|
|
719
|
-
this._removeVoxelRTs([this._voxelSlabDebugRT]);
|
|
720
|
-
this._voxelSlabDebugRT.dispose();
|
|
721
|
-
}
|
|
722
|
-
if (this._voxelDebugPass) {
|
|
723
|
-
this._voxelDebugPass.dispose();
|
|
724
|
-
}
|
|
725
634
|
// TODO - dispose all created voxel materials.
|
|
726
635
|
}
|
|
727
636
|
}
|