I am currently developing on a new mechanism to visualize laser beam hits on spaceships' shields. The development on the CPU side is done and the Vertex Shader is working fine, but I have an issue while creating the Pixel Shader: Any transparency value below 0.5 is invisible.
The following Pixel Shader is incredible simple: If the pixel is inside the hit radius, I show a semi-transparent blue pixel, otherwise nothing is shown.
float4 PS(PS_IN input) : SV_Target
{
if (input.impactDistances.x > 0.0f && input.impactDistances.x < 2.0f)
{
return float4(0.0f, 0.0f, 1.0f, 0.5f);
}
return float4(1.0f, 1.0f, 1.0f, 0.0f);
}
This results in something like this (see blue area above the yellow arrow).
Now, if I change the line
return float4(0.0f, 0.0f, 1.0f, 0.5f);
to
return float4(0.0f, 0.0f, 1.0f, 0.4f);
then the impact areas are completely invisible and I can't think of anything that causes this behaviour. Do you have any idea?
If it helps, here are my settings for the blend state that I use for the entire game.
var blendStateDescription = new SharpDX.Direct3D11.BlendStateDescription();
blendStateDescription.RenderTarget[0].IsBlendEnabled = true;
blendStateDescription.RenderTarget[0].RenderTargetWriteMask = SharpDX.Direct3D11.ColorWriteMaskFlags.All;
blendStateDescription.RenderTarget[0].SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha;
blendStateDescription.RenderTarget[0].BlendOperation = SharpDX.Direct3D11.BlendOperation.Add;
blendStateDescription.RenderTarget[0].DestinationBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha;
blendStateDescription.RenderTarget[0].SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.Zero;
blendStateDescription.RenderTarget[0].AlphaBlendOperation = SharpDX.Direct3D11.BlendOperation.Add;
blendStateDescription.RenderTarget[0].DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.One;
blendStateDescription.AlphaToCoverageEnable = true;
_blendState = new SharpDX.Direct3D11.BlendState(_device, blendStateDescription);
_deviceContext.OutputMerger.SetBlendState(_blendState);

blendStateDescription.AlphaToCoverageEnable = true;
will definitely create an issue in your case, setting it to false will apply correct alpha blending.