Directx 低于0.5f的Alpha值不可见

Directx 低于0.5f的Alpha值不可见,directx,directx-11,hlsl,sharpdx,pixel-shader,Directx,Directx 11,Hlsl,Sharpdx,Pixel Shader,我目前正在开发一种新的机制,以可视化激光束击中宇宙飞船的护盾。CPU端的开发已经完成,顶点着色器工作正常,但是我在创建像素着色器时遇到了一个问题:任何低于0.5的透明度值都是不可见的 下面的像素着色器非常简单:如果像素在命中半径内,我将显示一个半透明的蓝色像素,否则将不显示任何内容 float4 PS(PS_IN input) : SV_Target { if (input.impactDistances.x > 0.0f && input.impactDistan

我目前正在开发一种新的机制,以可视化激光束击中宇宙飞船的护盾。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);
}

然后影响区域是完全看不见的,我想不出是什么导致了这种行为。你知道吗

如果有帮助,这里是我在整个游戏中使用的混合状态的设置

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


在您的情况下肯定会产生问题,将其设置为false将应用正确的alpha混合。

渲染目标是否具有alpha通道?是的,我的RenderTargetView的格式为R8G8A8_UNorm。我看到Alpha通道的值下降到0.5f,但是任何更低的值都会导致不可见。混合状态的设置有点奇怪。alpha设置通常与颜色操作相同。
    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);