My mesh vertices are stored this way:
[source]
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0,DXGI_FORMAT_R32G32B32_FLOAT, 0,0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{"COLOR", 0, DXGI_FORMAT_R32_UINT, 0,D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0,D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
[/source]
It is presented to my shaders this way:
[source]
struct VS_INPUT{
float4 pos: POSITION;
float4 normal: NORMAL;
uint col: COLOR;
float2 tex: TEXCOORD0;
float4 tangent: TANGENT;
};
[/source]
The 3D vectors are magically converted into 4D with the w component set to 1. No idea where this is done, but it works.
I wonder if there's a similar trick to convert my UINT into a float4. The rest of my HLSL code needs colours as float4 so it has to be converted somewhere.
This is the function I use now. It works fine but something tells me that it is, as MJP would say, "extremely abnormal" and "off the beaten path". There must be a more efficient and cleaner way.
[source]
float4 MGetVertexColour(uint inCol){
if(inCol==0xffffffff) return float4(1,1,1,1);
float a=((inCol & 0xff000000) >>24);
float r=((inCol & 0xff0000) >> 16);
float g=((inCol & 0xff00) >> 8);
float b=((inCol & 0xff));
return float4(r,g,b,a)/255.0;
}
[/source]