Пример #1
0
        /// <summary>
        /// Returns default values for <see cref="D3D11.BlendDescription"/>.
        /// Original code from https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.Direct3D11/BlendStateDescription.cs
        /// </summary>
        private static D3D11.BlendDescription CreateDefaultBlendDescription()
        {
            var description = new D3D11.BlendDescription()
            {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false,
            };
            var renderTargets = description.RenderTarget;

            for (var i = 0; i < renderTargets.Length; i++)
            {
                renderTargets[i].IsBlendEnabled   = false;
                renderTargets[i].SourceBlend      = D3D11.Blend.One;
                renderTargets[i].DestinationBlend = D3D11.Blend.Zero;
                renderTargets[i].BlendOperation   = D3D11.BlendOperation.Add;

                renderTargets[i].SourceBlendAlpha      = D3D11.Blend.One;
                renderTargets[i].DestinationBlendAlpha = D3D11.Blend.Zero;
                renderTargets[i].BlendOperationAlpha   = D3D11.BlendOperation.Add;

                renderTargets[i].RenderTargetWriteMask = D3D11.ColorWriteEnable.All;
            }

            return(description);
        }
Пример #2
0
        private ID3D11BlendState CreateNewBlendState(ref BlendStateDescription description)
        {
            BlendAttachmentDescription[]        attachmentStates  = description.AttachmentStates;
            Vortice.Direct3D11.BlendDescription d3dBlendStateDesc = new Vortice.Direct3D11.BlendDescription();

            for (int i = 0; i < attachmentStates.Length; i++)
            {
                BlendAttachmentDescription state = attachmentStates[i];
                d3dBlendStateDesc.RenderTarget[i].IsBlendEnabled        = state.BlendEnabled;
                d3dBlendStateDesc.RenderTarget[i].RenderTargetWriteMask = ColorWriteEnable.All;
                d3dBlendStateDesc.RenderTarget[i].SourceBlend           = D3D11Formats.VdToD3D11Blend(state.SourceColorFactor);
                d3dBlendStateDesc.RenderTarget[i].DestinationBlend      = D3D11Formats.VdToD3D11Blend(state.DestinationColorFactor);
                d3dBlendStateDesc.RenderTarget[i].BlendOperation        = D3D11Formats.VdToD3D11BlendOperation(state.ColorFunction);
                d3dBlendStateDesc.RenderTarget[i].SourceBlendAlpha      = D3D11Formats.VdToD3D11Blend(state.SourceAlphaFactor);
                d3dBlendStateDesc.RenderTarget[i].DestinationBlendAlpha = D3D11Formats.VdToD3D11Blend(state.DestinationAlphaFactor);
                d3dBlendStateDesc.RenderTarget[i].BlendOperationAlpha   = D3D11Formats.VdToD3D11BlendOperation(state.AlphaFunction);
            }

            d3dBlendStateDesc.AlphaToCoverageEnable = description.AlphaToCoverageEnabled;

            return(_device.CreateBlendState(d3dBlendStateDesc));
        }