I tried changing "float4 Color: COLOR1" but didn't help because it's for Diffuse or specular color. I don't know what else to do, I don't know what to add.
I ran out of ideas.
HRESULT GenerateShader(ID3D11Device* pD3DDevice, ID3D11PixelShader**pShader, float r, float g, float b)
{
char szCast[] = "struct VS_OUT"
"{"
" float4 Position : SV_Position;"
" float4 Color : COLOR0;"
"};"
"float4 main( VS_OUT input ) : SV_Target"
"{"
" float4 fake;"
" fake.a = 0.5f;"
" fake.r = %0.2f;"
" fake.g = %0.2f;"
" fake.b = %0.2f;"
" return fake;"
"}";
ID3D10Blob* pBlob;
char szPixelShader[1000];
sprintf(szPixelShader, szCast, r, g, b);
ID3DBlob* d3dErrorMsgBlob;
HRESULT hr = D3DCompile(szPixelShader, sizeof(szPixelShader), "shader", NULL, NULL, "main", "ps_4_0", NULL, NULL, &pBlob, &d3dErrorMsgBlob);
if (FAILED(hr))
return hr;
hr = pD3DDevice->CreatePixelShader((DWORD*)pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, pShader);
if (FAILED(hr))
return hr;
return S_OK;
}
You appear to have taken the code from here: GenerateShader for DirectX11
The point of having the "%" sign in the original code:
is to edit the shader later on with sprintf and parameters r,g,b.
So writing %0.2f does not make sense. If you want hardcoded color values, try removing the "%" signs in your code, so it would be as below:
Where the call to sprintf would be unnecessary (and would create an error since the target string has no parameters to print the rgb values to).
For more info on sprintf.