小编NSF*_*SFW的帖子

6
推荐指数
1
解决办法
1407
查看次数

如何使用SharpDX Toolkit绘制透明3D对象?

我正在开发一个使用SharpDX和SharpDX Toolkit绘制简单3D形状的应用程序,Geometrics.Desktop样本对入门非常有帮助.现在我正在努力使一些形状变得透明,并且为了简单起见,我只是想让那个样本中的茶壶模型显得透明(也许半透明会更精确).

对于那些不熟悉Geometrics.Desktop示例的人,它会在3D中绘制一些简单的原始几何形状.作为一个示例应用程序,它非常简单,因此它是一个非常好的暂存器,用于试验SharpDX"Toolkit"库的3D功能.

我已将此添加到LoadContent方法(在启动时运行一次),以便准备Direct3D进行混合:

        var blendStateDescription = new BlendStateDescription();

        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;

        var blendState = SharpDX.Toolkit.Graphics.BlendState.New(this.GraphicsDevice, blendStateDescription);
        this.GraphicsDevice.SetBlendState(blendState);
Run Code Online (Sandbox Code Playgroud)

我已经设置了深度模板如下:

        var depthDisabledStencilDesc = new DepthStencilStateDescription()
        {
            IsDepthEnabled = false,
            DepthWriteMask = DepthWriteMask.All,
            DepthComparison = Comparison.Less,
            IsStencilEnabled = true,
            StencilReadMask = 0xFF,
            StencilWriteMask = 0xFF,
            // Stencil operation if pixel front-facing.
            FrontFace = new DepthStencilOperationDescription()
            {
                FailOperation = …
Run Code Online (Sandbox Code Playgroud)

c# direct3d direct3d11 sharpdx

6
推荐指数
1
解决办法
1628
查看次数