I've run into an issue when trying to write a simple rendering program in D3D11. I'm 90% sure it's to do with some faulty matrix multiplication or generation, but I've tried debugging the values of the matrices and they seem fine to me.
The problem is that no matter where I move the eye position, the rendered cube always appears the same.
The resulting screen image is like this:
Each vertex of the cube has a different colour, and the pixel shader should be blending between them, so the gradient effect you can see is between four vertices of the cube.
Here's some of my code
eyePos = XMVectorSet(0.0f, 1.0f, -5.0f, 0.0f);
lookAtPos = XMVectorSet(0.0f,1.0f,0.0f,0.0f);
up = XMVectorSet(0.0f,1.0f,0.0f,0.0f);
world = XMMatrixIdentity();
view = XMMatrixLookAtLH(eyePos, lookAtPos, up);
projection = XMMatrixPerspectiveFovLH(XM_PIDIV2, 1000.0f / 680.0f, 0.01f, 100.0f);
_pIContext->IASetVertexBuffers(0, 1, &_vertexBuffer, &stride, &offset);
_pIContext->IASetIndexBuffer(_indexBuffer, DXGI_FORMAT_R16_UINT, 0);
_pIContext->VSSetConstantBuffers(0, 1, &_cbWorldBuffer);
_pIContext->VSSetConstantBuffers(1, 1, &_cbViewBuffer);
_pIContext->VSSetConstantBuffers(2, 1, &_cbProjBuffer);
And then for shader code, we've got...
cbuffer worldBuffer : register(b0) {
matrix World;
float t;
}
cbuffer viewBuffer : register(b1) {
matrix View;
}
cbuffer projectionBuffer : register(b2) {
matrix Projection;
}
PS_INPUT vs(float4 pos : POSITION, float4 col : COLOUR) {
PS_INPUT output = (PS_INPUT)0;
output.Pos = mul(pos, World);
output.Pos = mul(pos, View);
output.Pos = mul(pos, Projection);
output.Colour = col;
return output;
}
float4 ps(PS_INPUT input) : SV_TARGET{
return input.Colour;
}
My gut tells me it's the projection matrix, although I've based this on another project I did, and comparing the code, I can't find out what I've done differently.