Example #1
0
        void DrawWithAlfaBlending(GraphicsDevice graphics,
                                  RasterizerStateDescription2 stated,
                                  IGeometryData geo)
        {
            var context = graphics.ImmediateContext;

            var mode = stated.CullMode;



            if (mode == CullMode.Back || mode == CullMode.None)
            {
                stated.CullMode = CullMode.Back;

                using (var rasterizerState = graphics.CreateRasterizerState(stated)) {
                    context.Rasterizer.State = rasterizerState;

                    graphics.ImmediateContext.DrawIndexed(geo.Indices.Length, 0, 0);
                }
            }

            if (mode == CullMode.Front || mode == CullMode.None)
            {
                stated.CullMode = CullMode.Front;

                using (var rasterizerState = graphics.CreateRasterizerState(stated)) {
                    context.Rasterizer.State = rasterizerState;

                    graphics.ImmediateContext.DrawIndexed(geo.Indices.Length, 0, 0);
                }
            }
        }
Example #2
0
    public TextureMaskRenderer(Device device, ShaderCache shaderCache)
    {
        this.device = device.QueryInterface <Device3>();

        var features = this.device.CheckD3D113Features2();

        var vertexShaderAndBytecode = shaderCache.GetVertexShader <TextureMaskRenderer>("texturing/processing/TextureMask");

        inputLayout  = new InputLayout(device, vertexShaderAndBytecode.Bytecode, MeshBuffers.InputElements);
        vertexShader = vertexShaderAndBytecode;

        var rasterizerStateDesc = new RasterizerStateDescription2()
        {
            FillMode = FillMode.Solid,
            CullMode = CullMode.None,
            IsFrontCounterClockwise = false,
            DepthBias                     = 0,
            SlopeScaledDepthBias          = 0.0f,
            DepthBiasClamp                = 0.0f,
            IsDepthClipEnabled            = true,
            IsScissorEnabled              = false,
            IsMultisampleEnabled          = true,
            IsAntialiasedLineEnabled      = false,
            ConservativeRasterizationMode = ConservativeRasterizationMode.On
        };

        rasterizerState = new RasterizerState2(this.device, rasterizerStateDesc);

        pixelShader = shaderCache.GetPixelShader <TextureMaskRenderer>("texturing/processing/TextureMask");

        var blendStateDesc = BlendStateDescription.Default();

        blendStateDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Alpha;
        blendState = new BlendState(device, blendStateDesc);
    }
        public SpherePointRenderTechnique()
        {
            layconst = new VertexLayoutConstructor(Vertex.Size)
                       .AddPositionElementAsVector4()
                       .AddColorElementAsVector4();
            var d = new CombinedShadersLoader(new ManifestResourceLoader(typeof(SpherePointRenderTechnique <>)));

            pass = new D3DShaderTechniquePass(d.Load(path, "SpP_"));

            vertexShader      = new DisposableSetter <VertexShader>(disposer);
            pixelShader       = new DisposableSetter <PixelShader>(disposer);
            geometryShader    = new DisposableSetter <GeometryShader>(disposer);
            depthStencilState = new DisposableSetter <DepthStencilState>(disposer);
            inputLayout       = new DisposableSetter <InputLayout>(disposer);

            rasterizerStateDescription = new RasterizerStateDescription2()
            {
                CullMode             = CullMode.None,
                FillMode             = FillMode.Solid,
                IsMultisampleEnabled = false,

                IsFrontCounterClockwise  = false,
                IsScissorEnabled         = false,
                IsAntialiasedLineEnabled = false,
                DepthBias            = 0,
                DepthBiasClamp       = .0f,
                SlopeScaledDepthBias = .0f
            };
        }
Example #4
0
        //readonly ShaderDebugMode debug1;

        public BackgroundRenderTechnique()
        {
            var d = new CombinedShadersLoader(new ManifestResourceLoader(typeof(BackgroundRenderTechnique <>)));

            pass = new D3DShaderTechniquePass(d.Load(path, "BG_"));

            vertexShader      = new DisposableSetter <VertexShader>(disposer);
            pixelShader       = new DisposableSetter <PixelShader>(disposer);
            depthStencilState = new DisposableSetter <DepthStencilState>(disposer);

            rasterizerStateDescription = new RasterizerStateDescription2()
            {
                CullMode             = CullMode.None,
                FillMode             = FillMode.Solid,
                IsMultisampleEnabled = false,

                IsFrontCounterClockwise  = false,
                IsScissorEnabled         = false,
                IsAntialiasedLineEnabled = false,
                DepthBias            = 0,
                DepthBiasClamp       = .0f,
                SlopeScaledDepthBias = .0f
            };

            //debug1 = new ShaderDebugMode(new System.IO.DirectoryInfo(@"D:\Storage_D\trash\archive\shaders\"), pass);
            //debug1.Activate();
        }
Example #5
0
        public OneFrameFlatWhiteRenderTechnique()
        {
            var d = new CombinedShadersLoader(new ManifestResourceLoader(typeof(OneFrameFlatWhiteRenderTechnique <>)));

            pass = new D3DShaderTechniquePass(d.Load(path, "BW_"));

            layconst = new VertexLayoutConstructor(Vertex.Size)
                       .AddPositionElementAsVector3();

            vertexShader = new DisposableSetter <VertexShader>(disposer);
            pixelShader  = new DisposableSetter <PixelShader>(disposer);
            inputLayout  = new DisposableSetter <InputLayout>(disposer);

            rasterizerStateDescription = new RasterizerStateDescription2()
            {
                CullMode             = CullMode.Front,
                FillMode             = FillMode.Solid,
                IsMultisampleEnabled = false,

                IsFrontCounterClockwise  = false,
                IsScissorEnabled         = false,
                IsAntialiasedLineEnabled = false,
                DepthBias            = 0,
                DepthBiasClamp       = .0f,
                SlopeScaledDepthBias = .0f
            };
        }
 public override RasterizerState CreateRasterizerState(RasterizerStateDescription2 description2)
 {
     if (device3 == null)
     {
         return(base.CreateRasterizerState(GraphicsDevice.ToRasterizerDesc0(description2)));
     }
     return(new RasterizerState2(device3, description2));
 }
Example #7
0
 static RenderableComponent AsLineList(RasterizerStateDescription2 rast, RenderTechniques technique)
 => new RenderableComponent(CullMode.None, PrimitiveTopology.LineList, technique)
 {
     Tag           = ElementTag.New(),
     IsValid       = true,
     HasBlendState = true,
     RasterizerStateDescription  = rast,
     DepthStencilStateDefinition = D3DDepthStencilDefinition.DepthEnabled,
     BlendStateDescription       = D3DBlendStateDescriptions.BlendStateDisabled,
 };
Example #8
0
        public RasterizerState CreateRasterizerState(RasterizerStateDescription2 description2)
        {
            var bs = directX.ImmediateContext.OutputMerger.BlendState;

            if (bs != null && bs.Description.AlphaToCoverageEnable && !description2.IsMultisampleEnabled)
            {
                // throw new Exception("BlendState.AlphaToCoverageEnable must be with RasterizerState.IsMultisampleEnabled");
                //description2.IsMultisampleEnabled = true;
            }

            return(directX.CreateRasterizerState(description2));
        }
Example #9
0
 internal static RasterizerStateDescription ToRasterizerDesc0(RasterizerStateDescription2 description2)
 {
     return(new RasterizerStateDescription {
         CullMode = description2.CullMode,
         DepthBias = description2.DepthBias,
         DepthBiasClamp = description2.DepthBiasClamp,
         FillMode = description2.FillMode,
         IsAntialiasedLineEnabled = description2.IsAntialiasedLineEnabled,
         IsDepthClipEnabled = description2.IsDepthClipEnabled,
         IsFrontCounterClockwise = description2.IsFrontCounterClockwise,
         IsMultisampleEnabled = description2.IsMultisampleEnabled,
         IsScissorEnabled = description2.IsScissorEnabled,
         SlopeScaledDepthBias = description2.SlopeScaledDepthBias,
     });
 }
Example #10
0
        /// <summary>
        /// Creates a cull front face rasterizer state
        /// </summary>
        /// <param name="graphics">Graphics</param>
        /// <returns>Creates the cull front face rasterizer state</returns>
        public static EngineRasterizerState CullFrontFace(Graphics graphics)
        {
            var desc = new RasterizerStateDescription2()
            {
                CullMode = CullMode.Back,
                FillMode = FillMode.Solid,
                IsFrontCounterClockwise  = true,
                IsAntialiasedLineEnabled = graphics.MultiSampled,
                IsMultisampleEnabled     = graphics.MultiSampled,
                IsScissorEnabled         = false,
                IsDepthClipEnabled       = true,
                DepthBias                     = 0,
                DepthBiasClamp                = 0.0f,
                SlopeScaledDepthBias          = 0.0f,
                ForcedSampleCount             = 0,
                ConservativeRasterizationMode = ConservativeRasterizationMode.Off,
            };

            return(graphics.CreateRasterizerState(desc));
        }
Example #11
0
 /// <summary>
 ///   Constructs a new <see cref = "T:SharpDX.Direct3D11.RasterizerState2" /> based on the specified description.
 /// </summary>
 /// <param name = "device">The device with which to associate the state object.</param>
 /// <param name = "description">The state description.</param>
 /// <returns>The newly created object.</returns>
 public RasterizerState2(Device3 device, RasterizerStateDescription2 description)
     : base(IntPtr.Zero)
 {
     device.CreateRasterizerState2(ref description, this);
 }
Example #12
0
 public abstract RasterizerState CreateRasterizerState(RasterizerStateDescription2 description2);
Example #13
0
 /// <summary>
 ///   Constructs a new <see cref = "T:SharpDX.Direct3D11.RasterizerState2" /> based on the specified description.
 /// </summary>
 /// <param name = "device">The device with which to associate the state object.</param>
 /// <param name = "description">The state description.</param>
 /// <returns>The newly created object.</returns>
 public RasterizerState2(Device3 device, RasterizerStateDescription2 description)
     : base(IntPtr.Zero)
 {
     device.CreateRasterizerState2(ref description, this);
 }
        void RenderingQuard(GraphicsDevice graphics, TProperties props)
        {
            var device  = graphics.D3DDevice;
            var context = graphics.ImmediateContext;

            context.ResolveSubresource(colorTargetTex2D.Get(), 0, colorTargetNoMSAA.Get().Resource, 0, colorDesc.Format);
            context.ResolveSubresource(alphaTargetTex2D.Get(), 0, alphaTargetNoMSAA.Get().Resource, 0, alphaDesc.Format);

            context.VertexShader.Set(vertexShaderQuard.Get());
            context.PixelShader.Set(pixelShaderQuard.Get());

            context.PixelShader.SetShaderResources(10, new[] {
                colorTargetNoMSAA.Get(), alphaTargetNoMSAA.Get()
            });
            context.PixelShader.SetSampler(0, targetSampler.Get());

            var inputSignature = ShaderSignature.GetInputSignature(quardPass.VertexShader.ReadCompiledBytes());

            context.InputAssembler.InputLayout = new InputLayout(device, inputSignature,
                                                                 new[] { new InputElement("SV_VERTEXID", 0, Format.R32_UInt, 0) });
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleStrip;

            var BSAlphaBlend = new BlendStateDescription();

            BSAlphaBlend.RenderTarget[0] = new RenderTargetBlendDescription()
            {
                AlphaBlendOperation = BlendOperation.Add,
                BlendOperation      = BlendOperation.Add,
                SourceBlend         = BlendOption.SourceAlpha,
                DestinationBlend    = BlendOption.InverseSourceAlpha,

                SourceAlphaBlend      = BlendOption.SourceAlpha,
                DestinationAlphaBlend = BlendOption.DestinationAlpha,
                IsBlendEnabled        = true,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };
            var DSSNoDepthNoStencil = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = false,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.Zero,
                DepthComparison  = Comparison.Always,
                FrontFace        = new DepthStencilOperationDescription()
                {
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Keep,
                    Comparison         = Comparison.Always
                },
                BackFace = new DepthStencilOperationDescription()
                {
                    Comparison         = Comparison.Always,
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Keep
                },
                StencilReadMask  = 0,
                StencilWriteMask = 0
            };

            context.OutputMerger.SetDepthStencilState(new DepthStencilState(device, DSSNoDepthNoStencil), 0);
            context.OutputMerger.SetBlendState(new BlendState(device, BSAlphaBlend),
                                               new SharpDX.Mathematics.Interop.RawColor4(0, 0, 0, 0), -1);

            //context.OutputMerger.SetTargets(quardTargetView.Get());

            var rester = new RasterizerStateDescription2 {
                CullMode                 = CullMode.None,
                FillMode                 = FillMode.Solid,
                DepthBias                = 0,
                DepthBiasClamp           = 0,
                SlopeScaledDepthBias     = 0,
                IsFrontCounterClockwise  = false,
                IsMultisampleEnabled     = false,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled       = false,
                IsScissorEnabled         = true
            };

            using (var rasterizerState = graphics.CreateRasterizerState(rester)) {
                context.Rasterizer.State = rasterizerState;
                graphics.ImmediateContext.Draw(4, 0);
            }
        }
Example #15
0
 public override RasterizerState CreateRasterizerState(RasterizerStateDescription2 description2)
 => CreateRasterizerState(GraphicsDevice.ToRasterizerDesc0(description2));