【问题标题】:Reconstructing world position from linear depth从线性深度重建世界位置
【发布时间】:2015-03-19 22:53:48
【问题描述】:

我在从以前存储在 glsl 中的线性深度重建世界位置时遇到问题。我在网上看了很多资料,但找不到我的问题... 所以这就是我得到的:

VS (storing depth to 32F):
float linDepth(float z) {
    return (-z-zNear)/(zFar-zNear);
}
void main() {
    vec4 position = uViewMatrix * uModelMatrix * vec4(aPosition, 1);
    depth = linDepth(position.z); //store linear view-depth
}

FS (reconstuction):
void main() {
    vec3 vUV = vec2(0..1, 0..1); (from screen aligned quad)
    vec3 ndc = vec3(vUV*2-1, linearViewDepth*2-1);
    vec4 v0 = inverse(uProjectionMatrix)*vec4(ndc, 1);
    vec3 reconViewPos = v0.xyz/v0.w;
    vec3 reconWorldPos = inverse(uViewMatrix) * v0;
}

...结果完全关闭。 虽然我通过使用不变的线性视图深度作为 ndc z 来感觉到一个问题。最后我希望应用光线插值方法:

VS (reconstruction, aligned screenquad):
out vec3 vViewRay;
void main() {
    gl_Position = aPosition;
    vec4 v = vec4(aPosition.x, aPosition.y, 1, 1); //ndc (at the back of cube)
    v = inverse(uProjectionMatrix) * v;
    v /= v.w; //view coordinate
    v /= v.z; //normalize by z for scaling
    vViewRay = v.xyz;
}

FS(reconstruction):
in vec3 vViewRay;
float delinDepth(float z) {
    return -(z*(zFar-zNear)+zNear);
}
void main() {
    vec3 reconViewPos = vViewRay * delinDepth(linearViewDepth);
}

【问题讨论】:

标签: opengl matrix glsl depth-buffer ndc


【解决方案1】:

最后第二个重建代码确实起作用了,我猜是在其他地方出了点问题……

【讨论】:

    猜你喜欢
    • 2017-07-02
    • 2013-04-21
    • 1970-01-01
    • 2013-06-21
    • 2017-03-15
    • 1970-01-01
    • 2014-12-28
    • 2020-03-26
    • 1970-01-01
    相关资源
    最近更新 更多