常量缓冲区的问题
我尝试在 d3d11 中使用常量缓冲区,但事实证明,当着色器将 pos 向量与矩阵相乘时,它不会返回任何内容,并且出现黑屏,我已经尝试了在教程中找到的所有内容,但我什么也没有,这是代码:
D3D11_BUFFER_DESC udesc;
ZeroMemory(&udesc,sizeof(D3D11_BUFFER_DESC));
udesc.Usage = D3D11_USAGE_DEFAULT;
udesc.CPUAccessFlags = 0;
udesc.ByteWidth = sizeof(uniformsperobj);
udesc.MiscFlags = 0;
udesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
hr = dispositivo->CreateBuffer(&udesc,NULL,&uniformbuffer);
//draw frame function//
model = XMMatrixIdentity();
campos = XMVectorSet(0.0f, 0.0f, -0.5f, 0.0f);
camtarget = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
camup = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
view = XMMatrixLookAtLH(posdecam, objdecam, arrdecam);
proyection = XMMatrixPerspectiveFovLH(0.4f * 3.14f, (float)WINDOW_WIDTH /WINDOW_HEIGHT, 1.0, 1000.0f);
XMMATRIX MVP = model*view*proyection;
upo.MVP = XMMatrixTranspose(MVP);
context->UpdateSubresource(uniformbuffer,0,NULL,&upo,0,0);
context->VSSetConstantBuffers(0,1,&uniformbuffer)
/*
********************************shaders.fx***********************************************
*/
cbuffer uniformesporobjeto
{
float4x4 MVP;
};
struct vertex
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};
vertex vshader(float4 position : POSITION, float4 color : COLOR)
{
vertex output;
output.Pos = mul(position, MVP);
output.Color = color;
return output;
}
float4 pshader(vertex input) : SV_TARGET
{
return input.Color;
}
抱歉,如果我发布了太多代码,但问题是我真的不知道错误是否是因为我很愚蠢
im trying to use constant buffers in d3d11 but turns out that when the shader multiplies the pos vector with the matrix it doesnt return anything and i get a black screen,i have tried everything that i found on tutorials but i had nothing,here is the code:
D3D11_BUFFER_DESC udesc;
ZeroMemory(&udesc,sizeof(D3D11_BUFFER_DESC));
udesc.Usage = D3D11_USAGE_DEFAULT;
udesc.CPUAccessFlags = 0;
udesc.ByteWidth = sizeof(uniformsperobj);
udesc.MiscFlags = 0;
udesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
hr = dispositivo->CreateBuffer(&udesc,NULL,&uniformbuffer);
//draw frame function//
model = XMMatrixIdentity();
campos = XMVectorSet(0.0f, 0.0f, -0.5f, 0.0f);
camtarget = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
camup = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
view = XMMatrixLookAtLH(posdecam, objdecam, arrdecam);
proyection = XMMatrixPerspectiveFovLH(0.4f * 3.14f, (float)WINDOW_WIDTH /WINDOW_HEIGHT, 1.0, 1000.0f);
XMMATRIX MVP = model*view*proyection;
upo.MVP = XMMatrixTranspose(MVP);
context->UpdateSubresource(uniformbuffer,0,NULL,&upo,0,0);
context->VSSetConstantBuffers(0,1,&uniformbuffer)
/*
********************************shaders.fx***********************************************
*/
cbuffer uniformesporobjeto
{
float4x4 MVP;
};
struct vertex
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};
vertex vshader(float4 position : POSITION, float4 color : COLOR)
{
vertex output;
output.Pos = mul(position, MVP);
output.Color = color;
return output;
}
float4 pshader(vertex input) : SV_TARGET
{
return input.Color;
}
sorry if i posted too much code but the problem is that i dont really know were the error is because im stupid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论