简体   繁体   English

OpenGLES iPhone深度融合问题

[英]OpenGLES iPhone Depth Blending problem

I am trying to make an OpenGLES 2.0 cube application. 我正在尝试制作OpenGLES 2.0多维数据集应用程序。 The idea was to have a texture (with an alpha 75%) applied to all 6 faces of the cube. 想法是将纹理(alpha为75%)应用于立方体的所有6个面。 This would mean that even if I rotate the cube i would be able to see all 6 faces at any given frame. 这意味着即使我旋转多维数据集,我也可以在任何给定的帧中看到所有6个面。 Now I have enabled depth test(my app needs this!!) and blending. 现在,我启用了深度测试(我的应用需要此功能!)和混合。 The Depth func is LEQUAL and blend func is SRC_ALPHA, ONE_MINUS_SRC_ALPHA. 深度函数为LEQUAL,混合函数为SRC_ALPHA,ONE_MINUS_SRC_ALPHA。

Now, the issue is that at some cube faces don't show the underlying faces. 现在的问题是,在某些多维数据集面上没有显示底层面。 I am not able to understand this because the logic works fine with the other cube faces. 我无法理解这一点,因为该逻辑可以与其他多维数据集面一起正常工作。 Just for the record, I have disabled CULL_FACE. 仅作记录,我已禁用CULL_FACE。

Thanks in advance. 提前致谢。

Regards, 问候,

Puzzler 益智游戏

Faces are drawn in order they are defined. 按定义顺序绘制面。 Now as cube is rotated their draw order is not changed. 现在,随着立方体旋转,它们的绘制顺序不会改变。 Some faces are drawn close to camera first. 首先在靠近相机的位置绘制一些脸部。 Then some face is drawn after that, but Z-test says that there already is a pixel closer to the camera so no drawing needs to be done. 然后在那之后绘制一些面部,但是Z-test说已经有一个像素更靠近相机,因此不需要绘制。

Problem here is that OpenGL|ES 2.0 does not sort faces when they are rendered. 这里的问题是OpenGL | ES 2.0在渲染面孔时不会对其进行排序。 Handling transparency and depth correctly remains as a real challenge in 3D programming, but for easy case like this, you can just sort the faces back to front. 在3D编程中,正确处理透明度和深度仍然是一个真正的挑战,但是对于像这样的简单情况,您可以将这些面从前到后进行排序。 Drawing back to front is called "Painter's algorithm" and sorting is called "depth sorting" or "z-sorting". 从头到尾称为“ Painter算法”,排序称为“深度排序”或“ z排序”。

Simple, definetly not best and surely inefficient way might work like this: 简单,绝对不是最好的,肯定是效率低下的方法可能会像这样工作:

  1. Calculate center vertex of the face by calculating average of three vertices 通过计算三个顶点的平均值来计算面的中心顶点
  2. Project them to screen space by transforming them through camera (view+projection) and possible model-matrices 通过相机(视图+投影)和可能的模型矩阵将它们转换为屏幕空间
  3. Sort their Z-values by some sort algorithm 通过某种排序算法对其Z值进行排序
  4. Build vertex buffer with vertices in this order or just rewrite index buffer in new order (less stuff to move around if vertices are not changed) 按此顺序用顶点构建顶点缓冲区,或仅按新顺序重写索引缓冲区(如果顶点不变,则可以移动的东西更少)
  5. Render cube as usual 像往常一样渲染立方体

There are better ways to handle this problem and there all kinds of advanced optimizations out there. 有更好的方法可以解决此问题,并且还有各种高级优化方法。 But I didn't found any tutorial to cover simple case like this. 但是我没有找到任何涵盖这种简单案例的教程。 Perhaps I just didn't found right keywords. 也许我只是找不到合适的关键字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM