应用投影矩阵后对象消失
Object disappears after applying projection matrix
我正在尝试使用 DirectX 显示一个 3D 立方体。我创建了一个 x64 c++ 窗口应用程序,以下顶点和索引描述了多维数据集(请注意,多维数据集故意没有底部(
Vertex cube[]
{
{-0.25f, -0.5f, 0.25f},
{-0.25f, 0.5f, 0.25f},
{0.25f, 0.5f, 0.25f},
{0.25f, -0.5f, 0.25f},
{-0.25f, -0.5f, 0.5f},
{-0.25f, 0.5f, 0.5f},
{0.25f, 0.5f, 0.5f},
{0.25f, -0.5f, 0.5f}
};
unsigned short cubeIndices[]{
0, 1, 2, // front
0, 2, 3,
4, 5, 6, // back
4, 6, 7,
1, 5, 6, // top
1, 6, 2,
0, 4, 5, // left
0, 5, 1,
3, 2, 6, // right
3, 6, 7
};
我没有深度/模板视图,因为我假设我不需要它,因为它只是一个简单的立方体。 我创建了一个常量缓冲区
struct ConstantBuffer {
DirectX::XMMATRIX model;
DirectX::XMMATRIX view;
DirectX::XMMATRIX projection;
};
此缓冲区是根据我从 SDK 的 DirectXMath 库中使用的方法填充的。
// Based on MSDN, direct x uses left handed und looks in positive Z
m_constantBufferData.model = m_constantBufferData.model * DirectX::XMMatrixTranslation(0.0f, 0.0f, 8.0f); // move it by 8 units in positive z)
m_constantBufferData.view = DirectX::XMMatrixIdentity(); // I assume we do not need to put anything in view, because the object is in positive z and center
m_constantBufferData.projection = DirectX::XMMatrixPerspectiveFovLH(DirectX::XMConvertToRadians(90.0f), 1920.0f/1080.0f, 0.1f, 100.0f);
//m_constantBufferData.projection = DirectX::XMMatrixOrthographicLH(1920.0f, 1080.0f, 0.1f, 100.0f);
后台缓冲区和窗口的大小为 1920x1080 像素。
我的顶点着色器如下所示:
cbuffer simpleConstantBuffer : register(b0)
{
matrix model;
matrix view;
matrix projection;
}
float4 main(float4 pos : POSITION) : SV_POSITION
{
float4 output = pos;
output = mul(output, model);
output = mul(output, view);
output = mul(output, projection);
return output;
}
我不知道可能出了什么问题。屏幕上没有绘制任何内容,尽管我的像素着色器输出红色,如果我将所有矩阵设置为单位矩阵,我会看到呈现立方体的红色正面。我假设它是透视矩阵的东西(正交也不起作用(?
知道如何进一步调试它或可能有什么问题吗?
更新: 作为补充,这就是 nvidia nsight 向我展示的常量缓冲区中的矩阵是什么,以防万一有帮助:
Model:
(1.00, 0.00, 0.00, 0.00)
(0.00, 1.00, 0.00, 0.00)
(0.00, 0.00, 1.00, 8.00)
(0.00, 0.00, 0.00, 1.00)
View:
(1.00, 0.00, 0.00, 0.00)
(0.00, 1.00, 0.00, 0.00)
(0.00, 0.00, 1.00, 1.00)
(0.00, 0.00, 0.00, 1.00)
Projection:
(0.56, 0.00, 0.00, 0.00)
(0.00, 1.00, 0.00, 0.00)
(0.00, 0.00, 1.00, -0.10)
(0.00, 0.00, 1.00, 0.00)
我在查看了微软github页面上的一些示例后才想通。出于某种原因,他们使用XMMatrixTranspose。应用后它可以工作。
但是,我不知道为什么我必须使用它,如果它是相同的技术,这意味着纯 DirectX 和 HLSL 着色器。我认为它们都是列/行主要,没有什么不同。但似乎矩阵函数返回另一种格式。
相关文章:
- 什么时候调用组成单元对象的析构函数
- 对RValue对象调用的LValue ref限定成员函数
- CMake-按正确顺序将项目与C运行时对象文件链接
- 空基优化子对象的地址
- 将对象数组的引用传递给函数
- 你能重载对象变量名本身返回的内容吗
- C++使用整数的压缩数组初始化对象
- 将地址分配给本地指针后,公共对象的变量将消失
- 应用投影矩阵后对象消失
- C++ 在地图上循环 - 消失的对象
- C++ GLUT 使对象在视口外消失
- 如何将指针分配给功能中的新对象,而不会使该对象在退出后消失
- 对象在另一个对象的变量中消失
- 字符串神秘地消失了,将字符串从C++带到对象C++
- 当在另一个较小的对象Opengl后面时,“大对象”将消失
- 创建一个新对象并将该对象存储在新类的向量中,属性消失
- openGl对象在特定位置消失
- OpenGL顶点着色器变换,对象消失
- QWebEngine & QWebChannel:传输对象"qt.webChannelTransport"在页面重新加载后消失
- 从共享对象符号表中消失"extern C"函数C++