directx11开发中遇到的问题1

1、更新常量缓存

错误的用m_d3dContext->GSSetConstantBuffers(
0,
1,
m_treeConstantBuffer.GetAddressOf()
);

    来代替m_d3dContext->VSSetConstantBuffers(
0,
1,
m_treeConstantBuffer.GetAddressOf()
);

主要原因是搞混了常量缓存的更新和shader类型也是有关系的

2、着色器的语义描述

错误的:

struct VertexShaderInput
{
float3 pos : POSITION;


float3 centerpos:POSITION;


};

正确的:

struct VertexShaderInput
{
float3 pos : POSITION0;

float3 centerpos:POSITION1;

};

const D3D11_INPUT_ELEMENT_DESC mytreeVertexDesc[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION", 1, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

3、几何着色器设为NULL

已经设置了几何着色器,如果不需要了,需设为NULL。

// 设置几何着色器
m_d3dContext->GSSetShader(
NULL,
nullptr,
0
);

4、更新shader中的矩阵需要转置

错误的:

XMStoreFloat4x4(&m_constantBufferData.model, m_matirxRX*m_matirxRZ*m_matrixRY);

正确的:

XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixTranspose(m_matirxRX*m_matirxRZ*m_matrixRY));

5、世界坐标变换

output.posW = mul(pos, W);

其中pos需要为(x,y,z,1.0)类型

6、左手坐标系与右手坐标系

XMMatrixLookAtRH为右手坐标系

XMMatrixLookAtLH为左手坐标系

在使用中确定使用一个即可。

7、创建常量缓存大小应为4的倍数

CD3D11_BUFFER_DESC constantBufferDesc(sizeof(ModelViewProjectionConstantBuffer), D3D11_BIND_CONSTANT_BUFFER);
DX::ThrowIfFailed(
m_deviceResources->GetD3DDevice()->CreateBuffer(
&constantBufferDesc,
nullptr,
&m_constantBuffer
));


// Constant buffer used to send MVP matrices to the vertex shader.
struct ModelViewProjectionConstantBuffer
{
DirectX::XMFLOAT4 gEyePosW;
DirectX::XMFLOAT4 gEmitPosW;

DirectX::XMFLOAT4 gEmitDirW;
// 游戏时间
float gGameTime;
// 时间步长
float gTimeStep;
float pad;
float pad2;
 DirectX::XMFLOAT4X4 model;
DirectX::XMFLOAT4X4 view;
        DirectX::XMFLOAT4X4 projection;
 
};
其中pad和pad2为补齐字节。其它buffer目前还没发现特殊的要求。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kupeThinkPoem

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值