ModelViewProjection 与 WorldViewProjection 相同吗?
我正在将一些代码从 HSLSL 和 XNA 转换为 CG 和 OpenGL。
该代码用于渲染体积数据。但体积数据也不是在每个维度上使用相同的距离进行采样,例如(0.9f、1f、1f)。因此需要应用比例因子。
在 XNA 和 HLSL 示例中,它们执行以下操作:
mul(input.Position * ScaleFactor, WorldViewProj);
将 WorldViewProj 传递到着色器中。
在OpenGL中,我的印象是glstate.matrix.mvp是ModelViewProjection,其中ModelView是World * View。显然我错了,因为当我执行以下操作时,没有绘制任何内容。
output.Position = mul( input.Position * scale, glstate.matrix.mvp);
体积是通过将 glMatrixMode 设置为 GL_MODELVIEW 来渲染的。我必须创建自己的矩阵吗?如果是的话,有什么好的教程吗? :D
I am converting some code from HSLSL and XNA to CG and OpenGL.
The code is for rendering volume data. But volume data is not also sampled using the same distance in each dimension, for example (0.9f, 1f, 1f). So a scale factor need to be applied.
In the XNA and HLSL example, they do the following:
mul(input.Position * ScaleFactor, WorldViewProj);
Where WorldViewProj is passed into the shader.
In OpenGL, I was under the impression that glstate.matrix.mvp was ModelViewProjection, where ModelView is World * View. Clearly I am wrong as when I do the following, nothing is drawn.
output.Position = mul( input.Position * scale, glstate.matrix.mvp);
The volume is been rendered with glMatrixMode set to GL_MODELVIEW. Will I have to create my own matrices? If so, any good tutorials? :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
glMatrixMode 有点像其他矩阵操作函数的
with
语句。所以应该被解释为
诸如此类。
此外,请参阅@Tobias Schlegel 的回答。着色器以所谓的“Uniforms”的形式获取“恒定”输入。旧版本的 OpenGL 传递固定的函数状态,例如模型视图矩阵。较新的 OpenGL 版本(OpenGL-3 核心及更高版本)弃用了所有内置矩阵操作内容。相反,用户应该跟踪变换管道并通过自定义制服提供所有所需的矩阵。这也允许模拟 DirectX 行为。
glMatrixMode is kind of like a
with
statement for the other matrix manipulation functions. Sois to be interpreted like
and so on.
Furthermore see the answer of @Tobias Schlegel. Shaders get their "constant" input in form of so called Uniforms. Older versions of OpenGL pass on the fixed function state, like the modelview matrix. Newer OpenGL versions (OpenGL-3 core and later) depreceated all the built in matrix manipulation stuff. Instead the user is expected to keep track of the transformation piple and to supply all required matrices through self defined uniforms. This also allows to emulate the DirectX behaviour.
在固定功能管道中,openGl 和 DirectX 的不同之处在于它们定义空间的方式。 OpenGL 只有模型空间和视图空间,因此有模型视图矩阵。在DX中还有一个世界空间。模型从模型空间转换到世界空间,然后转换到视图空间。
但是,在这种情况下,我认为您可以将模型和视图空间视为平等。如果您的模型以世界为中心(使模型->世界转换成为非操作),就会出现这种情况。
使用着色器时,您基本上可以自由地做任何您想做的事情并使用您想要的空间。
DX 还使用行优先和 openGl 列优先矩阵表示。因此,如果您复制 DX 示例,则必须转置矩阵并反转矩阵运算的顺序。
In the fixed function pipeline openGl and DirectX differ in the way they define spaces. OpenGl only has a Model- and a View-space, hence a ModelViewMatrix. In DX there is also a World-space. Models are translated from Model-space into World-space and then into View-space.
However, in this case i think that you can treat Model and View-space as equal. That would be the case if your model is centered in the World (making the Model->World translation a non-operation).
When using shaders you are basically free to do whatever you want and use the spaces you want.
Also DX uses row-major and openGl column-major matrix-representations. So if you copy DX examples you have to transpose the matrices and reverse the order of matrix-operations.