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

40 lines
1,009 B
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-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:00:40 +00:00
vTexCoord = vec2(gl_InstanceID % uFrameSize.x, gl_InstanceID / uFrameSize.x)/vec2(512,424);
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;
// Flip X as OpenGL and K4A have different conventions on which direction is positive.
posWorld.x *= -1;
vPosition = modelViewMatrix * posWorld;
}