我目前正在开发一种新的机制,以可视化激光束击中宇宙飞船的防护罩。在CPU端的开发已经完成,顶点着色器工作正常,但我在创建像素着色器时遇到了一个问题:任何低于0.5的透明度值都是不可见的。
下面的像素着色器非常简单:如果像素在命中半径内,我会显示一个半透明的蓝色像素,否则什么都不会显示。
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);
}结果如下所示(参见黄色箭头上方的蓝色区域)。

现在,如果我改变这行
return float4(0.0f, 0.0f, 1.0f, 0.5f);至
return float4(0.0f, 0.0f, 1.0f, 0.4f);然后,影响区域是完全看不见的,我想不出任何导致这种行为的原因。你有什么想法吗?
如果有用,下面是我在整个游戏中使用的混合状态的设置。
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);发布于 2020-09-30 19:45:43
blendStateDescription.AlphaToCoverageEnable =真;
在你的情况下肯定会产生问题,将其设置为false将应用正确的alpha混合。
https://stackoverflow.com/questions/63622724
复制相似问题