Attempting to reconstruct position from depth texture

Anything libgdx related goes here!

Attempting to reconstruct position from depth texture

Postby ajmd17 » Thu May 21, 2015 4:37 pm

Hey everyone! Just started using Libgdx a few weeks ago. I'm currently using 1.5.6.
What I'm attempting to do, is to recreate the world position, from a depth texture.
I am using a FBO to render the depth texture and store it, and then I am using a full-screen quad in order to render the shaders.

Vertex shader:
Code: Select all
attribute vec4 a_Position;     
                 attribute vec4 a_Color;
                 attribute vec2 a_texCoords;
                 varying vec4 v_Color;
                 varying vec2 v_texCoords;
                 void main()                   
                 {                             
                    v_Color = a_Color;
                    v_texCoords = a_texCoords;
                    gl_Position =   a_Position;   
                 }   



Fragment shader:
Code: Select all
#ifdef GL_ES
                 precision mediump float;
                 #endif
                 varying vec4 v_Color;
                 varying vec2 v_texCoords;
                 uniform sampler2D u_depthMap;
                 uniform mat4 u_invProjView;
                 
                 vec3 getPosition(vec2 uv, float depth) {
                      vec4 pos = vec4(uv, depth, 1.0)*2.0-1.0;
                      pos = u_invProjView * pos;
                      pos = pos/pos.w;
                      return pos.xyz;
                 }
                 
                 
                 void main()                                   
                 {                                           
                   float depth = texture2D(u_depthMap, v_texCoords).r;

                   gl_FragColor = vec4(getPosition(v_texCoords, depth), 1.0);
                 }





Nothing too crazy. However, it comes out completely wrong. There seems to be some sort of problem with matrices, but I'm unable to figure it out after fiddling around with it for the past two days. Just wondering if anyone could point out any major flaws :P


What it looks like:

http://imgur.com/HEiV3qO


And when I move the camera:

http://imgur.com/vFed7ap
ajmd17
 
Posts: 1
Joined: Thu May 21, 2015 4:28 pm

Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest