矩阵乘法 - 视图/投影、世界/投影等
在 HLSL 中有很多矩阵乘法,虽然我了解如何以及在何处使用它们,但我不确定它们是如何导出的或它们的实际目标是什么。
所以我想知道是否有在线资源可以解释这一点,我特别好奇将世界矩阵乘以视图矩阵以及世界+视图矩阵乘以投影矩阵背后的目的是什么。
In HLSL there's a lot of matrix multiplication and while I understand how and where to use them I'm not sure about how they are derived or what their actual goals are.
So I was wondering if there was a resource online that explains this, I'm particularly curious about what is the purpose behind multiplying a world matrix by a view matrix and a world+view matrix by a projection matrix.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在这篇维基百科文章或msdn。
本质上,当您将 3D 模型渲染到屏幕上时,您会从分散在 3D 空间中的简单顶点集合开始。这些顶点都有自己的位置,以“对象空间”表示。也就是说,它们通常具有在正在渲染的场景中没有意义的坐标,而仅表达同一模型的一个顶点与另一个顶点之间的关系。
例如,模型顶点的位置只能在 -1 到 1 的范围内(或类似的值,这取决于模型的创建方式)。
为了将模型渲染到正确的位置,您必须缩放、旋转并将其平移到场景中的“真实”位置。您要移动到的位置以“世界空间”坐标表示,该坐标也表示场景中顶点之间的真实关系。为此,您只需将每个顶点的位置与其世界矩阵相乘即可。必须创建此矩阵以包含您需要应用的平移/旋转/缩放参数,以便使对象出现在场景中的正确位置。
此时(将所有模型的所有顶点与世界矩阵相乘后)您的顶点以世界坐标表示,但您仍然无法正确渲染它们,因为它们的位置不相对于您的“视图” (即你的相机)。因此,这次您使用视图矩阵来乘以所有内容,该矩阵反映了渲染场景的视点的位置和方向。
所有顶点现在都处于正确的位置,但为了模拟透视,您仍然有将所有内容与投影矩阵相乘。最后的乘法确定顶点的位置如何根据距相机的距离而变化。
现在,所有顶点,从它们在“对象空间”中的位置开始,都已移动到屏幕上的最终位置,在那里它们将被渲染、光栅化,然后呈现。
You can get some info, from a mathematical viewpoint, on this wikipedia article or on msdn.
Essentially, when you render a 3d model to the screen, you start with a simple collection of vertices scattered in 3d space. These vertices all have their own positions expressed in "object space". That is, they usually have coordinates which have no meaning in the scene that is being rendered, but only express the relations between one vertex and the other of the same model.
For instance, the positions of the vertices of a model could only range from -1 to 1 (or similar, it depends on how the model has been created).
In order to render the model in the correct position, you have to scale, rotate and translate it to the "real" position in your scene. This position you are moving to is expressed in "world space" coordinates which also express the real relationships between vertices in your scene. To do so, you simply multiply each vertex' position with its World matrix. This matrix must be created to include the translation/rotation/scale parameters you need to apply, in order for the object to appear in the correct position in the scene.
At this point (after multiplying all vertices of all your models with a world matrix) your vertices are expressed in world coordinates, but you still cannot render them correctly because their position is not relative to your "view" (i.e. your camera). So, this time you multiply everything using a View matrix which reflects the position and orientation of the viewpoint from which you are rendering the scene.
All vertices are now in the correct position, but in order to simulate perspective you still have to multiply everything with a Projection matrix. This last multiplication determines how the position of the vertices changes based on distance from the camera.
And now finally all vertices, starting from their position in "object space", have been moved to the final position on the screen, where they will be rendered, rasterized and then presented.
在线资源:Direct3D 矩阵、投影指标,Direct3D 转换,DirectX API 中矩阵的重要性。
Online resources: Direct3D Matrices , Projection Metrices, Direct3D Transformation, The Importance of Matrices in the DirectX API.