@onerjs/core 8.54.4 → 8.54.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/Engines/WebGPU/Extensions/engine.cubeTexture.pure.js +1 -1
- package/Engines/WebGPU/Extensions/engine.cubeTexture.pure.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.rawTexture.pure.js +2 -2
- package/Engines/WebGPU/Extensions/engine.rawTexture.pure.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheRenderPipeline.d.ts +1 -0
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js +18 -4
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheTextureView.d.ts +13 -0
- package/Engines/WebGPU/webgpuCacheTextureView.js +32 -0
- package/Engines/WebGPU/webgpuCacheTextureView.js.map +1 -0
- package/Engines/WebGPU/webgpuRenderTargetWrapper.d.ts +10 -0
- package/Engines/WebGPU/webgpuRenderTargetWrapper.js +10 -0
- package/Engines/WebGPU/webgpuRenderTargetWrapper.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.pure.js +57 -4
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.pure.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureManager.d.ts +1 -1
- package/Engines/WebGPU/webgpuTextureManager.js +4 -2
- package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
- package/Engines/abstractEngine.pure.js +2 -2
- package/Engines/abstractEngine.pure.js.map +1 -1
- package/Engines/thinNativeEngine.pure.d.ts +5 -0
- package/Engines/thinNativeEngine.pure.js +29 -6
- package/Engines/thinNativeEngine.pure.js.map +1 -1
- package/Engines/webgpuEngine.pure.d.ts +1 -0
- package/Engines/webgpuEngine.pure.js +21 -8
- package/Engines/webgpuEngine.pure.js.map +1 -1
- package/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.d.ts +95 -1
- package/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.js +169 -4
- package/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.js.map +1 -1
- package/FlowGraph/Blocks/Data/Math/flowGraphMathCombineExtractBlocks.pure.d.ts +21 -6
- package/FlowGraph/Blocks/Data/Math/flowGraphMathCombineExtractBlocks.pure.js +28 -26
- package/FlowGraph/Blocks/Data/Math/flowGraphMathCombineExtractBlocks.pure.js.map +1 -1
- package/FlowGraph/Blocks/Data/Math/flowGraphMatrixMathBlocks.pure.d.ts +30 -2
- package/FlowGraph/Blocks/Data/Math/flowGraphMatrixMathBlocks.pure.js +111 -29
- package/FlowGraph/Blocks/Data/Math/flowGraphMatrixMathBlocks.pure.js.map +1 -1
- package/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.d.ts +56 -2
- package/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.js +99 -14
- package/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.js.map +1 -1
- package/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.pure.js +10 -2
- package/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Data/Utils/flowGraphArrayIndexBlock.pure.js +21 -1
- package/FlowGraph/Blocks/Data/Utils/flowGraphArrayIndexBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.d.ts +18 -0
- package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js +29 -2
- package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.pure.d.ts +15 -0
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.pure.js +44 -7
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphSceneReadyEventBlock.pure.d.ts +9 -0
- package/FlowGraph/Blocks/Event/flowGraphSceneReadyEventBlock.pure.js +9 -1
- package/FlowGraph/Blocks/Event/flowGraphSceneReadyEventBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.pure.d.ts +7 -0
- package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.pure.js +8 -1
- package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.d.ts +5 -0
- package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.js +8 -0
- package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.js.map +1 -0
- package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.pure.d.ts +37 -0
- package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.pure.js +44 -0
- package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.pure.js.map +1 -0
- package/FlowGraph/Blocks/Event/index.d.ts +1 -0
- package/FlowGraph/Blocks/Event/index.js +1 -0
- package/FlowGraph/Blocks/Event/index.js.map +1 -1
- package/FlowGraph/Blocks/Event/pure.d.ts +1 -0
- package/FlowGraph/Blocks/Event/pure.js +1 -0
- package/FlowGraph/Blocks/Event/pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphBezierCurveEasingBlock.pure.d.ts +4 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphBezierCurveEasingBlock.pure.js +67 -2
- package/FlowGraph/Blocks/Execution/Animation/flowGraphBezierCurveEasingBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.pure.d.ts +13 -0
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.pure.js +102 -7
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.pure.js +5 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphCancelDelayBlock.pure.js +5 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphCancelDelayBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphForLoopBlock.pure.d.ts +11 -2
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphForLoopBlock.pure.js +21 -3
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphForLoopBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphSetDelayBlock.pure.js +25 -4
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphSetDelayBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/flowGraphBlockFactory.js +18 -0
- package/FlowGraph/Blocks/flowGraphBlockFactory.js.map +1 -1
- package/FlowGraph/Blocks/flowGraphBlockNames.d.ts +9 -0
- package/FlowGraph/Blocks/flowGraphBlockNames.js +9 -0
- package/FlowGraph/Blocks/flowGraphBlockNames.js.map +1 -1
- package/FlowGraph/CustomTypes/flowGraphMatrix.d.ts +17 -3
- package/FlowGraph/CustomTypes/flowGraphMatrix.js +27 -21
- package/FlowGraph/CustomTypes/flowGraphMatrix.js.map +1 -1
- package/FlowGraph/flowGraphContext.d.ts +23 -0
- package/FlowGraph/flowGraphContext.js +29 -0
- package/FlowGraph/flowGraphContext.js.map +1 -1
- package/FlowGraph/flowGraphCoordinator.d.ts +58 -1
- package/FlowGraph/flowGraphCoordinator.js +72 -0
- package/FlowGraph/flowGraphCoordinator.js.map +1 -1
- package/FlowGraph/flowGraphDelayRegistry.d.ts +31 -0
- package/FlowGraph/flowGraphDelayRegistry.js +50 -0
- package/FlowGraph/flowGraphDelayRegistry.js.map +1 -0
- package/FlowGraph/flowGraphHostResolver.d.ts +69 -0
- package/FlowGraph/flowGraphHostResolver.js +25 -0
- package/FlowGraph/flowGraphHostResolver.js.map +1 -0
- package/FlowGraph/flowGraphMath.d.ts +48 -1
- package/FlowGraph/flowGraphMath.js +169 -4
- package/FlowGraph/flowGraphMath.js.map +1 -1
- package/FlowGraph/flowGraphPathConverterComponent.d.ts +14 -3
- package/FlowGraph/flowGraphPathConverterComponent.js +110 -18
- package/FlowGraph/flowGraphPathConverterComponent.js.map +1 -1
- package/FlowGraph/flowGraphSignalConnection.pure.js +7 -1
- package/FlowGraph/flowGraphSignalConnection.pure.js.map +1 -1
- package/FlowGraph/index.d.ts +2 -0
- package/FlowGraph/index.js +2 -0
- package/FlowGraph/index.js.map +1 -1
- package/FlowGraph/pure.d.ts +2 -0
- package/FlowGraph/pure.js +2 -0
- package/FlowGraph/pure.js.map +1 -1
- package/Maths/math.vector.pure.d.ts +10 -0
- package/Maths/math.vector.pure.js +13 -0
- package/Maths/math.vector.pure.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.d.ts +216 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.js +714 -67
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.d.ts +81 -4
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js +466 -52
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingPartProxyMesh.pure.d.ts +19 -0
- package/Meshes/GaussianSplatting/gaussianSplattingPartProxyMesh.pure.js +24 -0
- package/Meshes/GaussianSplatting/gaussianSplattingPartProxyMesh.pure.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.js +31 -6
- package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.pure.js +5 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.pure.js.map +1 -1
- package/Misc/greasedLineTools.js +1 -1
- package/Misc/greasedLineTools.js.map +1 -1
- package/Misc/tools.pure.js +14 -2
- package/Misc/tools.pure.js.map +1 -1
- package/Particles/gpuParticleSystem.pure.d.ts +66 -1
- package/Particles/gpuParticleSystem.pure.js +189 -49
- package/Particles/gpuParticleSystem.pure.js.map +1 -1
- package/Physics/v2/characterController.js +69 -17
- package/Physics/v2/characterController.js.map +1 -1
- package/XR/features/Layers/WebXRWebGPUCompositionLayer.d.ts +3 -9
- package/XR/features/Layers/WebXRWebGPUCompositionLayer.js +4 -11
- package/XR/features/Layers/WebXRWebGPUCompositionLayer.js.map +1 -1
- package/XR/features/WebXRAbstractFeature.d.ts +9 -0
- package/XR/features/WebXRAbstractFeature.js +16 -0
- package/XR/features/WebXRAbstractFeature.js.map +1 -1
- package/XR/features/WebXRDepthSensing.pure.d.ts +7 -0
- package/XR/features/WebXRDepthSensing.pure.js +350 -39
- package/XR/features/WebXRDepthSensing.pure.js.map +1 -1
- package/XR/features/WebXRImageTracking.pure.js.map +1 -1
- package/XR/features/WebXRLayers.pure.d.ts +6 -5
- package/XR/features/WebXRLayers.pure.js +65 -8
- package/XR/features/WebXRLayers.pure.js.map +1 -1
- package/XR/features/WebXRRawCameraAccess.pure.js +9 -2
- package/XR/features/WebXRRawCameraAccess.pure.js.map +1 -1
- package/XR/features/WebXRSpaceWarp.pure.d.ts +0 -1
- package/XR/features/WebXRSpaceWarp.pure.js +13 -4
- package/XR/features/WebXRSpaceWarp.pure.js.map +1 -1
- package/XR/features/WebXRWalkingLocomotion.pure.js.map +1 -1
- package/XR/webXRCamera.js +27 -0
- package/XR/webXRCamera.js.map +1 -1
- package/XR/webXRFeatureWarningRegistry.d.ts +14 -0
- package/XR/webXRFeatureWarningRegistry.js +19 -0
- package/XR/webXRFeatureWarningRegistry.js.map +1 -0
- package/XR/webXRFeaturesManager.d.ts +5 -0
- package/XR/webXRFeaturesManager.js +23 -4
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/XR/webXRGraphicsBinding.d.ts +17 -10
- package/XR/webXRGraphicsBinding.js +8 -5
- package/XR/webXRGraphicsBinding.js.map +1 -1
- package/XR/webXRSessionManager.d.ts +3 -5
- package/XR/webXRSessionManager.js +1 -3
- package/XR/webXRSessionManager.js.map +1 -1
- package/XR/webXRWebGPURenderTargetTextureProvider.d.ts +21 -5
- package/XR/webXRWebGPURenderTargetTextureProvider.js +38 -10
- package/XR/webXRWebGPURenderTargetTextureProvider.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
import { Color4 } from "../Maths/math.color.pure.js";
|
|
2
3
|
import { WebXRLayerRenderTargetTexture } from "./webXRLayerRenderTargetTexture.js";
|
|
3
4
|
import { WebXRLayerRenderTargetTextureProvider } from "./webXRRenderTargetTextureProvider.js";
|
|
4
5
|
/**
|
|
@@ -37,6 +38,11 @@ function GetBabylonDepthFormat(format) {
|
|
|
37
38
|
* @internal
|
|
38
39
|
*/
|
|
39
40
|
export class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {
|
|
41
|
+
constructor(_xrSessionManager, layerWrapper) {
|
|
42
|
+
super(_xrSessionManager.scene, layerWrapper);
|
|
43
|
+
this._xrSessionManager = _xrSessionManager;
|
|
44
|
+
this._transparentClearColor = new Color4(0, 0, 0, 0);
|
|
45
|
+
}
|
|
40
46
|
get _webgpuEngine() {
|
|
41
47
|
return this._engine;
|
|
42
48
|
}
|
|
@@ -66,6 +72,10 @@ export class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTarg
|
|
|
66
72
|
}
|
|
67
73
|
const renderTargetTexture = new WebXRLayerRenderTargetTexture("XR renderTargetTexture", { width, height }, this._scene);
|
|
68
74
|
renderTargetTexture.renderTarget._samples = renderTargetTexture.samples;
|
|
75
|
+
// The projection-layer texture is presented directly by the XR compositor (top-left origin, never
|
|
76
|
+
// re-sampled by Babylon), so opt this target out of the engine's render-target Y-flip / winding
|
|
77
|
+
// compensation and render it upright, matching the WebXR/WebGPU spec's plain render pass.
|
|
78
|
+
renderTargetTexture.renderTarget._disableEngineYFlip = true;
|
|
69
79
|
return renderTargetTexture;
|
|
70
80
|
}
|
|
71
81
|
/**
|
|
@@ -99,28 +109,46 @@ export class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTarg
|
|
|
99
109
|
* `camera.isRightCamera`, so this observer clears both eyes' targets. WebGL providers never attach it,
|
|
100
110
|
* so the WebGL path is unchanged.
|
|
101
111
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
112
|
+
* Color is cleared at most once per ENGINE FRAME, not once per `Scene.render`. The distinction matters:
|
|
113
|
+
* more than one scene can render the same XR camera within a single XR frame. `UtilityLayerRenderer`
|
|
114
|
+
* (used by controller pointer selection and near interaction) renders a second scene through the same
|
|
115
|
+
* rig cameras, and every `Scene.render` resets `RenderTargetTexture._cleared` for those cameras' targets
|
|
116
|
+
* (`Scene._checkCameraRenderTarget`), so a `_cleared`-based guard is defeated and each eye is re-cleared
|
|
117
|
+
* after it was drawn — presenting a clear-colored frame with the geometry gone. `AbstractEngine.frameId`
|
|
118
|
+
* only advances in `endFrame`, once per XR frame, so unlike `_cleared` it cannot be reset by another
|
|
119
|
+
* scene rendering the same camera.
|
|
120
|
+
*
|
|
121
|
+
* In immersive AR, color is cleared to transparent when `WebXRExperienceHelper` disables
|
|
122
|
+
* `Scene.autoClear`. WebGL XR framebuffers are cleared to transparent by the user agent, but WebGPU render
|
|
123
|
+
* passes require the application to request that clear explicitly. Skipping it leaves pixels from prior
|
|
124
|
+
* frames in passthrough regions, producing trails behind moving objects.
|
|
125
|
+
*
|
|
126
|
+
* Depth and stencil are still cleared on every notification, matching the previous behavior and the
|
|
127
|
+
* expectations of overlay scenes that draw on top of the main scene.
|
|
107
128
|
* @param renderTargetTexture the per-eye render target to clear each frame
|
|
108
129
|
*/
|
|
109
130
|
_attachPerEyeClearObserver(renderTargetTexture) {
|
|
131
|
+
let lastColorClearedFrameId = -1;
|
|
110
132
|
renderTargetTexture.onClearObservable.add((engine) => {
|
|
111
133
|
// Honor skipInitialClear so this observer preserves the default clear semantics it replaces.
|
|
112
134
|
if (renderTargetTexture.skipInitialClear) {
|
|
113
135
|
return;
|
|
114
136
|
}
|
|
115
137
|
const scene = renderTargetTexture.getScene();
|
|
138
|
+
const isImmersiveAR = this._xrSessionManager.sessionMode === "immersive-ar";
|
|
116
139
|
// When autoClear is disabled the scene does not clear render targets; match that so this observer
|
|
117
|
-
// does not force a clear the user opted out of.
|
|
118
|
-
|
|
140
|
+
// does not force a clear the user opted out of. Immersive AR is the exception: the experience
|
|
141
|
+
// helper disables autoClear because WebGL XR is cleared by the user agent, while WebGPU is not.
|
|
142
|
+
if (scene && !scene.autoClear && !isImmersiveAR) {
|
|
119
143
|
return;
|
|
120
144
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
engine.clear(
|
|
145
|
+
const clearColor = engine.frameId !== lastColorClearedFrameId;
|
|
146
|
+
const color = isImmersiveAR && scene && !scene.autoClear ? this._transparentClearColor : (renderTargetTexture.clearColor ?? scene?.clearColor ?? null);
|
|
147
|
+
engine.clear(color, clearColor, true, true);
|
|
148
|
+
if (clearColor) {
|
|
149
|
+
lastColorClearedFrameId = engine.frameId;
|
|
150
|
+
}
|
|
151
|
+
// Kept in sync so anything else reading the flag still sees this target as cleared this frame.
|
|
124
152
|
renderTargetTexture._cleared = true;
|
|
125
153
|
});
|
|
126
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRWebGPURenderTargetTextureProvider.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRWebGPURenderTargetTextureProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKjD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,qCAAqC,EAAE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C,KAAK,CAAC,mBAAmB,CAAC,UAAU,IAAI,KAAK,EAAE,UAAU,IAAI,IAAI,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YACrH,mBAAmB,CAAC,QAAQ,GAAG,IAAI,CAAC;QACxC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;;;OASG;IACO,yCAAyC,CAAC,mBAAwC,EAAE,YAAwB,EAAE,mBAAyC;QAC7J,MAAM,KAAK,GAAG,mBAAmB,CAAC,QAAQ,CAAC;QAC3C,IAAI,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,aAAa,CAAC,0BAA0B,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QACvE,CAAC;QACD,MAAM,KAAK,GAAG,mBAAmB,CAAC,YAAY,EAAE,oBAAoB,CAAC;QACrE,IAAI,KAAK,IAAI,mBAAmB,EAAE,CAAC;YAC/B,IAAI,CAAC,aAAa,CAAC,0BAA0B,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { Constants } from \"../Engines/constants\";\nimport { type WebGPUEngine } from \"../Engines/webgpuEngine\";\nimport { type InternalTexture } from \"../Materials/Textures/internalTexture\";\nimport { type RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture.pure\";\nimport { type Nullable } from \"../types\";\nimport { WebXRLayerRenderTargetTexture } from \"./webXRLayerRenderTargetTexture\";\nimport { WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\n\n/**\n * Maps a WebGPU depth/stencil {@link GPUTextureFormat} to the matching Babylon `TEXTUREFORMAT_*` constant.\n *\n * The engine reads `InternalTexture.format` (a Babylon constant) when it builds the render pass depth\n * attachment for a render target, so a depth texture wrapped from an external `GPUTexture` must carry the\n * correct Babylon format or the depth attachment pipeline format will not match the sub-image's texture.\n * @param format the WebGPU depth/stencil format requested when the layer was created\n * @returns the matching Babylon texture format constant\n */\nfunction GetBabylonDepthFormat(format: GPUTextureFormat): number {\n switch (format) {\n case \"depth16unorm\":\n return Constants.TEXTUREFORMAT_DEPTH16;\n case \"depth24plus\":\n return Constants.TEXTUREFORMAT_DEPTH24;\n case \"depth24plus-stencil8\":\n return Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\n case \"depth32float\":\n return Constants.TEXTUREFORMAT_DEPTH32_FLOAT;\n case \"depth32float-stencil8\":\n return Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8;\n case \"stencil8\":\n return Constants.TEXTUREFORMAT_STENCIL8;\n default:\n // Fall back to a combined depth/stencil format, which is the projection layer default.\n return Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\n }\n}\n\n/**\n * Provides render target textures for WebGPU-backed XR layers. Owns all WebGPU-specific texture wrapping\n * (via {@link WebGPUEngine.wrapWebGPUTexture} / {@link WebGPUEngine.updateWrappedWebGPUTexture}) so the base\n * provider can stay graphics-API-agnostic. Mirrors {@link WebXRWebGLRenderTargetTextureProvider} for the\n * WebGPU (XRGPUBinding) backend.\n * @internal\n */\nexport abstract class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\n private get _webgpuEngine(): WebGPUEngine {\n return this._engine as WebGPUEngine;\n }\n\n private _wrapColorTexture(texture: GPUTexture): InternalTexture {\n return this._webgpuEngine.wrapWebGPUTexture(texture);\n }\n\n private _wrapDepthTexture(texture: GPUTexture, depthStencilFormat: GPUTextureFormat): InternalTexture {\n const internalTexture = this._webgpuEngine.wrapWebGPUTexture(texture);\n // The engine derives the color attachment format automatically from the wrapped hardware texture,\n // but the depth attachment format is read from the Babylon InternalTexture.format, which\n // wrapWebGPUTexture does not set. Assign it here from the format the layer was created with.\n internalTexture.format = GetBabylonDepthFormat(depthStencilFormat);\n return internalTexture;\n }\n\n /**\n * Builds the render target shell as a {@link WebXRLayerRenderTargetTexture} for the single-view path so\n * each eye can bind its own array layer of a layered projection-layer texture. Multiview is not yet\n * supported on this WebGPU path and is delegated to the base implementation.\n * @param width the width of the render target\n * @param height the height of the render target\n * @param multiview whether the render target should be a multiview render target\n * @returns the created (but not yet registered) render target texture\n */\n protected override _createRenderTargetTextureShell(width: number, height: number, multiview: boolean): RenderTargetTexture {\n if (multiview) {\n return super._createRenderTargetTextureShell(width, height, multiview);\n }\n const renderTargetTexture = new WebXRLayerRenderTargetTexture(\"XR renderTargetTexture\", { width, height }, this._scene);\n renderTargetTexture.renderTarget!._samples = renderTargetTexture.samples;\n return renderTargetTexture;\n }\n\n /**\n * Wraps the sub-image's color (and optional depth/stencil) GPUTextures and builds a new render target\n * texture around them. Use this on first creation and whenever the sub-image texture size changes.\n * @param width the width of the render target\n * @param height the height of the render target\n * @param colorTexture the sub-image color GPUTexture\n * @param depthStencilTexture the sub-image depth/stencil GPUTexture, if any\n * @param depthStencilFormat the WebGPU depth/stencil format the layer was created with, if depth is provided\n * @param multiview whether the render target should be a multiview render target\n * @returns the created render target texture\n */\n protected _createRenderTargetTextureFromGPUTextures(\n width: number,\n height: number,\n colorTexture: GPUTexture,\n depthStencilTexture: Nullable<GPUTexture>,\n depthStencilFormat: GPUTextureFormat | undefined,\n multiview: boolean\n ): WebXRLayerRenderTargetTexture {\n const color = this._wrapColorTexture(colorTexture);\n const depth = depthStencilTexture && depthStencilFormat ? this._wrapDepthTexture(depthStencilTexture, depthStencilFormat) : null;\n // Single-view (the only path here) always builds a WebXRLayerRenderTargetTexture via the shell override above.\n const renderTargetTexture = this._createRenderTargetTextureInternal(width, height, color, depth, multiview) as WebXRLayerRenderTargetTexture;\n this._attachPerEyeClearObserver(renderTargetTexture);\n return renderTargetTexture;\n }\n\n /**\n * Ensures this render target is cleared every frame, including for the right eye.\n *\n * `Scene._clearFrameBuffer` skips clearing the right rig camera's framebuffer (`!camera.isRightCamera`).\n * That is a valid optimization for WebGL2 stereo, where both eyes render into a single side-by-side\n * texture and the left eye's full clear already covers the whole texture. WebGPU projection layers give\n * each eye its OWN render target (a distinct array layer rendered in a separate render pass), so the\n * right eye's color and — critically — depth would never be cleared, leaving its depth test to reject\n * every fragment (a black right eye). The scene notifies `onClearObservable` regardless of\n * `camera.isRightCamera`, so this observer clears both eyes' targets. WebGL providers never attach it,\n * so the WebGL path is unchanged.\n *\n * The observer mirrors the clear semantics of `Scene._clearFrameBuffer` (minus the right-eye skip): it\n * only clears when the scene has `autoClear` enabled, clears color at most once per frame (guarded by\n * `RenderTargetTexture._cleared`, which the scene resets per frame in `_checkCameraRenderTarget`), always\n * clears depth+stencil, and honors `skipInitialClear`. This keeps the \"clear once per RTT per frame\"\n * contract instead of clearing color on every notification.\n * @param renderTargetTexture the per-eye render target to clear each frame\n */\n private _attachPerEyeClearObserver(renderTargetTexture: RenderTargetTexture): void {\n renderTargetTexture.onClearObservable.add((engine) => {\n // Honor skipInitialClear so this observer preserves the default clear semantics it replaces.\n if (renderTargetTexture.skipInitialClear) {\n return;\n }\n const scene = renderTargetTexture.getScene();\n // When autoClear is disabled the scene does not clear render targets; match that so this observer\n // does not force a clear the user opted out of.\n if (scene && !scene.autoClear) {\n return;\n }\n // Clear color only once per frame (!_cleared), always clear depth+stencil, then mark the target\n // cleared for this frame so a second notification in the same frame does not re-clear color.\n engine.clear(renderTargetTexture.clearColor ?? scene?.clearColor ?? null, !renderTargetTexture._cleared, true, true);\n renderTargetTexture._cleared = true;\n });\n }\n\n /**\n * Repoints the wrapped color/depth textures of an existing render target at the current frame's\n * GPUTextures, preserving the RenderTargetTexture / InternalTexture identity held by the XR camera's\n * `outputRenderTarget`. The sub-image textures are only valid for the current frame and may rotate from\n * a compositor pool, so this must run every frame. The new GPUTextures must have the same dimensions as\n * the wrapped ones (guaranteed by the caller's size-change branch, which rebuilds instead).\n * @param renderTargetTexture the render target whose wrapped textures should be repointed\n * @param colorTexture the current frame's color GPUTexture\n * @param depthStencilTexture the current frame's depth/stencil GPUTexture, if any\n */\n protected _updateRenderTargetTextureFromGPUTextures(renderTargetTexture: RenderTargetTexture, colorTexture: GPUTexture, depthStencilTexture: Nullable<GPUTexture>): void {\n const color = renderTargetTexture._texture;\n if (color) {\n this._webgpuEngine.updateWrappedWebGPUTexture(color, colorTexture);\n }\n const depth = renderTargetTexture.renderTarget?._depthStencilTexture;\n if (depth && depthStencilTexture) {\n this._webgpuEngine.updateWrappedWebGPUTexture(depth, depthStencilTexture);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"webXRWebGPURenderTargetTextureProvider.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRWebGPURenderTargetTextureProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKjD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,qCAAqC,EAAE,MAAM,oCAAoC,CAAC;AAG3F;;;;;;;;GAQG;AACH,SAAS,qBAAqB,CAAC,MAAwB;IACnD,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,cAAc;YACf,OAAO,SAAS,CAAC,qBAAqB,CAAC;QAC3C,KAAK,aAAa;YACd,OAAO,SAAS,CAAC,qBAAqB,CAAC;QAC3C,KAAK,sBAAsB;YACvB,OAAO,SAAS,CAAC,8BAA8B,CAAC;QACpD,KAAK,cAAc;YACf,OAAO,SAAS,CAAC,2BAA2B,CAAC;QACjD,KAAK,uBAAuB;YACxB,OAAO,SAAS,CAAC,mCAAmC,CAAC;QACzD,KAAK,UAAU;YACX,OAAO,SAAS,CAAC,sBAAsB,CAAC;QAC5C;YACI,uFAAuF;YACvF,OAAO,SAAS,CAAC,8BAA8B,CAAC;IACxD,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,OAAgB,sCAAuC,SAAQ,qCAAqC;IAGtG,YACuB,iBAAsC,EACzD,YAA+B;QAE/B,KAAK,CAAC,iBAAiB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC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U,IAAI,KAAK,EAAE,UAAU,IAAI,IAAI,CAAC,CAAC;YACvJ,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAC5C,IAAI,UAAU,EAAE,CAAC;gBACb,uBAAuB,GAAG,MAAM,CAAC,OAAO,CAAC;YAC7C,CAAC;YACD,+FAA+F;YAC/F,mBAAmB,CAAC,QAAQ,GAAG,IAAI,CAAC;QACxC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;;;OASG;IACO,yCAAyC,CAAC,mBAAwC,EAAE,YAAwB,EAAE,mBAAyC;QAC7J,MAAM,KAAK,GAAG,mBAAmB,CAAC,QAAQ,CAAC;QAC3C,IAAI,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,aAAa,CAAC,0BAA0B,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QACvE,CAAC;QACD,MAAM,KAAK,GAAG,mBAAmB,CAAC,YAAY,EAAE,oBAAoB,CAAC;QACrE,IAAI,KAAK,IAAI,mBAAmB,EAAE,CAAC;YAC/B,IAAI,CAAC,aAAa,CAAC,0BAA0B,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { Constants } from \"../Engines/constants\";\nimport { type WebGPUEngine } from \"../Engines/webgpuEngine\";\nimport { type WebGPURenderTargetWrapper } from \"../Engines/WebGPU/webgpuRenderTargetWrapper\";\nimport { type InternalTexture } from \"../Materials/Textures/internalTexture\";\nimport { type RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture.pure\";\nimport { Color4 } from \"../Maths/math.color.pure\";\nimport { type Nullable } from \"../types\";\nimport { WebXRLayerRenderTargetTexture } from \"./webXRLayerRenderTargetTexture\";\nimport { type WebXRLayerWrapper } from \"./webXRLayerWrapper\";\nimport { WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\nimport { type WebXRSessionManager } from \"./webXRSessionManager\";\n\n/**\n * Maps a WebGPU depth/stencil {@link GPUTextureFormat} to the matching Babylon `TEXTUREFORMAT_*` constant.\n *\n * The engine reads `InternalTexture.format` (a Babylon constant) when it builds the render pass depth\n * attachment for a render target, so a depth texture wrapped from an external `GPUTexture` must carry the\n * correct Babylon format or the depth attachment pipeline format will not match the sub-image's texture.\n * @param format the WebGPU depth/stencil format requested when the layer was created\n * @returns the matching Babylon texture format constant\n */\nfunction GetBabylonDepthFormat(format: GPUTextureFormat): number {\n switch (format) {\n case \"depth16unorm\":\n return Constants.TEXTUREFORMAT_DEPTH16;\n case \"depth24plus\":\n return Constants.TEXTUREFORMAT_DEPTH24;\n case \"depth24plus-stencil8\":\n return Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\n case \"depth32float\":\n return Constants.TEXTUREFORMAT_DEPTH32_FLOAT;\n case \"depth32float-stencil8\":\n return Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8;\n case \"stencil8\":\n return Constants.TEXTUREFORMAT_STENCIL8;\n default:\n // Fall back to a combined depth/stencil format, which is the projection layer default.\n return Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\n }\n}\n\n/**\n * Provides render target textures for WebGPU-backed XR layers. Owns all WebGPU-specific texture wrapping\n * (via {@link WebGPUEngine.wrapWebGPUTexture} / {@link WebGPUEngine.updateWrappedWebGPUTexture}) so the base\n * provider can stay graphics-API-agnostic. Mirrors {@link WebXRWebGLRenderTargetTextureProvider} for the\n * WebGPU (XRGPUBinding) backend.\n * @internal\n */\nexport abstract class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\n private readonly _transparentClearColor = new Color4(0, 0, 0, 0);\n\n constructor(\n protected readonly _xrSessionManager: WebXRSessionManager,\n layerWrapper: WebXRLayerWrapper\n ) {\n super(_xrSessionManager.scene, layerWrapper);\n }\n\n private get _webgpuEngine(): WebGPUEngine {\n return this._engine as WebGPUEngine;\n }\n\n private _wrapColorTexture(texture: GPUTexture): InternalTexture {\n return this._webgpuEngine.wrapWebGPUTexture(texture);\n }\n\n private _wrapDepthTexture(texture: GPUTexture, depthStencilFormat: GPUTextureFormat): InternalTexture {\n const internalTexture = this._webgpuEngine.wrapWebGPUTexture(texture);\n // The engine derives the color attachment format automatically from the wrapped hardware texture,\n // but the depth attachment format is read from the Babylon InternalTexture.format, which\n // wrapWebGPUTexture does not set. Assign it here from the format the layer was created with.\n internalTexture.format = GetBabylonDepthFormat(depthStencilFormat);\n return internalTexture;\n }\n\n /**\n * Builds the render target shell as a {@link WebXRLayerRenderTargetTexture} for the single-view path so\n * each eye can bind its own array layer of a layered projection-layer texture. Multiview is not yet\n * supported on this WebGPU path and is delegated to the base implementation.\n * @param width the width of the render target\n * @param height the height of the render target\n * @param multiview whether the render target should be a multiview render target\n * @returns the created (but not yet registered) render target texture\n */\n protected override _createRenderTargetTextureShell(width: number, height: number, multiview: boolean): RenderTargetTexture {\n if (multiview) {\n return super._createRenderTargetTextureShell(width, height, multiview);\n }\n const renderTargetTexture = new WebXRLayerRenderTargetTexture(\"XR renderTargetTexture\", { width, height }, this._scene);\n renderTargetTexture.renderTarget!._samples = renderTargetTexture.samples;\n // The projection-layer texture is presented directly by the XR compositor (top-left origin, never\n // re-sampled by Babylon), so opt this target out of the engine's render-target Y-flip / winding\n // compensation and render it upright, matching the WebXR/WebGPU spec's plain render pass.\n (renderTargetTexture.renderTarget as WebGPURenderTargetWrapper)._disableEngineYFlip = true;\n return renderTargetTexture;\n }\n\n /**\n * Wraps the sub-image's color (and optional depth/stencil) GPUTextures and builds a new render target\n * texture around them. Use this on first creation and whenever the sub-image texture size changes.\n * @param width the width of the render target\n * @param height the height of the render target\n * @param colorTexture the sub-image color GPUTexture\n * @param depthStencilTexture the sub-image depth/stencil GPUTexture, if any\n * @param depthStencilFormat the WebGPU depth/stencil format the layer was created with, if depth is provided\n * @param multiview whether the render target should be a multiview render target\n * @returns the created render target texture\n */\n protected _createRenderTargetTextureFromGPUTextures(\n width: number,\n height: number,\n colorTexture: GPUTexture,\n depthStencilTexture: Nullable<GPUTexture>,\n depthStencilFormat: GPUTextureFormat | undefined,\n multiview: boolean\n ): WebXRLayerRenderTargetTexture {\n const color = this._wrapColorTexture(colorTexture);\n const depth = depthStencilTexture && depthStencilFormat ? this._wrapDepthTexture(depthStencilTexture, depthStencilFormat) : null;\n // Single-view (the only path here) always builds a WebXRLayerRenderTargetTexture via the shell override above.\n const renderTargetTexture = this._createRenderTargetTextureInternal(width, height, color, depth, multiview) as WebXRLayerRenderTargetTexture;\n this._attachPerEyeClearObserver(renderTargetTexture);\n return renderTargetTexture;\n }\n\n /**\n * Ensures this render target is cleared every frame, including for the right eye.\n *\n * `Scene._clearFrameBuffer` skips clearing the right rig camera's framebuffer (`!camera.isRightCamera`).\n * That is a valid optimization for WebGL2 stereo, where both eyes render into a single side-by-side\n * texture and the left eye's full clear already covers the whole texture. WebGPU projection layers give\n * each eye its OWN render target (a distinct array layer rendered in a separate render pass), so the\n * right eye's color and — critically — depth would never be cleared, leaving its depth test to reject\n * every fragment (a black right eye). The scene notifies `onClearObservable` regardless of\n * `camera.isRightCamera`, so this observer clears both eyes' targets. WebGL providers never attach it,\n * so the WebGL path is unchanged.\n *\n * Color is cleared at most once per ENGINE FRAME, not once per `Scene.render`. The distinction matters:\n * more than one scene can render the same XR camera within a single XR frame. `UtilityLayerRenderer`\n * (used by controller pointer selection and near interaction) renders a second scene through the same\n * rig cameras, and every `Scene.render` resets `RenderTargetTexture._cleared` for those cameras' targets\n * (`Scene._checkCameraRenderTarget`), so a `_cleared`-based guard is defeated and each eye is re-cleared\n * after it was drawn — presenting a clear-colored frame with the geometry gone. `AbstractEngine.frameId`\n * only advances in `endFrame`, once per XR frame, so unlike `_cleared` it cannot be reset by another\n * scene rendering the same camera.\n *\n * In immersive AR, color is cleared to transparent when `WebXRExperienceHelper` disables\n * `Scene.autoClear`. WebGL XR framebuffers are cleared to transparent by the user agent, but WebGPU render\n * passes require the application to request that clear explicitly. Skipping it leaves pixels from prior\n * frames in passthrough regions, producing trails behind moving objects.\n *\n * Depth and stencil are still cleared on every notification, matching the previous behavior and the\n * expectations of overlay scenes that draw on top of the main scene.\n * @param renderTargetTexture the per-eye render target to clear each frame\n */\n private _attachPerEyeClearObserver(renderTargetTexture: RenderTargetTexture): void {\n let lastColorClearedFrameId = -1;\n renderTargetTexture.onClearObservable.add((engine) => {\n // Honor skipInitialClear so this observer preserves the default clear semantics it replaces.\n if (renderTargetTexture.skipInitialClear) {\n return;\n }\n const scene = renderTargetTexture.getScene();\n const isImmersiveAR = this._xrSessionManager.sessionMode === \"immersive-ar\";\n // When autoClear is disabled the scene does not clear render targets; match that so this observer\n // does not force a clear the user opted out of. Immersive AR is the exception: the experience\n // helper disables autoClear because WebGL XR is cleared by the user agent, while WebGPU is not.\n if (scene && !scene.autoClear && !isImmersiveAR) {\n return;\n }\n const clearColor = engine.frameId !== lastColorClearedFrameId;\n const color = isImmersiveAR && scene && !scene.autoClear ? this._transparentClearColor : (renderTargetTexture.clearColor ?? scene?.clearColor ?? null);\n engine.clear(color, clearColor, true, true);\n if (clearColor) {\n lastColorClearedFrameId = engine.frameId;\n }\n // Kept in sync so anything else reading the flag still sees this target as cleared this frame.\n renderTargetTexture._cleared = true;\n });\n }\n\n /**\n * Repoints the wrapped color/depth textures of an existing render target at the current frame's\n * GPUTextures, preserving the RenderTargetTexture / InternalTexture identity held by the XR camera's\n * `outputRenderTarget`. The sub-image textures are only valid for the current frame and may rotate from\n * a compositor pool, so this must run every frame. The new GPUTextures must have the same dimensions as\n * the wrapped ones (guaranteed by the caller's size-change branch, which rebuilds instead).\n * @param renderTargetTexture the render target whose wrapped textures should be repointed\n * @param colorTexture the current frame's color GPUTexture\n * @param depthStencilTexture the current frame's depth/stencil GPUTexture, if any\n */\n protected _updateRenderTargetTextureFromGPUTextures(renderTargetTexture: RenderTargetTexture, colorTexture: GPUTexture, depthStencilTexture: Nullable<GPUTexture>): void {\n const color = renderTargetTexture._texture;\n if (color) {\n this._webgpuEngine.updateWrappedWebGPUTexture(color, colorTexture);\n }\n const depth = renderTargetTexture.renderTarget?._depthStencilTexture;\n if (depth && depthStencilTexture) {\n this._webgpuEngine.updateWrappedWebGPUTexture(depth, depthStencilTexture);\n }\n }\n}\n"]}
|