I am quite confused with how the game engine handles camera view in DirectX. I know all the matrix stuffs, but where the projection matrix goes finally seems rarely mentioned.
I looked up in the sample project by microsoft https://msdn.microsoft.com/en-us/windows/uwp/gaming/tutorial--create-your-first-metro-style-directx-game
in the GameRenderer::CreateWindowSizeDependentResources()
method, the projection process is implemented
XMFLOAT4X4 orientation = m_deviceResources->GetOrientationTransform3D();
ConstantBufferChangeOnResize changesOnResize;
XMStoreFloat4x4(
&changesOnResize.projection,
XMMatrixMultiply(
XMMatrixTranspose(m_game->GameCamera()->Projection()),
XMMatrixTranspose(XMLoadFloat4x4(&orientation))
)
);
d3dContext->UpdateSubresource(
m_constantBufferChangeOnResize.Get(),
0,
nullptr,
&changesOnResize,
0,
0
);
However I can't figure out what the UpdateSubresources
method has anything to do with projection (yet such projection in the UpdateSubresources
method exists in some other samples I found). But wouldn't it be absurd to change the entire buffer every frame for projection? Isn't the data in the buffer in world view coordinates?
The vertex shader seems also take the task of projection
PixelShaderInput output = (PixelShaderInput)0;
output.position = mul(mul(mul(input.position, world), view), projection);
I do think this one is more plausible for the task.
So the questions are:
Which one exactly is the process of projection, and how does it come along in two places?
If it happens in UpdateSubresources, what should I do with dynamic buffer?
If it happens in the shader, where does the world, view, projection matrics come from?
How should I use it with SharpDX
// Update Constant Buffer context.UpdateSubresource(ref worldViewProj, this.constantBuffer, 0);
the matrix is in a parameter list with the constantBuffer which holds vertices. Does this implies a transformation of such matrix on the vertices? \$\endgroup\$