@onerjs/core 8.32.7 → 8.32.8
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/AudioV2/abstractAudio/abstractSoundSource.js +12 -4
- package/AudioV2/abstractAudio/abstractSoundSource.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/baseWithPropertiesPostProcessBlock.js +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/baseWithPropertiesPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.d.ts +18 -0
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js +105 -15
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js +7 -7
- package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.js +1 -1
- package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.js.map +1 -1
- package/FrameGraph/Passes/pass.d.ts +11 -2
- package/FrameGraph/Passes/pass.js +14 -2
- package/FrameGraph/Passes/pass.js.map +1 -1
- package/FrameGraph/Passes/renderPass.d.ts +4 -2
- package/FrameGraph/Passes/renderPass.js +5 -2
- package/FrameGraph/Passes/renderPass.js.map +1 -1
- package/FrameGraph/Tasks/Layers/baseLayerTask.js +27 -31
- package/FrameGraph/Tasks/Layers/baseLayerTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/objectRendererTask.d.ts +41 -1
- package/FrameGraph/Tasks/Rendering/objectRendererTask.js +122 -0
- package/FrameGraph/Tasks/Rendering/objectRendererTask.js.map +1 -1
- package/FrameGraph/Tasks/Texture/clearTextureTask.js +6 -4
- package/FrameGraph/Tasks/Texture/clearTextureTask.js.map +1 -1
- package/FrameGraph/frameGraph.js +3 -0
- package/FrameGraph/frameGraph.js.map +1 -1
- package/FrameGraph/frameGraphRenderTarget.js +1 -0
- package/FrameGraph/frameGraphRenderTarget.js.map +1 -1
- package/FrameGraph/frameGraphTask.d.ts +2 -0
- package/FrameGraph/frameGraphTask.js +11 -0
- package/FrameGraph/frameGraphTask.js.map +1 -1
- package/FrameGraph/frameGraphTypes.d.ts +8 -0
- package/FrameGraph/frameGraphTypes.js.map +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.d.ts +9 -0
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js +66 -22
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js.map +1 -1
- package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js +3 -6
- package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +10 -5
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +17 -16
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Rendering/depthPeelingRenderer.d.ts +7 -78
- package/Rendering/depthPeelingRenderer.js +12 -398
- package/Rendering/depthPeelingRenderer.js.map +1 -1
- package/Rendering/depthPeelingSceneComponent.d.ts +3 -3
- package/Rendering/depthPeelingSceneComponent.js.map +1 -1
- package/Rendering/depthRenderer.js +9 -1
- 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/objectRenderer.d.ts +20 -0
- package/Rendering/objectRenderer.js +17 -1
- package/Rendering/objectRenderer.js.map +1 -1
- package/Rendering/renderingGroup.d.ts +10 -3
- package/Rendering/renderingGroup.js +24 -13
- package/Rendering/renderingGroup.js.map +1 -1
- package/Rendering/renderingManager.d.ts +6 -2
- package/Rendering/renderingManager.js +8 -2
- package/Rendering/renderingManager.js.map +1 -1
- package/Rendering/thinDepthPeelingRenderer.d.ts +120 -0
- package/Rendering/thinDepthPeelingRenderer.js +469 -0
- package/Rendering/thinDepthPeelingRenderer.js.map +1 -0
- package/Shaders/ShadersInclude/gaussianSplatting.js +1 -1
- package/Shaders/ShadersInclude/gaussianSplatting.js.map +1 -1
- package/Shaders/gaussianSplatting.vertex.js +2 -2
- package/Shaders/gaussianSplatting.vertex.js.map +1 -1
- package/Shaders/gaussianSplattingDepth.fragment.js +9 -2
- package/Shaders/gaussianSplattingDepth.fragment.js.map +1 -1
- package/Shaders/gaussianSplattingDepth.vertex.js +13 -2
- package/Shaders/gaussianSplattingDepth.vertex.js.map +1 -1
- package/Shaders/oitFinalSimpleBlend.fragment.d.ts +5 -0
- package/Shaders/oitFinalSimpleBlend.fragment.js +12 -0
- package/Shaders/oitFinalSimpleBlend.fragment.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/gaussianSplatting.js +1 -5
- package/ShadersWGSL/ShadersInclude/gaussianSplatting.js.map +1 -1
- package/ShadersWGSL/gaussianSplatting.vertex.js +2 -2
- package/ShadersWGSL/gaussianSplatting.vertex.js.map +1 -1
- package/ShadersWGSL/gaussianSplattingDepth.fragment.js +12 -3
- package/ShadersWGSL/gaussianSplattingDepth.fragment.js.map +1 -1
- package/ShadersWGSL/gaussianSplattingDepth.vertex.js +13 -2
- package/ShadersWGSL/gaussianSplattingDepth.vertex.js.map +1 -1
- package/ShadersWGSL/oitFinalSimpleBlend.fragment.d.ts +5 -0
- package/ShadersWGSL/oitFinalSimpleBlend.fragment.js +13 -0
- package/ShadersWGSL/oitFinalSimpleBlend.fragment.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,69 +1,15 @@
|
|
|
1
|
-
import type { Effect } from "../Materials/effect.js";
|
|
2
|
-
import type { SubMesh } from "../Meshes/subMesh.js";
|
|
3
|
-
import type { AbstractMesh } from "../Meshes/abstractMesh.js";
|
|
4
|
-
import { SmartArray } from "../Misc/smartArray.js";
|
|
5
1
|
import type { Scene } from "../scene.js";
|
|
6
2
|
import type { PrePassRenderer } from "./prePassRenderer.js";
|
|
7
|
-
import "
|
|
8
|
-
import { ShaderLanguage } from "../Materials/shaderLanguage.js";
|
|
3
|
+
import { ThinDepthPeelingRenderer } from "./thinDepthPeelingRenderer.js";
|
|
9
4
|
/**
|
|
10
5
|
* The depth peeling renderer that performs
|
|
11
6
|
* Order independant transparency (OIT).
|
|
12
7
|
* This should not be instanciated directly, as it is part of a scene component
|
|
13
8
|
*/
|
|
14
|
-
export declare class DepthPeelingRenderer {
|
|
15
|
-
private _scene;
|
|
16
|
-
private _engine;
|
|
17
|
-
private _depthMrts;
|
|
18
|
-
private _thinTextures;
|
|
19
|
-
private _colorMrts;
|
|
20
|
-
private _blendBackMrt;
|
|
9
|
+
export declare class DepthPeelingRenderer extends ThinDepthPeelingRenderer {
|
|
21
10
|
private _outputRT;
|
|
22
|
-
private _blendBackEffectWrapper;
|
|
23
|
-
private _blendBackEffectWrapperPingPong;
|
|
24
|
-
private _finalEffectWrapper;
|
|
25
|
-
private _effectRenderer;
|
|
26
|
-
private _currentPingPongState;
|
|
27
11
|
private _prePassEffectConfiguration;
|
|
28
12
|
private _blendBackTexture;
|
|
29
|
-
private _layoutCacheFormat;
|
|
30
|
-
private _layoutCache;
|
|
31
|
-
private _renderPassIds;
|
|
32
|
-
private _candidateSubMeshes;
|
|
33
|
-
private _excludedSubMeshes;
|
|
34
|
-
private _excludedMeshes;
|
|
35
|
-
private static _DEPTH_CLEAR_VALUE;
|
|
36
|
-
private static _MIN_DEPTH;
|
|
37
|
-
private static _MAX_DEPTH;
|
|
38
|
-
private _colorCache;
|
|
39
|
-
private _passCount;
|
|
40
|
-
/**
|
|
41
|
-
* Number of depth peeling passes. As we are using dual depth peeling, each pass two levels of transparency are processed.
|
|
42
|
-
*/
|
|
43
|
-
get passCount(): number;
|
|
44
|
-
set passCount(count: number);
|
|
45
|
-
private _useRenderPasses;
|
|
46
|
-
/**
|
|
47
|
-
* Instructs the renderer to use render passes. It is an optimization that makes the rendering faster for some engines (like WebGPU) but that consumes more memory, so it is disabled by default.
|
|
48
|
-
*/
|
|
49
|
-
get useRenderPasses(): boolean;
|
|
50
|
-
set useRenderPasses(usePasses: boolean);
|
|
51
|
-
/**
|
|
52
|
-
* Add a mesh in the exclusion list to prevent it to be handled by the depth peeling renderer
|
|
53
|
-
* @param mesh The mesh to exclude from the depth peeling renderer
|
|
54
|
-
*/
|
|
55
|
-
addExcludedMesh(mesh: AbstractMesh): void;
|
|
56
|
-
/**
|
|
57
|
-
* Remove a mesh from the exclusion list of the depth peeling renderer
|
|
58
|
-
* @param mesh The mesh to remove
|
|
59
|
-
*/
|
|
60
|
-
removeExcludedMesh(mesh: AbstractMesh): void;
|
|
61
|
-
/** Shader language used by the renderer */
|
|
62
|
-
protected _shaderLanguage: ShaderLanguage;
|
|
63
|
-
/**
|
|
64
|
-
* Gets the shader language used in this renderer
|
|
65
|
-
*/
|
|
66
|
-
get shaderLanguage(): ShaderLanguage;
|
|
67
13
|
/**
|
|
68
14
|
* Instanciates the depth peeling renderer
|
|
69
15
|
* @param scene Scene to attach to
|
|
@@ -71,38 +17,21 @@ export declare class DepthPeelingRenderer {
|
|
|
71
17
|
* @returns The depth peeling renderer
|
|
72
18
|
*/
|
|
73
19
|
constructor(scene: Scene, passCount?: number);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
private _createTextures;
|
|
77
|
-
private _disposeTextures;
|
|
20
|
+
protected _createTextures(): void;
|
|
21
|
+
protected _disposeTextures(): void;
|
|
78
22
|
private _updateTextures;
|
|
79
23
|
private _updateTextureReferences;
|
|
80
|
-
private _createEffects;
|
|
81
24
|
/**
|
|
82
25
|
* Links to the prepass renderer
|
|
83
26
|
* @param prePassRenderer The scene PrePassRenderer
|
|
84
27
|
*/
|
|
85
28
|
setPrePassRenderer(prePassRenderer: PrePassRenderer): void;
|
|
86
|
-
|
|
87
|
-
* Binds depth peeling textures on an effect
|
|
88
|
-
* @param effect The effect to bind textures on
|
|
89
|
-
*/
|
|
90
|
-
bind(effect: Effect): void;
|
|
91
|
-
private _renderSubMeshes;
|
|
92
|
-
private _finalCompose;
|
|
29
|
+
protected _finalCompose(writeId: number): void;
|
|
93
30
|
/**
|
|
94
31
|
* Checks if the depth peeling renderer is ready to render transparent meshes
|
|
95
32
|
* @returns true if the depth peeling renderer is ready to render the transparent meshes
|
|
96
33
|
*/
|
|
97
34
|
isReady(): boolean;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
* @param transparentSubMeshes List of transparent meshes to render
|
|
101
|
-
* @returns The array of submeshes that could not be handled by this renderer
|
|
102
|
-
*/
|
|
103
|
-
render(transparentSubMeshes: SmartArray<SubMesh>): SmartArray<SubMesh>;
|
|
104
|
-
/**
|
|
105
|
-
* Disposes the depth peeling renderer and associated resources
|
|
106
|
-
*/
|
|
107
|
-
dispose(): void;
|
|
35
|
+
protected _beforeRender(): void;
|
|
36
|
+
protected _afterRender(): void;
|
|
108
37
|
}
|
|
@@ -2,15 +2,10 @@
|
|
|
2
2
|
* Implementation based on https://medium.com/@shrekshao_71662/dual-depth-peeling-implementation-in-webgl-11baa061ba4b
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { MultiRenderTarget } from "../Materials/Textures/multiRenderTarget.js";
|
|
6
|
-
import { Color4 } from "../Maths/math.color.js";
|
|
7
|
-
import { SmartArray } from "../Misc/smartArray.js";
|
|
8
5
|
import { ThinTexture } from "../Materials/Textures/thinTexture.js";
|
|
9
|
-
import { EffectRenderer, EffectWrapper } from "../Materials/effectRenderer.js";
|
|
10
6
|
import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture.js";
|
|
11
7
|
import { Logger } from "../Misc/logger.js";
|
|
12
|
-
import {
|
|
13
|
-
import "../Engines/Extensions/engine.multiRender.js";
|
|
8
|
+
import { ThinDepthPeelingRenderer } from "./thinDepthPeelingRenderer.js";
|
|
14
9
|
class DepthPeelingEffectConfiguration {
|
|
15
10
|
constructor() {
|
|
16
11
|
/**
|
|
@@ -32,58 +27,7 @@ class DepthPeelingEffectConfiguration {
|
|
|
32
27
|
* Order independant transparency (OIT).
|
|
33
28
|
* This should not be instanciated directly, as it is part of a scene component
|
|
34
29
|
*/
|
|
35
|
-
export class DepthPeelingRenderer {
|
|
36
|
-
/**
|
|
37
|
-
* Number of depth peeling passes. As we are using dual depth peeling, each pass two levels of transparency are processed.
|
|
38
|
-
*/
|
|
39
|
-
get passCount() {
|
|
40
|
-
return this._passCount;
|
|
41
|
-
}
|
|
42
|
-
set passCount(count) {
|
|
43
|
-
if (this._passCount === count) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
this._passCount = count;
|
|
47
|
-
this._createRenderPassIds();
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Instructs the renderer to use render passes. It is an optimization that makes the rendering faster for some engines (like WebGPU) but that consumes more memory, so it is disabled by default.
|
|
51
|
-
*/
|
|
52
|
-
get useRenderPasses() {
|
|
53
|
-
return this._useRenderPasses;
|
|
54
|
-
}
|
|
55
|
-
set useRenderPasses(usePasses) {
|
|
56
|
-
if (this._useRenderPasses === usePasses) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
this._useRenderPasses = usePasses;
|
|
60
|
-
this._createRenderPassIds();
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Add a mesh in the exclusion list to prevent it to be handled by the depth peeling renderer
|
|
64
|
-
* @param mesh The mesh to exclude from the depth peeling renderer
|
|
65
|
-
*/
|
|
66
|
-
addExcludedMesh(mesh) {
|
|
67
|
-
if (this._excludedMeshes.indexOf(mesh.uniqueId) === -1) {
|
|
68
|
-
this._excludedMeshes.push(mesh.uniqueId);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Remove a mesh from the exclusion list of the depth peeling renderer
|
|
73
|
-
* @param mesh The mesh to remove
|
|
74
|
-
*/
|
|
75
|
-
removeExcludedMesh(mesh) {
|
|
76
|
-
const index = this._excludedMeshes.indexOf(mesh.uniqueId);
|
|
77
|
-
if (index !== -1) {
|
|
78
|
-
this._excludedMeshes.splice(index, 1);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Gets the shader language used in this renderer
|
|
83
|
-
*/
|
|
84
|
-
get shaderLanguage() {
|
|
85
|
-
return this._shaderLanguage;
|
|
86
|
-
}
|
|
30
|
+
export class DepthPeelingRenderer extends ThinDepthPeelingRenderer {
|
|
87
31
|
/**
|
|
88
32
|
* Instanciates the depth peeling renderer
|
|
89
33
|
* @param scene Scene to attach to
|
|
@@ -91,113 +35,20 @@ export class DepthPeelingRenderer {
|
|
|
91
35
|
* @returns The depth peeling renderer
|
|
92
36
|
*/
|
|
93
37
|
constructor(scene, passCount = 5) {
|
|
94
|
-
|
|
95
|
-
this._currentPingPongState = 0;
|
|
96
|
-
this._layoutCacheFormat = [[true], [true, true], [true, true, true]];
|
|
97
|
-
this._layoutCache = [];
|
|
98
|
-
this._candidateSubMeshes = new SmartArray(10);
|
|
99
|
-
this._excludedSubMeshes = new SmartArray(10);
|
|
100
|
-
this._excludedMeshes = [];
|
|
101
|
-
this._colorCache = [
|
|
102
|
-
new Color4(DepthPeelingRenderer._DEPTH_CLEAR_VALUE, DepthPeelingRenderer._DEPTH_CLEAR_VALUE, 0, 0),
|
|
103
|
-
new Color4(-DepthPeelingRenderer._MIN_DEPTH, DepthPeelingRenderer._MAX_DEPTH, 0, 0),
|
|
104
|
-
new Color4(0, 0, 0, 0),
|
|
105
|
-
];
|
|
106
|
-
/** Shader language used by the renderer */
|
|
107
|
-
this._shaderLanguage = 0 /* ShaderLanguage.GLSL */;
|
|
108
|
-
this._scene = scene;
|
|
109
|
-
this._engine = scene.getEngine();
|
|
110
|
-
this._passCount = passCount;
|
|
38
|
+
super(scene, passCount);
|
|
111
39
|
// We need a depth texture for opaque
|
|
112
40
|
if (!scene.enablePrePassRenderer()) {
|
|
113
41
|
Logger.Warn("Depth peeling for order independant transparency could not enable PrePass, aborting.");
|
|
114
42
|
return;
|
|
115
43
|
}
|
|
116
|
-
for (let i = 0; i < this._layoutCacheFormat.length; ++i) {
|
|
117
|
-
this._layoutCache[i] = this._engine.buildTextureLayout(this._layoutCacheFormat[i]);
|
|
118
|
-
}
|
|
119
|
-
this._renderPassIds = [];
|
|
120
|
-
this.useRenderPasses = false;
|
|
121
|
-
if (this._engine.isWebGPU) {
|
|
122
|
-
this._shaderLanguage = 1 /* ShaderLanguage.WGSL */;
|
|
123
|
-
}
|
|
124
44
|
this._prePassEffectConfiguration = new DepthPeelingEffectConfiguration();
|
|
125
45
|
this._createTextures();
|
|
126
|
-
this._createEffects();
|
|
127
|
-
}
|
|
128
|
-
_createRenderPassIds() {
|
|
129
|
-
this._releaseRenderPassIds();
|
|
130
|
-
if (this._useRenderPasses) {
|
|
131
|
-
for (let i = 0; i < this._passCount + 1; ++i) {
|
|
132
|
-
if (!this._renderPassIds[i]) {
|
|
133
|
-
this._renderPassIds[i] = this._engine.createRenderPassId(`DepthPeelingRenderer - pass #${i}`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
_releaseRenderPassIds() {
|
|
139
|
-
for (let i = 0; i < this._renderPassIds.length; ++i) {
|
|
140
|
-
this._engine.releaseRenderPassId(this._renderPassIds[i]);
|
|
141
|
-
}
|
|
142
|
-
this._renderPassIds = [];
|
|
46
|
+
this._createEffects("oitFinal", ["uFrontColor", "uBackColor"]);
|
|
143
47
|
}
|
|
144
48
|
_createTextures() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
height: this._engine.getRenderHeight(),
|
|
148
|
-
};
|
|
149
|
-
// 2 for ping pong
|
|
150
|
-
this._depthMrts = [
|
|
151
|
-
new MultiRenderTarget("depthPeelingDepth0MRT", size, 3, this._scene, undefined, [
|
|
152
|
-
"depthPeelingDepth0MRT_depth",
|
|
153
|
-
"depthPeelingDepth0MRT_frontColor",
|
|
154
|
-
"depthPeelingDepth0MRT_backColor",
|
|
155
|
-
]),
|
|
156
|
-
new MultiRenderTarget("depthPeelingDepth1MRT", size, 3, this._scene, undefined, [
|
|
157
|
-
"depthPeelingDepth1MRT_depth",
|
|
158
|
-
"depthPeelingDepth1MRT_frontColor",
|
|
159
|
-
"depthPeelingDepth1MRT_backColor",
|
|
160
|
-
]),
|
|
161
|
-
];
|
|
162
|
-
this._colorMrts = [
|
|
163
|
-
new MultiRenderTarget("depthPeelingColor0MRT", size, 2, this._scene, { generateDepthBuffer: false }, [
|
|
164
|
-
"depthPeelingColor0MRT_frontColor",
|
|
165
|
-
"depthPeelingColor0MRT_backColor",
|
|
166
|
-
]),
|
|
167
|
-
new MultiRenderTarget("depthPeelingColor1MRT", size, 2, this._scene, { generateDepthBuffer: false }, [
|
|
168
|
-
"depthPeelingColor1MRT_frontColor",
|
|
169
|
-
"depthPeelingColor1MRT_backColor",
|
|
170
|
-
]),
|
|
171
|
-
];
|
|
172
|
-
this._blendBackMrt = new MultiRenderTarget("depthPeelingBackMRT", size, 1, this._scene, { generateDepthBuffer: false }, ["depthPeelingBackMRT_blendBack"]);
|
|
49
|
+
super._createTextures();
|
|
50
|
+
const size = this._getTextureSize();
|
|
173
51
|
this._outputRT = new RenderTargetTexture("depthPeelingOutputRTT", size, this._scene, false);
|
|
174
|
-
// 0 is a depth texture
|
|
175
|
-
// 1 is a color texture
|
|
176
|
-
const optionsArray = [
|
|
177
|
-
{
|
|
178
|
-
format: 7, // For MSAA we need RGBA
|
|
179
|
-
samplingMode: 1,
|
|
180
|
-
type: this._engine.getCaps().textureFloatLinearFiltering ? 1 : 2,
|
|
181
|
-
label: "DepthPeelingRenderer-DepthTexture",
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
format: 5,
|
|
185
|
-
samplingMode: 1,
|
|
186
|
-
type: 2, // For MSAA we need FLOAT
|
|
187
|
-
label: "DepthPeelingRenderer-ColorTexture",
|
|
188
|
-
},
|
|
189
|
-
];
|
|
190
|
-
for (let i = 0; i < 2; i++) {
|
|
191
|
-
const depthTexture = this._engine._createInternalTexture(size, optionsArray[0], false);
|
|
192
|
-
const frontColorTexture = this._engine._createInternalTexture(size, optionsArray[1], false);
|
|
193
|
-
const backColorTexture = this._engine._createInternalTexture(size, optionsArray[1], false);
|
|
194
|
-
this._depthMrts[i].setInternalTexture(depthTexture, 0);
|
|
195
|
-
this._depthMrts[i].setInternalTexture(frontColorTexture, 1);
|
|
196
|
-
this._depthMrts[i].setInternalTexture(backColorTexture, 2);
|
|
197
|
-
this._colorMrts[i].setInternalTexture(frontColorTexture, 0);
|
|
198
|
-
this._colorMrts[i].setInternalTexture(backColorTexture, 1);
|
|
199
|
-
this._thinTextures.push(new ThinTexture(depthTexture), new ThinTexture(frontColorTexture), new ThinTexture(backColorTexture));
|
|
200
|
-
}
|
|
201
52
|
}
|
|
202
53
|
// TODO : explore again MSAA with depth peeling when
|
|
203
54
|
// we are able to fetch individual samples in a multisampled renderbuffer
|
|
@@ -216,15 +67,9 @@ export class DepthPeelingRenderer {
|
|
|
216
67
|
}
|
|
217
68
|
this._thinTextures[i].dispose();
|
|
218
69
|
}
|
|
219
|
-
for (let i = 0; i < 2; i++) {
|
|
220
|
-
this._depthMrts[i].dispose(true);
|
|
221
|
-
this._colorMrts[i].dispose(true);
|
|
222
|
-
this._blendBackMrt.dispose(true);
|
|
223
|
-
}
|
|
224
|
-
this._outputRT.dispose();
|
|
225
70
|
this._thinTextures = [];
|
|
226
|
-
this.
|
|
227
|
-
|
|
71
|
+
this._outputRT.dispose();
|
|
72
|
+
super._disposeTextures();
|
|
228
73
|
}
|
|
229
74
|
_updateTextures() {
|
|
230
75
|
if (this._depthMrts[0].getSize().width !== this._engine.getRenderWidth() || this._depthMrts[0].getSize().height !== this._engine.getRenderHeight()) {
|
|
@@ -255,57 +100,6 @@ export class DepthPeelingRenderer {
|
|
|
255
100
|
}
|
|
256
101
|
return true;
|
|
257
102
|
}
|
|
258
|
-
_createEffects() {
|
|
259
|
-
this._blendBackEffectWrapper = new EffectWrapper({
|
|
260
|
-
fragmentShader: "oitBackBlend",
|
|
261
|
-
useShaderStore: true,
|
|
262
|
-
engine: this._engine,
|
|
263
|
-
samplerNames: ["uBackColor"],
|
|
264
|
-
uniformNames: [],
|
|
265
|
-
shaderLanguage: this._shaderLanguage,
|
|
266
|
-
extraInitializationsAsync: async () => {
|
|
267
|
-
if (this._shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
|
|
268
|
-
await import("../ShadersWGSL/oitBackBlend.fragment.js");
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
await import("../Shaders/oitBackBlend.fragment.js");
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
});
|
|
275
|
-
this._blendBackEffectWrapperPingPong = new EffectWrapper({
|
|
276
|
-
fragmentShader: "oitBackBlend",
|
|
277
|
-
useShaderStore: true,
|
|
278
|
-
engine: this._engine,
|
|
279
|
-
samplerNames: ["uBackColor"],
|
|
280
|
-
uniformNames: [],
|
|
281
|
-
shaderLanguage: this._shaderLanguage,
|
|
282
|
-
extraInitializationsAsync: async () => {
|
|
283
|
-
if (this._shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
|
|
284
|
-
await import("../ShadersWGSL/oitBackBlend.fragment.js");
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
await import("../Shaders/oitBackBlend.fragment.js");
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
this._finalEffectWrapper = new EffectWrapper({
|
|
292
|
-
fragmentShader: "oitFinal",
|
|
293
|
-
useShaderStore: true,
|
|
294
|
-
engine: this._engine,
|
|
295
|
-
samplerNames: ["uFrontColor", "uBackColor"],
|
|
296
|
-
uniformNames: [],
|
|
297
|
-
shaderLanguage: this._shaderLanguage,
|
|
298
|
-
extraInitializationsAsync: async () => {
|
|
299
|
-
if (this._shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
|
|
300
|
-
await import("../ShadersWGSL/oitFinal.fragment.js");
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
await import("../Shaders/oitFinal.fragment.js");
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
this._effectRenderer = new EffectRenderer(this._engine);
|
|
308
|
-
}
|
|
309
103
|
/**
|
|
310
104
|
* Links to the prepass renderer
|
|
311
105
|
* @param prePassRenderer The scene PrePassRenderer
|
|
@@ -313,54 +107,6 @@ export class DepthPeelingRenderer {
|
|
|
313
107
|
setPrePassRenderer(prePassRenderer) {
|
|
314
108
|
prePassRenderer.addEffectConfiguration(this._prePassEffectConfiguration);
|
|
315
109
|
}
|
|
316
|
-
/**
|
|
317
|
-
* Binds depth peeling textures on an effect
|
|
318
|
-
* @param effect The effect to bind textures on
|
|
319
|
-
*/
|
|
320
|
-
bind(effect) {
|
|
321
|
-
effect.setTexture("oitDepthSampler", this._thinTextures[this._currentPingPongState * 3]);
|
|
322
|
-
effect.setTexture("oitFrontColorSampler", this._thinTextures[this._currentPingPongState * 3 + 1]);
|
|
323
|
-
}
|
|
324
|
-
_renderSubMeshes(transparentSubMeshes) {
|
|
325
|
-
let mapMaterialContext;
|
|
326
|
-
if (this._useRenderPasses) {
|
|
327
|
-
mapMaterialContext = {};
|
|
328
|
-
}
|
|
329
|
-
for (let j = 0; j < transparentSubMeshes.length; j++) {
|
|
330
|
-
const material = transparentSubMeshes.data[j].getMaterial();
|
|
331
|
-
let previousShaderHotSwapping = true;
|
|
332
|
-
let previousBFC = false;
|
|
333
|
-
const subMesh = transparentSubMeshes.data[j];
|
|
334
|
-
let drawWrapper;
|
|
335
|
-
let firstDraw = false;
|
|
336
|
-
if (this._useRenderPasses) {
|
|
337
|
-
drawWrapper = subMesh._getDrawWrapper();
|
|
338
|
-
firstDraw = !drawWrapper;
|
|
339
|
-
}
|
|
340
|
-
if (material) {
|
|
341
|
-
previousShaderHotSwapping = material.allowShaderHotSwapping;
|
|
342
|
-
previousBFC = material.backFaceCulling;
|
|
343
|
-
material.allowShaderHotSwapping = false;
|
|
344
|
-
material.backFaceCulling = false;
|
|
345
|
-
}
|
|
346
|
-
subMesh.render(false);
|
|
347
|
-
if (firstDraw) {
|
|
348
|
-
// first time we draw this submesh: we replace the material context
|
|
349
|
-
drawWrapper = subMesh._getDrawWrapper(); // we are sure it is now non empty as we just rendered the submesh
|
|
350
|
-
if (drawWrapper.materialContext) {
|
|
351
|
-
let newMaterialContext = mapMaterialContext[drawWrapper.materialContext.uniqueId];
|
|
352
|
-
if (!newMaterialContext) {
|
|
353
|
-
newMaterialContext = mapMaterialContext[drawWrapper.materialContext.uniqueId] = this._engine.createMaterialContext();
|
|
354
|
-
}
|
|
355
|
-
subMesh._getDrawWrapper().materialContext = newMaterialContext;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
if (material) {
|
|
359
|
-
material.allowShaderHotSwapping = previousShaderHotSwapping;
|
|
360
|
-
material.backFaceCulling = previousBFC;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
110
|
_finalCompose(writeId) {
|
|
365
111
|
const output = this._scene.prePassRenderer?.setCustomOutput(this._outputRT);
|
|
366
112
|
if (output) {
|
|
@@ -381,145 +127,13 @@ export class DepthPeelingRenderer {
|
|
|
381
127
|
* @returns true if the depth peeling renderer is ready to render the transparent meshes
|
|
382
128
|
*/
|
|
383
129
|
isReady() {
|
|
384
|
-
return
|
|
385
|
-
this._blendBackEffectWrapperPingPong.effect.isReady() &&
|
|
386
|
-
this._finalEffectWrapper.effect.isReady() &&
|
|
387
|
-
this._updateTextures());
|
|
130
|
+
return super.isReady() && this._updateTextures();
|
|
388
131
|
}
|
|
389
|
-
|
|
390
|
-
* Renders transparent submeshes with depth peeling
|
|
391
|
-
* @param transparentSubMeshes List of transparent meshes to render
|
|
392
|
-
* @returns The array of submeshes that could not be handled by this renderer
|
|
393
|
-
*/
|
|
394
|
-
render(transparentSubMeshes) {
|
|
395
|
-
this._candidateSubMeshes.length = 0;
|
|
396
|
-
this._excludedSubMeshes.length = 0;
|
|
397
|
-
if (!this.isReady()) {
|
|
398
|
-
return this._excludedSubMeshes;
|
|
399
|
-
}
|
|
400
|
-
if (this._scene.activeCamera) {
|
|
401
|
-
this._engine.setViewport(this._scene.activeCamera.viewport);
|
|
402
|
-
}
|
|
403
|
-
for (let i = 0; i < transparentSubMeshes.length; i++) {
|
|
404
|
-
const subMesh = transparentSubMeshes.data[i];
|
|
405
|
-
const material = subMesh.getMaterial();
|
|
406
|
-
const fillMode = material && subMesh.getRenderingMesh()._getRenderingFillMode(material.fillMode);
|
|
407
|
-
if (material &&
|
|
408
|
-
(fillMode === Material.TriangleFanDrawMode || fillMode === Material.TriangleFillMode || fillMode === Material.TriangleStripDrawMode) &&
|
|
409
|
-
this._excludedMeshes.indexOf(subMesh.getMesh().uniqueId) === -1) {
|
|
410
|
-
this._candidateSubMeshes.push(subMesh);
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
this._excludedSubMeshes.push(subMesh);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
if (!this._candidateSubMeshes.length) {
|
|
417
|
-
this._engine.bindFramebuffer(this._colorMrts[1].renderTarget);
|
|
418
|
-
this._engine.bindAttachments(this._layoutCache[1]);
|
|
419
|
-
this._engine.clear(this._colorCache[2], true, false, false);
|
|
420
|
-
this._engine.unBindFramebuffer(this._colorMrts[1].renderTarget);
|
|
421
|
-
this._finalCompose(1);
|
|
422
|
-
return this._excludedSubMeshes;
|
|
423
|
-
}
|
|
424
|
-
const currentRenderPassId = this._engine.currentRenderPassId;
|
|
132
|
+
_beforeRender() {
|
|
425
133
|
this._scene.prePassRenderer._enabled = false;
|
|
426
|
-
if (this._useRenderPasses) {
|
|
427
|
-
this._engine.currentRenderPassId = this._renderPassIds[0];
|
|
428
|
-
}
|
|
429
|
-
// Clears
|
|
430
|
-
this._engine.bindFramebuffer(this._depthMrts[0].renderTarget);
|
|
431
|
-
this._engine.bindAttachments(this._layoutCache[0]);
|
|
432
|
-
this._engine.clear(this._colorCache[0], true, false, false);
|
|
433
|
-
this._engine.unBindFramebuffer(this._depthMrts[0].renderTarget);
|
|
434
|
-
this._engine.bindFramebuffer(this._depthMrts[1].renderTarget);
|
|
435
|
-
this._engine.bindAttachments(this._layoutCache[0]);
|
|
436
|
-
this._engine.clear(this._colorCache[1], true, false, false);
|
|
437
|
-
this._engine.unBindFramebuffer(this._depthMrts[1].renderTarget);
|
|
438
|
-
this._engine.bindFramebuffer(this._colorMrts[0].renderTarget);
|
|
439
|
-
this._engine.bindAttachments(this._layoutCache[1]);
|
|
440
|
-
this._engine.clear(this._colorCache[2], true, false, false);
|
|
441
|
-
this._engine.unBindFramebuffer(this._colorMrts[0].renderTarget);
|
|
442
|
-
this._engine.bindFramebuffer(this._colorMrts[1].renderTarget);
|
|
443
|
-
this._engine.bindAttachments(this._layoutCache[1]);
|
|
444
|
-
this._engine.clear(this._colorCache[2], true, false, false);
|
|
445
|
-
this._engine.unBindFramebuffer(this._colorMrts[1].renderTarget);
|
|
446
|
-
// Draw depth for first pass
|
|
447
|
-
this._engine.bindFramebuffer(this._depthMrts[0].renderTarget);
|
|
448
|
-
this._engine.bindAttachments(this._layoutCache[0]);
|
|
449
|
-
this._engine.setAlphaMode(11); // in WebGPU, when using MIN or MAX equation, the src / dst color factors should not use SRC_ALPHA and the src / dst alpha factors must be 1 else WebGPU will throw a validation error
|
|
450
|
-
this._engine.setAlphaEquation(3);
|
|
451
|
-
this._engine.depthCullingState.depthMask = false;
|
|
452
|
-
this._engine.depthCullingState.depthTest = true;
|
|
453
|
-
this._engine.applyStates();
|
|
454
|
-
this._currentPingPongState = 1;
|
|
455
|
-
// Render
|
|
456
|
-
this._renderSubMeshes(this._candidateSubMeshes);
|
|
457
|
-
this._engine.unBindFramebuffer(this._depthMrts[0].renderTarget);
|
|
458
|
-
this._scene.resetCachedMaterial();
|
|
459
|
-
// depth peeling ping-pong
|
|
460
|
-
let readId = 0;
|
|
461
|
-
let writeId = 0;
|
|
462
|
-
for (let i = 0; i < this._passCount; i++) {
|
|
463
|
-
readId = i % 2;
|
|
464
|
-
writeId = 1 - readId;
|
|
465
|
-
this._currentPingPongState = readId;
|
|
466
|
-
if (this._useRenderPasses) {
|
|
467
|
-
this._engine.currentRenderPassId = this._renderPassIds[i + 1];
|
|
468
|
-
}
|
|
469
|
-
if (this._scene.activeCamera) {
|
|
470
|
-
this._engine.setViewport(this._scene.activeCamera.viewport);
|
|
471
|
-
}
|
|
472
|
-
// Clears
|
|
473
|
-
this._engine.bindFramebuffer(this._depthMrts[writeId].renderTarget);
|
|
474
|
-
this._engine.bindAttachments(this._layoutCache[0]);
|
|
475
|
-
this._engine.clear(this._colorCache[0], true, false, false);
|
|
476
|
-
this._engine.unBindFramebuffer(this._depthMrts[writeId].renderTarget);
|
|
477
|
-
this._engine.bindFramebuffer(this._colorMrts[writeId].renderTarget);
|
|
478
|
-
this._engine.bindAttachments(this._layoutCache[1]);
|
|
479
|
-
this._engine.clear(this._colorCache[2], true, false, false);
|
|
480
|
-
this._engine.unBindFramebuffer(this._colorMrts[writeId].renderTarget);
|
|
481
|
-
this._engine.bindFramebuffer(this._depthMrts[writeId].renderTarget);
|
|
482
|
-
this._engine.bindAttachments(this._layoutCache[2]);
|
|
483
|
-
this._engine.setAlphaMode(11); // the value does not matter (as MAX operation does not use them) but the src and dst color factors should not use SRC_ALPHA else WebGPU will throw a validation error
|
|
484
|
-
this._engine.setAlphaEquation(3);
|
|
485
|
-
this._engine.depthCullingState.depthTest = false;
|
|
486
|
-
this._engine.applyStates();
|
|
487
|
-
// Render
|
|
488
|
-
this._renderSubMeshes(this._candidateSubMeshes);
|
|
489
|
-
this._engine.unBindFramebuffer(this._depthMrts[writeId].renderTarget);
|
|
490
|
-
this._scene.resetCachedMaterial();
|
|
491
|
-
// Back color
|
|
492
|
-
this._engine.bindFramebuffer(this._blendBackMrt.renderTarget);
|
|
493
|
-
this._engine.bindAttachments(this._layoutCache[0]);
|
|
494
|
-
this._engine.setAlphaEquation(0);
|
|
495
|
-
this._engine.setAlphaMode(17);
|
|
496
|
-
this._engine.applyStates();
|
|
497
|
-
const blendBackEffectWrapper = writeId === 0 || !this._useRenderPasses ? this._blendBackEffectWrapper : this._blendBackEffectWrapperPingPong;
|
|
498
|
-
this._engine.enableEffect(blendBackEffectWrapper.drawWrapper);
|
|
499
|
-
blendBackEffectWrapper.effect.setTexture("uBackColor", this._thinTextures[writeId * 3 + 2]);
|
|
500
|
-
this._effectRenderer.render(blendBackEffectWrapper);
|
|
501
|
-
this._engine.unBindFramebuffer(this._blendBackMrt.renderTarget);
|
|
502
|
-
}
|
|
503
|
-
this._engine.currentRenderPassId = currentRenderPassId;
|
|
504
|
-
// Final composition on default FB
|
|
505
|
-
this._finalCompose(writeId);
|
|
506
|
-
this._scene.prePassRenderer._enabled = true;
|
|
507
|
-
this._engine.depthCullingState.depthMask = true;
|
|
508
|
-
this._engine.depthCullingState.depthTest = true;
|
|
509
|
-
return this._excludedSubMeshes;
|
|
510
134
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
*/
|
|
514
|
-
dispose() {
|
|
515
|
-
this._disposeTextures();
|
|
516
|
-
this._blendBackEffectWrapper.dispose();
|
|
517
|
-
this._finalEffectWrapper.dispose();
|
|
518
|
-
this._effectRenderer.dispose();
|
|
519
|
-
this._releaseRenderPassIds();
|
|
135
|
+
_afterRender() {
|
|
136
|
+
this._scene.prePassRenderer._enabled = true;
|
|
520
137
|
}
|
|
521
138
|
}
|
|
522
|
-
DepthPeelingRenderer._DEPTH_CLEAR_VALUE = -99999.0;
|
|
523
|
-
DepthPeelingRenderer._MIN_DEPTH = 0;
|
|
524
|
-
DepthPeelingRenderer._MAX_DEPTH = 1;
|
|
525
139
|
//# sourceMappingURL=depthPeelingRenderer.js.map
|