【发布时间】:2014-04-18 15:36:57
【问题描述】:
我正在尝试从深度缓冲区(渲染为颜色纹理,然后使用 glReadPixels 读取)中获取正确的 Z 值,然后取消投影以获得真实的 3D 空间坐标。在 iPad Air 上它可以完美运行,但在 iPad 3 或 iPad 4 上却不行。
iPad 3/4 和 iPad Air 具有:
OpenGL ES 2.0 IMGSGX554-97.7 和 OpenGL ES 2.0 Apple A7 GPU - 27.23
GLSL 版本 OpenGL ES GLSL ES 1.00
OpenGL 深度位 24 - 在所有设备上
glDepthFunc(GL_LEQUAL);
glDepthRangef(0, 1.0);
glClearDepthf(1.0);
在片段着色器中:
precision highp float;
// .... some code and variables
const float maxnum = 256.0;
vec4 pack (float depth)
{
const vec4 bitSh = vec4(maxnum * maxnum * maxnum,
maxnum * maxnum,
maxnum,
1.0);
const vec4 bitMsk = vec4(0,
1.0 / maxnum,
1.0 / maxnum,
1.0 / maxnum);
vec4 comp = fract(depth * bitSh);
comp -= comp.xxyz * bitMsk;
return comp;
}
void main()
{
gl_FragColor = pack(gl_FragCoord.z);
}
在 iPad Air 上我们可以看到:
在 iPad 3/4 上:
【问题讨论】:
-
我知道 Apple A7 GPU 和之前的 PowerVR SGX GPU 之间的唯一精度差异是
lowp和mediump在 A7(均为 16 位)上是相同的。旧型号有lowp= 12 位和mediump= 16 位。 -
@AndonM.Coleman 好的,如果它是正确的 - 那么我不能使用 gl_FragCoord.z,因为它不准确。我尝试使用顶点着色器中的坐标,但这并没有太大帮助。你会建议尝试什么?
标签: opengl-es precision framebuffer depth-buffer