Hey everyone! New to the forum. Came here desperately looking for help with something I’ve been struggling with over the last few days. ???
For some bizarre reason, there seems to be something wrong with my matrices when I try to reconstruct the world position from a depth texture - everything seems to skewed.
Here is some of my GLSL code:
Vertex Shader:
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:
#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);
}
Here is an image of what appears immediately:
http://imgur.com/HEiV3qO