什么是DirectX Vertex中的RHW [英] What is RHW in DirectX Vertex

查看:145
本文介绍了什么是DirectX Vertex中的RHW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道RHW是互惠的同质W,但是有人可以解释它的用法和作用吗?

I know RHW is Reciprocal Homogeneous W, but could someone explain how it can be used and what it does ?

推荐答案

gamedev论坛上的解释发布 msdn .

Explanation on gamedev forum post and msdn.

引用gamedev,OP jpetrie 的答案:

to quote the answer from gamedev, OP jpetrie:

RHW是齐次(夹空间)w坐标的倒数一个顶点(例如1/w).

RHW is the reciprocal of the homogeneous (clip space) w coordinate of a vertex (e.g., 1/w).

回想一下,我们必须将3D向量扩展到4D向量才能成为能够将它们与4x4矩阵相乘(我们这样做是因为4x4矩阵使我们可以完全编码旋转,平移,和缩放条件).为此,我们经常设置(或假设)展开第四个(w)分量是模型顶点的1,其性质我们用来将模型空间顶点带入世界或视图的变换空格不包含任何会改变w成分的术语.

Recall that we must expand our 3D vectors to 4D vectors in order to be able to multiply them with 4x4 matrices (which we do because 4x4 matrices allow us to completely encode both rotational, translational, and scaling terms). In doing so we often set (or assume) the expanded fourth (w) component is 1 for model vertices, and the nature of the transforms we use to bring model-space vertices into world or view space doesn't include any terms that alter the w component.

但是,典型的透视投影转换通常需要遵循一般形式

However, the typical perspective projection transformation often takes the follow general form

A 0 0 0 0 B 0 0 0 0 C D 0 0 E 0

A 0 0 0 0 B 0 0 0 0 C D 0 0 E 0

与普通视图空间顶点向量相乘时(x,y,z,1),给你一个像(Ax,By,Cz + E,zD)的向量-注意所得顶点的w分量与w成正比原始输入的z分量.另请注意,您之后的空格通过该矩阵相乘的结果称为剪辑空间,因为其性质转换的结果使视锥从长方体扭曲成长方体,边缘更容易进行剪裁.

which, when multiplied with a general view-space vertex vector (x,y,z,1), gives you a vector like (Ax, By, Cz + E, zD) -- note that the resulting vertex has a w component that is proportional to the original input's z component. Also note that the space you're in after multiplication by this matrix is called clip space, because the nature of the transform has distorted the viewing frustum into a cuboid, the edges of which are much easier to perform clipping against.

裁剪后,图形管线除以w分量根据距离缩放事物以提供透视效果.该除法不能在矩阵变换中编码.

After clipping, the graphics pipeline divided by the w component to scale things based on distance to give you the perspective effect. This division cannot be encoded in a matrix transform.

现在,除以w等于乘以的倒数w,以及要求您提供的倒数的原因带有w坐标的剪辑空间可能是回溯到除法明显比乘法慢.使用时预转换的顶点,从模型到世界到剪切空间的视图被跳过,但管道的其余部分(划分通过w,转换为窗口坐标并进行光栅化)仍然必须发生.由于跳过了投影变换,因此是管道确定要除以的w坐标的依据通过,所以它要求您.

Now, division by w is the same as multiplication by the reciprocal of w, and the reason that you are required to give the reciprocal of the clip space w coordinate is probably a throwback to the time when division was significantly slower than multiplication. When you use pre-transformed vertices, the transformation from model to world to view to clip space is skipped, but the rest of the pipeline (division by w, conversion to window coordinates, and rasterization, obviously) must still happen. Since the projection transform was skipped, there is no basis for the pipeline to determine the w coordinate to divide by, so it asks you for it.

该值有一些有趣的用途,但在大多数情况下人们在进行2D渲染时会使用预变换的顶点,在这种情况下,将RHW值设置为1最为有用导致除数为空.

There are some interesting uses for the value, but for the most part people use pretransformed vertices when doing 2D rendering, and in that case its most useful to set the RHW value to 1, which effectively causes the divide to be a no-op.

这篇关于什么是DirectX Vertex中的RHW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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