I am trying to pass a float to a shader to control the alpha channel.
The shader works fine if I hard code a value, but I am having trouble getting the float to the shader via my application.
I have setup an XMFLOAT4 to a constant buffer and have set all of the values XMFLOAT4 to 0.5 (although I should only have to set the first one).
But for some reason it isn't working.
This is the shader (snipped a bit)
cbuffer cbChangesAlpha : register(b3)
{
float4 image_alpha;
}
float4 PShader( PS_Input frag ) : SV_TARGET
{
float4 fRet = colorMap_.Sample( colorSampler_, frag.tex0 );
fRet.a = image_alpha.w; // works if I hard code a value
return fRet;
}
And this is my in-app code
// setting up the XMFLOAT4 constant buffer
ZeroMemory(&constDesc,sizeof(constDesc));
constDesc.BindFlags=D3D11_BIND_CONSTANT_BUFFER;
constDesc.ByteWidth=sizeof(XMFLOAT4);
constDesc.Usage=D3D11_USAGE_DEFAULT;
if(FAILED(d3dDevice->CreateBuffer(&constDesc,0,&floatCB)))
return 11114;
and part of my render loop
XMFLOAT4 image_alpha;
image_alpha.w=0.5;
image_alpha.x=0.5;
image_alpha.y=0.5;
image_alpha.z=0.5;
d3dContext->UpdateSubresource(floatCB,0,0,&image_alpha,0,0);
d3dContext->VSSetConstantBuffers(3,1,&floatCB);
All complies and executes ok but I just get a black screen. If I hard code the shader to be a value between 0 & 1 it works correctly. So, it seems that the image_alpha values are not getting to the shader correctly.
Any advice would be awesome