This extension provides support for the Media
Capture Depth Stream Extensions. Specifically, it supports
uploading to a WebGL texture a video element whose
source is a MediaStream object containing a
depth track.
video element whose source is a MediaStream
object containing a
depth track may be uploaded to a WebGL
texture of format RGB and type
UNSIGNED_SHORT_5_6_5.
var ext = gl.getExtension("WEBGL_texture_from_depth_video");
if (ext) {
navigator.getUserMedia({ video: true }, successVideo, failureVideo);
}
var depthVideo;
function successVideo(s) {
// wire the stream into a <video> element for playback
depthVideo = document.querySelector('#video');
depthVideo.src = URL.createObjectURL(s);
depthVideo.play();
}
// ... later, in the rendering loop ...
if (ext) {
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGB,
gl.RGB,
gl.UNSIGNED_SHORT_5_6_5,
depthVideo
);
}
<script id="fragment-shader" type="x-shader/x-fragment">
varying vec2 v_texCoord;
// u_tex points to the texture unit containing the depth texture.
uniform sampler2D u_tex;
void main() {
vec4 floatColor = texture2D(u_tex, v_texCoord);
vec3 rgb = floatColor.rgb;
...
float depth = 63488. * rgb.r + 2016. * rgb.g + 31. * rgb.b;
...
}
</script>