@babylonjs/core 7.43.0 → 7.44.0
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/Actions/actionEvent.d.ts +4 -4
- package/Buffers/bufferUtils.d.ts +8 -1
- package/Buffers/bufferUtils.js +15 -0
- package/Buffers/bufferUtils.js.map +1 -1
- package/Culling/Helper/boundingInfoHelper.d.ts +2 -9
- package/Culling/Helper/boundingInfoHelper.js +2 -9
- package/Culling/Helper/boundingInfoHelper.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engine.d.ts +5 -2
- package/FlowGraph/flowGraphConnection.d.ts +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.d.ts +42 -0
- package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js +78 -0
- package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js.map +1 -0
- package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.d.ts +3 -19
- package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js +3 -49
- package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.d.ts +3 -19
- package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js +3 -49
- package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.d.ts +3 -19
- package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js +3 -49
- package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.d.ts +2 -17
- package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js +3 -45
- package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.d.ts +2 -17
- package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js +3 -44
- package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.d.ts +3 -19
- package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js +3 -49
- package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.d.ts +47 -0
- package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js +65 -0
- package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js.map +1 -0
- package/FrameGraph/Node/Blocks/index.d.ts +1 -0
- package/FrameGraph/Node/Blocks/index.js +1 -0
- package/FrameGraph/Node/Blocks/index.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/passTask.d.ts +29 -0
- package/FrameGraph/Tasks/PostProcesses/passTask.js +31 -0
- package/FrameGraph/Tasks/PostProcesses/passTask.js.map +1 -0
- package/FrameGraph/frameGraphTextureManager.d.ts +1 -1
- package/FrameGraph/index.d.ts +1 -0
- package/FrameGraph/index.js +1 -0
- package/FrameGraph/index.js.map +1 -1
- package/Gizmos/planeRotationGizmo.js +10 -0
- package/Gizmos/planeRotationGizmo.js.map +1 -1
- package/Inputs/scene.inputManager.js +2 -2
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Materials/GreasedLine/greasedLinePluginMaterial.d.ts +6 -2
- package/Materials/GreasedLine/greasedLinePluginMaterial.js +8 -2
- package/Materials/GreasedLine/greasedLinePluginMaterial.js.map +1 -1
- package/Materials/GreasedLine/greasedLinePluginMaterialShadersWGSL.js +11 -3
- package/Materials/GreasedLine/greasedLinePluginMaterialShadersWGSL.js.map +1 -1
- package/Materials/GreasedLine/greasedLineSimpleMaterial.d.ts +1 -0
- package/Materials/GreasedLine/greasedLineSimpleMaterial.js +1 -0
- package/Materials/GreasedLine/greasedLineSimpleMaterial.js.map +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js +1 -3
- package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/subSurfaceBlock.js +3 -3
- package/Materials/Node/Blocks/PBR/subSurfaceBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +4 -2
- package/Materials/Node/nodeMaterial.js +7 -5
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +1 -0
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/Textures/Filtering/hdrFiltering.js +1 -0
- package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.d.ts +69 -0
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js +187 -0
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js.map +1 -0
- package/Materials/Textures/hdrCubeTexture.d.ts +5 -1
- package/Materials/Textures/hdrCubeTexture.js +29 -3
- package/Materials/Textures/hdrCubeTexture.js.map +1 -1
- package/Materials/Textures/index.d.ts +4 -0
- package/Materials/Textures/index.js +4 -0
- package/Materials/Textures/index.js.map +1 -1
- package/Materials/standardMaterial.d.ts +1 -2
- package/Materials/standardMaterial.js +0 -2
- package/Materials/standardMaterial.js.map +1 -1
- package/Meshes/Builders/planeBuilder.js +2 -2
- package/Meshes/Builders/planeBuilder.js.map +1 -1
- package/Meshes/Compression/dracoCodec.d.ts +4 -4
- package/Meshes/Compression/dracoCodec.js.map +1 -1
- package/Meshes/Compression/dracoCompression.d.ts +1 -1
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Compression/dracoCompressionWorker.d.ts +16 -30
- package/Meshes/Compression/dracoCompressionWorker.js +128 -22
- package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
- package/Meshes/Compression/dracoDecoder.d.ts +4 -9
- package/Meshes/Compression/dracoDecoder.js +5 -5
- package/Meshes/Compression/dracoDecoder.js.map +1 -1
- package/Meshes/Compression/dracoDecoder.types.d.ts +52 -0
- package/Meshes/Compression/dracoDecoder.types.js +2 -0
- package/Meshes/Compression/dracoDecoder.types.js.map +1 -0
- package/Meshes/Compression/dracoEncoder.d.ts +91 -0
- package/Meshes/Compression/dracoEncoder.js +239 -0
- package/Meshes/Compression/dracoEncoder.js.map +1 -0
- package/Meshes/Compression/dracoEncoder.types.d.ts +82 -0
- package/Meshes/Compression/dracoEncoder.types.js +2 -0
- package/Meshes/Compression/dracoEncoder.types.js.map +1 -0
- package/Meshes/Compression/index.d.ts +1 -0
- package/Meshes/Compression/index.js +1 -0
- package/Meshes/Compression/index.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +92 -2
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +286 -10
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineBaseMesh.js +4 -2
- package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.js +1 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
- package/Meshes/Node/Blocks/Textures/geometryTextureBlock.d.ts +1 -1
- package/Meshes/mesh.d.ts +2 -2
- package/Meshes/transformNode.js +2 -0
- package/Meshes/transformNode.js.map +1 -1
- package/Misc/decorators.serialization.js +2 -0
- package/Misc/decorators.serialization.js.map +1 -1
- package/Misc/greasedLineTools.d.ts +1 -1
- package/Misc/logger.d.ts +2 -1
- package/Misc/logger.js +2 -1
- package/Misc/logger.js.map +1 -1
- package/Morph/morphTargetManager.d.ts +1 -0
- package/Morph/morphTargetManager.js +6 -1
- package/Morph/morphTargetManager.js.map +1 -1
- package/Particles/pointsCloudSystem.d.ts +3 -3
- package/Physics/v2/Plugins/havokPlugin.d.ts +2 -2
- package/PostProcesses/index.d.ts +1 -0
- package/PostProcesses/index.js +1 -0
- package/PostProcesses/index.js.map +1 -1
- package/PostProcesses/passPostProcess.d.ts +2 -3
- package/PostProcesses/passPostProcess.js +36 -48
- package/PostProcesses/passPostProcess.js.map +1 -1
- package/PostProcesses/thinPassPostProcess.d.ts +48 -0
- package/PostProcesses/thinPassPostProcess.js +113 -0
- package/PostProcesses/thinPassPostProcess.js.map +1 -0
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
- package/Rendering/iblCdfGenerator.d.ts +13 -5
- package/Rendering/iblCdfGenerator.js +67 -10
- package/Rendering/iblCdfGenerator.js.map +1 -1
- package/Shaders/ShadersInclude/gaussianSplatting.js +6 -6
- package/Shaders/ShadersInclude/gaussianSplatting.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockReflection.js +13 -8
- package/Shaders/ShadersInclude/pbrBlockReflection.js.map +1 -1
- package/Shaders/gaussianSplatting.vertex.js +2 -1
- package/Shaders/gaussianSplatting.vertex.js.map +1 -1
- package/Shaders/hdrIrradianceFiltering.fragment.d.ts +9 -0
- package/Shaders/hdrIrradianceFiltering.fragment.js +25 -0
- package/Shaders/hdrIrradianceFiltering.fragment.js.map +1 -0
- package/Shaders/hdrIrradianceFiltering.vertex.d.ts +5 -0
- package/Shaders/hdrIrradianceFiltering.vertex.js +15 -0
- package/Shaders/hdrIrradianceFiltering.vertex.js.map +1 -0
- package/Shaders/pbr.fragment.js +1 -3
- package/Shaders/pbr.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js +13 -8
- package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js.map +1 -1
- package/ShadersWGSL/greasedLine.fragment.js +9 -3
- package/ShadersWGSL/greasedLine.fragment.js.map +1 -1
- package/ShadersWGSL/greasedLine.vertex.js +12 -2
- package/ShadersWGSL/greasedLine.vertex.js.map +1 -1
- package/ShadersWGSL/hdrIrradianceFiltering.fragment.d.ts +9 -0
- package/ShadersWGSL/hdrIrradianceFiltering.fragment.js +26 -0
- package/ShadersWGSL/hdrIrradianceFiltering.fragment.js.map +1 -0
- package/ShadersWGSL/hdrIrradianceFiltering.vertex.d.ts +5 -0
- package/ShadersWGSL/hdrIrradianceFiltering.vertex.js +16 -0
- package/ShadersWGSL/hdrIrradianceFiltering.vertex.js.map +1 -0
- package/ShadersWGSL/outline.fragment.js +1 -1
- package/ShadersWGSL/outline.fragment.js.map +1 -1
- package/ShadersWGSL/passCube.fragment.js +1 -1
- package/ShadersWGSL/passCube.fragment.js.map +1 -1
- package/ShadersWGSL/pbr.fragment.js +1 -3
- package/ShadersWGSL/pbr.fragment.js.map +1 -1
- package/XR/features/WebXRDepthSensing.d.ts +24 -2
- package/XR/features/WebXRDepthSensing.js +320 -26
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +9 -5
- package/scene.js.map +1 -1
|
@@ -3,9 +3,9 @@ import type { WebXRSessionManager } from "../webXRSessionManager";
|
|
|
3
3
|
import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
|
|
4
4
|
import { Observable } from "../../Misc/observable";
|
|
5
5
|
import type { Nullable } from "../../types";
|
|
6
|
-
import { InternalTexture } from "../../Materials/Textures/internalTexture";
|
|
6
|
+
import type { InternalTexture } from "../../Materials/Textures/internalTexture";
|
|
7
7
|
export type WebXRDepthUsage = "cpu" | "gpu";
|
|
8
|
-
export type WebXRDepthDataFormat = "ushort" | "float";
|
|
8
|
+
export type WebXRDepthDataFormat = "ushort" | "float" | "luminance-alpha";
|
|
9
9
|
/**
|
|
10
10
|
* Options for Depth Sensing feature
|
|
11
11
|
*/
|
|
@@ -18,6 +18,23 @@ export interface IWebXRDepthSensingOptions {
|
|
|
18
18
|
* The desired depth sensing data format for the session
|
|
19
19
|
*/
|
|
20
20
|
dataFormatPreference: WebXRDepthDataFormat[];
|
|
21
|
+
/**
|
|
22
|
+
* Depth sensing will be enabled on all materials per default, if the GPU variant is enabled.
|
|
23
|
+
* If you just want to use the texture or the CPU variant instead set this to true.
|
|
24
|
+
*/
|
|
25
|
+
disableDepthSensingOnMaterials?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* If set to true the occluded pixels will not be discarded but the pixel color will be changed based on the occlusion factor
|
|
28
|
+
* Enabling this will lead to worse performance but slightly better outcome.
|
|
29
|
+
* It is possible we will change this in the future to look even better.
|
|
30
|
+
*/
|
|
31
|
+
useToleranceFactorForDepthSensing?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* If set to true the texture will be set to be used for visualization.
|
|
34
|
+
* In this case it will probably NOT work correctly on the materials.
|
|
35
|
+
* So be aware that, for the time being, you can only use one or the other.
|
|
36
|
+
*/
|
|
37
|
+
prepareTextureForVisualization?: boolean;
|
|
21
38
|
}
|
|
22
39
|
type GetDepthInMetersType = (x: number, y: number) => number;
|
|
23
40
|
/**
|
|
@@ -29,10 +46,12 @@ export declare class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
29
46
|
private _width;
|
|
30
47
|
private _height;
|
|
31
48
|
private _rawValueToMeters;
|
|
49
|
+
private _textureType;
|
|
32
50
|
private _normDepthBufferFromNormView;
|
|
33
51
|
private _cachedDepthBuffer;
|
|
34
52
|
private _cachedWebGLTexture;
|
|
35
53
|
private _cachedDepthImageTexture;
|
|
54
|
+
private _onCameraObserver;
|
|
36
55
|
/**
|
|
37
56
|
* Width of depth data. If depth data is not exist, returns null.
|
|
38
57
|
*/
|
|
@@ -60,6 +79,7 @@ export declare class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
60
79
|
/**
|
|
61
80
|
* Latest cached InternalTexture which containing depth buffer information.
|
|
62
81
|
* This can be used when the depth usage is "gpu".
|
|
82
|
+
* @deprecated This will be removed in the future. Use latestDepthImageTexture
|
|
63
83
|
*/
|
|
64
84
|
get latestInternalTexture(): Nullable<InternalTexture>;
|
|
65
85
|
/**
|
|
@@ -102,6 +122,7 @@ export declare class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
102
122
|
* @returns true if successful.
|
|
103
123
|
*/
|
|
104
124
|
attach(force?: boolean | undefined): boolean;
|
|
125
|
+
detach(): boolean;
|
|
105
126
|
/**
|
|
106
127
|
* Dispose this feature and all of the resources attached
|
|
107
128
|
*/
|
|
@@ -114,5 +135,6 @@ export declare class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
114
135
|
* @returns augmentation object for the xr session init object.
|
|
115
136
|
*/
|
|
116
137
|
getXRSessionInitExtension(): Promise<Partial<XRSessionInit>>;
|
|
138
|
+
private _getInternalTextureFromDepthInfo;
|
|
117
139
|
}
|
|
118
140
|
export {};
|
|
@@ -6,7 +6,222 @@ import { Texture } from "../../Materials/Textures/texture.js";
|
|
|
6
6
|
import { Observable } from "../../Misc/observable.js";
|
|
7
7
|
|
|
8
8
|
import { WebGLHardwareTexture } from "../../Engines/WebGL/webGLHardwareTexture.js";
|
|
9
|
-
import {
|
|
9
|
+
import { MaterialPluginBase } from "../../Materials/materialPluginBase.js";
|
|
10
|
+
import { MaterialDefines } from "../../Materials/materialDefines.js";
|
|
11
|
+
import { PBRBaseMaterial } from "../../Materials/PBR/pbrBaseMaterial.js";
|
|
12
|
+
import { RegisterMaterialPlugin } from "../../Materials/materialPluginManager.js";
|
|
13
|
+
import { Matrix } from "../../Maths/math.vector.js";
|
|
14
|
+
class DepthSensingMaterialDefines extends MaterialDefines {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
/**
|
|
18
|
+
* Is the feature enabled
|
|
19
|
+
*/
|
|
20
|
+
this.DEPTH_SENSING = false;
|
|
21
|
+
/**
|
|
22
|
+
* Is the texture type provided as a texture array
|
|
23
|
+
*/
|
|
24
|
+
this.DEPTH_SENSING_TEXTURE_ARRAY = false;
|
|
25
|
+
/**
|
|
26
|
+
* Is the texture type provided as Alpha-Luminance (unpacked differently on the shader)
|
|
27
|
+
*/
|
|
28
|
+
this.DEPTH_SENSING_TEXTURE_AL = false;
|
|
29
|
+
/**
|
|
30
|
+
* Should the shader discard the pixel if the depth is less than the asset depth
|
|
31
|
+
* Will lead to better performance. the other variant is to change the color based on a tolerance factor
|
|
32
|
+
*/
|
|
33
|
+
this.DEPTH_SENSING_DISCARD = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let isPluginEnabled = false;
|
|
37
|
+
let depthTexture = null;
|
|
38
|
+
let alphaLuminanceTexture = false;
|
|
39
|
+
const screenSize = { width: 512, height: 512 };
|
|
40
|
+
const shaderViewport = { x: 0, y: 0, width: 1, height: 1 };
|
|
41
|
+
let globalRawValueToMeters = 1;
|
|
42
|
+
let viewIndex = 0;
|
|
43
|
+
let enableDiscard = true;
|
|
44
|
+
const uvTransform = Matrix.Identity();
|
|
45
|
+
const managedMaterialPlugins = [];
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
class WebXRDepthSensingMaterialPlugin extends MaterialPluginBase {
|
|
50
|
+
/** @internal */
|
|
51
|
+
_markAllDefinesAsDirty() {
|
|
52
|
+
this._enable(this._isEnabled);
|
|
53
|
+
this.markAllDefinesAsDirty();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Gets whether the mesh debug plugin is enabled in the material.
|
|
57
|
+
*/
|
|
58
|
+
get isEnabled() {
|
|
59
|
+
return this._isEnabled;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sets whether the mesh debug plugin is enabled in the material.
|
|
63
|
+
* @param value enabled
|
|
64
|
+
*/
|
|
65
|
+
set isEnabled(value) {
|
|
66
|
+
if (this._isEnabled === value) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this._isEnabled = value;
|
|
70
|
+
this._markAllDefinesAsDirty();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets a boolean indicating that the plugin is compatible with a given shader language.
|
|
74
|
+
* @param shaderLanguage The shader language to use.
|
|
75
|
+
* @returns true if the plugin is compatible with the shader language
|
|
76
|
+
*/
|
|
77
|
+
isCompatible(shaderLanguage) {
|
|
78
|
+
switch (shaderLanguage) {
|
|
79
|
+
case 0 /* ShaderLanguage.GLSL */:
|
|
80
|
+
return true;
|
|
81
|
+
default:
|
|
82
|
+
// no webgpu for webxr yet, however - if this is not true the plugin fails to load.
|
|
83
|
+
// webxr is currently only supported on webgl, and the plugin is disabled per default.
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
constructor(material) {
|
|
88
|
+
super(material, "DepthSensing", 222, new DepthSensingMaterialDefines());
|
|
89
|
+
this._isEnabled = false;
|
|
90
|
+
this._varColorName = material instanceof PBRBaseMaterial ? "finalColor" : "color";
|
|
91
|
+
managedMaterialPlugins.push(this);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Prepare the defines
|
|
95
|
+
* @param defines the defines
|
|
96
|
+
*/
|
|
97
|
+
prepareDefines(defines) {
|
|
98
|
+
defines.DEPTH_SENSING = !!depthTexture && isPluginEnabled;
|
|
99
|
+
defines.DEPTH_SENSING_TEXTURE_ARRAY = depthTexture?.is2DArray ?? false;
|
|
100
|
+
defines.DEPTH_SENSING_TEXTURE_AL = alphaLuminanceTexture;
|
|
101
|
+
defines.DEPTH_SENSING_DISCARD = enableDiscard;
|
|
102
|
+
}
|
|
103
|
+
getUniforms() {
|
|
104
|
+
return {
|
|
105
|
+
// first, define the UBO with the correct type and size.
|
|
106
|
+
ubo: [
|
|
107
|
+
{ name: "ds_invScreenSize", size: 2, type: "vec2" },
|
|
108
|
+
{ name: "ds_rawValueToMeters", size: 1, type: "float" },
|
|
109
|
+
{ name: "ds_viewIndex", size: 1, type: "float" },
|
|
110
|
+
{ name: "ds_shaderViewport", size: 4, type: "vec4" },
|
|
111
|
+
{ name: "ds_uvTransform", size: 16, type: "mat4" },
|
|
112
|
+
],
|
|
113
|
+
// now, on the fragment shader, add the uniform itself in case uniform buffers are not supported by the engine
|
|
114
|
+
fragment: `#ifdef DEPTH_SENSING
|
|
115
|
+
uniform vec2 ds_invScreenSize;
|
|
116
|
+
uniform float ds_rawValueToMeters;
|
|
117
|
+
uniform float ds_viewIndex;
|
|
118
|
+
uniform vec4 ds_shaderViewport;
|
|
119
|
+
uniform mat4 ds_uvTransform;
|
|
120
|
+
#endif
|
|
121
|
+
`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
getSamplers(samplers) {
|
|
125
|
+
samplers.push("ds_depthSampler");
|
|
126
|
+
}
|
|
127
|
+
bindForSubMesh(uniformBuffer) {
|
|
128
|
+
if (isPluginEnabled && depthTexture) {
|
|
129
|
+
uniformBuffer.updateFloat2("ds_invScreenSize", 1 / screenSize.width, 1 / screenSize.height);
|
|
130
|
+
uniformBuffer.updateFloat("ds_rawValueToMeters", globalRawValueToMeters);
|
|
131
|
+
uniformBuffer.updateFloat("ds_viewIndex", viewIndex);
|
|
132
|
+
uniformBuffer.updateFloat4("ds_shaderViewport", shaderViewport.x, shaderViewport.y, shaderViewport.width, shaderViewport.height);
|
|
133
|
+
uniformBuffer.setTexture("ds_depthSampler", depthTexture);
|
|
134
|
+
uniformBuffer.updateMatrix("ds_uvTransform", uvTransform);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
getClassName() {
|
|
138
|
+
return "DepthSensingMaterialPlugin";
|
|
139
|
+
}
|
|
140
|
+
getCustomCode(shaderType) {
|
|
141
|
+
return shaderType === "vertex"
|
|
142
|
+
? {
|
|
143
|
+
CUSTOM_VERTEX_MAIN_BEGIN: `
|
|
144
|
+
#ifdef DEPTH_SENSING
|
|
145
|
+
#ifdef MULTIVIEW
|
|
146
|
+
ds_viewIndexMultiview = float(gl_ViewID_OVR);
|
|
147
|
+
#endif
|
|
148
|
+
#endif
|
|
149
|
+
`,
|
|
150
|
+
CUSTOM_VERTEX_DEFINITIONS: `
|
|
151
|
+
#ifdef DEPTH_SENSING
|
|
152
|
+
#ifdef MULTIVIEW
|
|
153
|
+
varying float ds_viewIndexMultiview;
|
|
154
|
+
#endif
|
|
155
|
+
#endif
|
|
156
|
+
`,
|
|
157
|
+
}
|
|
158
|
+
: {
|
|
159
|
+
CUSTOM_FRAGMENT_DEFINITIONS: `
|
|
160
|
+
#ifdef DEPTH_SENSING
|
|
161
|
+
#ifdef DEPTH_SENSING_TEXTURE_ARRAY
|
|
162
|
+
uniform highp sampler2DArray ds_depthSampler;
|
|
163
|
+
#else
|
|
164
|
+
uniform sampler2D ds_depthSampler;
|
|
165
|
+
#endif
|
|
166
|
+
#ifdef MULTIVIEW
|
|
167
|
+
varying float ds_viewIndexMultiview;
|
|
168
|
+
#endif
|
|
169
|
+
#endif
|
|
170
|
+
`,
|
|
171
|
+
CUSTOM_FRAGMENT_MAIN_BEGIN: `
|
|
172
|
+
#ifdef DEPTH_SENSING
|
|
173
|
+
#ifdef MULTIVIEW
|
|
174
|
+
float ds_viewIndexSet = ds_viewIndexMultiview;
|
|
175
|
+
vec2 ds_compensation = vec2(0.0, 0.0);
|
|
176
|
+
#else
|
|
177
|
+
float ds_viewIndexSet = ds_viewIndex;
|
|
178
|
+
vec2 ds_compensation = vec2(ds_viewIndexSet, 0.0);
|
|
179
|
+
#endif
|
|
180
|
+
vec2 ds_baseUv = gl_FragCoord.xy * ds_invScreenSize;
|
|
181
|
+
#ifdef DEPTH_SENSING_TEXTURE_ARRAY
|
|
182
|
+
vec2 ds_uv = ds_baseUv - ds_compensation;
|
|
183
|
+
vec3 ds_depthUv = vec3((ds_uvTransform * vec4(ds_uv, 0.0, 1.0)).xy, ds_viewIndexSet);
|
|
184
|
+
#else
|
|
185
|
+
vec2 ds_depthUv = (ds_uvTransform * vec4(ds_baseUv.x, 1.0 - ds_baseUv.y, 0.0, 1.0)).xy;
|
|
186
|
+
#endif
|
|
187
|
+
#ifdef DEPTH_SENSING_TEXTURE_AL
|
|
188
|
+
// from alpha-luminance - taken from the explainer
|
|
189
|
+
vec2 ds_alphaLuminance = texture(ds_depthSampler, ds_depthUv).ra;
|
|
190
|
+
float ds_cameraDepth = dot(ds_alphaLuminance, vec2(255.0, 256.0 * 255.0));
|
|
191
|
+
#else
|
|
192
|
+
float ds_cameraDepth = texture(ds_depthSampler, ds_depthUv).r;
|
|
193
|
+
#endif
|
|
194
|
+
|
|
195
|
+
ds_cameraDepth = ds_cameraDepth * ds_rawValueToMeters;
|
|
196
|
+
|
|
197
|
+
float ds_assetDepth = gl_FragCoord.z;
|
|
198
|
+
#ifdef DEPTH_SENSING_DISCARD
|
|
199
|
+
if(ds_cameraDepth < ds_assetDepth) {
|
|
200
|
+
discard;
|
|
201
|
+
}
|
|
202
|
+
#endif
|
|
203
|
+
#endif
|
|
204
|
+
`,
|
|
205
|
+
CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: `
|
|
206
|
+
#ifdef DEPTH_SENSING
|
|
207
|
+
#ifndef DEPTH_SENSING_DISCARD
|
|
208
|
+
const float ds_depthTolerancePerM = 0.005;
|
|
209
|
+
float ds_occlusion = clamp(1.0 - 0.5 * (ds_cameraDepth - ds_assetDepth) / (ds_depthTolerancePerM * ds_assetDepth) +
|
|
210
|
+
0.5, 0.0, 1.0);
|
|
211
|
+
${this._varColorName} *= (1.0 - ds_occlusion);
|
|
212
|
+
#endif
|
|
213
|
+
#endif
|
|
214
|
+
`,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
dispose(_forceDisposeTextures) {
|
|
218
|
+
const index = managedMaterialPlugins.indexOf(this);
|
|
219
|
+
if (index !== -1) {
|
|
220
|
+
managedMaterialPlugins.splice(index, 1);
|
|
221
|
+
}
|
|
222
|
+
super.dispose(_forceDisposeTextures);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
10
225
|
/**
|
|
11
226
|
* WebXR Feature for WebXR Depth Sensing Module
|
|
12
227
|
* @since 5.49.1
|
|
@@ -56,31 +271,20 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
56
271
|
return "ushort";
|
|
57
272
|
case "float32":
|
|
58
273
|
return "float";
|
|
274
|
+
case "unsigned-short":
|
|
275
|
+
return "ushort";
|
|
59
276
|
}
|
|
60
277
|
}
|
|
61
278
|
/**
|
|
62
279
|
* Latest cached InternalTexture which containing depth buffer information.
|
|
63
280
|
* This can be used when the depth usage is "gpu".
|
|
281
|
+
* @deprecated This will be removed in the future. Use latestDepthImageTexture
|
|
64
282
|
*/
|
|
65
283
|
get latestInternalTexture() {
|
|
66
284
|
if (!this._cachedWebGLTexture) {
|
|
67
285
|
return null;
|
|
68
286
|
}
|
|
69
|
-
|
|
70
|
-
const internalTexture = new InternalTexture(engine, 0 /* InternalTextureSource.Unknown */);
|
|
71
|
-
internalTexture.isCube = false;
|
|
72
|
-
internalTexture.invertY = false;
|
|
73
|
-
internalTexture._useSRGBBuffer = false;
|
|
74
|
-
internalTexture.format = this.depthDataFormat === "ushort" ? 2 : 5;
|
|
75
|
-
internalTexture.generateMipMaps = false;
|
|
76
|
-
internalTexture.type = this.depthDataFormat === "ushort" ? 5 : 1;
|
|
77
|
-
internalTexture.samplingMode = 7;
|
|
78
|
-
internalTexture.width = this.width ?? 0;
|
|
79
|
-
internalTexture.height = this.height ?? 0;
|
|
80
|
-
internalTexture._cachedWrapU = 1;
|
|
81
|
-
internalTexture._cachedWrapV = 1;
|
|
82
|
-
internalTexture._hardwareTexture = new WebGLHardwareTexture(this._cachedWebGLTexture, engine._gl);
|
|
83
|
-
return internalTexture;
|
|
287
|
+
return this._getInternalTextureFromDepthInfo();
|
|
84
288
|
}
|
|
85
289
|
/**
|
|
86
290
|
* cached depth buffer
|
|
@@ -89,7 +293,7 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
89
293
|
if (!this._cachedDepthBuffer) {
|
|
90
294
|
return null;
|
|
91
295
|
}
|
|
92
|
-
return this.depthDataFormat === "
|
|
296
|
+
return this.depthDataFormat === "float" ? new Float32Array(this._cachedDepthBuffer) : new Uint16Array(this._cachedDepthBuffer);
|
|
93
297
|
}
|
|
94
298
|
/**
|
|
95
299
|
* Latest cached Texture of depth image which is made from the depth buffer data.
|
|
@@ -108,10 +312,12 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
108
312
|
this._width = null;
|
|
109
313
|
this._height = null;
|
|
110
314
|
this._rawValueToMeters = null;
|
|
315
|
+
this._textureType = null;
|
|
111
316
|
this._normDepthBufferFromNormView = null;
|
|
112
317
|
this._cachedDepthBuffer = null;
|
|
113
318
|
this._cachedWebGLTexture = null;
|
|
114
319
|
this._cachedDepthImageTexture = null;
|
|
320
|
+
this._onCameraObserver = null;
|
|
115
321
|
/**
|
|
116
322
|
* Event that notify when `DepthInformation.getDepthInMeters` is available.
|
|
117
323
|
* `getDepthInMeters` method needs active XRFrame (not available for cached XRFrame)
|
|
@@ -120,6 +326,7 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
120
326
|
this.xrNativeFeatureName = "depth-sensing";
|
|
121
327
|
// https://immersive-web.github.io/depth-sensing/
|
|
122
328
|
Tools.Warn("depth-sensing is an experimental and unstable feature.");
|
|
329
|
+
enableDiscard = !options.useToleranceFactorForDepthSensing;
|
|
123
330
|
}
|
|
124
331
|
/**
|
|
125
332
|
* attach this feature
|
|
@@ -136,14 +343,57 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
136
343
|
return false;
|
|
137
344
|
}
|
|
138
345
|
this._glBinding = new XRWebGLBinding(this._xrSessionManager.session, this._xrSessionManager.scene.getEngine()._gl);
|
|
346
|
+
isPluginEnabled = !this.options.disableDepthSensingOnMaterials;
|
|
347
|
+
if (isPluginEnabled) {
|
|
348
|
+
managedMaterialPlugins.forEach((plugin) => {
|
|
349
|
+
plugin.isEnabled = true;
|
|
350
|
+
});
|
|
351
|
+
this._onCameraObserver = this._xrSessionManager.scene.onBeforeCameraRenderObservable.add((camera) => {
|
|
352
|
+
if (!isPluginEnabled) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
// make sure this is a webxr camera
|
|
356
|
+
if (camera.outputRenderTarget) {
|
|
357
|
+
const viewport = camera.rigCameras.length > 0 ? camera.rigCameras[0].viewport : camera.viewport;
|
|
358
|
+
screenSize.width = camera.outputRenderTarget.getRenderWidth() / (camera.rigParent ? camera.rigParent.rigCameras.length || 1 : 1);
|
|
359
|
+
screenSize.height = camera.outputRenderTarget.getRenderHeight();
|
|
360
|
+
shaderViewport.x = viewport.x;
|
|
361
|
+
shaderViewport.y = viewport.y;
|
|
362
|
+
shaderViewport.width = viewport.width;
|
|
363
|
+
shaderViewport.height = viewport.height;
|
|
364
|
+
// find the viewIndex
|
|
365
|
+
if (camera.rigParent) {
|
|
366
|
+
// should use the viewIndexes array!
|
|
367
|
+
viewIndex = camera.isLeftCamera ? 0 : 1;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
139
372
|
return true;
|
|
140
373
|
}
|
|
374
|
+
detach() {
|
|
375
|
+
isPluginEnabled = false;
|
|
376
|
+
depthTexture = null;
|
|
377
|
+
this._cachedWebGLTexture = null;
|
|
378
|
+
this._cachedDepthBuffer = null;
|
|
379
|
+
managedMaterialPlugins.forEach((plugin) => {
|
|
380
|
+
plugin.isEnabled = false;
|
|
381
|
+
});
|
|
382
|
+
if (this._onCameraObserver) {
|
|
383
|
+
this._xrSessionManager.scene.onBeforeCameraRenderObservable.remove(this._onCameraObserver);
|
|
384
|
+
}
|
|
385
|
+
return super.detach();
|
|
386
|
+
}
|
|
141
387
|
/**
|
|
142
388
|
* Dispose this feature and all of the resources attached
|
|
143
389
|
*/
|
|
144
390
|
dispose() {
|
|
145
391
|
this._cachedDepthImageTexture?.dispose();
|
|
146
392
|
this.onGetDepthInMetersAvailable.clear();
|
|
393
|
+
// cleanup
|
|
394
|
+
if (this._onCameraObserver) {
|
|
395
|
+
this._xrSessionManager.scene.onBeforeCameraRenderObservable.remove(this._onCameraObserver);
|
|
396
|
+
}
|
|
147
397
|
}
|
|
148
398
|
_onXRFrame(_xrFrame) {
|
|
149
399
|
const referenceSPace = this._xrSessionManager.referenceSpace;
|
|
@@ -174,43 +424,63 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
174
424
|
if (depthInfo === null) {
|
|
175
425
|
return;
|
|
176
426
|
}
|
|
177
|
-
const { data, width, height, rawValueToMeters, getDepthInMeters } = depthInfo;
|
|
427
|
+
const { data, width, height, rawValueToMeters, getDepthInMeters, normDepthBufferFromNormView } = depthInfo;
|
|
178
428
|
this._width = width;
|
|
179
429
|
this._height = height;
|
|
180
430
|
this._rawValueToMeters = rawValueToMeters;
|
|
181
431
|
this._cachedDepthBuffer = data;
|
|
432
|
+
globalRawValueToMeters = rawValueToMeters;
|
|
433
|
+
alphaLuminanceTexture = dataFormat === "luminance-alpha";
|
|
434
|
+
uvTransform.fromArray(normDepthBufferFromNormView.matrix);
|
|
182
435
|
// to avoid Illegal Invocation error, bind `this`
|
|
183
436
|
this.onGetDepthInMetersAvailable.notifyObservers(getDepthInMeters.bind(depthInfo));
|
|
184
437
|
if (!this._cachedDepthImageTexture) {
|
|
185
|
-
this._cachedDepthImageTexture = RawTexture.CreateRTexture(null, width, height, this._xrSessionManager.scene, false,
|
|
438
|
+
this._cachedDepthImageTexture = RawTexture.CreateRTexture(null, width, height, this._xrSessionManager.scene, false, false, Texture.NEAREST_SAMPLINGMODE, 1);
|
|
439
|
+
depthTexture = this._cachedDepthImageTexture;
|
|
186
440
|
}
|
|
441
|
+
let float32Array = null;
|
|
187
442
|
switch (dataFormat) {
|
|
188
443
|
case "ushort":
|
|
189
|
-
|
|
444
|
+
case "luminance-alpha":
|
|
445
|
+
float32Array = Float32Array.from(new Uint16Array(data));
|
|
190
446
|
break;
|
|
191
447
|
case "float":
|
|
192
|
-
|
|
448
|
+
float32Array = new Float32Array(data);
|
|
193
449
|
break;
|
|
194
450
|
default:
|
|
195
451
|
break;
|
|
196
452
|
}
|
|
453
|
+
if (float32Array) {
|
|
454
|
+
if (this.options.prepareTextureForVisualization) {
|
|
455
|
+
float32Array = float32Array.map((val) => val * rawValueToMeters);
|
|
456
|
+
}
|
|
457
|
+
this._cachedDepthImageTexture.update(float32Array);
|
|
458
|
+
}
|
|
197
459
|
}
|
|
198
460
|
_updateDepthInformationAndTextureWebGLDepthUsage(webglBinding, view, dataFormat) {
|
|
199
461
|
const depthInfo = webglBinding.getDepthInformation(view);
|
|
200
462
|
if (depthInfo === null) {
|
|
201
463
|
return;
|
|
202
464
|
}
|
|
203
|
-
const { texture, width, height } = depthInfo;
|
|
465
|
+
const { texture, width, height, textureType, rawValueToMeters, normDepthBufferFromNormView } = depthInfo;
|
|
466
|
+
globalRawValueToMeters = rawValueToMeters;
|
|
467
|
+
alphaLuminanceTexture = dataFormat === "luminance-alpha";
|
|
468
|
+
uvTransform.fromArray(normDepthBufferFromNormView.matrix);
|
|
469
|
+
if (this._cachedWebGLTexture) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
204
472
|
this._width = width;
|
|
205
473
|
this._height = height;
|
|
206
474
|
this._cachedWebGLTexture = texture;
|
|
475
|
+
this._textureType = textureType;
|
|
207
476
|
const scene = this._xrSessionManager.scene;
|
|
208
|
-
const
|
|
209
|
-
const internalTexture = engine.wrapWebGLTexture(texture);
|
|
477
|
+
const internalTexture = this._getInternalTextureFromDepthInfo();
|
|
210
478
|
if (!this._cachedDepthImageTexture) {
|
|
211
|
-
this._cachedDepthImageTexture = RawTexture.CreateRTexture(null, width, height, scene, false, true, Texture.NEAREST_SAMPLINGMODE, dataFormat === "
|
|
479
|
+
this._cachedDepthImageTexture = RawTexture.CreateRTexture(null, width, height, scene, false, true, Texture.NEAREST_SAMPLINGMODE, dataFormat === "float" ? 1 : 0);
|
|
212
480
|
}
|
|
213
481
|
this._cachedDepthImageTexture._texture = internalTexture;
|
|
482
|
+
depthTexture = this._cachedDepthImageTexture;
|
|
483
|
+
this._xrSessionManager.scene.markAllMaterialsAsDirty(1);
|
|
214
484
|
}
|
|
215
485
|
/**
|
|
216
486
|
* Extends the session init object if needed
|
|
@@ -231,10 +501,12 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
231
501
|
});
|
|
232
502
|
const dataFormats = this.options.dataFormatPreference.map((format) => {
|
|
233
503
|
switch (format) {
|
|
234
|
-
case "
|
|
504
|
+
case "luminance-alpha":
|
|
235
505
|
return "luminance-alpha";
|
|
236
506
|
case "float":
|
|
237
507
|
return "float32";
|
|
508
|
+
case "ushort":
|
|
509
|
+
return "unsigned-short";
|
|
238
510
|
}
|
|
239
511
|
});
|
|
240
512
|
resolve({
|
|
@@ -249,6 +521,27 @@ export class WebXRDepthSensing extends WebXRAbstractFeature {
|
|
|
249
521
|
}
|
|
250
522
|
});
|
|
251
523
|
}
|
|
524
|
+
_getInternalTextureFromDepthInfo() {
|
|
525
|
+
const engine = this._xrSessionManager.scene.getEngine();
|
|
526
|
+
const dataFormat = this.depthDataFormat;
|
|
527
|
+
const textureType = this._textureType;
|
|
528
|
+
if (!this._width || !this._height || !this._cachedWebGLTexture) {
|
|
529
|
+
throw new Error("Depth information is not available");
|
|
530
|
+
}
|
|
531
|
+
const internalTexture = engine.wrapWebGLTexture(this._cachedWebGLTexture, false, 1, this._width || 256, this._height || 256);
|
|
532
|
+
internalTexture.isCube = false;
|
|
533
|
+
internalTexture.invertY = false;
|
|
534
|
+
internalTexture._useSRGBBuffer = false;
|
|
535
|
+
internalTexture.format = dataFormat === "luminance-alpha" ? 2 : 5;
|
|
536
|
+
internalTexture.generateMipMaps = false;
|
|
537
|
+
internalTexture.type =
|
|
538
|
+
dataFormat === "float" ? 1 : dataFormat === "ushort" ? 5 : 0;
|
|
539
|
+
internalTexture._cachedWrapU = 1;
|
|
540
|
+
internalTexture._cachedWrapV = 1;
|
|
541
|
+
internalTexture._hardwareTexture = new WebGLHardwareTexture(this._cachedWebGLTexture, engine._gl);
|
|
542
|
+
internalTexture.is2DArray = textureType === "texture-array";
|
|
543
|
+
return internalTexture;
|
|
544
|
+
}
|
|
252
545
|
}
|
|
253
546
|
/**
|
|
254
547
|
* The module's name
|
|
@@ -263,4 +556,5 @@ WebXRDepthSensing.Version = 1;
|
|
|
263
556
|
WebXRFeaturesManager.AddWebXRFeature(WebXRDepthSensing.Name, (xrSessionManager, options) => {
|
|
264
557
|
return () => new WebXRDepthSensing(xrSessionManager, options);
|
|
265
558
|
}, WebXRDepthSensing.Version, false);
|
|
559
|
+
RegisterMaterialPlugin("WebXRDepthSensingMaterialPlugin", (material) => new WebXRDepthSensingMaterialPlugin(material));
|
|
266
560
|
//# sourceMappingURL=WebXRDepthSensing.js.map
|