Tutorial 4: 3D Spaces

Rasterization

The process of converting a triangle defined by three vertices to a bunch of pixels covered by the triangle is called rasterization.

There are several spaces commonly used in computer graphics: (几种空间)

object space(model space):局部空间(局部坐标系)

world space:世界空间(世界坐标系)

view space(camera space):观察空间(观察坐标系)

projection space:投影空间

screen space:屏幕空间

下图是一个简单的绘制流水线,每一个space的变换都是一个transformation,transformation实际上就是一个矩阵相乘的过程。

 

vertex shader receivecs input vertex data in object space.(VS的输入为对象的局部坐标)

World space is a space shared by every object in the scene.

View space is used for the entire scene.In the view space, the origin is at the viewer or camera. The view direction difines the positive Z axis. An "up" direction defined by the appication

becomes the positive Y axis.(照相机的朝向定义了Z方向,up方向定义了Y方向。)

Projection space refers to the space after applying transformation from view space. In this space, visible content has X and Y coordinates ranging from -1 to 1, and Z coordinate ranging from 0 to 1.

Screen space is often used to refer to locations in the frame buffer. Because frame buffer is usually a 2D texture, screen space is a  2D space. The top-left corner is the origin with coordinates (0, 0). The positive X goes to right and positive Y goes down. For a  buffer that is w pixels wide and h pixels high, the most lower-right pixel has the coordinates (w - 1, h - 1).

各种Transformation的理解

View transformation是将camera/viewer的变换的逆变换作用于WS中的vertices。XMMatrixLookAtLH()函数帮忙完成此工作。

FOV(field-of-view)

d/h is the cotangent of half of FOV.

理解此段:

Instead, the GPU generally performs projection transformation first, and then clips against the view frustum volume (GPU一般首先进行投影变换,然后进行裁剪) . The effect of projection transformation on the view frustum is that the pyramid shaped view frustum becomes a box in projection space. This is because, as mentioned previously, in projection space the X and Y coordinates are based on the X/Z and Y/Z in 3D space.  Therefore, point a and point b will have the same X and Y coordinates in projection space, which is why the view frustum becomes a box.

(cliping 就是过滤掉view frustum之外的对象。因为投影变换在cliping之前,而投影变换使得view frustum变成为一个box,从而简化了cliping的计算。)

Projection Space:

  投影空间指的是对观察空间应用投影矩阵后得到的空间。在投影空间中,X和Y的范围皆为-1到1,Z坐标的范围为0到1。将投影空间设定为以上数值是为了便于进行视景体裁剪。可以通过XMMatrixPerspectiveFovLH方便地获得投影变换矩阵。

XMMatrixPerspectiveFovLH函数原型:

XMMATRIX XMMatrixPerspectiveFovLH(FLOAT FovAngleY, FLOAT AspectRatio, FLOAT NearZ, FLOAT FarZ);

  参数FovAngleY表示的是Y方向的视野

  参数AspectRatio表示观察空间的宽高比,通常设置为render target的宽高比

  参数NearZ和FarZ分别表示视景体的远近平面

  通过FovAngleY和AspectRatio可以得到FovAngleX,用于计算视景体

posted @ 2011-02-15 11:32  斯芬克斯  阅读(629)  评论(0编辑  收藏  举报