我有正确的逆投影矩阵。但似乎没有什么是对的!重建后的位置是否完全变形,z 值是否太小?有人建议吗?
vec3 calculatePosition(vec2 coord, float depth)
{
vec4 clipSpaceLocation;
clipSpaceLocation.x = coord.x * 2.0 - 1.0;
clipSpaceLocation.y = coord.y * 2.0 - 1.0;
clipSpaceLocation.z = depth * 2.0 - 1.0;
clipSpaceLocation.w = 1.0;
vec4 homogenousPosition = uProjectionInverse * clipSpaceLocation;
return homogenousPosition.xyz / homogenousPosition.w;
}
z 值约为 -0,001;为什么?
坐标和深度是:
vec2 coord = vec2(gl_FragCoord.x / width, gl_FragCoord.y / height);
float currentDepth = texture(depthBuffer, coord).r;
我必须为大学实施 SSAO,并且我使用 Eclipse 和 Java 以及 lwjgl-plugin。请我需要帮助。我不到一星期。
编辑:我现在已经尝试过了......但仍然没有被简化:
float camera_space_z_from_depth(sampler2D depthbuffer, vec2 uv) {
float depth = texture(depthbuffer, uv).x;
return (2 * uNearPlane) / (uFarPlane + uNearPlane - depth * (uFarPlane - uNearPlane));
}
vec3 calculatePosition(vec2 coord, float depth)
{
vec4 clipSpaceLocation;
clipSpaceLocation.x = coord.x * 2.0 - 1.0;
clipSpaceLocation.y = coord.y * 2.0 - 1.0;
clipSpaceLocation.z = depth * 2.0 - 1.0;
clipSpaceLocation.w = 1.0;
vec4 homogenousPosition = uProjectionInverse * clipSpaceLocation;
return homogenousPosition.xyz / homogenousPosition.w;
}
vec3 getPosition(vec2 coord){
float currentDepth = camera_space_z_from_depth(depthBuffer,coord);
vec3 position = calculatePosition(coord, currentDepth);
return position;
}