0
我有問題從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);
}
http://stackoverflow.com /問題/ 13711252 /什麼,做-GL-fragcoord-Z-GL-fragcoord-W-代表 – 2015-01-21 16:42:20