Karmux
02-24-2012, 12:14 PM
Hi,
I'm tring to reconstruct eye space position from depth buffer, but my result doesn't look correct.
This is my current and one of the shortest implementations i found:
float depth = texture2D(depthBuffer, texCoord).r;
vec2 xy = texCoord * 2.0 - 1.0;
vec4 clipPos = vec4(xy, depth, 1.0);
// I pass inverseProjectionMatrix as uniform
vec4 homo = inverseProjectionMatrix * clipPos;
vec3 position = homo.xyz / homo.w;
gl_FragColor = vec4(position, 1.0);
(from: http://www.gamedev.net/topic/577382-calculate-eye-space-position-from-depth/)
This gives me only green-yellow-red colors and no visible 3D objects:
http://www.upload.ee/image/2106871/positions.png
But the correct result should look like this (top right)?
http://mynameismjp.files.wordpress.com/2010/03/position16f.png
I have tried out many examples. Some of them were too difficult and others gave also artifacts etc. If i visualize depth texture, then everything looks correct.
Can anybody see mistake in above code?
I'm tring to reconstruct eye space position from depth buffer, but my result doesn't look correct.
This is my current and one of the shortest implementations i found:
float depth = texture2D(depthBuffer, texCoord).r;
vec2 xy = texCoord * 2.0 - 1.0;
vec4 clipPos = vec4(xy, depth, 1.0);
// I pass inverseProjectionMatrix as uniform
vec4 homo = inverseProjectionMatrix * clipPos;
vec3 position = homo.xyz / homo.w;
gl_FragColor = vec4(position, 1.0);
(from: http://www.gamedev.net/topic/577382-calculate-eye-space-position-from-depth/)
This gives me only green-yellow-red colors and no visible 3D objects:
http://www.upload.ee/image/2106871/positions.png
But the correct result should look like this (top right)?
http://mynameismjp.files.wordpress.com/2010/03/position16f.png
I have tried out many examples. Some of them were too difficult and others gave also artifacts etc. If i visualize depth texture, then everything looks correct.
Can anybody see mistake in above code?