简体   繁体   English

DirectX 11:着色器无法创建世界视图矩阵

[英]DirectX 11: Shader not creating world view matrix

After coming across this problem here , where the the Entity::draw() call would not be displayed due to the vertex shader values returning 0 on multiplication with the world view matrix. 过这样的问题来了之后这里 ,其中的Entity::draw()调用不会因顶点着色器值与世界观矩阵乘法返回0来显示。

在此处输入图片说明

The problem was funneled to a faulty constant buffer input. 问题被归结为错误的常量缓冲区输入。 However, after checking the values, I can't seem to understand the problem at hand. 但是,在检查了值之后,我似乎无法理解当前的问题。 I pre-multiplied the World, View, and Projection matrices: 我预乘了世界,视图和投影矩阵:

mWorld = XMMatrixIdentity();
mView = XMMatrixLookAtLH(Eye, At, Up);
mProjection = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1.0, 0.0f, 1000.0f);
mWVP = mWorld*mView*mProjection;

mWVP

-0.999999940, 0.000000000,  0.000000000, 0.000000000
 0.000000000, 0.999999940,  0.000000000, 0.000000000
 0.000000000, 0.000000000, -1.00000000, -1.00000000
 0.000000000, 0.000000000,  5.00000000,  5.00000000

mWVP enters the constant buffer after being transposed: mWVP转置后进入常量缓冲区:

WorldCB.mWorldVP = XMMatrixTranspose(mWVP);
DeviceContext->UpdateSubresource(MatrixBuffer, 0, NULL, &WorldCB, 0, 0);
DeviceContext->VSSetConstantBuffers(0, 1, &MatrixBuffer);

XMMatrixTranspose(mWVP);

-0.999999940, 0.000000000,  0.000000000, 0.000000000
 0.000000000, 0.999999940,  0.000000000, 0.000000000
 0.000000000, 0.000000000, -1.00000000,  5.00000000
 0.000000000, 0.000000000, -1.00000000,  5.00000000

Which looks OK, at least to me. 至少对我来说看起来不错。 Next my shader starts doing its thing, but here's where things get funky, checking the disassembly yields that when: 接下来,我的着色器开始做它的事情,但是在这里事情变得很时髦,检查反汇编在以下情况下产生的结果:

output.position = mul(position, WVP);

Vertex Shader:
00000000  dp4 o0.x, v0.xyzw, cb0[0].xyzw  
00000001  dp4 o0.y, v0.xyzw, cb0[1].xyzw  
00000002  dp4 o0.z, v0.xyzw, cb0[2].xyzw  
00000003  dp4 o0.w, v0.xyzw, cb0[3].xyzw  
00000004  mov o1.xyzw, v1.xyzw  

For each multiplication, values return 0. And if output.position = position; 对于每个乘法,值返回0 output.position = position; Values are correct, and the box displays, but not inside the world transformation. 值是正确的,并且会显示该框,但不会在世界范围内转换。

The full shader file below: 完整的着色器文件如下:

cbuffer ConstantBuffer:register(b0)
{
    matrix WVP;
}

struct VOut
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
};

VOut VShader(float4 position : POSITION, float4 color : COLOR)
{
    VOut output;
    output.position = mul(position, WVP); // position;
    output.color = color;

    return output;
}


float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
     return color;
}

Edit: Also noted that the Transpose of the World matrix equals zero: 编辑:还注意到世界矩阵的转置等于零:

ObjectSpace = m_Scale*m_Rotation*m_Translate;
mWVP = ObjectSpace*direct3D.mView*direct3D.mProjection;

LocalWorld.mWorldVP = XMMatrixTranspose(wWVP);

XMMatrixTranspose(wWVP) comes out: XMMatrixTranspose(wWVP)出来了:

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

And is likely the problem. 并且可能是问题所在。 Any guesses as to why the transpose of a matrix would equal 0? 关于矩阵转置为何等于0的任何猜测?

The near plane of the perspective projection must be some value larger than zero. 透视投影的近平面必须大于零。 If it is zero, then the near plane is exactly where the camera is located, and everything in the scene converges to a single point. 如果为零,则近平面就是相机所在的位置,并且场景中的所有内容都收敛到一个点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM