-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebXRManager: Added depth sensing support (v2). (#27586)
* add support for depth sensing * add support for depth sensing * use EXT_frag_depth for depth sensing * Create WebXRDepthSensing * Rename WebXRDepthSensing to WebXRDepthSensing.js * Update WebXRManager.js * Update WebXRDepthSensing.js * Update WebXRManager.js * Update WebXRDepthSensing.js * Update WebXRDepthSensing.js * Update WebXRDepthSensing.js * Update WebXRManager.js * pass correct depth/far clip in non-occlusion cases * Update WebGLRenderer.js * Update WebXRManager.js --------- Co-authored-by: mrdoob <info@mrdoob.com>
- Loading branch information
Showing
6 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { PlaneGeometry } from '../../geometries/PlaneGeometry.js'; | ||
import { ShaderMaterial } from '../../materials/ShaderMaterial.js'; | ||
import { Mesh } from '../../objects/Mesh.js'; | ||
import { Texture } from '../../textures/Texture.js'; | ||
|
||
const _occlusion_vertex = ` | ||
void main() { | ||
gl_Position = vec4( position, 1.0 ); | ||
}`; | ||
|
||
const _occlusion_fragment = ` | ||
uniform sampler2DArray depthColor; | ||
uniform float depthWidth; | ||
uniform float depthHeight; | ||
void main() { | ||
vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight ); | ||
if ( coord.x >= 1.0 ) { | ||
gl_FragDepthEXT = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r; | ||
} else { | ||
gl_FragDepthEXT = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r; | ||
} | ||
}`; | ||
|
||
class WebXRDepthSensing { | ||
|
||
constructor() { | ||
|
||
this.texture = null; | ||
this.mesh = null; | ||
|
||
this.depthNear = 0; | ||
this.depthFar = 0; | ||
|
||
} | ||
|
||
init( renderer, depthData, renderState ) { | ||
|
||
if ( this.texture === null ) { | ||
|
||
const texture = new Texture(); | ||
|
||
const texProps = renderer.properties.get( texture ); | ||
texProps.__webglTexture = depthData.texture; | ||
|
||
if ( ( depthData.depthNear != renderState.depthNear ) || ( depthData.depthFar != renderState.depthFar ) ) { | ||
|
||
this.depthNear = depthData.depthNear; | ||
this.depthFar = depthData.depthFar; | ||
|
||
} | ||
|
||
this.texture = texture; | ||
|
||
} | ||
|
||
} | ||
|
||
render( renderer, cameraXR ) { | ||
|
||
if ( this.texture !== null ) { | ||
|
||
if ( this.mesh === null ) { | ||
|
||
const viewport = cameraXR.cameras[ 0 ].viewport; | ||
const material = new ShaderMaterial( { | ||
extensions: { fragDepth: true }, | ||
vertexShader: _occlusion_vertex, | ||
fragmentShader: _occlusion_fragment, | ||
uniforms: { | ||
depthColor: { value: this.texture }, | ||
depthWidth: { value: viewport.z }, | ||
depthHeight: { value: viewport.w } | ||
} | ||
} ); | ||
|
||
this.mesh = new Mesh( new PlaneGeometry( 20, 20 ), material ); | ||
|
||
} | ||
|
||
renderer.render( this.mesh, cameraXR ); | ||
|
||
} | ||
|
||
} | ||
|
||
reset() { | ||
|
||
this.texture = null; | ||
this.mesh = null; | ||
|
||
} | ||
|
||
} | ||
|
||
export { WebXRDepthSensing }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters