5.2 Operations carried out in view space

来源:互联网 发布:psv淘宝哪家店好 编辑:程序博客网 时间:2024/05/16 04:46

5.2 Operations carried out in view space

Culling or back-face elimination

Culling or back-face elimination is an operation that compares the orientation of complete polygons with the view point of centre of projection and removes those polygons that cannot be seen. If a scene only contains a single convex object, then culling generalizes to hidden surface removal. A general hidden surface removal algorithm is always required when one polygon partially obscures another. On average, half of the polygons in a polyhedron are back-facing and the advantage of this process is that a simple test removes these polygons from consideration by a more expensive hidden surface removal algorithm.

5.2 视图空间内的操作

拣选或背面排除

拣选或者背面排除都是取一个完整多边形的朝向来与投影的视点中心方向相比较之后,移除那些不能被观察到的多边形。如果一个场景中只包含了一个凸面体,culling generalizes to hidden surface removal?当一个多边形遮盖了另一个多边形时,一个简单的隐藏面移除算法会被调用。一般说来,一个多面体将会有一半的多边形处于背面,而这样做的好处即是使用一个简单的test,计算是否移走了这些多边形,而不使用一个需要更大开销的隐藏面移除算法。

The test for visibility is straightforward and is best carried out in view space. We calculate the outward normal for a polygon and examine the sign of the dot product of this and the vector from the centre of projection. Thus:

Visibility: = Np×N>0;

Where:

                Np is the polygon normal

                N is the ‘line of sight’ vector

可见测试非常的直观,而且在视图空间中效果是最好的。我们会计算一个多边形的外表面法向量,同时点乘投影中心的向量。因此:

                可见:=  Np×N>0;

其中:

                Np是多边形的法向量

                N是视线向量

 

The view volume

The view volume was introduced as a semi-infinite pyramid. In many applications this is further constrained to a general view volume which is defined by a view plane window, a near clip plane and a far clip plane, but to simplify matters we will dispense with the near clip plane, which is of limited practical utility, and reconsider a view volume defined only by a view plane window and a far clip plane, note that the far clip plane is a cut-off plane normal to the viewing direction and any objects beyond this cannot be seen. In effect we have turned a semi-infinite pyramid into an infinite one. Far clip planes are extremely useful and can be used to cut down the number of polygons that need to be processed when rendering a very complex scene. For example, when flying through an environment in a three-dimensional computer game we may specify a far clip plane and use depth modulated fog to diminish the disturbance as objects ’switch-on’ when they suddenly intersect the far clip plane.

视域

视域是一个半无限的金字塔。在大多的程序中,这被进一步定义为被视图面板窗口(一个近剪切平面和一个远剪切平面)定义的视域。但为了更为简化,我们省掉了没有太多功用的近剪切平面,认为视域就是一个由远剪切平面和视图面板窗口组成的。远剪切平面是一个定点平面,该平面垂直于观测方向,同时,任何在这之外的物体都不能被观测到。实际上,我们把一个半无限的金字塔改为了一个无限的。远剪切平面非常的有用,并且在对一个非常复杂的场景进行渲染你的时候,可以用于缩减多边形数量。例如,在计算机游戏中,我们飞过一个三维的环境,我们就会用到远剪切平面,同时使用深度雾模型来减少当物体出现在屏幕中(与原剪切平面相交)时产生的干扰。

 

If we further simplify the geometry by specifying a square view plane window of dimension 2h arranged symmetrically about the viewing direction, then the four planes defining the sides of the view volume are given by:

进一步的简化为一个正方形的视图面板窗口按2h(高)对称,此时,定义了这个视域的四条边如下。

Xv =

Yv =

Clipping against the view volume can now be carried out using polygon plane intersection calculations given in Section 1.4.3. This illustrates the principle of clipping, but the calculations involved are more efficiently carried out in three-dimensional screen space as we shall see.

这样,视域剪切面就由多边形平面相交计算之后得到。这阐明了剪切的原理,但是在三维的屏幕看哦你哦关键中,计算会更加的有效。

 

Three-dimensional screen space

The final three-dimensional space in our pipeline we call three-dimensional screen space. In this space we carry out (practical) clipping against the view volume and the rendering processes that we will describe later. Three-dimensional screen space is used because it simplifies both clipping and hidden surface removal – the classic hidden surface removal algorithm being the Z-buffer algorithm which operates by comparing the depth values associated with different objects that project onto the same pixel. Also in this space there is a final transformation to two-dimensional view plane coordinates – sometimes called the perspective divide. (The terms ‘screen’ and ‘view plane’ mean slightly different things. Strictly speaking screen coordinates are derived from view plane coordinates by a device-dependent transformation.)

三维屏幕空间

在管道最后的三维空间我们称为三维屏幕空间。在这个空间中,我们完成基于视域的剪切平面,同时将会进行后面将会提到的渲染。三维屏幕空间的使用,简化了剪切平面和隐藏平面的移除——最为经典的隐藏平面移除算法就是Z-buffer算法,Z-buffer算法通过比较将要投影到同一个像素的不同物体的深度值。同时,在这个空间中,有一个到二维视图平面的最后转换——称为透视分割(屏幕和视图面板是有些微不同的。严格说来,屏幕坐标源于设备相关的转换的视图平面坐标)。

Because the viewing surface in computer graphics is deemed to be flat we consider the class of projections known as planar geometric projections. Two basic projections, perspective and parallel, are now described. These projections and the difference in their nature are illustrated in 5.8.

在计算机图形中,观察表面被认为是平的,因此投影的class当作平坦的集合投影。两种基础投影,透视投影和平行投影。他们的不同将会如下。

A perspective projection is the more popular or common choice in computer graphics because it incorporates foreshortening. In a perspective projection relative dimensions are not preserved, and a distant line is displayed smaller than a nearer line of the same length. This effect enables human beings to perceive depth in a two-dimensional photograph or a stylization of three-dimensional reality. A perspective projection is characterized by a point known as the centre of projection and the projection of three-dimensional points onto the view plane is the intersection of the lines from each point to the centre of projection. These lines are called projectors.

在计算机图形中,透视投影更为常用些。因为它包括了透视缩短法。在透视投影中,相对尺寸不会被保存,并且远处的线段将会比近处的长度相同的线段显示得更短。这一功能使得我们感觉到一个二维图像中的深度(或者一个三维现实的风格)。透视投影的特点是取一个点为投影中心,而三维的点在视图面板上的投影是每一个点发出的线到投影中心的交点。这些线段被称为projectors

=                        s: screen        v: view plane

=                       

 

View volume and depth

We now consider extending the above simple transformations to include the simplified view volume introduced before. We discuss in more detail the transformation of the third component of screen space, namely Zs – ignored so far because the derivation of this transformation is somewhat subtle. Now, the bulk of the computation involved in rendering an image takes place in screen space. In screen space polygons are clipped against scan lines and pixels, and hidden surface calculations are performed on these clipped fragments. In order to perform hidden surface calculations (in the Z-buffer algorithm) depth information has to be generated on arbitrary points within the polygon. In practical terms this means, given a line and plane in screen space, being able to intersect the line with the plane, and to interpolate the depth of this intersection point, lying on the line, from the depth of the two end points. This is only a meaningful operation in screen space providing that in moving from eye space to screen space, lines transform into lines and planes transform into planes. It can be shown (Newman and Sproull 1973) that these conditions are satisfied provided the transformation of z takes the form:

Zs = A + B/Zv

视域及深度

现在把之前提到的简单的转换进行延伸,把前面介绍简化的视域添加进来。将会主要阐述屏幕空间的第三个组成部分即Zs(之前一直被忽略,也是因为它的转换一般是比较细微的)。至今,对一张图片在屏幕空间中的渲染占去了大半的计算。在屏幕空间中,多边形沿着扫描线及像素被剪切,同时,隐藏面的计算也表现在这些剪切片段上。为了表示隐藏面的计算(Z-buffer算法),多边形任意点的深度信息已经被计算出了。在实际运用中,这表示在屏幕空间中的一条直线和平面,这条线可能与平面相交,同时把深度值插入到交点(lying on the line, from the depth of the two end points)。屏幕空间中的这个操作只有在从眼坐标转换到屏幕坐标,直线转化到直线、平面转换到平面时才有意义。当Z满足如下条件时,这就成立:

Zs = A + B/Zv

Where A and B are constants. These constants are determined from the following constraints:

1.       Choosing B<0 so that as Zv increases then so does Zs. This preserves our intuitive Euclidean notion of depth. If one point is behind another, then it will have a larger Zv value, if B<0 it will also have a larger Zs value.

2.       An important practical consideration concerning depth is the accuracy to which we store its value. To ensure this is as high as possible we normalize the range of Zs values so that the range ZvÎ[d, f] maps into the range ZsÎ[0, 1].

其中AB是常量。且由以下条件决定:

1.       B<0,所以Zs随着Zv增加而增加。这与我们几何学中的深度概念吻合。如果一个点位于另一个之后,那么它的Zv值比较大,如果B<0,那么Zs值也更大。

2.       一个关于深度值的更为重要的一点是与精确度相关的。确保其精确值越高越好,我们把ZvÎ[d, f]映射到ZsÎ[0, 1]

The full perspective transformation is given by:

Xs = d

Ys = d

Zs =

Where the additional constant, h, appearing in the transformation for Xs and Ys ensures that these values fall in the range [-1, 1] over the square screen. Adopting a similar manipulation to Section 5.2.3, we have

X =

Y =

Z =

W = Zv

We can now express the overall transformation from world space to screen space as a single transformation obtained by concatenating the view and perspective transformation giving:

从世界空间到屏幕空间可以表示为:

屏幕空间 = TpersTview   一个为投影坐标  另一个为视图坐标

It is instructive to consider the relationship between Zv and Zs a little more closely; although as we have seen by construction, they both provide a measure of the depth of a point, interpolating along a line in eye space is not the same as interpolating this line in screen space. Equal intervals in Zv are compared with the corresponding intervals in Zs. As Zv approaches the far clipping plane, Zs approaches 1 more rapidly. Thus, objects in screen space get pushed and distorted towards the back of the viewing frustum. This difference can lead to errors when interpolating quantities, other than position, in screen space.

ZvZs之间的关系考虑得更近一些是有好处的。从结构中可以得出,他们都表示了点的深度,在眼空间中沿着一条直线进行插值与在屏幕空间中进行同一操作是不一样的。在Zv中的相等组距与Zs中的相对组距是相似的。因为Zv接近了远剪切平面,Zs接近1。因此,在屏幕空间中的物体会朝着背面的观察截面产生变形。这个不同就会导致在屏幕空间中插入quantities(除了位置) 时产生错误。

In spite of this difficulty, by its very construction screen space is eminently suited to perform the hidden surface calculation. All rays passing through the view point are now parallel to the Zs axis because the centre of projection has been moved to negative infinity along the Zs axis. This can be seen by putting Zv = 0 into the above equation giving Zs = -∞. Making those rays that hit the eye parallel, in screen space, means that hidden surface calculation need only be carried out on those points that have the same (Xs, Ys) coordinates. The test reduces to a simple comparison between Zs values to tell if a point is in front of another. The transformation of a box with one side parallel to the image plane is shown in Figure 5.12. Here rays from the vertices of the box to the view point become parallel in three-dimensional screen space.

尽管比较困难,但是屏幕坐标结构非常适合隐藏面计算。所有通过视点的射线都平行于Zs轴,因为投影的中心已经被移动到了Zs的负无穷远。这相当于在上面的等式中让Zv=0Zs = -∞。让这些在屏幕空间中的射线hitparallel,这样就只用针对那些有着相同坐标点进行隐藏面计算。这样,就只需要对比Zs值就可以知道哪些点位置更靠前了。

The overall precision required for the screen depth is a function of scene complexity. For most scenes 8 bits is insufficient and 16 bits usually suffices. The effect of insufficient precision is easily seen when, for example, a Z-buffer algorithm is used in conjunction with two intersecting objects. If the objects exhibit a curve where they intersect, this will produce aliasing artefacts of increasing severity as the precision of the screen depth is reduced.

总体的屏幕深度的精确度是不好把握的。大多数屏幕来说,8位是不够的,而16位则可以。当精确度不够的时候,效果是很明显的。例如,Z-buffer算法常用于计算两个相交物体的结合处。如果在相交的地方,物体呈现的是弯曲的,那么随着屏幕深度的精确度的降低,将会出现锯齿效果。

Now return to the problem of clipping. It is easily seen from Figure5.12 that in the homogeneous coordinate representation of screen space the sides of the view volume are parallel. This means that clipping calculations reduce to limit comparisons – we no longer have to substitute points into plane equations. The clipping operations must be performed on the homogeneous coordinates before the perspective divide, and translating the definition of the viewing frustum into homogeneous coordinates give us the clipping limits:

现在回到剪切的问题。从图5.12可以看出,在其次坐标表示屏幕空间的时候,视域的边都是平行的。这就意味着剪切计算已经简化到limit comparisons(极限比较)——我们不再需要把点带入到平面等式中。在进行投影分割前,剪切操作必须在其次式坐标中实行,

-w ≤ x ≤ w

-w ≤y ≤w

0 ≤z ≤w