相机异常行为,DX11

发布于 2024-12-29 16:43:15 字数 1000 浏览 0 评论 0原文

我一直在使用 directx11 编写一个程序,并且编写了一个操作视图矩阵的基本相机类。当我测试程序时,结果是场景没有移动,但是当我移动相机时,它会产生切断任意位置可见内容的效果。我附上了一些图片来说明我的意思。

我现在只让像素着色器输出红色像素。

我的顶点着色器基于 SDK 示例:

cbuffer cbChangeOnResize :寄存器(b1) { 矩阵投影; 我已经为这个问题

cbuffer cbChangesEveryFrame : register(b2)
{
    matrix View;
    matrix World;
};


struct VS_INPUT
{
    float4 Pos : POSITION;
    float2 Tex : TEXCOORD0;
};

struct PS_INPUT
{
    float4 Pos : SV_POSITION;
    float2 Tex : TEXCOORD0;
};

PS_INPUT TEX_VS(VS_INPUT input)
{
    PS_INPUT output = (PS_INPUT)0;
    output.Pos = mul(input.Pos, World);
    output.Pos = mul(output.Pos, View);
    output.Pos = mul(output.Pos, Projection);
    output.Tex = input.Tex;

    return output;
}

绞尽脑汁好几天了,但我不知道是什么导致了这个问题,甚至不知道哪些代码是相关的 PIX 显示世界、视图和投影矩阵似乎存在并且正在被应用,尽管很明显有些地方不对劲。

谢谢。

I've been writing a program using directx11, and I have written a basic camera class which manipulates a view matrix. When I test the program, the result is that the scene does not move, but when I move the camera it has the effect of cutting off what is visible at an arbitrary location. I've attached some pictures to show what I mean.

I have left my pixel shader only outputting red pixels for now.

My vertex shader is based on the SDK example:


cbuffer cbChangeOnResize : register(b1)
{
matrix Projection;
};

cbuffer cbChangesEveryFrame : register(b2)
{
    matrix View;
    matrix World;
};


struct VS_INPUT
{
    float4 Pos : POSITION;
    float2 Tex : TEXCOORD0;
};

struct PS_INPUT
{
    float4 Pos : SV_POSITION;
    float2 Tex : TEXCOORD0;
};

PS_INPUT TEX_VS(VS_INPUT input)
{
    PS_INPUT output = (PS_INPUT)0;
    output.Pos = mul(input.Pos, World);
    output.Pos = mul(output.Pos, View);
    output.Pos = mul(output.Pos, Projection);
    output.Tex = input.Tex;

    return output;
}

I have been scratching my head for a couple of days about this problem, but I don't know what is causing this, or even which pieces of code are relevant. PIX shows that the world, view and projection matrices appear to exist and are being applied, although it is evident that something is not right.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

第七度阳光i 2025-01-05 16:43:15

在将矩阵传递到着色器之前,您可以使用 row_major 修饰符而不是转置矩阵

You can use row_major modifier instead of transposing matrices before passing them inside shader

南…巷孤猫 2025-01-05 16:43:15

数学失败,我将视图矩阵而不是其转置发送到着色器。

Mathematical fail, I had sent the view matrix instead of its transpose to the shader.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文