Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SharpDX/DX11α混合物_C#_Directx_Directx 11_Sharpdx - Fatal编程技术网

C# SharpDX/DX11α混合物

C# SharpDX/DX11α混合物,c#,directx,directx-11,sharpdx,C#,Directx,Directx 11,Sharpdx,我正在尝试使用alpha与SharpDX混合。如果我在输出合并上设置混合状态,则根本不会渲染任何内容,而且我完全不知道为什么。当从不设置混合状态时,一切正常。即使使用默认混合描述设置混合状态,也不会渲染任何内容。我想我遗漏了一些步骤,或者我做了一些错误的事情,所以我将粘贴我得到的,希望有人能指出一些东西 我使用以下代码设置了BlendState: bs = new BlendState(Devices.Device11, new BlendStateDescription()); var bl

我正在尝试使用alpha与SharpDX混合。如果我在输出合并上设置混合状态,则根本不会渲染任何内容,而且我完全不知道为什么。当从不设置混合状态时,一切正常。即使使用默认混合描述设置混合状态,也不会渲染任何内容。我想我遗漏了一些步骤,或者我做了一些错误的事情,所以我将粘贴我得到的,希望有人能指出一些东西

我使用以下代码设置了BlendState:

bs = new BlendState(Devices.Device11, new BlendStateDescription());

var blendDesc = new RenderTargetBlendDescription(
    true,
    BlendOption.SourceAlpha,
    BlendOption.InverseSourceAlpha,
    BlendOperation.Add,
    BlendOption.One,
    BlendOption.Zero,
    BlendOperation.Add,
    ColorWriteMaskFlags.All);

bs.Description.RenderTarget[0] = blendDesc;
…下面是我的渲染循环的内容。如果我所做的只是注释掉context.outputMerge.setblenstate(bs),我的网格渲染很好(没有任何混合,即):

对我来说,渲染到纹理和使用该格式是很重要的。我认为混合可能适用于特定的格式,但我找不到任何提示此类内容的信息

我也在进行多重采样,这就是为什么我在渲染方法的末尾调用ResolveSubresource(…)。我要复制到的纹理与RenderTarget具有相同的描述,但具有不同的SampleDescription

说到多重采样,这里是我使用的光栅化状态:

rs = new RasterizerState(Devices.Device11, new RasterizerStateDescription()
{
    FillMode = FillMode.Solid,
    CullMode = CullMode.Back,
    IsFrontCounterClockwise = true,
    DepthBias = 0,
    DepthBiasClamp = 0,
    SlopeScaledDepthBias = 0,
    IsDepthClipEnabled = true,
    IsScissorEnabled = false,
    IsMultisampleEnabled = true,
    IsAntialiasedLineEnabled = true
});
我使用一个着色器进行渲染,它基本上是一个“Hello World”着色器加上一个摄影机矩阵和基本法线方向照明。我已经验证了我的顶点alpha值是它们应该是什么,就像它们被填充到它们的顶点缓冲区一样。。。即使我在像素着色器的末尾将它们的alpha硬编码为1,只要我使用BlendState,我仍然一无所获。在不使用BlendState的情况下,无论alpha值如何,所有内容都会按预期呈现不透明。我甚至尝试在着色器本身中实现混合状态,但似乎没有任何效果。一切都呈现为完全没有定义混合

如果有必要的话,我会在我的设备上使用FeatureLevel.Level.Level_11_0


不幸的是,这几乎是我不得不继续下去的。就像我说的,这个问题在这一点上对我来说完全是个谜。

只是想为将来来到这里的任何人更新这个。对我有效的东西很简单:

            BlendStateDescription blendStateDescription = new BlendStateDescription
            {
                AlphaToCoverageEnable = false,
            };

            blendStateDescription.RenderTarget[0].IsBlendEnabled = true;
            blendStateDescription.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
            blendStateDescription.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha;
            blendStateDescription.RenderTarget[0].BlendOperation = BlendOperation.Add;
            blendStateDescription.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero;
            blendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
            blendStateDescription.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;
            blendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;

            this._context.OutputMerger.BlendState = new BlendState(_device,blendStateDescription);
我还处理了着色器中的alpha组件,如果您想手动向模型添加透明度,伪代码:

float4 PixelShaderMain( PixelShaderArgs pixelShaderArgs ) 
    : SV_Target
{
    float u = pixelShaderArgs.col.x;
    float v = pixelShaderArgs.col.y;
    float4 color = ShaderTexture.Load(int3(convertUVToPixel(u,v),0));
    return float4(color.r,color.g,color.b,0.5); // 50% transparency
}

希望这能帮助一些人,而不是得到一个基本上毫无意义的死页。大家好

看起来像是这个的复制品啊,我明白了。谢谢亚历山大!我想在这里应该做的是把我的问题标记为重复的,但我还没有找到一种方法。我已经读到,通常它是由其他人做的,他们有足够的声誉或是版主。。。在不满足这些要求的情况下,有没有什么特殊的方法可以解决我自己的问题?
            BlendStateDescription blendStateDescription = new BlendStateDescription
            {
                AlphaToCoverageEnable = false,
            };

            blendStateDescription.RenderTarget[0].IsBlendEnabled = true;
            blendStateDescription.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
            blendStateDescription.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha;
            blendStateDescription.RenderTarget[0].BlendOperation = BlendOperation.Add;
            blendStateDescription.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero;
            blendStateDescription.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
            blendStateDescription.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;
            blendStateDescription.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;

            this._context.OutputMerger.BlendState = new BlendState(_device,blendStateDescription);
float4 PixelShaderMain( PixelShaderArgs pixelShaderArgs ) 
    : SV_Target
{
    float u = pixelShaderArgs.col.x;
    float v = pixelShaderArgs.col.y;
    float4 color = ShaderTexture.Load(int3(convertUVToPixel(u,v),0));
    return float4(color.r,color.g,color.b,0.5); // 50% transparency
}