【问题标题】:OpenGL ES Depth Buffer rendering (iOS simulator VS real device)OpenGL ES Depth Buffer渲染(iOS模拟器VS真机)
【发布时间】:2015-03-17 20:30:37
【问题描述】:

使用 iOS 模拟器 Getting the true z value from the depth buffer 渲染深度缓冲区时,一切正常。 但是在真实设备上渲染会产生不好的结果:深度仅使用很少的值(没有淡入淡出)渲染,就像您将图像显示为 256 值颜色范围时一样。

这是fbo生成的代码:

glGenFramebuffers(1, &sceneFBO);
glGenTextures(2, textures_scene);
glBindTexture(GL_TEXTURE_2D, textures_scene[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, widthResolution, heightResolution, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glBindTexture(GL_TEXTURE_2D, textures_scene[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, widthResolution, heightResolution, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);

//TODO: GL_DEPTH_COMPONENT cannot be GL_UNSIGNED_BYTE ?

glBindFramebuffer(GL_FRAMEBUFFER, sceneFBO);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures_scene[0], 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textures_scene[1], 0);

似乎 GL_DEPTH_ATTACHMENT fbo 的唯一工作值是 GL_UNSIGNED_INT。但是仅仅渲染深度是不够的……

PS:我不想再次将场景显示到带有 z 值的 GL_COLOR_ATTACHMENT0 中,以便获得正确的深度(出于性能原因),也不想使用 OpenGL ES3.0 或新金属(iPhone4s支持)。

有什么想法吗?

【问题讨论】:

    标签: c++ ios opengl-es


    【解决方案1】:

    ES 1 或 2 中没有深度缓冲区支持。请参阅此问题的答案:glReadPixels doesn't read depth buffer values on iOS

    【讨论】:

      【解决方案2】:

      似乎,不可能将GL_UNSIGNED_BYTE 用作type 参数和GL_DEPTH_COMPONENT 作为internalformat,仅允许使用GL_UNSIGNED_SHORTGL_UNSIGNED_INT GL_OES_depth_texture 扩展规范:https://www.khronos.org/registry/gles/extensions/OES/OES_depth_texture.txt

      【讨论】:

        【解决方案3】:

        我终于把 z 值放在了场景的 alpha 部分(我没有为这个 fbo 使用透明度)。

         color.w=(gl_postion.z-near)/(far-near)
        

        有点 mcgyver,但它可以完成工作。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-03-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-18
          • 1970-01-01
          • 2013-05-15
          相关资源
          最近更新 更多