一些关于OpenGL透明度的问题 [英] Some questions about OpenGL transparency

查看:208
本文介绍了一些关于OpenGL透明度的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个有关OpenGL混合的问题。



1)我知道我必须先画不透明的物体,然后从不透明的物体上回到前面。所以我把它们放在一个列表中,取决于到中心的距离(0,0,0)。但是,转换(旋转和平移)会影响我测量距离的中心吗?第二,如果我绘制的项目是三角形,怎么做我测量距离?它的香?到其正中心?

解决方案

您当然需要将转换考虑在内以进行排序。应用所有的转换,然后按产生的深度(z坐标)进行排序是最直接的方法。

实现同样效果的最有效方式是对每个对象(或使用相同变换的对象集合)应用逆向变换一次,然后计算每个顶点/三角形的深度作为顶点与此逆向变换视图向量的点积。这需要每个三角形只有一个点积,而不是对它们进行全面转换。而且三角形的数量通常比对象的数量大得多。



至于要使用哪一点:真的没有解决方案适用于所有情况。三角形的中心应该和任何东西一样好。这种方法是一种近似,在许多情况下工作得很好,但在某些情况下并不完全正确。

为了说明依赖透明度的透明度所面临的基本挑战,我们来看几个例子。在下图中,视图方向是从左到右,我们看着两个三角形A和B的边:

  \ 
\
B
\
\\
\\
view -----> \
A
\
\

从视觉上看,很显然B在A后面,需要先画出。然而:


  • B的最近点比A的最近点更接近视点。

  • B的最远点比A的最远点更靠近视点。
  • B的中心点比A的中心点更接近视点。



通过比较每个三角形的单个深度值,您无法正确排序这些三角形。为了正确处理这个问题,你必须考虑几何,并使用更复杂的标准来正确地订购。



然后有些情况下没有有效的订单:

  \ / 
\ /
view -----> \ /
/ \
BA
/ \

在这里,没有A和B的排序顺序是有效的。 B的部分位于A的后面,A的部分位于B的后面。只要有三角形相交,就是这种情况。正确解决这个问题的唯一方法就是分割三角形。



还有没有任何相交三角形的配置,没有有效的顺序。这是一个有4个三角形的例子,这次从顶部看:

  ___________ 
| \ \ |
__ | _\ ________ \ | ___
| \ | | __ /
| ______ \ |
| ________ / \ |
| \ \ _____ | __
| \ _______ / |
__ | \ |
/ __ | \ ______________ |
| \ \ |
| __________ \ \ |

这些困难是订单独立透明度渲染方法如此吸引人的重要原因,除了避免开销的分拣。


I have two questions about OpenGL blending.

1) I know I have to draw opaque objects first and then draw from back to front the non-opaque ones. So I put them in a list depending in the distance to the center (0,0,0). But do transformations (rotate and translate) affect the "center" from where I measure the distance?

2) And second, if the items I draw are triangles, how do I measure the distance? To its incenter? To its orthocenter?

解决方案

You certainly need to take the transformations into account for sorting. Applying all the transformations, and then sorting by the resulting depth (z-coordinate), is the most direct approach.

A mostly more efficient way of achieving the same thing is to apply the inverse transformations to your view direction once for each object (or set of objects that use the same transformations), and then calculate the depth of each vertex/triangle as the dot product of the vertex with this inverse-transformed view vector. This will require only one dot product per triangle, instead of applying full transformations to them. And the number of triangles is often orders magnitude larger than the number of objects.

As to which point to use: There's really no solution that will work for all cases. The center of the triangle should e as good as anything. This whole approach is an approximation that will work sufficiently well in many cases, but will not be entirely correct in some scenarios.

To illustrate the fundamental challenges with order-dependent transparency, let's look at a few examples. In the following figure, the view direction is from left to right, and we look at two triangles A and B edge on:

             \
              \
               B
                \
               \ \
                \ \
view ----->      \
                  A
                   \
                    \

Visually, it's clear that B is behind A, and needs to be drawn first. Yet:

  • The closest point of B is closer to the view point than the closest point of A.
  • The farthest point of B is closer to the view point than the farthest point of A.
  • The center point of B is closer to the view point than the center point of A.

You can't sort these triangles correctly by comparing one single depth value from each of them. To handle this properly, you have to take the geometry into account, and use more complex criteria to order them properly.

Then there are cases where there is no valid order:

               \    /
                \  /
view ----->      \/
                 /\
                B  A
               /    \

Here, there is no sorting order for A and B that would be valid. Parts of B are behind A, and parts of A are behind B. This will be the case whenever you have intersecting triangles. The only way to correctly resolve this is to split triangles.

There are also configuration without any intersecting triangles where there is no valid order. This is an example with 4 triangles, looking from the top this time:

             ___________
   |\        \          |
 __|_\________\         |___
|              \        |__/
|         ______\       |
|________/       \      |
   |     \        \_____|__
   |      \_______/        |
 __|       \               |
/__|        \______________|
   |         \        \ |
   |__________\        \|

These difficulties are an important reason why order independent transparency rendering methods are so attractive, beyond just avoiding the overhead of sorting.

这篇关于一些关于OpenGL透明度的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆