realityplayground-of/zoneb/bin/data/shaders/render.vert

44 lines
1.1 KiB
GLSL
Raw Normal View History

2020-10-18 16:52:22 +00:00
#ifdef GL_ES
precision mediump float;
#endif
// OF built-in attributes.
uniform mat4 modelViewMatrix;
// Custom attributes.
2020-10-18 16:52:22 +00:00
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;
2020-10-19 09:02:40 +00:00
uniform ivec2 uDepthFrameSize;
2020-10-18 16:52:22 +00:00
uniform vec2 u_resolution;
out vec4 vPosition;
out vec2 vTexCoord;
flat out int vValid;
void main()
{
2020-10-19 09:02:40 +00:00
vTexCoord = vec2(gl_InstanceID % uFrameSize.x, gl_InstanceID / uFrameSize.x) / uDepthFrameSize;
2020-10-18 16:52:22 +00:00
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;
2020-10-19 14:14:53 +00:00
if(depth < 0.012) vValid = 0;
if(depth > 0.04) vValid = 0;
// Flip X as OpenGL and K4A have different conventions on which direction is positive.
posWorld.x *= -1;
vPosition = modelViewMatrix * posWorld;
}