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.
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:
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;
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:
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?