常量缓冲区的问题

发布于 2025-01-10 11:56:52 字数 1537 浏览 0 评论 0原文

我尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文