I am trying to understand shader programming, but at this point, documentation wont help me further.
1] Does the data type & size of the buffers have to match?
In the DX tutorial 4 from the DX SDK, they have a struct:
struct SimpleVertex{
XMFLOAT3 Pos;
XMFLOAT4 Color;
};
While in their shader file, they define:
struct VS_OUTPUT{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
};
They define Pos as a vector of 3 in one file, while it is 4 in another. How is this correct? I thought the size of the data have to match.
2] To create another constant buffer, is this the steps I need to do?
// Make in shader file
cbuffer LightBuffer : register(b0){
float3 lDir;
float4 lColor;
}
// Make in C++ file
struct LightBuffer{
XMFLOAT3 Direction;
XMFLOAT4 Color;
};
...
LightBuffer lb;
lb.Direction=XMFLOAT3(-1.0f, -10.0f, 4.0f); // Make an instance of it
lb.Color=XMFLOAT4(0.35f, 0.5f, 1.0f, 1.0f);
...
ID3D11Buffer* lightBuffer=NULL; // Declare in global scope
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
bd.Usage=D3D11_USAGE_DEFAULT;
bd.ByteWidth=sizeof(LightBuffer);
bd.BindFlags=D3D11_BIND_CONSTANT_BUFFER;
hr=graphics->deviceInterface->CreateBuffer(&bd, NULL, &lightBuffer);
graphics->deviceContext->UpdateSubresource(lightBuffer, 0, NULL, &lb, 0, 0);
graphics->deviceContext->PSSetConstantBuffers(0, 1, &lightBuffer);
These are the steps I did, which was similar to the constant buffer in the tutorial. It ends up producing nothing.
I found out by accident that if I change the type of LightBuffer::XMFLOAT3 Direction to XMFLOAT4, it works. What am I not understanding? Why cant I have the type I wish?
Thanks for reading.