#ifdef GL_ES precision mediump float; #endif // OF built-in attributes. uniform mat4 modelViewMatrix; // Custom attributes. uniform sampler2D uDepthTex; // Sampler for the depth space data uniform sampler2D uWorldTex; // Transformation from kinect depth/color space to kinect world space uniform ivec2 uFrameSize; uniform vec2 u_resolution; out vec4 vPosition; out vec2 vTexCoord; flat out int vValid; void main() { vTexCoord = vec2(gl_InstanceID % uFrameSize.x, gl_InstanceID / uFrameSize.x)/u_resolution; float depth = texture2D(uDepthTex, vTexCoord).x; vec4 ray = texture2D(uWorldTex, vTexCoord); vValid = (depth != 0 && ray.x != 0 && ray.y != 0) ? 1 : 0; vec4 posWorld = vec4(1); posWorld.z = depth * 65535.0; // Remap to float range. posWorld.x = ray.x * posWorld.z; posWorld.y = ray.y * posWorld.z; // Flip X as OpenGL and K4A have different conventions on which direction is positive. posWorld.x *= -1; vPosition = modelViewMatrix * posWorld; }