@onerjs/core 8.54.3 → 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/DeviceInput/webDeviceInputSystem.js +4 -0
- package/DeviceInput/webDeviceInputSystem.js.map +1 -1
- 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/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js +3 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.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 +487 -54
- 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 +48 -10
- 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/Meshes/abstractMesh.pure.js +5 -3
- package/Meshes/abstractMesh.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/Plugins/havokPlugin.d.ts +15 -0
- package/Physics/v2/Plugins/havokPlugin.js +16 -6
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/characterController.js +71 -19
- package/Physics/v2/characterController.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/clusteredLightingCompute.d.ts +5 -0
- package/ShadersWGSL/ShadersInclude/clusteredLightingCompute.js +29 -0
- package/ShadersWGSL/ShadersInclude/clusteredLightingCompute.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/lightFragment.js +2 -3
- package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.d.ts +1 -0
- package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.js +2 -17
- package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.d.ts +6 -0
- package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.js +123 -0
- package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.d.ts +1 -1
- package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js +2 -111
- package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
- package/ShadersWGSL/background.fragment.js +2 -1
- package/ShadersWGSL/background.fragment.js.map +1 -1
- package/ShadersWGSL/default.fragment.js +2 -1
- package/ShadersWGSL/default.fragment.js.map +1 -1
- package/ShadersWGSL/openpbr.fragment.js +2 -1
- package/ShadersWGSL/openpbr.fragment.js.map +1 -1
- package/ShadersWGSL/pbr.fragment.js +2 -1
- package/ShadersWGSL/pbr.fragment.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
- package/scene.pure.d.ts +7 -0
- package/scene.pure.js +8 -0
- package/scene.pure.js.map +1 -1
|
@@ -37,14 +37,22 @@ class DepthSensingMaterialDefines extends MaterialDefines {
|
|
|
37
37
|
}
|
|
38
38
|
let IsPluginEnabled = false;
|
|
39
39
|
let DepthTexture = null;
|
|
40
|
+
let DepthTextureRight = null;
|
|
40
41
|
let AlphaLuminanceTexture = false;
|
|
41
42
|
const ScreenSize = { width: 512, height: 512 };
|
|
42
43
|
const ShaderViewport = { x: 0, y: 0, width: 1, height: 1 };
|
|
43
44
|
let GlobalRawValueToMeters = 1;
|
|
45
|
+
let GlobalRawValueToMetersRight = 1;
|
|
46
|
+
let GlobalDepthAvailableLeft = 0;
|
|
47
|
+
let GlobalDepthAvailableRight = 0;
|
|
48
|
+
let GlobalWorldScale = 1;
|
|
44
49
|
let ViewIndex = 0;
|
|
45
50
|
let EnableDiscard = true;
|
|
46
51
|
const UvTransform = /*#__PURE__*/ Matrix.Identity();
|
|
52
|
+
const UvTransformRight = /*#__PURE__*/ Matrix.Identity();
|
|
53
|
+
const RightView = /*#__PURE__*/ Matrix.Identity();
|
|
47
54
|
const ManagedMaterialPlugins = [];
|
|
55
|
+
const WebGPUGPUDepthWarning = "WebXR Depth Sensing is unavailable with WebGPU XR when the session negotiates gpu-optimized depth because XRGPUBinding has no environment-depth equivalent; request cpu-optimized depth to use the feature.";
|
|
48
56
|
/**
|
|
49
57
|
* @internal
|
|
50
58
|
*/
|
|
@@ -79,11 +87,10 @@ class WebXRDepthSensingMaterialPlugin extends MaterialPluginBase {
|
|
|
79
87
|
isCompatible(shaderLanguage) {
|
|
80
88
|
switch (shaderLanguage) {
|
|
81
89
|
case 0 /* ShaderLanguage.GLSL */:
|
|
90
|
+
case 1 /* ShaderLanguage.WGSL */:
|
|
82
91
|
return true;
|
|
83
92
|
default:
|
|
84
|
-
|
|
85
|
-
// webxr is currently only supported on webgl, and the plugin is disabled per default.
|
|
86
|
-
return true;
|
|
93
|
+
return false;
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
constructor(material) {
|
|
@@ -103,44 +110,175 @@ class WebXRDepthSensingMaterialPlugin extends MaterialPluginBase {
|
|
|
103
110
|
defines.DEPTH_SENSING_TEXTURE_AL = AlphaLuminanceTexture;
|
|
104
111
|
defines.DEPTH_SENSING_DISCARD = EnableDiscard;
|
|
105
112
|
}
|
|
106
|
-
getUniforms() {
|
|
113
|
+
getUniforms(shaderLanguage = 0 /* ShaderLanguage.GLSL */) {
|
|
114
|
+
const ubo = [
|
|
115
|
+
{ name: "ds_invScreenSize", size: 2, type: "vec2" },
|
|
116
|
+
{ name: "ds_rawValueToMeters", size: 1, type: "float" },
|
|
117
|
+
{ name: "ds_viewIndex", size: 1, type: "float" },
|
|
118
|
+
{ name: "ds_shaderViewport", size: 4, type: "vec4" },
|
|
119
|
+
{ name: "ds_uvTransform", size: 16, type: "mat4" },
|
|
120
|
+
];
|
|
121
|
+
if (shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
|
|
122
|
+
ubo.push({ name: "ds_rawValueToMetersRight", size: 1, type: "float" }, { name: "ds_depthAvailableLeft", size: 1, type: "float" }, { name: "ds_depthAvailableRight", size: 1, type: "float" }, { name: "ds_worldScale", size: 1, type: "float" }, { name: "ds_viewDepthSign", size: 1, type: "float" }, { name: "ds_uvTransformRight", size: 16, type: "mat4" }, { name: "ds_viewRight", size: 16, type: "mat4" });
|
|
123
|
+
}
|
|
107
124
|
return {
|
|
108
125
|
// first, define the UBO with the correct type and size.
|
|
109
|
-
ubo
|
|
110
|
-
{ name: "ds_invScreenSize", size: 2, type: "vec2" },
|
|
111
|
-
{ name: "ds_rawValueToMeters", size: 1, type: "float" },
|
|
112
|
-
{ name: "ds_viewIndex", size: 1, type: "float" },
|
|
113
|
-
{ name: "ds_shaderViewport", size: 4, type: "vec4" },
|
|
114
|
-
{ name: "ds_uvTransform", size: 16, type: "mat4" },
|
|
115
|
-
],
|
|
126
|
+
ubo,
|
|
116
127
|
// now, on the fragment shader, add the uniform itself in case uniform buffers are not supported by the engine
|
|
117
|
-
fragment:
|
|
128
|
+
fragment: shaderLanguage === 0 /* ShaderLanguage.GLSL */
|
|
129
|
+
? `#ifdef DEPTH_SENSING
|
|
118
130
|
uniform vec2 ds_invScreenSize;
|
|
119
131
|
uniform float ds_rawValueToMeters;
|
|
120
132
|
uniform float ds_viewIndex;
|
|
121
133
|
uniform vec4 ds_shaderViewport;
|
|
122
134
|
uniform mat4 ds_uvTransform;
|
|
123
135
|
#endif
|
|
124
|
-
|
|
136
|
+
`
|
|
137
|
+
: "",
|
|
125
138
|
};
|
|
126
139
|
}
|
|
127
140
|
getSamplers(samplers) {
|
|
128
141
|
samplers.push("ds_depthSampler");
|
|
142
|
+
samplers.push("ds_depthSamplerRight");
|
|
129
143
|
}
|
|
130
144
|
bindForSubMesh(uniformBuffer) {
|
|
131
145
|
if (IsPluginEnabled && DepthTexture) {
|
|
146
|
+
const isWGSL = this._material.shaderLanguage === 1 /* ShaderLanguage.WGSL */;
|
|
132
147
|
uniformBuffer.updateFloat2("ds_invScreenSize", 1 / ScreenSize.width, 1 / ScreenSize.height);
|
|
133
148
|
uniformBuffer.updateFloat("ds_rawValueToMeters", GlobalRawValueToMeters);
|
|
134
149
|
uniformBuffer.updateFloat("ds_viewIndex", ViewIndex);
|
|
135
150
|
uniformBuffer.updateFloat4("ds_shaderViewport", ShaderViewport.x, ShaderViewport.y, ShaderViewport.width, ShaderViewport.height);
|
|
136
151
|
uniformBuffer.setTexture("ds_depthSampler", DepthTexture);
|
|
137
152
|
uniformBuffer.updateMatrix("ds_uvTransform", UvTransform);
|
|
153
|
+
if (isWGSL) {
|
|
154
|
+
uniformBuffer.updateFloat("ds_rawValueToMetersRight", GlobalRawValueToMetersRight);
|
|
155
|
+
uniformBuffer.updateFloat("ds_depthAvailableLeft", GlobalDepthAvailableLeft);
|
|
156
|
+
uniformBuffer.updateFloat("ds_depthAvailableRight", GlobalDepthAvailableRight);
|
|
157
|
+
uniformBuffer.updateFloat("ds_worldScale", GlobalWorldScale);
|
|
158
|
+
uniformBuffer.updateFloat("ds_viewDepthSign", this._material.getScene().useRightHandedSystem ? -1 : 1);
|
|
159
|
+
uniformBuffer.setTexture("ds_depthSamplerRight", DepthTextureRight);
|
|
160
|
+
uniformBuffer.updateMatrix("ds_uvTransformRight", UvTransformRight);
|
|
161
|
+
uniformBuffer.updateMatrix("ds_viewRight", RightView);
|
|
162
|
+
}
|
|
138
163
|
}
|
|
139
164
|
}
|
|
140
165
|
getClassName() {
|
|
141
166
|
return "DepthSensingMaterialPlugin";
|
|
142
167
|
}
|
|
143
|
-
getCustomCode(shaderType) {
|
|
168
|
+
getCustomCode(shaderType, shaderLanguage = 0 /* ShaderLanguage.GLSL */) {
|
|
169
|
+
if (shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
|
|
170
|
+
return shaderType === "vertex"
|
|
171
|
+
? {
|
|
172
|
+
CUSTOM_VERTEX_MAIN_BEGIN: `
|
|
173
|
+
#ifdef DEPTH_SENSING
|
|
174
|
+
#ifdef MULTIVIEW
|
|
175
|
+
vertexOutputs.ds_viewIndexMultiview = f32(gl_ViewID_OVR);
|
|
176
|
+
#endif
|
|
177
|
+
#endif
|
|
178
|
+
`,
|
|
179
|
+
CUSTOM_VERTEX_DEFINITIONS: `
|
|
180
|
+
#ifdef DEPTH_SENSING
|
|
181
|
+
#ifdef MULTIVIEW
|
|
182
|
+
varying ds_viewIndexMultiview: f32;
|
|
183
|
+
#endif
|
|
184
|
+
#endif
|
|
185
|
+
`,
|
|
186
|
+
}
|
|
187
|
+
: {
|
|
188
|
+
CUSTOM_FRAGMENT_DEFINITIONS: `
|
|
189
|
+
#ifdef DEPTH_SENSING
|
|
190
|
+
#ifdef DEPTH_SENSING_TEXTURE_ARRAY
|
|
191
|
+
var ds_depthSampler: texture_2d_array<f32>;
|
|
192
|
+
#else
|
|
193
|
+
var ds_depthSampler: texture_2d<f32>;
|
|
194
|
+
#endif
|
|
195
|
+
var ds_depthSamplerSampler: sampler;
|
|
196
|
+
#if defined(MULTIVIEW) && !defined(DEPTH_SENSING_TEXTURE_ARRAY)
|
|
197
|
+
var ds_depthSamplerRight: texture_2d<f32>;
|
|
198
|
+
var ds_depthSamplerRightSampler: sampler;
|
|
199
|
+
#endif
|
|
200
|
+
#ifdef MULTIVIEW
|
|
201
|
+
varying ds_viewIndexMultiview: f32;
|
|
202
|
+
#endif
|
|
203
|
+
#endif
|
|
204
|
+
`,
|
|
205
|
+
CUSTOM_FRAGMENT_MAIN_BEGIN: `
|
|
206
|
+
#ifdef DEPTH_SENSING
|
|
207
|
+
#ifdef MULTIVIEW
|
|
208
|
+
let ds_viewIndexSet: f32 = fragmentInputs.ds_viewIndexMultiview;
|
|
209
|
+
let ds_compensation: vec2f = vec2f(0.0, 0.0);
|
|
210
|
+
#else
|
|
211
|
+
let ds_viewIndexSet: f32 = uniforms.ds_viewIndex;
|
|
212
|
+
let ds_compensation: vec2f = vec2f(ds_viewIndexSet, 0.0);
|
|
213
|
+
#endif
|
|
214
|
+
let ds_baseUvBottomLeft: vec2f = (fragmentInputs.position.xy * uniforms.ds_invScreenSize - uniforms.ds_shaderViewport.xy) / uniforms.ds_shaderViewport.zw;
|
|
215
|
+
let ds_baseUv: vec2f = vec2f(ds_baseUvBottomLeft.x, 1.0 - ds_baseUvBottomLeft.y);
|
|
216
|
+
var ds_depthSample: vec4f = vec4f(0.0);
|
|
217
|
+
var ds_rawValueToMetersSet: f32 = uniforms.ds_rawValueToMeters;
|
|
218
|
+
#if defined(MULTIVIEW) && !defined(DEPTH_SENSING_TEXTURE_ARRAY)
|
|
219
|
+
var ds_depthAvailable: f32 = uniforms.ds_depthAvailableLeft;
|
|
220
|
+
if (ds_viewIndexSet < 0.5) {
|
|
221
|
+
if (ds_depthAvailable > 0.5) {
|
|
222
|
+
let ds_depthUv: vec2f = (uniforms.ds_uvTransform * vec4f(ds_baseUv, 0.0, 1.0)).xy;
|
|
223
|
+
ds_depthSample = textureSampleLevel(ds_depthSampler, ds_depthSamplerSampler, ds_depthUv, 0.0);
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
ds_depthAvailable = uniforms.ds_depthAvailableRight;
|
|
227
|
+
if (ds_depthAvailable > 0.5) {
|
|
228
|
+
let ds_depthUv: vec2f = (uniforms.ds_uvTransformRight * vec4f(ds_baseUv, 0.0, 1.0)).xy;
|
|
229
|
+
ds_depthSample = textureSampleLevel(ds_depthSamplerRight, ds_depthSamplerRightSampler, ds_depthUv, 0.0);
|
|
230
|
+
}
|
|
231
|
+
ds_rawValueToMetersSet = uniforms.ds_rawValueToMetersRight;
|
|
232
|
+
}
|
|
233
|
+
#else
|
|
234
|
+
let ds_depthAvailable: f32 = 1.0;
|
|
235
|
+
#ifdef DEPTH_SENSING_TEXTURE_ARRAY
|
|
236
|
+
let ds_uv: vec2f = ds_baseUv - ds_compensation;
|
|
237
|
+
let ds_depthUv: vec2f = (uniforms.ds_uvTransform * vec4f(ds_uv, 0.0, 1.0)).xy;
|
|
238
|
+
ds_depthSample = textureSample(ds_depthSampler, ds_depthSamplerSampler, ds_depthUv, i32(ds_viewIndexSet));
|
|
239
|
+
#else
|
|
240
|
+
let ds_depthUv: vec2f = (uniforms.ds_uvTransform * vec4f(ds_baseUv, 0.0, 1.0)).xy;
|
|
241
|
+
ds_depthSample = textureSample(ds_depthSampler, ds_depthSamplerSampler, ds_depthUv);
|
|
242
|
+
#endif
|
|
243
|
+
#endif
|
|
244
|
+
var ds_cameraDepth: f32;
|
|
245
|
+
#ifdef DEPTH_SENSING_TEXTURE_AL
|
|
246
|
+
let ds_alphaLuminance: vec2f = ds_depthSample.ra;
|
|
247
|
+
ds_cameraDepth = dot(ds_alphaLuminance, vec2f(255.0, 256.0 * 255.0));
|
|
248
|
+
#else
|
|
249
|
+
ds_cameraDepth = ds_depthSample.r;
|
|
250
|
+
#endif
|
|
251
|
+
|
|
252
|
+
ds_cameraDepth = ds_cameraDepth * ds_rawValueToMetersSet;
|
|
253
|
+
|
|
254
|
+
var ds_viewPosition: vec4f = scene.view * vec4f(fragmentInputs.vPositionW, 1.0);
|
|
255
|
+
#ifdef MULTIVIEW
|
|
256
|
+
if (ds_viewIndexSet >= 0.5) {
|
|
257
|
+
ds_viewPosition = uniforms.ds_viewRight * vec4f(fragmentInputs.vPositionW, 1.0);
|
|
258
|
+
}
|
|
259
|
+
#endif
|
|
260
|
+
let ds_assetDepth: f32 = (ds_viewPosition.z * uniforms.ds_viewDepthSign) / uniforms.ds_worldScale;
|
|
261
|
+
#ifdef DEPTH_SENSING_DISCARD
|
|
262
|
+
if (ds_depthAvailable > 0.5 && ds_cameraDepth > 0.0 && ds_cameraDepth < ds_assetDepth) {
|
|
263
|
+
discard;
|
|
264
|
+
}
|
|
265
|
+
#endif
|
|
266
|
+
#endif
|
|
267
|
+
`,
|
|
268
|
+
CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: `
|
|
269
|
+
#ifdef DEPTH_SENSING
|
|
270
|
+
#ifndef DEPTH_SENSING_DISCARD
|
|
271
|
+
if (ds_depthAvailable > 0.5 && ds_cameraDepth > 0.0) {
|
|
272
|
+
let ds_depthTolerancePerM: f32 = 0.005;
|
|
273
|
+
let ds_occlusion: f32 = clamp(1.0 - 0.5 * (ds_cameraDepth - ds_assetDepth) / (ds_depthTolerancePerM * ds_assetDepth) +
|
|
274
|
+
0.5, 0.0, 1.0);
|
|
275
|
+
${this._varColorName} *= (1.0 - ds_occlusion);
|
|
276
|
+
}
|
|
277
|
+
#endif
|
|
278
|
+
#endif
|
|
279
|
+
`,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
144
282
|
return shaderType === "vertex"
|
|
145
283
|
? {
|
|
146
284
|
CUSTOM_VERTEX_MAIN_BEGIN: `
|
|
@@ -320,7 +458,12 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
320
458
|
this._cachedDepthBuffer = null;
|
|
321
459
|
this._cachedWebGLTexture = null;
|
|
322
460
|
this._cachedDepthImageTexture = null;
|
|
461
|
+
this._cachedDepthImageTextureWrapsExternalTexture = false;
|
|
462
|
+
this._cpuDepthViewStates = [];
|
|
463
|
+
this._disableAutoAttachBeforeWebGPUGPUDepth = false;
|
|
464
|
+
this._disabledForWebGPUGPUDepth = false;
|
|
323
465
|
this._onCameraObserver = null;
|
|
466
|
+
this._onSessionEndedObserver = null;
|
|
324
467
|
/**
|
|
325
468
|
* Event that notify when `DepthInformation.getDepthInMeters` is available.
|
|
326
469
|
* `getDepthInMeters` method needs active XRFrame (not available for cached XRFrame)
|
|
@@ -328,9 +471,17 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
328
471
|
this.onGetDepthInMetersAvailable = new Observable();
|
|
329
472
|
this.xrNativeFeatureName = "depth-sensing";
|
|
330
473
|
// https://immersive-web.github.io/depth-sensing/
|
|
331
|
-
|
|
474
|
+
if (!this._xrSessionManager.scene.getEngine().isWebGPU) {
|
|
475
|
+
Logger.Warn("depth-sensing is an experimental and unstable feature.");
|
|
476
|
+
}
|
|
332
477
|
EnableDiscard = !options.useToleranceFactorForDepthSensing;
|
|
333
478
|
RegisterMaterialPlugin("WebXRDepthSensingMaterialPlugin", (material) => new WebXRDepthSensingMaterialPlugin(material));
|
|
479
|
+
this._onSessionEndedObserver = this._xrSessionManager.onXRSessionEnded.add(() => {
|
|
480
|
+
if (this._disabledForWebGPUGPUDepth) {
|
|
481
|
+
this._disabledForWebGPUGPUDepth = false;
|
|
482
|
+
this.disableAutoAttach = this._disableAutoAttachBeforeWebGPUGPUDepth;
|
|
483
|
+
}
|
|
484
|
+
});
|
|
334
485
|
}
|
|
335
486
|
/**
|
|
336
487
|
* attach this feature
|
|
@@ -339,14 +490,31 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
339
490
|
* @returns true if successful.
|
|
340
491
|
*/
|
|
341
492
|
attach(force) {
|
|
342
|
-
|
|
493
|
+
const engine = this._xrSessionManager.scene.getEngine();
|
|
494
|
+
const depthUsage = this._xrSessionManager.session.depthUsage;
|
|
495
|
+
const depthDataFormat = this._xrSessionManager.session.depthDataFormat;
|
|
496
|
+
if (engine.isWebGPU && depthUsage === "gpu-optimized") {
|
|
497
|
+
if (this._disabledForWebGPUGPUDepth) {
|
|
498
|
+
this.disableAutoAttach = true;
|
|
499
|
+
return false;
|
|
500
|
+
}
|
|
501
|
+
this._disableAutoAttachBeforeWebGPUGPUDepth = this._autoAttachPolicyBeforeAttach ?? this.disableAutoAttach;
|
|
502
|
+
this._disabledForWebGPUGPUDepth = true;
|
|
503
|
+
return this._disableAutoAttach(WebGPUGPUDepthWarning);
|
|
504
|
+
}
|
|
505
|
+
if (depthUsage == null || depthDataFormat == null) {
|
|
343
506
|
return false;
|
|
344
507
|
}
|
|
345
|
-
|
|
346
|
-
if (isBothDepthUsageAndFormatNull) {
|
|
508
|
+
if (!super.attach(force)) {
|
|
347
509
|
return false;
|
|
348
510
|
}
|
|
349
|
-
|
|
511
|
+
if (!engine.isWebGPU) {
|
|
512
|
+
const graphicsBinding = this._xrSessionManager._getGraphicsBinding();
|
|
513
|
+
if (graphicsBinding.bindingType !== 0 /* WebXRGraphicsBindingType.WebGL */) {
|
|
514
|
+
throw new Error("Expected a WebGL graphics binding for WebXR Depth Sensing.");
|
|
515
|
+
}
|
|
516
|
+
this._glBinding = graphicsBinding.binding;
|
|
517
|
+
}
|
|
350
518
|
IsPluginEnabled = !this.options.disableDepthSensingOnMaterials;
|
|
351
519
|
if (IsPluginEnabled) {
|
|
352
520
|
for (const plugin of ManagedMaterialPlugins) {
|
|
@@ -359,16 +527,28 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
359
527
|
// make sure this is a webxr camera
|
|
360
528
|
if (camera.outputRenderTarget) {
|
|
361
529
|
const viewport = camera.rigCameras.length > 0 ? camera.rigCameras[0].viewport : camera.viewport;
|
|
362
|
-
ScreenSize.width = camera.outputRenderTarget.getRenderWidth() / (camera.rigParent ? camera.rigParent.rigCameras.length || 1 : 1);
|
|
530
|
+
ScreenSize.width = camera.outputRenderTarget.getRenderWidth() / (!engine.isWebGPU && camera.rigParent ? camera.rigParent.rigCameras.length || 1 : 1);
|
|
363
531
|
ScreenSize.height = camera.outputRenderTarget.getRenderHeight();
|
|
364
532
|
ShaderViewport.x = viewport.x;
|
|
365
533
|
ShaderViewport.y = viewport.y;
|
|
366
534
|
ShaderViewport.width = viewport.width;
|
|
367
535
|
ShaderViewport.height = viewport.height;
|
|
536
|
+
GlobalWorldScale = this._xrSessionManager.worldScalingFactor;
|
|
368
537
|
// find the viewIndex
|
|
369
538
|
if (camera.rigParent) {
|
|
370
|
-
|
|
371
|
-
ViewIndex =
|
|
539
|
+
const viewIndex = camera.rigParent.rigCameras.indexOf(camera);
|
|
540
|
+
ViewIndex = viewIndex === -1 ? 0 : viewIndex;
|
|
541
|
+
if (engine.isWebGPU && this.depthUsage === "cpu") {
|
|
542
|
+
this._bindCPUDepthView(ViewIndex, false);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
else if (camera._renderingMultiview && engine.isWebGPU && this.depthUsage === "cpu") {
|
|
546
|
+
ViewIndex = 0;
|
|
547
|
+
const rightCamera = camera.rigCameras[1];
|
|
548
|
+
if (rightCamera) {
|
|
549
|
+
RightView.copyFrom(rightCamera.getViewMatrix());
|
|
550
|
+
}
|
|
551
|
+
this._bindCPUDepthView(0, true);
|
|
372
552
|
}
|
|
373
553
|
}
|
|
374
554
|
});
|
|
@@ -378,13 +558,34 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
378
558
|
detach() {
|
|
379
559
|
IsPluginEnabled = false;
|
|
380
560
|
DepthTexture = null;
|
|
561
|
+
DepthTextureRight = null;
|
|
381
562
|
this._cachedWebGLTexture = null;
|
|
382
563
|
this._cachedDepthBuffer = null;
|
|
564
|
+
this._width = null;
|
|
565
|
+
this._height = null;
|
|
566
|
+
this._rawValueToMeters = null;
|
|
567
|
+
this._textureType = null;
|
|
568
|
+
this._normDepthBufferFromNormView = null;
|
|
569
|
+
let cachedTextureDisposed = false;
|
|
570
|
+
for (const viewState of this._cpuDepthViewStates) {
|
|
571
|
+
viewState.texture?.dispose();
|
|
572
|
+
cachedTextureDisposed || (cachedTextureDisposed = viewState.texture === this._cachedDepthImageTexture);
|
|
573
|
+
}
|
|
574
|
+
this._cpuDepthViewStates.length = 0;
|
|
575
|
+
if (!cachedTextureDisposed) {
|
|
576
|
+
if (this._cachedDepthImageTextureWrapsExternalTexture && this._cachedDepthImageTexture?._texture) {
|
|
577
|
+
this._cachedDepthImageTexture._texture._hardwareTexture = null;
|
|
578
|
+
}
|
|
579
|
+
this._cachedDepthImageTexture?.dispose();
|
|
580
|
+
}
|
|
581
|
+
this._cachedDepthImageTexture = null;
|
|
582
|
+
this._cachedDepthImageTextureWrapsExternalTexture = false;
|
|
383
583
|
for (const plugin of ManagedMaterialPlugins) {
|
|
384
584
|
plugin.isEnabled = false;
|
|
385
585
|
}
|
|
386
586
|
if (this._onCameraObserver) {
|
|
387
587
|
this._xrSessionManager.scene.onBeforeCameraRenderObservable.remove(this._onCameraObserver);
|
|
588
|
+
this._onCameraObserver = null;
|
|
388
589
|
}
|
|
389
590
|
return super.detach();
|
|
390
591
|
}
|
|
@@ -392,9 +593,12 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
392
593
|
* Dispose this feature and all of the resources attached
|
|
393
594
|
*/
|
|
394
595
|
dispose() {
|
|
596
|
+
if (this._onSessionEndedObserver) {
|
|
597
|
+
this._xrSessionManager.onXRSessionEnded.remove(this._onSessionEndedObserver);
|
|
598
|
+
this._onSessionEndedObserver = null;
|
|
599
|
+
}
|
|
395
600
|
super.dispose();
|
|
396
601
|
UnregisterMaterialPlugin("WebXRDepthSensingMaterialPlugin");
|
|
397
|
-
this._cachedDepthImageTexture?.dispose();
|
|
398
602
|
this.onGetDepthInMetersAvailable.clear();
|
|
399
603
|
// cleanup
|
|
400
604
|
if (this._onCameraObserver) {
|
|
@@ -407,14 +611,24 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
407
611
|
}
|
|
408
612
|
_onXRFrame(_xrFrame) {
|
|
409
613
|
const referenceSPace = this._xrSessionManager.referenceSpace;
|
|
614
|
+
const depthUsage = this.depthUsage;
|
|
615
|
+
if (depthUsage === "cpu") {
|
|
616
|
+
for (const viewState of this._cpuDepthViewStates) {
|
|
617
|
+
viewState.available = false;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
410
620
|
const pose = _xrFrame.getViewerPose(referenceSPace);
|
|
411
621
|
if (pose == null) {
|
|
622
|
+
if (depthUsage === "cpu") {
|
|
623
|
+
this._clearCPUDepthBinding();
|
|
624
|
+
}
|
|
412
625
|
return;
|
|
413
626
|
}
|
|
414
|
-
for (
|
|
415
|
-
|
|
627
|
+
for (let viewIndex = 0; viewIndex < pose.views.length; viewIndex++) {
|
|
628
|
+
const view = pose.views[viewIndex];
|
|
629
|
+
switch (depthUsage) {
|
|
416
630
|
case "cpu":
|
|
417
|
-
this._updateDepthInformationAndTextureCPUDepthUsage(_xrFrame, view, this.depthDataFormat);
|
|
631
|
+
this._updateDepthInformationAndTextureCPUDepthUsage(_xrFrame, view, viewIndex, this.depthDataFormat);
|
|
418
632
|
break;
|
|
419
633
|
case "gpu":
|
|
420
634
|
if (!this._glBinding) {
|
|
@@ -428,43 +642,138 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
428
642
|
break;
|
|
429
643
|
}
|
|
430
644
|
}
|
|
645
|
+
if (depthUsage === "cpu" && !this._cpuDepthViewStates.some((viewState) => viewState.available)) {
|
|
646
|
+
this._clearCPUDepthBinding();
|
|
647
|
+
}
|
|
431
648
|
}
|
|
432
|
-
_updateDepthInformationAndTextureCPUDepthUsage(frame, view, dataFormat) {
|
|
649
|
+
_updateDepthInformationAndTextureCPUDepthUsage(frame, view, viewIndex, dataFormat) {
|
|
433
650
|
const depthInfo = frame.getDepthInformation(view);
|
|
434
|
-
if (depthInfo
|
|
651
|
+
if (depthInfo == null) {
|
|
435
652
|
return;
|
|
436
653
|
}
|
|
437
654
|
const { data, width, height, rawValueToMeters, getDepthInMeters, normDepthBufferFromNormView } = depthInfo;
|
|
655
|
+
let viewState = this._cpuDepthViewStates[viewIndex];
|
|
656
|
+
if (!viewState) {
|
|
657
|
+
viewState = {
|
|
658
|
+
available: true,
|
|
659
|
+
height,
|
|
660
|
+
rawValueToMeters,
|
|
661
|
+
texture: null,
|
|
662
|
+
uvTransform: Matrix.Identity(),
|
|
663
|
+
visualizationDepthBuffer: null,
|
|
664
|
+
width,
|
|
665
|
+
};
|
|
666
|
+
this._cpuDepthViewStates[viewIndex] = viewState;
|
|
667
|
+
}
|
|
668
|
+
const textureSizeChanged = viewState.width !== width || viewState.height !== height;
|
|
438
669
|
this._width = width;
|
|
439
670
|
this._height = height;
|
|
440
671
|
this._rawValueToMeters = rawValueToMeters;
|
|
672
|
+
this._normDepthBufferFromNormView = normDepthBufferFromNormView;
|
|
441
673
|
this._cachedDepthBuffer = data;
|
|
442
|
-
GlobalRawValueToMeters = rawValueToMeters;
|
|
443
674
|
AlphaLuminanceTexture = dataFormat === "luminance-alpha";
|
|
444
|
-
|
|
675
|
+
viewState.height = height;
|
|
676
|
+
viewState.available = true;
|
|
677
|
+
viewState.rawValueToMeters = rawValueToMeters;
|
|
678
|
+
viewState.uvTransform.fromArray(normDepthBufferFromNormView.matrix);
|
|
679
|
+
viewState.width = width;
|
|
445
680
|
// to avoid Illegal Invocation error, bind `this`
|
|
446
681
|
this.onGetDepthInMetersAvailable.notifyObservers(getDepthInMeters.bind(depthInfo));
|
|
447
|
-
if (!
|
|
448
|
-
|
|
449
|
-
|
|
682
|
+
if (!viewState.texture || textureSizeChanged) {
|
|
683
|
+
viewState.texture?.dispose();
|
|
684
|
+
viewState.texture = RawTexture.CreateRTexture(null, width, height, this._xrSessionManager.scene, false, false, Texture.NEAREST_SAMPLINGMODE, 1);
|
|
450
685
|
}
|
|
451
|
-
|
|
686
|
+
this._cachedDepthImageTextureWrapsExternalTexture = false;
|
|
687
|
+
this._cachedDepthImageTexture = viewState.texture;
|
|
688
|
+
let depthValues = null;
|
|
452
689
|
switch (dataFormat) {
|
|
453
690
|
case "ushort":
|
|
454
691
|
case "luminance-alpha":
|
|
455
|
-
|
|
692
|
+
depthValues = new Uint16Array(data);
|
|
456
693
|
break;
|
|
457
694
|
case "float":
|
|
458
|
-
|
|
695
|
+
depthValues = new Float32Array(data);
|
|
459
696
|
break;
|
|
460
697
|
default:
|
|
461
698
|
break;
|
|
462
699
|
}
|
|
463
|
-
if (
|
|
700
|
+
if (depthValues) {
|
|
701
|
+
let uploadData;
|
|
464
702
|
if (this.options.prepareTextureForVisualization) {
|
|
465
|
-
|
|
703
|
+
if (!viewState.visualizationDepthBuffer || viewState.visualizationDepthBuffer.length !== depthValues.length) {
|
|
704
|
+
viewState.visualizationDepthBuffer = new Float32Array(depthValues.length);
|
|
705
|
+
}
|
|
706
|
+
uploadData = viewState.visualizationDepthBuffer;
|
|
707
|
+
for (let index = 0; index < depthValues.length; index++) {
|
|
708
|
+
uploadData[index] = depthValues[index] * rawValueToMeters;
|
|
709
|
+
}
|
|
466
710
|
}
|
|
467
|
-
|
|
711
|
+
else {
|
|
712
|
+
uploadData = depthValues instanceof Float32Array ? depthValues : Float32Array.from(depthValues);
|
|
713
|
+
}
|
|
714
|
+
viewState.texture.update(uploadData);
|
|
715
|
+
}
|
|
716
|
+
if (!this._xrSessionManager.scene.getEngine().isWebGPU) {
|
|
717
|
+
const hadDepthTexture = !!DepthTexture;
|
|
718
|
+
DepthTexture = viewState.texture;
|
|
719
|
+
DepthTextureRight = null;
|
|
720
|
+
GlobalDepthAvailableLeft = 1;
|
|
721
|
+
GlobalDepthAvailableRight = 0;
|
|
722
|
+
GlobalRawValueToMeters = viewState.rawValueToMeters;
|
|
723
|
+
UvTransform.copyFrom(viewState.uvTransform);
|
|
724
|
+
if (!hadDepthTexture) {
|
|
725
|
+
this._xrSessionManager.scene.markAllMaterialsAsDirty(1);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
_clearCPUDepthBinding() {
|
|
730
|
+
if (DepthTexture) {
|
|
731
|
+
DepthTexture = null;
|
|
732
|
+
DepthTextureRight = null;
|
|
733
|
+
this._xrSessionManager.scene.markAllMaterialsAsDirty(1);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
_bindCPUDepthView(viewIndex, multiview) {
|
|
737
|
+
const leftViewState = this._cpuDepthViewStates[0];
|
|
738
|
+
const rightViewState = multiview ? this._cpuDepthViewStates[1] : null;
|
|
739
|
+
const viewState = multiview
|
|
740
|
+
? leftViewState?.available && leftViewState.texture
|
|
741
|
+
? leftViewState
|
|
742
|
+
: rightViewState?.available && rightViewState.texture
|
|
743
|
+
? rightViewState
|
|
744
|
+
: null
|
|
745
|
+
: this._cpuDepthViewStates[viewIndex];
|
|
746
|
+
if (!viewState?.available || !viewState.texture) {
|
|
747
|
+
this._clearCPUDepthBinding();
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const hadDepthTexture = !!DepthTexture;
|
|
751
|
+
if (multiview && leftViewState?.available && leftViewState.texture) {
|
|
752
|
+
GlobalDepthAvailableLeft = 1;
|
|
753
|
+
DepthTexture = leftViewState.texture;
|
|
754
|
+
GlobalRawValueToMeters = leftViewState.rawValueToMeters;
|
|
755
|
+
UvTransform.copyFrom(leftViewState.uvTransform);
|
|
756
|
+
}
|
|
757
|
+
else {
|
|
758
|
+
GlobalDepthAvailableLeft = multiview ? 0 : 1;
|
|
759
|
+
DepthTexture = viewState.texture;
|
|
760
|
+
GlobalRawValueToMeters = viewState.rawValueToMeters;
|
|
761
|
+
UvTransform.copyFrom(viewState.uvTransform);
|
|
762
|
+
}
|
|
763
|
+
if (multiview && rightViewState?.available && rightViewState.texture) {
|
|
764
|
+
GlobalDepthAvailableRight = 1;
|
|
765
|
+
DepthTextureRight = rightViewState.texture;
|
|
766
|
+
GlobalRawValueToMetersRight = rightViewState.rawValueToMeters;
|
|
767
|
+
UvTransformRight.copyFrom(rightViewState.uvTransform);
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
GlobalDepthAvailableRight = 0;
|
|
771
|
+
DepthTextureRight = viewState.texture;
|
|
772
|
+
GlobalRawValueToMetersRight = viewState.rawValueToMeters;
|
|
773
|
+
UvTransformRight.copyFrom(viewState.uvTransform);
|
|
774
|
+
}
|
|
775
|
+
if (!hadDepthTexture) {
|
|
776
|
+
this._xrSessionManager.scene.markAllMaterialsAsDirty(1);
|
|
468
777
|
}
|
|
469
778
|
}
|
|
470
779
|
_updateDepthInformationAndTextureWebGLDepthUsage(webglBinding, view, dataFormat) {
|
|
@@ -487,8 +796,10 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
487
796
|
const internalTexture = this._getInternalTextureFromDepthInfo();
|
|
488
797
|
if (!this._cachedDepthImageTexture) {
|
|
489
798
|
this._cachedDepthImageTexture = RawTexture.CreateRTexture(null, width, height, scene, false, true, Texture.NEAREST_SAMPLINGMODE, dataFormat === "float" ? 1 : 0);
|
|
799
|
+
this._cachedDepthImageTexture._texture?.dispose();
|
|
490
800
|
}
|
|
491
801
|
this._cachedDepthImageTexture._texture = internalTexture;
|
|
802
|
+
this._cachedDepthImageTextureWrapsExternalTexture = true;
|
|
492
803
|
DepthTexture = this._cachedDepthImageTexture;
|
|
493
804
|
this._xrSessionManager.scene.markAllMaterialsAsDirty(1);
|
|
494
805
|
}
|