【发布时间】:2020-08-27 19:09:28
【问题描述】:
我目前正在开发一种新机制,以可视化激光束击中宇宙飞船的护盾。 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);
【问题讨论】:
-
你的渲染目标有 alpha 通道吗?
-
是的,我的 RenderTargetView 的格式是 R8G8B8A8_UNorm。我看到 Alpha 通道的值降至 0.5f,但任何较低的值都会导致不可见。
-
你有一种奇怪的混合状态设置。您的 alpha 设置通常与颜色操作相同。
标签: directx directx-11 hlsl sharpdx pixel-shader