My idea is simple: all the colors I have, are in RGB(A) format [0-255, 0-255, 0-255, 0-255].
For me it seems a good idea to pass only 4 bytes as one unsigned value and somehow (automatically) decode it in a shader to unorm float[3].
Instead of a way I always follow: pass 12 bytes as float[3] from C++ directly.
Is it possible to reinterpret 4 bytes as float4 inside a shader?
C++
struct RdAmbientLight
{
unsigned colorUNorm = 0xFFFFFFFF;
//Other data
};
void DefPass2::createPsAmbientColorCb()
{
CD3D11_BUFFER_DESC constantBufferDesc(sizeof(RdAmbientLight), D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
m_device->CreateBuffer(&constantBufferDesc, nullptr, &m_psAmbientCb);
}
HLSL:
cbuffer AmbientLight: register(b1)
{
unorm float4 Color; //< Some automatic decoding
};