private static void SetupRenderTargetBlendDescriptionAccordingToTheMode(BlendMode blendMode,
                                                                                ref RenderTargetBlendDescription targetDescription)
        {
            switch (blendMode)
            {
            case BlendMode.Normal:
                targetDescription.DestinationBlend = BlendOption.InverseSourceAlpha;
                break;

            case BlendMode.Additive:
                break;

            case BlendMode.Subtractive:
                targetDescription.BlendOperation = BlendOperation.ReverseSubtract;
                break;

            case BlendMode.LightEffect:
                targetDescription.SourceBlend    = BlendOption.DestinationColor;
                targetDescription.BlendOperation = BlendOperation.Add;
                break;

            default:
                targetDescription.IsBlendEnabled = false;
                break;
            }
        }
Esempio n. 2
0
        public GrassRendrer(Form1 F)
            : base(F.Device)
        {
            this.P = F;
            this.CallFrequency = STDCallFrequencys.Always;
            E3 = new EffectWrapper("Grass_Mesh.fx", D);
            BlendStateDescription bsd = new BlendStateDescription()
            {
                AlphaToCoverageEnable = true,
                IndependentBlendEnable = false,
            };
            RenderTargetBlendDescription rtbd = new RenderTargetBlendDescription()
            {
                BlendEnable = true,
                BlendOperation = BlendOperation.Add,
                BlendOperationAlpha = BlendOperation.Add,
                RenderTargetWriteMask = ColorWriteMaskFlags.All,
                DestinationBlend = BlendOption.InverseSourceAlpha,
                SourceBlend = BlendOption.SourceAlpha,
                SourceBlendAlpha = BlendOption.Zero,
                DestinationBlendAlpha = BlendOption.One
            };
            bsd.RenderTargets[0] = rtbd;
            bsd0 = BlendState.FromDescription(D.HadrwareDevice(), bsd);

            StaticVertex[] vs = new StaticVertex[100];
            mBuffer = new DynamicMeshBuffer<StaticVertex>(D, PrimitiveTopology.PointList);
            mBuffer.Write(vs);
        }
Esempio n. 3
0
        public void SetBlendState(H1BlendStateDescription blendState, Int32 numRenderTargets)
        {
            BlendStateDescription blendStateRef = BlendStateDescription.Default();

            blendStateRef.AlphaToCoverageEnable  = blendState.AlphaToCoverageEnable;
            blendStateRef.IndependentBlendEnable = blendState.IndependentBlendEnable;

            for (Int32 i = 0; i < numRenderTargets; ++i)
            {
                RenderTargetBlendDescription   rtBlendDescDest = blendStateRef.RenderTarget[i];
                H1RenderTargetBlendDescription rtBlendDescSrc  = blendState.RenderTargets[i];
                rtBlendDescDest.IsBlendEnabled = rtBlendDescSrc.BlendEnable;
                rtBlendDescDest.LogicOpEnable  = rtBlendDescSrc.LogicOpEnable;

                rtBlendDescDest.SourceBlend      = H1RHIDefinitionHelper.ConvertToBlend(rtBlendDescSrc.SrcBlend);
                rtBlendDescDest.DestinationBlend = H1RHIDefinitionHelper.ConvertToBlend(rtBlendDescSrc.DestBlend);
                rtBlendDescDest.BlendOperation   = H1RHIDefinitionHelper.ConvertToBlendOp(rtBlendDescSrc.BlendOp);

                rtBlendDescDest.SourceAlphaBlend      = H1RHIDefinitionHelper.ConvertToBlend(rtBlendDescSrc.SrcBlendAlpha);
                rtBlendDescDest.DestinationAlphaBlend = H1RHIDefinitionHelper.ConvertToBlend(rtBlendDescSrc.DestBlendAlpha);
                rtBlendDescDest.AlphaBlendOperation   = H1RHIDefinitionHelper.ConvertToBlendOp(rtBlendDescSrc.BlendOpAlpha);

                rtBlendDescDest.LogicOp = H1RHIDefinitionHelper.ConvertToLogicOp(rtBlendDescSrc.LogicOp);
                rtBlendDescDest.RenderTargetWriteMask = H1RHIDefinitionHelper.ConvertToColorWriteMaskFlags(rtBlendDescSrc.RenderTargetWriteMask);
            }

            // newly assign the created blend state
            m_GraphicsPipelineStateDesc.BlendState = blendStateRef;
        }
Esempio n. 4
0
        public RenderTargetBlend(RenderTargetBlendDescription bRenderTargetBlend)
        {
            if (bRenderTargetBlend.BlendEnable)
            {
                SrcFactor = CtObjectGL.BlendFactor(bRenderTargetBlend.SourceBlend);
                DestFactor = CtObjectGL.BlendFactor(bRenderTargetBlend.DestinationBlend);
                EquationMode = CtObjectGL.BlendFunc(bRenderTargetBlend.BlendOperation);

                SrcFactorAlpha = CtObjectGL.BlendFactor(bRenderTargetBlend.SourceBlendAlpha);
                DestFactorAlpha = CtObjectGL.BlendFactor(bRenderTargetBlend.DestinationBlendAlpha);
                EquationModeAlpha = CtObjectGL.BlendFunc(bRenderTargetBlend.BlendOperationAlpha);
            }
            else
            {
                SrcFactor = BlendFactor.One;
                DestFactor = BlendFactor.Zero;
                EquationMode = BlendFunc.Add;

                SrcFactorAlpha = BlendFactor.One;
                DestFactorAlpha = BlendFactor.Zero;
                EquationModeAlpha = BlendFunc.Add;
            }

            Separate = SrcFactor != SrcFactorAlpha || DestFactor != DestFactorAlpha || EquationMode != EquationModeAlpha;
        }
Esempio n. 5
0
        /// <summary>
        /// SetupBlendState
        /// </summary>
        void SetupBlendState()
        {
            var rtbd = new RenderTargetBlendDescription();

            bool enabled = true;

            if (BlendState.DstAlpha == Blend.Zero && BlendState.SrcAlpha == Blend.One &&
                BlendState.DstColor == Blend.Zero && BlendState.SrcColor == Blend.One)
            {
                enabled = false;
            }

            rtbd.IsBlendEnabled        = enabled;
            rtbd.BlendOperation        = Converter.Convert(BlendState.ColorOp);
            rtbd.AlphaBlendOperation   = Converter.Convert(BlendState.AlphaOp);
            rtbd.RenderTargetWriteMask = (ColorWriteMaskFlags)(int)BlendState.WriteMask;
            rtbd.DestinationBlend      = Converter.Convert(BlendState.DstColor);
            rtbd.SourceBlend           = Converter.Convert(BlendState.SrcColor);
            rtbd.DestinationAlphaBlend = Converter.Convert(BlendState.DstAlpha);
            rtbd.SourceAlphaBlend      = Converter.Convert(BlendState.SrcAlpha);

            var bsd = new BlendStateDescription();

            bsd.AlphaToCoverageEnable  = false;
            bsd.IndependentBlendEnable = false;
            bsd.RenderTarget[0]        = rtbd;

            blendFactor   = SharpDXHelper.Convert(BlendState.BlendFactor);
            blendMsaaMask = BlendState.MultiSampleMask;

            blendState = new D3DBlendState(device.Device, bsd);
        }
Esempio n. 6
0
        /// <summary>
        /// <p>Create a blend-state object that encapsules blend state for the output-merger stage.</p>
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
        /// <param name="renderTargetBlend0">The render target blend description for the first render target.</param>
        /// <param name="blendFactor">The blend factor.</param>
        /// <param name="mask">The mask.</param>
        /// <returns>A new <see cref="BlendState" /> instance.</returns>
        /// <msdn-id>ff476500</msdn-id>
        ///   <unmanaged>HRESULT ID3D11Device::CreateBlendState([In] const D3D11_BLEND_DESC* pBlendStateDesc,[Out, Fast] ID3D11BlendState** ppBlendState)</unmanaged>
        ///   <unmanaged-short>ID3D11Device::CreateBlendState</unmanaged-short>
        /// <remarks><p>An application can create up to 4096 unique blend-state objects. For each object created, the runtime checks to see if a previous object  has the same state. If such a previous object exists, the runtime will return a reference to previous instance instead of creating a duplicate object.</p></remarks>
        public static BlendState New(GraphicsDevice device, RenderTargetBlendDescription renderTargetBlend0, Color4 blendFactor, int mask = -1)
        {
            var description = BlendStateDescription.Default();

            description.RenderTarget[0] = renderTargetBlend0;

            return(new BlendState(device, description, blendFactor, mask));
        }
Esempio n. 7
0
        internal static BlendState FromDesc(RenderTargetBlendDescription desc)
        {
            var temp = new BlendStateDescription();

            temp.RenderTarget[0] = desc;

            return(new BlendState(Display.device, temp));
        }
Esempio n. 8
0
 private static bool IsBlendEnabled(ref RenderTargetBlendDescription renderTarget)
 {
     return(renderTarget.BlendOperationAlpha != BlendOperation.Add ||
            renderTarget.SourceBlendAlpha != Blend.One ||
            renderTarget.DestinationBlendAlpha != Blend.Zero ||
            renderTarget.BlendOperation != BlendOperation.Add ||
            renderTarget.SourceBlend != Blend.One ||
            renderTarget.DestinationBlend != Blend.Zero);
 }
 public BlendStateChangeCommand(RenderTargetBlendDescription bStateDesc)
     : base(CommandType.BlendStateChange)
 {
     CommandAttributes |= CommandAttributes.MonoRendering;
     Description = bStateDesc;
     blendStateDescription = new BlendStateDescription();
     blendStateDescription.RenderTargets[0] = Description;
     blendState = BlendState.FromDescription(Game.Context.Device, blendStateDescription);
 }
Esempio n. 10
0
        public static BlendState CreateBlendState(this Device device, RenderTargetBlendDescription description)
        {
            var desc = new BlendStateDescription {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false
            };

            desc.RenderTargets[0] = description;
            return(BlendState.FromDescription(device, desc));
        }
Esempio n. 11
0
        private void BuildPSOs()
        {
            //
            // PSO for opaque objects.
            //

            var opaquePsoDesc = new GraphicsPipelineStateDescription
            {
                InputLayout           = _inputLayout,
                RootSignature         = _rootSignature,
                VertexShader          = _shaders["standardVS"],
                PixelShader           = _shaders["opaquePS"],
                RasterizerState       = RasterizerStateDescription.Default(),
                BlendState            = BlendStateDescription.Default(),
                DepthStencilState     = DepthStencilStateDescription.Default(),
                SampleMask            = unchecked ((int)uint.MaxValue),
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                SampleDescription     = new SampleDescription(MsaaCount, MsaaQuality),
                DepthStencilFormat    = DepthStencilFormat,
                StreamOutput          = new StreamOutputDescription() //find out how this should actually be done later
            };

            opaquePsoDesc.RenderTargetFormats[0] = BackBufferFormat;
            _psos["opaque"] = Device.CreateGraphicsPipelineState(opaquePsoDesc);

            //
            // PSO for highlight objects.
            //

            GraphicsPipelineStateDescription highlightPsoDesc = opaquePsoDesc.Copy();

            // Change the depth test from < to <= so that if we draw the same triangle twice, it will
            // still pass the depth test. This is needed because we redraw the picked triangle with a
            // different material to highlight it. If we do not use <=, the triangle will fail the
            // depth test the 2nd time we try and draw it.
            highlightPsoDesc.DepthStencilState.DepthComparison = Comparison.LessEqual;

            // Standard transparency blending.
            var transparencyBlendDesc = new RenderTargetBlendDescription
            {
                IsBlendEnabled        = true,
                LogicOpEnable         = false,
                SourceBlend           = BlendOption.SourceAlpha,
                DestinationBlend      = BlendOption.InverseSourceAlpha,
                BlendOperation        = BlendOperation.Add,
                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation   = BlendOperation.Add,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            highlightPsoDesc.BlendState.RenderTarget[0] = transparencyBlendDesc;
            _psos["highlight"] = Device.CreateGraphicsPipelineState(highlightPsoDesc);
        }
 public RenderTargetBlendDataContract(RenderTargetBlendDescription desc)
 {
     IsBlendEnabled        = desc.IsBlendEnabled;
     SourceBlend           = (int)desc.SourceBlend;
     DestinationBlend      = (int)desc.DestinationBlend;
     BlendOperation        = (int)desc.BlendOperation;
     SourceAlphaBlend      = (int)desc.SourceAlphaBlend;
     DestinationAlphaBlend = (int)desc.DestinationAlphaBlend;
     AlphaBlendOperation   = (int)desc.AlphaBlendOperation;
     RenderTargetWriteMask = (int)desc.RenderTargetWriteMask;
 }
		public BlendStateDescription(BlendOption sourceBlend, BlendOption destinationBlend)
			: this()
		{
			RenderTarget[0] = new RenderTargetBlendDescription
			{
				IsBlendEnabled = true,
				SourceBlend = sourceBlend,
				SourceAlphaBlend = sourceBlend,
				DestinationBlend = destinationBlend,
				DestinationAlphaBlend = destinationBlend
			};
		}
Esempio n. 14
0
 public BlendStateDescription(BlendOption sourceBlend, BlendOption destinationBlend)
     : this()
 {
     RenderTarget[0] = new RenderTargetBlendDescription
     {
         IsBlendEnabled        = true,
         SourceBlend           = sourceBlend,
         SourceAlphaBlend      = sourceBlend,
         DestinationBlend      = destinationBlend,
         DestinationAlphaBlend = destinationBlend
     };
 }
Esempio n. 15
0
        public CombineFinalRenderer(DX11Game game, GBuffer gBuffer)
        {
            this.game    = game;
            this.gBuffer = gBuffer;
            var device = game.Device;

            context = device.ImmediateContext;

            shader = BasicShader.LoadAutoreload(game,
                                                new System.IO.FileInfo(
                                                    CompiledShaderCache.Current.RootShaderPath + "Deferred\\CombineFinal.fx"));

            shader.SetTechnique("Technique0");

            quad = new FullScreenQuad(device);

            layout = FullScreenQuad.CreateInputLayout(device, shader.GetCurrentPass(0));

            var desc = new Texture2DDescription
            {
                BindFlags =
                    BindFlags.RenderTarget | BindFlags.ShaderResource,
                Format            = Format.R16G16B16A16_Float,
                Width             = gBuffer.Width,
                Height            = gBuffer.Height,
                ArraySize         = 1,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels         = 1
            };

            lightAccumulationMap = new Texture2D(device, desc);

            lightAccumulationRTV = new RenderTargetView(device, lightAccumulationMap);
            LightAccumulationRV  = new ShaderResourceView(device, lightAccumulationMap);

            var bsDesc = new BlendStateDescription();
            var b      = new RenderTargetBlendDescription();

            b.BlendEnable           = true;
            b.BlendOperation        = BlendOperation.Add;
            b.BlendOperationAlpha   = BlendOperation.Add;
            b.DestinationBlend      = BlendOption.One;
            b.DestinationBlendAlpha = BlendOption.One;
            b.SourceBlend           = BlendOption.One;
            b.SourceBlendAlpha      = BlendOption.One;
            b.RenderTargetWriteMask = ColorWriteMaskFlags.All;
            bsDesc.RenderTargets[0] = b;


            blendState = BlendState.FromDescription(device, bsDesc);
        }
Esempio n. 16
0
        public void SetDefaultstate()
        {
            // shader pipeline
            m_D3dDevice.ImmediateContext.InputAssembler.InputLayout       = null;
            m_D3dDevice.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            m_D3dDevice.ImmediateContext.VertexShader.Set(null);
            m_D3dDevice.ImmediateContext.HullShader.Set(null);
            m_D3dDevice.ImmediateContext.DomainShader.Set(null);
            m_D3dDevice.ImmediateContext.GeometryShader.Set(null);
            m_D3dDevice.ImmediateContext.PixelShader.Set(null);

            // render state
            m_D3dDevice.ImmediateContext.Rasterizer.State = RasterizerState.FromDescription(m_D3dDevice, new RasterizerStateDescription()
            {
                CullMode = CullMode.Back,
                FillMode = FillMode.Solid,
            });

            m_D3dDevice.ImmediateContext.OutputMerger.DepthStencilState = DepthStencilState.FromDescription(m_D3dDevice, new DepthStencilStateDescription()
            {
                DepthComparison  = Comparison.Less,
                DepthWriteMask   = DepthWriteMask.All,
                IsDepthEnabled   = true,
                IsStencilEnabled = false
            });

            var blendState = new RenderTargetBlendDescription()
            {
                BlendEnable           = false,
                BlendOperation        = BlendOperation.Add,
                DestinationBlend      = BlendOption.InverseSourceAlpha,
                SourceBlend           = BlendOption.SourceAlpha,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            var blendStateDesc = new BlendStateDescription();

            blendStateDesc.AlphaToCoverageEnable  = false;
            blendStateDesc.IndependentBlendEnable = false;
            blendStateDesc.RenderTargets[0]       = blendState;

            m_D3dDevice.ImmediateContext.OutputMerger.BlendState = BlendState.FromDescription(m_D3dDevice, blendStateDesc);
        }
Esempio n. 17
0
        GraphicsPipelineState makeTriangle(ResourceCreateContext ctx)
        {
            var triangleVertex = UniqueCreator.Graphics.Gpu.Shaders.triangle_vertex.Factory.Create();
            var trianglePixel  = UniqueCreator.Graphics.Gpu.Shaders.triangle_pixel.Factory.Create();

            var description2 = new GraphicsPipelineStateDescription();

            var rasterizerState = new RasterizerDescription();

            var samples = new SampleDescription
            {
                Count   = 1,
                Quality = 0
            };

            var depthStencil = new DepthStencilDescription
            {
                DepthEnable    = true,
                StencilEnable  = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthFunc      = ComparisonFunction.Less
            };

            depthStencil.BackFace.StencilFailOperation      = StencilOperation.Keep;
            depthStencil.BackFace.StencilPassOperation      = StencilOperation.Keep;
            depthStencil.BackFace.StencilFunction           = ComparisonFunction.Always;
            depthStencil.BackFace.StencilDepthFailOperation = StencilOperation.Keep;
            depthStencil.FrontFace        = depthStencil.BackFace;
            depthStencil.StencilReadMask  = 0xff;
            depthStencil.StencilWriteMask = 0xff;


            rasterizerState.CullMode = CullMode.Back;
            rasterizerState.FillMode = FillMode.Solid;
            rasterizerState.FrontCounterClockwise = true;
            rasterizerState.AntialiasedLineEnable = false;
            rasterizerState.ConservativeRaster    = ConservativeRasterizationMode.Off;
            rasterizerState.DepthBias             = 0;
            rasterizerState.DepthBiasClamp        = 0.0f;
            rasterizerState.SlopeScaledDepthBias  = 0.0f;
            rasterizerState.DepthClipEnable       = true;
            rasterizerState.ForcedSampleCount     = 0;
            rasterizerState.MultisampleEnable     = false;

            var blendState = new BlendDescription
            {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false
            };

            var blend = new RenderTargetBlendDescription
            {
                BlendEnable           = false,
                LogicOperationEnable  = false,
                BlendOperation        = BlendOperation.Add,
                BlendOperationAlpha   = BlendOperation.Add,
                LogicOperation        = LogicOperation.Clear,
                DestinationBlend      = Blend.DestinationColor,
                DestinationBlendAlpha = Blend.DestinationAlpha,
                SourceBlend           = Blend.SourceColor,
                SourceBlendAlpha      = Blend.SourceAlpha,
                RenderTargetWriteMask = 0xF
            };

            blendState.RenderTargets = new RenderTargetBlendDescription[] { blend };

            description2.VS                = triangleVertex;
            description2.PS                = trianglePixel;
            description2.SampleMask        = 0xFFFFFFFF;
            description2.RasterizerState   = rasterizerState;
            description2.PrimitiveTopology = PrimitiveTopologyType.Triangle;
            description2.Samples           = samples;
            description2.DepthStencilState = depthStencil;
            description2.DsvFormat         = GraphicsFormat.D32_Single;
            description2.IbStripCutValue   = IndexBufferStripCut.ValueDisabled;
            description2.BlendState        = blendState;
            description2.RtvFormats.Add(GraphicsFormat.R8G8B8A8_UNORM);

            return(new GraphicsPipelineState(ctx, description2));
        }
        /// <summary>
        /// Устанавливает параметры блендинга, растеризации, Буффера глубины и бледн фактор (влияет на то какой процент из цвета пикселя будет усачтвовать в блендинге)
        /// </summary>
        protected virtual void SetStates()
        {
            //Установка Сампрелар для текстуры.
            SamplerStateDescription description = SamplerStateDescription.Default();

            description.Filter         = Filter.MinMagMipLinear;
            description.AddressU       = TextureAddressMode.Wrap;
            description.AddressV       = TextureAddressMode.Wrap;
            _drawer.Samplerdescription = description;

            //Устанавливаем параметры буффера глубины
            DepthStencilStateDescription DStateDescripshion = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = true,
                DepthComparison  = Comparison.Less,
                DepthWriteMask   = SharpDX.Direct3D11.DepthWriteMask.All,
                IsStencilEnabled = false,
                StencilReadMask  = 0xff, // 0xff (no mask)
                StencilWriteMask = 0xff, // 0xff (no mask)
                // Configure FrontFace depth/stencil operations
                FrontFace = new DepthStencilOperationDescription()
                {
                    Comparison         = Comparison.Always,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Increment
                },
                // Configure BackFace depth/stencil operations
                BackFace = new DepthStencilOperationDescription()
                {
                    Comparison         = Comparison.Always,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Decrement
                }
            };

            _drawer.DepthStencilDescripshion = DStateDescripshion;

            //Устанавливаем параметры растеризации так чтобы обратная сторона объекта не спряталась.
            RasterizerStateDescription rasterizerStateDescription = RasterizerStateDescription.Default();

            rasterizerStateDescription.CullMode = CullMode.None;
            rasterizerStateDescription.FillMode = FillMode.Solid;
            _drawer.RasterizerDescription       = rasterizerStateDescription;

            //TODO: донастроить параметры блендинга для прозрачности.
            #region Формула бледнинга
            //(FC) - Final Color
            //(SP) - Source Pixel
            //(DP) - Destination Pixel
            //(SBF) - Source Blend Factor
            //(DBF) - Destination Blend Factor
            //(FA) - Final Alpha
            //(SA) - Source Alpha
            //(DA) - Destination Alpha
            //(+) - Binaray Operator described below
            //(X) - Cross Multiply Matrices
            //Формула для блендинга
            //(FC) = (SP)(X)(SBF)(+)(DP)(X)(DPF)
            //(FA) = (SA)(SBF)(+)(DA)(DBF)
            //ИСПОЛЬЗОВАНИЕ
            //_dx11DeviceContext.OutputMerger.SetBlendState(
            //    _blendState,
            //     new SharpDX.Mathematics.Interop.RawColor4(0.75f, 0.75f, 0.75f, 1f));
            //ЭТО ДЛЯ НЕПРОЗРАЧНЫХ _dx11DeviceContext.OutputMerger.SetBlendState(null, null);
            #endregion

            RenderTargetBlendDescription targetBlendDescription = new RenderTargetBlendDescription()
            {
                IsBlendEnabled        = new SharpDX.Mathematics.Interop.RawBool(true),
                SourceBlend           = BlendOption.SourceColor,
                DestinationBlend      = BlendOption.BlendFactor,
                BlendOperation        = BlendOperation.Add,
                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation   = BlendOperation.Add,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            BlendStateDescription blendDescription = BlendStateDescription.Default();
            blendDescription.AlphaToCoverageEnable = new SharpDX.Mathematics.Interop.RawBool(false);
            blendDescription.RenderTarget[0]       = targetBlendDescription;
            _drawer.BlendDescription = blendDescription;

            SharpDX.Mathematics.Interop.RawColor4 blenF = new SharpDX.Mathematics.Interop.RawColor4(0.3f, 0.3f, 0.3f, 0.3f);
            _drawer.BlendFactor = blenF;
        }
Esempio n. 19
0
        public void SetDefaultstate()
        {
            // shader pipeline
            m_D3dDevice.ImmediateContext.InputAssembler.InputLayout = null;
            m_D3dDevice.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            m_D3dDevice.ImmediateContext.VertexShader.Set(null);
            m_D3dDevice.ImmediateContext.HullShader.Set(null);
            m_D3dDevice.ImmediateContext.DomainShader.Set(null);
            m_D3dDevice.ImmediateContext.GeometryShader.Set(null);
            m_D3dDevice.ImmediateContext.PixelShader.Set(null);

            // render state
            m_D3dDevice.ImmediateContext.Rasterizer.State = RasterizerState.FromDescription(m_D3dDevice, new RasterizerStateDescription()
                {
                    CullMode = CullMode.Back,
                    FillMode = FillMode.Solid,
                });

            m_D3dDevice.ImmediateContext.OutputMerger.DepthStencilState = DepthStencilState.FromDescription(m_D3dDevice, new DepthStencilStateDescription()
                {
                    DepthComparison     = Comparison.Less,
                    DepthWriteMask      = DepthWriteMask.All,
                    IsDepthEnabled      = true,
                    IsStencilEnabled    = false
                });

            var blendState = new RenderTargetBlendDescription()
                {
                    BlendEnable = false,
                    BlendOperation = BlendOperation.Add,
                    DestinationBlend = BlendOption.InverseSourceAlpha,
                    SourceBlend = BlendOption.SourceAlpha,
                    RenderTargetWriteMask = ColorWriteMaskFlags.All
                };

            var blendStateDesc = new BlendStateDescription();
            blendStateDesc.AlphaToCoverageEnable = false;
            blendStateDesc.IndependentBlendEnable = false;
            blendStateDesc.RenderTargets[0] = blendState;

            m_D3dDevice.ImmediateContext.OutputMerger.BlendState = BlendState.FromDescription(m_D3dDevice, blendStateDesc);
        }
Esempio n. 20
0
 /// <summary>
 /// <p>Create a blend-state object that encapsulates blend state for the output-merger stage.</p>
 /// </summary>
 /// <param name="device">The  <see cref="DirectXDevice"/>.</param>
 /// <param name="renderTargetBlend0">The render target blend description for the first render target.</param>
 /// <param name="mask">The mask.</param>
 /// <returns>A new <see cref="BlendState" /> instance.</returns>
 /// <msdn-id>ff476500</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateBlendState([In] const D3D11_BLEND_DESC* pBlendStateDesc,[Out, Fast] ID3D11BlendState** ppBlendState)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateBlendState</unmanaged-short>
 /// <remarks><p>An application can create up to 4096 unique blend-state objects. For each object created, the runtime checks to see if a previous object  has the same state. If such a previous object exists, the runtime will return a reference to previous instance instead of creating a duplicate object.</p></remarks>
 public static BlendState New(DirectXDevice device, RenderTargetBlendDescription renderTargetBlend0,
                              int mask = -1)
 {
     return(New(device, renderTargetBlend0, Color.White, mask));
 }
Esempio n. 21
0
        public void Evaluate(int SpreadMax)
        {
            if (this.mode.IsChanged || this.FInState.IsChanged)
            {
                this.FOutState.SliceCount = SpreadMax;

                for (int i = 0; i < SpreadMax; i++)
                {
                    DX11RenderState rs;
                    if (this.FInState.IsConnected)
                    {
                        rs = this.FInState[i].Clone();
                    }
                    else
                    {
                        rs = new DX11RenderState();
                    }

                    BlendStateDescription        bs     = rs.Blend;
                    RenderTargetBlendDescription target = bs.RenderTargets[0];

                    //Note: to optimize a little, we do the following :
                    //In any case, if blend is disabled, we enable it as otherwise modes with do nothing
                    //Only exception is replace, if blend is disabled we leave as it is

                    switch (mode[i])
                    {
                    case AlphaOperationMode.Keep:
                        target.BlendEnable           = true;
                        target.BlendOperation        = BlendOperation.Add;
                        target.DestinationBlendAlpha = BlendOption.One;
                        target.SourceBlendAlpha      = BlendOption.Zero;
                        break;

                    case AlphaOperationMode.Replace:
                        if (target.BlendEnable)
                        {
                            target.BlendOperation        = BlendOperation.Add;
                            target.DestinationBlendAlpha = BlendOption.Zero;
                            target.SourceBlendAlpha      = BlendOption.One;
                        }
                        break;

                    case AlphaOperationMode.Multiply:
                        target.BlendEnable           = true;
                        target.BlendOperation        = BlendOperation.Add;
                        target.DestinationBlendAlpha = BlendOption.SourceAlpha;
                        target.SourceBlendAlpha      = BlendOption.Zero;
                        break;

                    case AlphaOperationMode.Interpolate:
                        target.BlendEnable           = true;
                        target.BlendOperation        = BlendOperation.Add;
                        target.DestinationBlendAlpha = BlendOption.InverseSourceAlpha;
                        target.SourceBlendAlpha      = BlendOption.SourceAlpha;
                        break;
                    }

                    bs.RenderTargets[0] = target;
                    rs.Blend            = bs;

                    this.FOutState[i] = rs;
                }
            }
        }
        private void BuildPSOs()
        {
            //
            // PSO for opaque objects.
            //

            var opaquePsoDesc = new GraphicsPipelineStateDescription
            {
                InputLayout           = _inputLayout,
                RootSignature         = _rootSignature,
                VertexShader          = _shaders["standardVS"],
                PixelShader           = _shaders["opaquePS"],
                RasterizerState       = RasterizerStateDescription.Default(),
                BlendState            = BlendStateDescription.Default(),
                DepthStencilState     = DepthStencilStateDescription.Default(),
                SampleMask            = unchecked ((int)0xFFFFFFFF),
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                SampleDescription     = new SampleDescription(MsaaCount, MsaaQuality),
                DepthStencilFormat    = DepthStencilFormat,
                StreamOutput          = new StreamOutputDescription() //find out how this should actually be done later
            };

            opaquePsoDesc.RenderTargetFormats[0] = BackBufferFormat;

            _psos["opaque"] = Device.CreateGraphicsPipelineState(opaquePsoDesc);

            //
            // PSO for transparent objects.
            //

            GraphicsPipelineStateDescription transparentPsoDesc = opaquePsoDesc.Copy();

            var transparencyBlendDesc = new RenderTargetBlendDescription
            {
                IsBlendEnabled        = true,
                LogicOpEnable         = false,
                SourceBlend           = BlendOption.SourceAlpha,
                DestinationBlend      = BlendOption.InverseSourceAlpha,
                BlendOperation        = BlendOperation.Add,
                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation   = BlendOperation.Add,
                LogicOp = LogicOperation.Noop,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            transparentPsoDesc.BlendState.RenderTarget[0] = transparencyBlendDesc;

            _psos["transparent"] = Device.CreateGraphicsPipelineState(transparentPsoDesc);

            //
            // PSO for alpha tested objects.
            //

            GraphicsPipelineStateDescription alphaTestedPsoDesc = opaquePsoDesc.Copy();

            alphaTestedPsoDesc.PixelShader = _shaders["alphaTestedPS"];
            alphaTestedPsoDesc.RasterizerState.CullMode = CullMode.None;

            _psos["alphaTested"] = Device.CreateGraphicsPipelineState(alphaTestedPsoDesc);

            //
            // PSO for tree sprites.
            //

            GraphicsPipelineStateDescription treeSpritePsoDesc = opaquePsoDesc.Copy();

            treeSpritePsoDesc.VertexShader             = _shaders["treeSpriteVS"];
            treeSpritePsoDesc.GeometryShader           = _shaders["treeSpriteGS"];
            treeSpritePsoDesc.PixelShader              = _shaders["treeSpritePS"];
            treeSpritePsoDesc.PrimitiveTopologyType    = PrimitiveTopologyType.Point;
            treeSpritePsoDesc.InputLayout              = _treeSpriteInputLayout;
            treeSpritePsoDesc.RasterizerState.CullMode = CullMode.None;

            _psos["treeSprites"] = Device.CreateGraphicsPipelineState(treeSpritePsoDesc);
        }
Esempio n. 23
0
        public override void Initialize()
        {
            try
            {
                #region Rasterizer States

                RasterizerStateDescription rStateDefault = new RasterizerStateDescription()
                {
                    FillMode = FillMode.Solid,
                    CullMode = CullMode.Back,
                    IsFrontCounterclockwise = true,
                    DepthBias      = 0,
                    DepthBiasClamp = 0,
                    //SlopeScaledDepthBias = 0.0f,
                    //IsDepthClipEnabled = true
                };

                rasterizerStateDefault = RasterizerState.FromDescription(DeviceManager.Instance.device, rStateDefault);

                RasterizerStateDescription rStateDefaultNC = rStateDefault;
                rStateDefaultNC.CullMode = CullMode.None;
                rasterizerStateDefaultNC = RasterizerState.FromDescription(DeviceManager.Instance.device, rStateDefaultNC);

                RasterizerStateDescription rStateWireframe = new RasterizerStateDescription()
                {
                    FillMode = FillMode.Wireframe,
                    CullMode = CullMode.None,
                    IsFrontCounterclockwise = true,
                    DepthBias      = 0,
                    DepthBiasClamp = 0,
                    //SlopeScaledDepthBias = 0.0f,
                    //IsDepthClipEnabled = true
                };

                rasterizerStateWireframe = RasterizerState.FromDescription(DeviceManager.Instance.device, rStateWireframe);

                #endregion

                #region Blend States

                RenderTargetBlendDescription rtBlendDefault = new RenderTargetBlendDescription()
                {
                    BlendEnable           = true,
                    BlendOperation        = BlendOperation.Add,
                    RenderTargetWriteMask = ColorWriteMaskFlags.All,
                    SourceBlend           = BlendOption.SourceAlpha,
                    DestinationBlend      = BlendOption.InverseSourceAlpha,
                    BlendOperationAlpha   = BlendOperation.Add,
                    SourceBlendAlpha      = BlendOption.One,
                    DestinationBlendAlpha = BlendOption.Zero
                };

                BlendStateDescription bBlendStateDefault = new BlendStateDescription();
                bBlendStateDefault.AlphaToCoverageEnable  = false;
                bBlendStateDefault.IndependentBlendEnable = false;
                bBlendStateDefault.RenderTargets[0]       = rtBlendDefault;

                blendStateDefault = BlendState.FromDescription(DeviceManager.Instance.device, bBlendStateDefault);

                RenderTargetBlendDescription rtBlendAddColour = new RenderTargetBlendDescription()
                {
                    BlendEnable           = true,
                    BlendOperation        = BlendOperation.Add,
                    RenderTargetWriteMask = ColorWriteMaskFlags.All,
                    SourceBlend           = BlendOption.One,
                    DestinationBlend      = BlendOption.One,
                    BlendOperationAlpha   = BlendOperation.Add,
                    SourceBlendAlpha      = BlendOption.One,
                    DestinationBlendAlpha = BlendOption.Zero
                };

                BlendStateDescription bBlendStateAddColour = new BlendStateDescription();
                bBlendStateAddColour.AlphaToCoverageEnable  = false;
                bBlendStateAddColour.IndependentBlendEnable = false;
                bBlendStateAddColour.RenderTargets[0]       = rtBlendAddColour;

                blendStateAddColour = BlendState.FromDescription(DeviceManager.Instance.device, bBlendStateAddColour);

                // UseAlphaMask = textureAttributes & 0x0010

                /*RenderTargetBlendDescription rtBlendSubstactColour = new RenderTargetBlendDescription()
                 * {
                 * BlendEnable = true,
                 * BlendOperation = BlendOperation.ReverseSubtract,
                 * RenderTargetWriteMask = ColorWriteMaskFlags.All,
                 * SourceBlend = BlendOption.SourceColor, // One works too
                 * DestinationBlend = BlendOption.InverseSourceColor, // One works too
                 * BlendOperationAlpha = BlendOperation.Add,
                 * SourceBlendAlpha = BlendOption.One,
                 * DestinationBlendAlpha = BlendOption.Zero
                 * };*/

                RenderTargetBlendDescription rtBlendDepth = new RenderTargetBlendDescription()
                {
                    BlendEnable           = false,
                    RenderTargetWriteMask = ColorWriteMaskFlags.None
                };

                BlendStateDescription bBlendStateDepth = new BlendStateDescription();
                bBlendStateDepth.AlphaToCoverageEnable  = false;
                bBlendStateDepth.IndependentBlendEnable = false;
                bBlendStateDepth.RenderTargets[0]       = rtBlendDepth;

                blendStateDepth = BlendState.FromDescription(DeviceManager.Instance.device, bBlendStateDepth);

                #endregion

                #region Depth Stencils

                DepthStencilOperationDescription frontFace = new DepthStencilOperationDescription()
                {
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Increment,
                    PassOperation      = StencilOperation.Keep,
                    Comparison         = Comparison.Always
                };

                DepthStencilOperationDescription backFace = new DepthStencilOperationDescription()
                {
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Decrement,
                    PassOperation      = StencilOperation.Keep,
                    Comparison         = Comparison.Always
                };

                DepthStencilStateDescription dsStateSolid = new DepthStencilStateDescription
                {
                    DepthComparison  = Comparison.LessEqual,
                    DepthWriteMask   = DepthWriteMask.All,
                    IsDepthEnabled   = true,
                    IsStencilEnabled = false,
                    StencilReadMask  = 0xFF,
                    StencilWriteMask = 0xFF,
                    FrontFace        = frontFace,
                    BackFace         = backFace
                };

                depthStencilStateSolid = DepthStencilState.FromDescription(DeviceManager.Instance.device, dsStateSolid);

                DepthStencilStateDescription dsStateTranslucent = new DepthStencilStateDescription
                {
                    DepthComparison  = Comparison.LessEqual,
                    DepthWriteMask   = DepthWriteMask.Zero,
                    IsDepthEnabled   = true,
                    IsStencilEnabled = false,
                    StencilReadMask  = 0xFF,
                    StencilWriteMask = 0xFF,
                    FrontFace        = frontFace,
                    BackFace         = backFace
                };

                depthStencilStateTranslucent = DepthStencilState.FromDescription(DeviceManager.Instance.device, dsStateTranslucent);

                DepthStencilStateDescription dsStateDepth = new DepthStencilStateDescription
                {
                    DepthComparison  = Comparison.LessEqual,
                    DepthWriteMask   = DepthWriteMask.All,
                    IsDepthEnabled   = true,
                    IsStencilEnabled = false,
                    StencilReadMask  = 0xFF,
                    StencilWriteMask = 0xFF,
                    FrontFace        = frontFace,
                    BackFace         = backFace
                };

                depthStencilStateDepth = DepthStencilState.FromDescription(DeviceManager.Instance.device, dsStateDepth);

                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        private void BuildPSOs()
        {
            //
            // PSO for opaque objects.
            //

            var opaquePsoDesc = new GraphicsPipelineStateDescription
            {
                InputLayout           = _inputLayout,
                RootSignature         = _rootSignature,
                VertexShader          = _shaders["standardVS"],
                PixelShader           = _shaders["opaquePS"],
                RasterizerState       = RasterizerStateDescription.Default(),
                BlendState            = BlendStateDescription.Default(),
                DepthStencilState     = DepthStencilStateDescription.Default(),
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                SampleDescription     = new SampleDescription(MsaaCount, MsaaQuality),
                DepthStencilFormat    = DepthStencilFormat,
                StreamOutput          = new StreamOutputDescription() //find out how this should actually be done later
            };

            opaquePsoDesc.RenderTargetFormats[0] = BackBufferFormat;
            _psos["opaque"] = Device.CreateGraphicsPipelineState(opaquePsoDesc);

            //
            // PSO for transparent objects.
            //

            GraphicsPipelineStateDescription transparentPsoDesc = opaquePsoDesc.Copy();
            var transparencyBlendDesc = new RenderTargetBlendDescription
            {
                IsBlendEnabled        = true,
                LogicOpEnable         = false,
                SourceBlend           = BlendOption.SourceAlpha,
                DestinationBlend      = BlendOption.InverseSourceAlpha,
                BlendOperation        = BlendOperation.Add,
                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation   = BlendOperation.Add,
                LogicOp = LogicOperation.Noop,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            transparentPsoDesc.BlendState.RenderTarget[0] = transparencyBlendDesc;
            _psos["transparent"] = Device.CreateGraphicsPipelineState(transparentPsoDesc);

            //
            // PSO for alpha tested objects.
            //

            GraphicsPipelineStateDescription alphaTestedPsoDesc = opaquePsoDesc.Copy();

            alphaTestedPsoDesc.PixelShader = _shaders["alphaTestedPS"];
            alphaTestedPsoDesc.RasterizerState.CullMode = CullMode.None;
            _psos["alphaTested"] = Device.CreateGraphicsPipelineState(alphaTestedPsoDesc);

            //
            // PSO for drawing waves.
            //

            GraphicsPipelineStateDescription wavesRenderPSO = transparentPsoDesc.Copy();

            wavesRenderPSO.VertexShader = _shaders["wavesVS"];
            _psos["wavesRender"]        = Device.CreateGraphicsPipelineState(wavesRenderPSO);

            //
            // PSO for compositing post process.
            //

            GraphicsPipelineStateDescription compositePSO = opaquePsoDesc.Copy();

            compositePSO.RootSignature = _postProcessRootSignature;

            // Disable depth test.
            compositePSO.DepthStencilState.IsDepthEnabled  = false;
            compositePSO.DepthStencilState.DepthWriteMask  = DepthWriteMask.Zero;
            compositePSO.DepthStencilState.DepthComparison = Comparison.Always;
            compositePSO.VertexShader = _shaders["compositeVS"];
            compositePSO.PixelShader  = _shaders["compositePS"];
            _psos["composite"]        = Device.CreateGraphicsPipelineState(compositePSO);

            //
            // PSO for disturbing waves.
            //

            var wavesDisturbPSO = new ComputePipelineStateDescription
            {
                RootSignaturePointer = _wavesRootSignature,
                ComputeShader        = _shaders["wavesDisturbCS"],
                Flags = PipelineStateFlags.None
            };

            _psos["wavesDisturb"] = Device.CreateComputePipelineState(wavesDisturbPSO);

            //
            // PSO for updating waves.
            //

            var wavesUpdatePSO = new ComputePipelineStateDescription
            {
                RootSignaturePointer = _wavesRootSignature,
                ComputeShader        = _shaders["wavesUpdateCS"],
                Flags = PipelineStateFlags.None
            };

            _psos["wavesUpdate"] = Device.CreateComputePipelineState(wavesUpdatePSO);

            //
            // PSO for sobel.
            //

            var sobelPSO = new ComputePipelineStateDescription
            {
                RootSignaturePointer = _postProcessRootSignature,
                ComputeShader        = _shaders["sobelCS"],
                Flags = PipelineStateFlags.None
            };

            _psos["sobel"] = Device.CreateComputePipelineState(sobelPSO);
        }
Esempio n. 25
0
        private void BuildPSOs()
        {
            //
            // PSO for opaque objects.
            //

            var opaquePsoDesc = new GraphicsPipelineStateDescription
            {
                InputLayout           = _inputLayout,
                RootSignature         = _rootSignature,
                VertexShader          = _shaders["standardVS"],
                PixelShader           = _shaders["opaquePS"],
                RasterizerState       = RasterizerStateDescription.Default(),
                BlendState            = BlendStateDescription.Default(),
                DepthStencilState     = DepthStencilStateDescription.Default(),
                SampleMask            = unchecked ((int)0xFFFFFFFF),
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                SampleDescription     = new SampleDescription(MsaaCount, MsaaQuality),
                DepthStencilFormat    = DepthStencilFormat,
                StreamOutput          = new StreamOutputDescription() //find out how this should actually be done later
            };

            opaquePsoDesc.RenderTargetFormats[0] = BackBufferFormat;
            _psos["opaque"] = Device.CreateGraphicsPipelineState(opaquePsoDesc);

            //
            // PSO for transparent objects.
            //

            GraphicsPipelineStateDescription transparentPsoDesc = opaquePsoDesc.Copy();
            var transparencyBlendDesc = new RenderTargetBlendDescription
            {
                IsBlendEnabled        = true,
                LogicOpEnable         = false,
                SourceBlend           = BlendOption.SourceAlpha,
                DestinationBlend      = BlendOption.InverseSourceAlpha,
                BlendOperation        = BlendOperation.Add,
                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation   = BlendOperation.Add,
                LogicOp = LogicOperation.Noop,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            transparentPsoDesc.BlendState.RenderTarget[0] = transparencyBlendDesc;
            _psos["transparent"] = Device.CreateGraphicsPipelineState(transparentPsoDesc);

            //
            // PSO for marking stencil mirrors.
            //

            // We are not rendering backfacing polygons, so these settings do not matter.
            var backFaceDSO = new DepthStencilOperationDescription
            {
                FailOperation      = StencilOperation.Keep,
                DepthFailOperation = StencilOperation.Keep,
                PassOperation      = StencilOperation.Replace,
                Comparison         = Comparison.Always
            };

            var mirrorBlendState = BlendStateDescription.Default();

            mirrorBlendState.RenderTarget[0].RenderTargetWriteMask = 0;
            var mirrorDSS = new DepthStencilStateDescription
            {
                IsDepthEnabled   = true,
                DepthWriteMask   = DepthWriteMask.Zero,
                DepthComparison  = Comparison.Less,
                IsStencilEnabled = true,
                StencilReadMask  = 0xff,
                StencilWriteMask = 0xff,

                FrontFace = new DepthStencilOperationDescription
                {
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Replace,
                    Comparison         = Comparison.Always
                },
                BackFace = backFaceDSO
            };

            GraphicsPipelineStateDescription markMirrorsPsoDesc = opaquePsoDesc.Copy();

            markMirrorsPsoDesc.BlendState        = mirrorBlendState;
            markMirrorsPsoDesc.DepthStencilState = mirrorDSS;
            _psos["markStencilMirrors"]          = Device.CreateGraphicsPipelineState(markMirrorsPsoDesc);

            //
            // PSO for stencil reflections.
            //

            var reflectionDSS = new DepthStencilStateDescription
            {
                IsDepthEnabled   = true,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Less,
                IsStencilEnabled = true,
                StencilReadMask  = 0xff,
                StencilWriteMask = 0xff,

                FrontFace = new DepthStencilOperationDescription
                {
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Keep,
                    Comparison         = Comparison.Equal
                },
                BackFace = backFaceDSO
            };

            GraphicsPipelineStateDescription drawReflectionsPsoDesc = opaquePsoDesc.Copy();

            drawReflectionsPsoDesc.DepthStencilState        = reflectionDSS;
            drawReflectionsPsoDesc.RasterizerState.CullMode = CullMode.Back;
            drawReflectionsPsoDesc.RasterizerState.IsFrontCounterClockwise = true;
            _psos["drawStencilReflections"] = Device.CreateGraphicsPipelineState(drawReflectionsPsoDesc);

            //
            // PSO for shadow objects.
            //

            var shadowDSS = new DepthStencilStateDescription
            {
                IsDepthEnabled   = true,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Less,
                IsStencilEnabled = true,
                StencilReadMask  = 0xff,
                StencilWriteMask = 0xff,

                FrontFace = new DepthStencilOperationDescription
                {
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Increment,
                    Comparison         = Comparison.Equal
                },
                BackFace = backFaceDSO
            };

            GraphicsPipelineStateDescription shadowPsoDesc = transparentPsoDesc.Copy();

            shadowPsoDesc.DepthStencilState = shadowDSS;
            _psos["shadow"] = Device.CreateGraphicsPipelineState(shadowPsoDesc);
        }
Esempio n. 26
0
 public static BlendState CreateBlendState(this Device device, RenderTargetBlendDescription description) {
     var desc = new BlendStateDescription {
         AlphaToCoverageEnable = false,
         IndependentBlendEnable = false
     };
     desc.RenderTargets[0] = description;
     return BlendState.FromDescription(device, desc);
 }
Esempio n. 27
0
        public static void Initialize()
        {
            var sampler = new SamplerStateDescription()
            {
                Filter             = Filter.MinMagMipLinear,
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy  = 16,
                MipLodBias         = 0,
                MinimumLod         = -float.MaxValue,
                MaximumLod         = float.MaxValue
            };

            sampler.AddressU = TextureAddressMode.Clamp;
            sampler.AddressV = TextureAddressMode.Clamp;
            samplerClamp     = new SamplerState(Display.device, sampler);

            sampler.AddressU = TextureAddressMode.Wrap;
            sampler.AddressV = TextureAddressMode.Wrap;
            samplerWrap      = new SamplerState(Display.device, sampler);

            sampler.Filter       = Filter.Anisotropic;
            samplerWrapAnistropy = new SamplerState(Display.device, sampler);

            var dssd = new DepthStencilStateDescription {
                IsDepthEnabled   = true,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Less,
            };

            depthDefaultState = new DepthStencilState(Display.device, dssd);

            var dssdwriteOff = new DepthStencilStateDescription {
                IsDepthEnabled   = true,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.Zero,
                DepthComparison  = Comparison.Less,
            };

            depthWriteOff = new DepthStencilState(Display.device, dssdwriteOff);

            var dssdisabled = new DepthStencilStateDescription {
                IsDepthEnabled   = false,
                IsStencilEnabled = false,
            };

            depthDisabled = new DepthStencilState(Display.device, dssdisabled);

            var solidParentOp = new RenderTargetBlendDescription();

            solidParentOp.IsBlendEnabled        = false;
            solidParentOp.RenderTargetWriteMask = ColorWriteMaskFlags.All;

            var transParentOp = new RenderTargetBlendDescription {
                IsBlendEnabled        = true,
                RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue,
                AlphaBlendOperation   = BlendOperation.Add,
                BlendOperation        = BlendOperation.Add,

                SourceAlphaBlend      = BlendOption.Zero,
                DestinationAlphaBlend = BlendOption.Zero,

                SourceBlend      = BlendOption.SourceAlpha,
                DestinationBlend = BlendOption.InverseSourceAlpha,
            };

            var addParentOp = new RenderTargetBlendDescription {
                IsBlendEnabled        = true,
                RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue,
                AlphaBlendOperation   = BlendOperation.Add,
                BlendOperation        = BlendOperation.Add,

                SourceAlphaBlend      = BlendOption.Zero,
                DestinationAlphaBlend = BlendOption.Zero,

                SourceBlend      = BlendOption.SourceAlpha,
                DestinationBlend = BlendOption.One,
            };


            var shadowParentOp = new RenderTargetBlendDescription();

            shadowParentOp.IsBlendEnabled        = false;
            shadowParentOp.RenderTargetWriteMask = 0;


            var drawingParentOp = new RenderTargetBlendDescription {
                IsBlendEnabled        = true,
                RenderTargetWriteMask = ColorWriteMaskFlags.All,
                AlphaBlendOperation   = BlendOperation.Add,
                BlendOperation        = BlendOperation.Add,

                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.One,

                SourceBlend      = BlendOption.SourceAlpha,
                DestinationBlend = BlendOption.InverseSourceAlpha,
            };


            var differenceParentOp = new RenderTargetBlendDescription {
                IsBlendEnabled        = true,
                RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue,
                AlphaBlendOperation   = BlendOperation.Add,
                BlendOperation        = BlendOperation.Add,

                SourceAlphaBlend      = BlendOption.SourceAlpha,
                DestinationAlphaBlend = BlendOption.One,

                SourceBlend      = BlendOption.InverseDestinationColor,
                DestinationBlend = BlendOption.InverseSourceColor,
            };

            blendStateSolid      = FromDesc(solidParentOp);
            blendStateTrans      = FromDesc(transParentOp);
            blendStateAdd        = FromDesc(addParentOp);
            blendStateShadow     = FromDesc(shadowParentOp);
            blendStateDrawing    = FromDesc(drawingParentOp);
            blendStateDifference = FromDesc(differenceParentOp);

            var rastState = new RasterizerStateDescription();

            rastState.CullMode = CullMode.Front;
            rastState.FillMode = FillMode.Solid;
            rastState.IsFrontCounterClockwise  = true;
            rastState.IsMultisampleEnabled     = true;
            rastState.IsDepthClipEnabled       = true;
            rastState.IsAntialiasedLineEnabled = true;
            rastStateSolid = new RasterizerState(Display.device, rastState);

            rastState.CullMode = CullMode.None;
            //rastState.IsScissorEnabled=true;
            rastStateDrawing = new RasterizerState(Display.device, rastState);

            var rastStatewire = new RasterizerStateDescription();

            rastStatewire.CullMode = CullMode.None;
            rastStatewire.FillMode = FillMode.Wireframe;
            rastStatewire.IsFrontCounterClockwise = true;
            rastStatewire.IsDepthClipEnabled      = true;
            rastStateWire = new RasterizerState(Display.device, rastStatewire);

            var rastStateNoCull1 = new RasterizerStateDescription();

            rastStateNoCull1.CullMode = CullMode.None;
            rastStateNoCull1.FillMode = FillMode.Solid;
            rastStateNoCull1.IsFrontCounterClockwise = true;
            rastStateNoCull1.IsDepthClipEnabled      = true;
            rastStateNoCull1.IsDepthClipEnabled      = true;
            rastStateNoCull = new RasterizerState(Display.device, rastStateNoCull1);
        }
Esempio n. 28
0
 public RenderTargetBlendViewModel(int number, RenderTargetBlendDescription description)
 {
     _number      = number;
     _description = description;
 }
Esempio n. 29
0
        protected override void CreateState()
        {
            InputElement[] inputElements = new InputElement[]
            {
                new InputElement("SV_Position", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0),
                new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 24, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 28, 0)
            };
            //Установка Сампрелар для текстуры.
            SamplerStateDescription description = SamplerStateDescription.Default();

            description.Filter   = Filter.MinMagMipLinear;
            description.AddressU = TextureAddressMode.Wrap;
            description.AddressV = TextureAddressMode.Wrap;
            //Устанавливаем параметры буффера глубины
            DepthStencilStateDescription DStateDescripshion = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = true,
                DepthComparison  = Comparison.Less,
                DepthWriteMask   = DepthWriteMask.All,
                IsStencilEnabled = false,
                StencilReadMask  = 0xff, // 0xff (no mask)
                StencilWriteMask = 0xff, // 0xff (no mask)
                // Configure FrontFace depth/stencil operations
                FrontFace = new DepthStencilOperationDescription()
                {
                    Comparison         = Comparison.Always,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Increment
                },
                // Configure BackFace depth/stencil operations
                BackFace = new DepthStencilOperationDescription()
                {
                    Comparison         = Comparison.Always,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Decrement
                }
            };
            //Устанавливаем параметры растеризации так чтобы обратная сторона объекта не спряталась.
            RasterizerStateDescription rasterizerStateDescription = RasterizerStateDescription.Default();

            rasterizerStateDescription.CullMode = CullMode.None;
            rasterizerStateDescription.FillMode = FillMode.Solid;
            //TODO: донастроить параметры блендинга для прозрачности.
            #region Формула бледнинга
            //(FC) - Final Color
            //(SP) - Source Pixel
            //(DP) - Destination Pixel
            //(SBF) - Source Blend Factor
            //(DBF) - Destination Blend Factor
            //(FA) - Final Alpha
            //(SA) - Source Alpha
            //(DA) - Destination Alpha
            //(+) - Binaray Operator described below
            //(X) - Cross Multiply Matrices
            //Формула для блендинга
            //(FC) = (SP)(X)(SBF)(+)(DP)(X)(DPF)
            //(FA) = (SA)(SBF)(+)(DA)(DBF)
            //ИСПОЛЬЗОВАНИЕ
            //_dx11DeviceContext.OutputMerger.SetBlendState(
            //    _blendState,
            //     new SharpDX.Mathematics.Interop.RawColor4(0.75f, 0.75f, 0.75f, 1f));
            //ЭТО ДЛЯ НЕПРОЗРАЧНЫХ _dx11DeviceContext.OutputMerger.SetBlendState(null, null);
            #endregion
            RenderTargetBlendDescription targetBlendDescription = new RenderTargetBlendDescription()
            {
                IsBlendEnabled        = new RawBool(true),
                SourceBlend           = BlendOption.SourceColor,
                DestinationBlend      = BlendOption.BlendFactor,
                BlendOperation        = BlendOperation.Add,
                SourceAlphaBlend      = BlendOption.SourceAlpha,
                DestinationAlphaBlend = BlendOption.DestinationAlpha,
                AlphaBlendOperation   = BlendOperation.Add,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };
            BlendStateDescription blendDescription = BlendStateDescription.Default();
            blendDescription.AlphaToCoverageEnable  = new RawBool(true);
            blendDescription.IndependentBlendEnable = new RawBool(true);
            //  blendDescription.RenderTarget[0] = targetBlendDescription;

            InitDrawer("Shaders\\ShadedCube.hlsl",
                       inputElements,
                       "Textures\\lava.jpg",
                       description,
                       DStateDescripshion,
                       rasterizerStateDescription,
                       blendDescription
                       );
        }
Esempio n. 30
0
        private void Initialize(IntPtr handle)
        {
            m_SwapChainHelper = new SwapChainHelper(handle);
            Device            = m_SwapChainHelper.CreateDeviceWithSwapChain(DeviceCreationFlags.Debug);
            DeviceContext     = Device.ImmediateContext;

            MainRenderTarget = new RenderTarget
                               (
                m_SwapChainHelper.GetRenderTargetView(),
                Screen.Instance.Width,
                Screen.Instance.Height
                               );

            scene_ = new Scene(new Color4(0.0f, 0.2f, 0.7f, 1.0f));

            // On récupère le RenderTargetView généré par notre swapchain représentant
            // le backBuffer

            new LightManager();
            new ProjectorManager();
            new CollisionManager();
            new TimeHelper();
            new LayerManager();

            // Initialisation de la transparence
            RenderTargetBlendDescription desc = new RenderTargetBlendDescription()
            {
                AlphaBlendOperation = BlendOperation.Add,
                BlendOperation      = BlendOperation.Add,

                SourceAlphaBlend      = BlendOption.SourceAlpha,
                DestinationAlphaBlend = BlendOption.One,

                SourceBlend      = BlendOption.SourceAlpha,
                DestinationBlend = BlendOption.InverseSourceAlpha,

                IsBlendEnabled        = true,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            BlendStateDescription blendStateDesc = new BlendStateDescription()
            {
                IndependentBlendEnable = false,        // DirectX peut utiliser 8 RenderTarget simultanément, chauqe renderTarget
                // peut être lié à un RenderTargetBlendDescription différent
                AlphaToCoverageEnable = false
            };

            blendStateDesc.RenderTarget[0] = desc;

            mainBlend = new BlendState(Device, blendStateDesc);

            DeviceContext.OutputMerger.BlendState = mainBlend;
            // Fin Transparence

            InitializeRasterState();

            new GlowingManager(Screen.Instance.Width, Screen.Instance.Height);
            m_ApplicationInformation = new ApplicationInformation();

            renderTex       = new RenderTexture(Screen.Instance.Width, Screen.Instance.Height);
            imageProcessing = new ImageProcessing(Screen.Instance.Width, Screen.Instance.Height, renderTex.SRV);
            //renderTarget.DepthStencil.SetDepthComparison( Comparison.LessEqual );
            MainRenderTarget.DepthStencil.SetDepthComparison(Comparison.LessEqual);
            new InputManager(m_renderForm);
        }
Esempio n. 31
0
        private void BuildPSOs()
        {
            //
            // PSO for opaque objects.
            //

            var opaquePsoDesc = new GraphicsPipelineStateDescription
            {
                InputLayout           = _inputLayout,
                RootSignature         = _rootSignature,
                VertexShader          = _shaders["standardVS"],
                PixelShader           = _shaders["opaquePS"],
                RasterizerState       = RasterizerStateDescription.Default(),
                BlendState            = BlendStateDescription.Default(),
                DepthStencilState     = DepthStencilStateDescription.Default(),
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                SampleDescription     = new SampleDescription(MsaaCount, MsaaQuality),
                DepthStencilFormat    = DepthStencilFormat,
                StreamOutput          = new StreamOutputDescription() //find out how this should actually be done later
            };

            opaquePsoDesc.RenderTargetFormats[0] = BackBufferFormat;

            _psos["opaque"] = Device.CreateGraphicsPipelineState(opaquePsoDesc);

            //
            // PSO for transparent objects.
            //

            GraphicsPipelineStateDescription transparentPsoDesc = opaquePsoDesc.Copy();

            var transparencyBlendDesc = new RenderTargetBlendDescription
            {
                IsBlendEnabled        = true,
                LogicOpEnable         = false, // TODO: rename to IsLogicOpEnabled
                SourceBlend           = BlendOption.SourceAlpha,
                DestinationBlend      = BlendOption.InverseSourceAlpha,
                BlendOperation        = BlendOperation.Add,
                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation   = BlendOperation.Add,
                LogicOp = LogicOperation.Noop,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            transparentPsoDesc.BlendState.RenderTarget[0] = transparencyBlendDesc;

            _psos["transparent"] = Device.CreateGraphicsPipelineState(transparentPsoDesc);

            //
            // PSO for alpha tested objects.
            //

            GraphicsPipelineStateDescription alphaTestedPsoDesc = opaquePsoDesc.Copy();

            alphaTestedPsoDesc.PixelShader = _shaders["alphaTestedPS"];
            alphaTestedPsoDesc.RasterizerState.CullMode = CullMode.None;

            _psos["alphaTested"] = Device.CreateGraphicsPipelineState(alphaTestedPsoDesc);

            //
            // PSO for horizontal blur.
            //

            var horzBlurPso = new ComputePipelineStateDescription
            {
                RootSignaturePointer = _postProcessRootSignature,
                ComputeShader        = _shaders["horzBlurCS"],
                Flags = PipelineStateFlags.None
            };

            _psos["horzBlur"] = Device.CreateComputePipelineState(horzBlurPso);

            //
            // PSO for vertical blur.
            //

            var vertBlurPso = new ComputePipelineStateDescription
            {
                RootSignaturePointer = _postProcessRootSignature,
                ComputeShader        = _shaders["vertBlurCS"],
                Flags = PipelineStateFlags.None
            };

            _psos["vertBlur"] = Device.CreateComputePipelineState(vertBlurPso);
        }
Esempio n. 32
0
        void Attach()
        {
            disposer = new DisposeGroup();

            var device = Renderer.Device;

            string noteShaderData;
            var    assembly = Assembly.GetExecutingAssembly();

            using (var stream = assembly.GetManifestResourceStream("Iris.Previews.DX11.notes.fx"))
                using (var reader = new IO.StreamReader(stream))
                    noteShaderData = reader.ReadToEnd();
            notesShader = disposer.Add(new ShaderManager(
                                           device,
                                           ShaderBytecode.Compile(noteShaderData, "VS_Note", "vs_4_0", ShaderFlags.None, EffectFlags.None),
                                           ShaderBytecode.Compile(noteShaderData, "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None),
                                           ShaderBytecode.Compile(noteShaderData, "GS_Note", "gs_4_0", ShaderFlags.None, EffectFlags.None)
                                           ));

            noteLayout = disposer.Add(new InputLayout(device, ShaderSignature.GetInputSignature(notesShader.vertexShaderByteCode), new[] {
                new InputElement("START", 0, Format.R32_Float, 0, 0),
                new InputElement("END", 0, Format.R32_Float, 4, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 8, 0),
            }));

            noteConstants = new NotesGlobalConstants()
            {
                NoteBorder   = 0.002f,
                NoteLeft     = -0.2f,
                NoteRight    = 0.0f,
                ScreenAspect = 1f
            };

            noteBuffer = new Buffer(device, new BufferDescription()
            {
                BindFlags           = BindFlags.VertexBuffer,
                CpuAccessFlags      = CpuAccessFlags.Write,
                OptionFlags         = ResourceOptionFlags.None,
                SizeInBytes         = 40 * noteBufferLength,
                Usage               = ResourceUsage.Dynamic,
                StructureByteStride = 0
            });

            globalNoteConstants = new Buffer(device, new BufferDescription()
            {
                BindFlags           = BindFlags.ConstantBuffer,
                CpuAccessFlags      = CpuAccessFlags.Write,
                OptionFlags         = ResourceOptionFlags.None,
                SizeInBytes         = 32,
                Usage               = ResourceUsage.Dynamic,
                StructureByteStride = 0
            });

            var renderTargetDesc = new RenderTargetBlendDescription();

            renderTargetDesc.IsBlendEnabled        = true;
            renderTargetDesc.SourceBlend           = BlendOption.SourceAlpha;
            renderTargetDesc.DestinationBlend      = BlendOption.InverseSourceAlpha;
            renderTargetDesc.BlendOperation        = BlendOperation.Add;
            renderTargetDesc.SourceAlphaBlend      = BlendOption.One;
            renderTargetDesc.DestinationAlphaBlend = BlendOption.One;
            renderTargetDesc.AlphaBlendOperation   = BlendOperation.Add;
            renderTargetDesc.RenderTargetWriteMask = ColorWriteMaskFlags.All;

            BlendStateDescription desc = new BlendStateDescription();

            desc.AlphaToCoverageEnable  = false;
            desc.IndependentBlendEnable = false;
            desc.RenderTarget[0]        = renderTargetDesc;

            var blendStateEnabled = new BlendState(device, desc);

            device.ImmediateContext.OutputMerger.SetBlendState(blendStateEnabled);

            RasterizerStateDescription renderStateDesc = new RasterizerStateDescription
            {
                CullMode                 = CullMode.None,
                DepthBias                = 0,
                DepthBiasClamp           = 0,
                FillMode                 = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled       = false,
                IsFrontCounterClockwise  = false,
                IsMultisampleEnabled     = true,
                IsScissorEnabled         = false,
                SlopeScaledDepthBias     = 0
            };
            var rasterStateSolid = new RasterizerState(device, renderStateDesc);

            device.ImmediateContext.Rasterizer.State = rasterStateSolid;
        }
Esempio n. 33
0
        private void BuildPSOs()
        {
            //
            // PSO for opaque objects.
            //

            var opaquePsoDesc = new GraphicsPipelineStateDescription
            {
                InputLayout           = _inputLayout,
                RootSignature         = _rootSignature,
                VertexShader          = _shaders["standardVS"],
                PixelShader           = _shaders["opaquePS"],
                RasterizerState       = RasterizerStateDescription.Default(),
                BlendState            = BlendStateDescription.Default(),
                DepthStencilState     = DepthStencilStateDescription.Default(),
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                SampleDescription     = new SampleDescription(MsaaCount, MsaaQuality),
                DepthStencilFormat    = DepthStencilFormat
            };

            opaquePsoDesc.RenderTargetFormats[0] = BackBufferFormat;

            _psos["opaque"] = Device.CreateGraphicsPipelineState(opaquePsoDesc);

            //
            // PSO for transparent objects.
            //

            GraphicsPipelineStateDescription transparentPsoDesc = opaquePsoDesc.Copy();

            var transparencyBlendDesc = new RenderTargetBlendDescription
            {
                IsBlendEnabled        = true,
                LogicOpEnable         = false, // TODO: API suggestion: Rename to IsLogicOpEnabled similar to IsBlendEnabled.
                SourceBlend           = BlendOption.SourceAlpha,
                DestinationBlend      = BlendOption.InverseSourceAlpha,
                BlendOperation        = BlendOperation.Add,
                SourceAlphaBlend      = BlendOption.One,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation   = BlendOperation.Add,
                LogicOp = LogicOperation.Noop,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            transparentPsoDesc.BlendState.RenderTarget[0] = transparencyBlendDesc;

            _psos["transparent"] = Device.CreateGraphicsPipelineState(transparentPsoDesc);

            //
            // PSO for alpha tested objects.
            //

            GraphicsPipelineStateDescription alphaTestedPsoDesc = opaquePsoDesc.Copy();

            alphaTestedPsoDesc.PixelShader = _shaders["alphaTestedPS"];
            alphaTestedPsoDesc.RasterizerState.CullMode = CullMode.None;

            _psos["alphaTested"] = Device.CreateGraphicsPipelineState(alphaTestedPsoDesc);
        }
Esempio n. 34
0
        public override void Initialize()
        {
            try
            {
                using (ShaderBytecode geometryShaderByteCode = ShaderBytecode.CompileFromFile(
                           "Shaders/Sprite.fx",
                           "mainGS",
                           "gs_4_0",
                           ShaderFlags.None,
                           EffectFlags.None,
                           null,
                           new IncludeFX("Shaders")))
                {
                    geometryShader = new GeometryShader(DeviceManager.Instance.device, geometryShaderByteCode);
                }

                using (ShaderBytecode vertexShaderByteCode = ShaderBytecode.CompileFromFile(
                           "Shaders/Sprite.fx",
                           "mainVS",
                           "vs_4_0",
                           ShaderFlags.None,
                           EffectFlags.None,
                           null,
                           new IncludeFX("Shaders")))
                {
                    vertexShader   = new VertexShader(DeviceManager.Instance.device, vertexShaderByteCode);
                    inputSignature = ShaderSignature.GetInputSignature(vertexShaderByteCode);
                }

                using (ShaderBytecode pixelShaderByteCode = ShaderBytecode.CompileFromFile(
                           "Shaders/Sprite.fx",
                           "mainPS",
                           "ps_4_0",
                           ShaderFlags.None,
                           EffectFlags.None,
                           null,
                           new IncludeFX("Shaders")))
                {
                    pixelShader = new PixelShader(DeviceManager.Instance.device, pixelShaderByteCode);
                }

                layout = new InputLayout(DeviceManager.Instance.device, inputSignature, elements);

                #region Blend States

                RenderTargetBlendDescription rtBlendDefault = new RenderTargetBlendDescription()
                {
                    BlendEnable           = true,
                    BlendOperation        = BlendOperation.Add,
                    RenderTargetWriteMask = ColorWriteMaskFlags.All,
                    SourceBlend           = BlendOption.SourceAlpha,
                    DestinationBlend      = BlendOption.InverseSourceAlpha,
                    BlendOperationAlpha   = BlendOperation.Add,
                    SourceBlendAlpha      = BlendOption.SourceAlpha,
                    DestinationBlendAlpha = BlendOption.InverseSourceAlpha,
                };

                BlendStateDescription bBlendStateDefault = new BlendStateDescription();
                bBlendStateDefault.AlphaToCoverageEnable  = false;
                bBlendStateDefault.IndependentBlendEnable = false;
                bBlendStateDefault.RenderTargets[0]       = rtBlendDefault;

                blendStateDepth = BlendState.FromDescription(DeviceManager.Instance.device, bBlendStateDefault);

                #endregion

                #region Depth Stencils

                DepthStencilStateDescription dsStateNoDepth = new DepthStencilStateDescription()
                {
                    IsDepthEnabled = false,
                    DepthWriteMask = DepthWriteMask.Zero
                };

                depthStencilStateNoDepth = DepthStencilState.FromDescription(DeviceManager.Instance.device, dsStateNoDepth);

                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 35
0
        public DefaultRenderer(D3D11 renderer)
        {
            random = new Random();

            device  = renderer.Device;
            context = device.ImmediateContext;
            target  = renderer.RenderTargetView;


            unsafe
            {
                dxBuffer = new Buffer(device, new BufferDescription()
                {
                    BindFlags           = BindFlags.VertexBuffer,
                    CpuAccessFlags      = CpuAccessFlags.Write,
                    OptionFlags         = ResourceOptionFlags.None,
                    SizeInBytes         = sizeof(VertexStruct) * buffer.Length,
                    Usage               = ResourceUsage.Dynamic,
                    StructureByteStride = 0
                });

                var constantsSize = sizeof(GlobalConstants);
                if (constantsSize % 16 != 0)
                {
                    constantsSize += 16 - (constantsSize % 16);
                }
                globalConstants = new Buffer(device, new BufferDescription()
                {
                    BindFlags           = BindFlags.ConstantBuffer,
                    CpuAccessFlags      = CpuAccessFlags.Write,
                    OptionFlags         = ResourceOptionFlags.None,
                    SizeInBytes         = constantsSize,
                    Usage               = ResourceUsage.Dynamic,
                    StructureByteStride = 0
                });
            }

            vertexShaderByteCode = ShaderBytecode.Compile(noteShaderData, "VS", "vs_4_0", ShaderFlags.None, EffectFlags.None);
            pixelShaderByteCode  = ShaderBytecode.Compile(noteShaderData, "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None);

            vertexShader = new VertexShader(device, vertexShaderByteCode);
            pixelShader  = new PixelShader(device, pixelShaderByteCode);

            noteShader = new ShaderManager(
                device,
                ShaderBytecode.Compile(noteShaderData, "VS", "vs_4_0", ShaderFlags.None, EffectFlags.None),
                ShaderBytecode.Compile(noteShaderData, "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None)
                );

            vertLayout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), new[] {
                new InputElement("POSITION", 0, Format.R32G32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 8, 0),
            });

            //disabling backface culling, as well as some other stuff
            RasterizerStateDescription renderStateDesc = new RasterizerStateDescription
            {
                CullMode                 = CullMode.None,
                DepthBias                = 0,
                DepthBiasClamp           = 0,
                FillMode                 = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled       = false,
                IsFrontCounterClockwise  = false,
                IsMultisampleEnabled     = true,
                IsScissorEnabled         = false,
                SlopeScaledDepthBias     = 0
            };
            var rasterStateSolid = new RasterizerState(device, renderStateDesc);

            device.ImmediateContext.Rasterizer.State = rasterStateSolid;

            //transparency mode
            var renderTargetDesc = new RenderTargetBlendDescription();

            renderTargetDesc.IsBlendEnabled        = true;
            renderTargetDesc.SourceBlend           = BlendOption.SourceAlpha;
            renderTargetDesc.DestinationBlend      = BlendOption.InverseSourceAlpha;
            renderTargetDesc.BlendOperation        = BlendOperation.Add;
            renderTargetDesc.SourceAlphaBlend      = BlendOption.One;
            renderTargetDesc.DestinationAlphaBlend = BlendOption.One;
            renderTargetDesc.AlphaBlendOperation   = BlendOperation.Add;
            renderTargetDesc.RenderTargetWriteMask = ColorWriteMaskFlags.All;

            BlendStateDescription desc = new BlendStateDescription();

            desc.AlphaToCoverageEnable  = false;
            desc.IndependentBlendEnable = false;
            desc.RenderTarget[0]        = renderTargetDesc;

            var blendStateEnabled = new BlendState(device, desc);

            device.ImmediateContext.OutputMerger.SetBlendState(blendStateEnabled);
        }
Esempio n. 36
0
        public GlowingManager(int width, int height)
        {
            // On Initialise le transform, puisqu'on se trouve en dehors de la scène
            transform_ = new Transform();
            transform_.SetScale(Screen.Instance.Width, Screen.Instance.Height, 1.0f);
            transform_.Translate(0.0f, 0.0f, 0.5f);

            // Initialisation du material servant à dessiner le quad final
            m_DrawingMaterial = new MaterialDX11("vDefault.cso", "pUnlit.cso", "gDefault.cso");

            // Initialisation du Quad que l'on utilise pour dessiner
            modelrenderer = new MeshRenderer(m_DrawingMaterial, Quad.GetMesh());

            PostProcessingView = new View(new Transform(), new OrthoProjection(Screen.Instance.Width, Screen.Instance.Height, 0.1f, 100.0f));

            Quaternion xquat = Quaternion.RotationAxis(new Vector3(1.0f, 0.0f, 0.0f), 0 * 0.01f);
            Quaternion yquat = Quaternion.RotationAxis(new Vector3(0.0f, 1.0f, 0.0f), 0 * 0.01f);

            Quaternion rotQuat = Quaternion.Multiply(xquat, yquat);
            Matrix     mview   = Matrix.AffineTransformation(1.0f, rotQuat, new Vector3(00.0f, 0.0f, 10.0f));

            Instance = this;

            MaterialDX11 HBlurMaterial = new MaterialDX11("vDefault.cso", "pHBlur.cso", "gDefault.cso");

            HBlurMaterial.AddConstantBuffer <HBlurDesc>(new HBlurDesc(width / 2, 50));

            MaterialDX11 VBlurMaterial = new MaterialDX11("vDefault.cso", "pVBlur.cso", "gDefault.cso");

            VBlurMaterial.AddConstantBuffer <VBlurDesc>(new VBlurDesc(height / 2, 50));

            m_Material = new MaterialDX11("vDefault.cso", "pGlow.cso", "gDefault.cso");
            m_Material.AddConstantBuffer <GlowDesc>(new GlowDesc(false, false, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)));

            m_RenderTexture   = new RenderTexture(width, height);
            m_ImageProcessing = new ImageProcessing(width, height, m_RenderTexture.SRV);

            m_ImageProcessing.AddPasse(HBlurMaterial);
            m_ImageProcessing.AddPasse(HBlurMaterial);

            m_ImageProcessing.AddPasse(VBlurMaterial);
            m_ImageProcessing.AddPasse(VBlurMaterial);

            // Additive Blending
            RenderTargetBlendDescription renderdesc = new RenderTargetBlendDescription()
            {
                BlendOperation      = BlendOperation.Add,
                AlphaBlendOperation = BlendOperation.Add,

                SourceAlphaBlend      = BlendOption.Zero,
                DestinationAlphaBlend = BlendOption.Zero,

                SourceBlend      = BlendOption.One,
                DestinationBlend = BlendOption.One,


                IsBlendEnabled        = true,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            };

            BlendStateDescription blendStateDesc2 = new BlendStateDescription()
            {
                IndependentBlendEnable = false,                // DirectX peut utiliser 8 RenderTarget simultanément, chauqe renderTarget
                // peut être lié à un RenderTargetBlendDescription différent
                AlphaToCoverageEnable = false
            };

            blendStateDesc2.RenderTarget[0] = renderdesc;

            glowingBlending = new BlendState(ApplicationDX11.Instance.Device, blendStateDesc2);
        }