WEBGL_texture_from_depth_video
WebGL working group (public_webgl 'at' khronos.org)
Ningxin Hu, Intel
Anssi Kostiainen, Intel
Rob Manson, buildAR
Members of the WebGL working group
Last modified date: January 24, 2015
Revision: 2
WebGL extension #NN
Written against the WebGL API 1.0 specification.
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.
When this extension is enabled:
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
.
[Exposed=(Window,Worker), LegacyNoInterfaceObject] interface WEBGL_texture_from_depth_video { };
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>
Revision 1, 2014/11/03
Revision 2, 2015/01/24