Hello. I've got a problem i was tryin to resolve last hour...
I want to update 2 constant buffers to the shader: one per frame (view*projection) and one per every object (world matrix)
cbuffer cbPerFrameViewProjection : register(cb0)
{
float4x4 ViewProjection;
};
cbuffer cbPerObjectWorldMatrix : register(cb1)
{
float4x4 World;
};
With trial and error i noticed i cannot set both at once.
From what i read, i got to pass 0/1 to VSSetConstantBuffers:
0 for camera (because cb0)
and 1 for world (because cb1)
it did not work. So for temporary test, i decided to multiply the XMMATRIX (world*view*proj) on cpu and simply pass it to cbPerObjectWorldMatrix. And now:
when i set cbuffer cbPerObjectWorldMatrix : register(cb1) and first param to 1 in VSSetConstantBuffers it did NOT draw anything.
When i set cbPerObjectWorldMatrix : register(cb0) and apram to 0, it worked. Other 0/1 combinations do not work too
d3d11DevCon->VSSetConstantBuffers(0, 1, &cbPerObjectBuffer); // works with cbPerObjectWorldMatrix : register(cb0)
Edit: first param 0 also works with cb1... and even wtih cb any number... whats goin on here
d3d11DevCon->VSSetConstantBuffers(1, 1, &cbPerObjectBuffer); // does not with cbPerObjectWorldMatrix : register(cb1)
So from what i see it COMPLETLY ignores the register cb number part...
Whats wrong?
tl;dr
How can i make 2 or more constant buffers and properly refer to and update each?
At the beginning of frame i call
d3d11DevCon->UpdateSubresource(cbPerFrameBuffer, 0, NULL, &XMMatrixTranspose(cam.GetViewMatrix()*cam.GetProjectionMatrix()), 0, 0);
d3d11DevCon->VSSetConstantBuffers(1, 1, &cbPerFrameBuffer); // 1 for cb1
And for every object
d3d11DevCon->UpdateSubresource(cbPerObjectBuffer, 0, NULL, &XMMatrixTranspose(world.GetTransform()), 0, 0);
d3d11DevCon->VSSetConstantBuffers(0, 1, &cbPerObjectBuffer); // 0 for cb0
Thanks in advance