Example #1
0
        void CreateStates()
        {
            var d = DepthStencilStateDescription.Default();

            d.IsDepthEnabled   = true;
            d.IsStencilEnabled = false;

            var r = RasterizerStateDescription.Default();

            r.FillMode = SharpDX.Direct3D11.FillMode.Solid;
            r.CullMode = CullMode.None;

            var b = BlendStateDescription.Default();

            b.AlphaToCoverageEnable = new RawBool(true);
            var s = new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter             = Filter.Anisotropic,
                MaximumAnisotropy  = 16,
                MaximumLod         = float.MaxValue,
                MinimumLod         = 0,
                MipLodBias         = 0.0f
            };

            _samler     = new SamplerState(_dx11Device, s);
            _depth      = new DepthStencilState(_dx11Device, d);
            _rasterizer = new RasterizerState(_dx11Device, r);
            _dx11DeviceContext.OutputMerger.DepthStencilState = _depth;
        }
Example #2
0
        protected override void InitializeInternal()
        {
            var desc = RasterizerStateDescription.Default();

            desc.IsFrontCounterClockwise = Settings.WindingOrder == WindingOrder.Counterclockwise;
            desc.FillMode                 = Settings.RenderWireframe ? FillMode.Wireframe : FillMode.Solid;
            desc.IsDepthClipEnabled       = Settings.EnableDepthTest;
            desc.IsMultisampleEnabled     = Settings.Antialiasing == Antialiasing.Multisample;
            desc.IsAntialiasedLineEnabled = Settings.Antialiasing == Antialiasing.LinesOnly;
            switch (Settings.TriangleCulling)
            {
            case TriangleCulling.DrawFrontFacing:
                desc.CullMode = CullMode.Back;
                break;

            case TriangleCulling.DrawBackFacing:
                desc.CullMode = CullMode.Front;
                break;

            case TriangleCulling.DrawAll:
                desc.CullMode = CullMode.None;
                break;
            }
            State = new global::SharpDX.Direct3D11.RasterizerState(DeviceManager.Device, desc);
        }
        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;

            _opaquePso = Device.CreateGraphicsPipelineState(opaquePsoDesc);
        }
Example #4
0
        private void BuildPSO()
        {
            var psoDesc = new GraphicsPipelineStateDescription
            {
                InputLayout           = _inputLayout,
                RootSignature         = _rootSignature,
                VertexShader          = _mvsByteCode,
                PixelShader           = _mpsByteCode,
                RasterizerState       = RasterizerStateDescription.Default(),
                BlendState            = BlendStateDescription.Default(),
                DepthStencilState     = DepthStencilStateDescription.Default(),
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                SampleDescription     = new SampleDescription(MsaaCount, MsaaQuality),
                DepthStencilFormat    = DepthStencilFormat,

                //Flags = PipelineStateFlags.None,
                //IBStripCutValue = IndexBufferStripCutValue.Disabled,
                //NodeMask = 0,
                //CachedPSO = new CachedPipelineState(),
                //DomainShader = new ShaderBytecode(),
                //GeometryShader = new ShaderBytecode(),
                //HullShader = new ShaderBytecode(),

                //RenderTargetFormats = new Format[] { },
                StreamOutput = new StreamOutputDescription()
            };

            psoDesc.RenderTargetFormats[0] = BackBufferFormat;

            _pso = Device.CreateGraphicsPipelineState(psoDesc);
        }
Example #5
0
        public void SetRasterizerState(H1RasterizerDescription rasterizerDesc)
        {
            RasterizerStateDescription newRasterizerStateDesc = RasterizerStateDescription.Default();

            newRasterizerStateDesc.FillMode = H1RHIDefinitionHelper.ConvertToFillMode(rasterizerDesc.FillMode);
            newRasterizerStateDesc.CullMode = H1RHIDefinitionHelper.ConvertToCullMode(rasterizerDesc.CullMode);
            newRasterizerStateDesc.IsFrontCounterClockwise = rasterizerDesc.FrontCounterClockwise;
            newRasterizerStateDesc.DepthBias                = rasterizerDesc.DepthBias;
            newRasterizerStateDesc.DepthBiasClamp           = rasterizerDesc.DepthBiasClamp;
            newRasterizerStateDesc.SlopeScaledDepthBias     = rasterizerDesc.SlopeScaledDepthBias;
            newRasterizerStateDesc.IsDepthClipEnabled       = rasterizerDesc.DepthClipEnable;
            newRasterizerStateDesc.IsMultisampleEnabled     = rasterizerDesc.MultiSampleEnable;
            newRasterizerStateDesc.IsAntialiasedLineEnabled = rasterizerDesc.AntialiasedLineEnable;
            newRasterizerStateDesc.ForcedSampleCount        = rasterizerDesc.ForcedSampleCount;

            if (rasterizerDesc.ConservativeRasterMode == H1ConservativeRasterizationMode.On)
            {
                newRasterizerStateDesc.ConservativeRaster = ConservativeRasterizationMode.On;
            }
            else
            {
                newRasterizerStateDesc.ConservativeRaster = ConservativeRasterizationMode.Off;
            }

            // assign the newly created rasterizer state desc
            m_GraphicsPipelineStateDesc.RasterizerState = newRasterizerStateDesc;
        }
Example #6
0
        public ControlDevice(Control control)
        {
            {
                this.control = control;
                var desc = new SwapChainDescription()
                {
                    BufferCount       = 1,
                    ModeDescription   = new ModeDescription(control.Width, control.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm_SRgb),
                    IsWindowed        = true,
                    OutputHandle      = control.Handle,
                    SampleDescription = new SampleDescription(1, 0),
                    SwapEffect        = SwapEffect.Discard,
                    Usage             = Usage.RenderTargetOutput,
                };

                SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out this.device, out this.swapChain);
                this.context    = this.device.ImmediateContext;
                this.backBuffer = SharpDX.Direct3D11.Resource.FromSwapChain <Texture2D>(this.swapChain, 0);
                this.renderView = new RenderTargetView(this.device, this.backBuffer);
                this.context.Rasterizer.SetViewport(new Viewport(0, 0, control.Width, control.Height, 0f, 1f));
                RasterizerStateDescription desc2 = RasterizerStateDescription.Default();
                desc2.CullMode = CullMode.None;
                RasterizerState state = new RasterizerState(this.device, desc2);
                this.context.Rasterizer.State = state;
            }
        }
        private void CreatePSO(InputElement[] inputElementDescs, ShaderBytecode vertexShader, ShaderBytecode pixelShader)
        {
            // Describe and create the graphics pipeline state object (PSO).
            var psoDesc = new GraphicsPipelineStateDescription()
            {
                InputLayout        = new InputLayoutDescription(inputElementDescs),
                RootSignature      = rootSignature,
                VertexShader       = vertexShader,
                PixelShader        = pixelShader,
                RasterizerState    = RasterizerStateDescription.Default(),
                BlendState         = BlendStateDescription.Default(),
                DepthStencilFormat = SharpDX.DXGI.Format.D32_Float,
                DepthStencilState  = new DepthStencilStateDescription()
                {
                    IsDepthEnabled   = true,
                    DepthComparison  = Comparison.LessEqual,
                    DepthWriteMask   = DepthWriteMask.All,
                    IsStencilEnabled = false
                },
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                Flags             = PipelineStateFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                StreamOutput      = new StreamOutputDescription()
            };

            psoDesc.RenderTargetFormats[0] = SharpDX.DXGI.Format.R8G8B8A8_UNorm;

            pipelineState = device.CreateGraphicsPipelineState(psoDesc);

            commandList = device.CreateCommandList(CommandListType.Direct, commandAllocator, pipelineState);
            commandList.Close();
        }
Example #8
0
    private RasterizerState MakeNoCullRasterizerState(Device device)
    {
        RasterizerStateDescription desc = RasterizerStateDescription.Default();

        desc.CullMode = CullMode.None;
        return(new RasterizerState(device, desc));
    }
Example #9
0
        protected void SetUp(int width, int height)
        {
            _Device = CreateDevice(width, height);

            CreateView(width, height);

            var depthDesc = DepthStencilStateDescription.Default();

            _StencilState = new DepthStencilState(Device, depthDesc);
            var blendDesc = BlendStateDescription.Default();

            blendDesc.RenderTarget[0].IsBlendEnabled        = true;
            blendDesc.RenderTarget[0].SourceBlend           = BlendOption.SourceAlpha;
            blendDesc.RenderTarget[0].DestinationBlend      = BlendOption.InverseSourceAlpha;
            blendDesc.RenderTarget[0].BlendOperation        = BlendOperation.Add;
            blendDesc.RenderTarget[0].SourceAlphaBlend      = BlendOption.One;
            blendDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
            blendDesc.RenderTarget[0].AlphaBlendOperation   = BlendOperation.Add;
            blendDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            _BlendState = new BlendState(Device, blendDesc);

            var raster = RasterizerStateDescription.Default();

            raster.CullMode             = CullMode.Front;
            raster.IsMultisampleEnabled = RenderTarget.Description.SampleDescription.Count > 1;

            _RasterizerState = new RasterizerState(Device, raster);
        }
        public _3DWaveManager(DeviceContext DeviceContext)
        {
            InputElement[] inputElements = new InputElement[]
            {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 12, 0)
            };


            _drawer = new Drawer(
                "Shaders\\Shader.hlsl",
                inputElements,
                DeviceContext);

            var res = RasterizerStateDescription.Default();

            res.CullMode                  = CullMode.None;
            res.IsDepthClipEnabled        = false;
            _drawer.RasterizerDescription = res;

            var sampler = SamplerStateDescription.Default();

            sampler.AddressU           = TextureAddressMode.Wrap;
            sampler.AddressV           = TextureAddressMode.Wrap;
            sampler.AddressW           = TextureAddressMode.Wrap;
            sampler.Filter             = Filter.MinMagMipLinear;
            _drawer.Samplerdescription = sampler;

            var des = DepthStencilStateDescription.Default();

            des.DepthComparison = Comparison.Less;
            _drawer.DepthStencilDescripshion = des;
            _cube = new Wave(DeviceContext.Device, "Textures\\grass.jpg");
        }
        public States(Device device)
        {
            _device = device;
            var d = DepthStencilStateDescription.Default();

            d.IsDepthEnabled         = true;
            d.IsStencilEnabled       = false;
            DepthStencilDescripshion = d;
            var r = RasterizerStateDescription.Default();

            r.CullMode            = CullMode.None;
            r.FillMode            = SharpDX.Direct3D11.FillMode.Solid;
            RasterizerDescription = r;
            var b = BlendStateDescription.Default();

            b.AlphaToCoverageEnable = new RawBool(true);
            BlendDescription        = b;
            var s = new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter             = Filter.Anisotropic,
                MaximumAnisotropy  = 16,
                MaximumLod         = float.MaxValue,
                MinimumLod         = 0,
                MipLodBias         = 0.0f
            };
        }
Example #12
0
        protected void Initialize(PipelineStateDescription description)
        {
            var pipelineStateDescription = new GraphicsPipelineStateDescription()
            {
                // From mesh
                InputLayout = FromVertexLayout(description.InputLayout),

                // From effect
                RootSignature = description.RootSignature.NativeRootSignature,
                VertexShader  = new SharpDX.Direct3D12.ShaderBytecode(description.VertexShader),
                PixelShader   = new SharpDX.Direct3D12.ShaderBytecode(description.PixelShader),

                // Common
                RasterizerState       = RasterizerStateDescription.Default(),
                BlendState            = BlendStateDescription.Default(),
                DepthStencilFormat    = Format.D32_Float,
                DepthStencilState     = DepthStencilStateDescription.Default(),
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                Flags             = PipelineStateFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                StreamOutput      = new StreamOutputDescription()
            };

            pipelineStateDescription.RenderTargetFormats[0] = Format.B8G8R8A8_UNorm;
            NativePipelineState = Device.NativeDevice.CreateGraphicsPipelineState(pipelineStateDescription);
        }
        private void BuildPSOs()
        {
            //
            // PSO for opaque objects.
            //

            var opaquePsoDesc = new GraphicsPipelineStateDescription
            {
                InputLayout           = _inputLayout,
                RootSignature         = _rootSignature,
                VertexShader          = _shaders["tessVS"],
                HullShader            = _shaders["tessHS"],
                DomainShader          = _shaders["tessDS"],
                PixelShader           = _shaders["tessPS"],
                RasterizerState       = RasterizerStateDescription.Default(),
                BlendState            = BlendStateDescription.Default(),
                DepthStencilState     = DepthStencilStateDescription.Default(),
                SampleMask            = unchecked ((int)0xFFFFFFFF),
                PrimitiveTopologyType = PrimitiveTopologyType.Patch,
                RenderTargetCount     = 1,
                SampleDescription     = new SampleDescription(MsaaCount, MsaaQuality),
                DepthStencilFormat    = DepthStencilFormat
            };

            opaquePsoDesc.RenderTargetFormats[0]   = BackBufferFormat;
            opaquePsoDesc.RasterizerState.FillMode = FillMode.Wireframe;

            _psos["opaque"] = Device.CreateGraphicsPipelineState(opaquePsoDesc);
        }
        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
            };

            opaquePsoDesc.RenderTargetFormats[0] = BackBufferFormat;

            _psos["opaque"] = Device.CreateGraphicsPipelineState(opaquePsoDesc);
        }
Example #15
0
 public static StateDescriptions Default()
 {
     return(new StateDescriptions {
         rasterizer = RasterizerStateDescription.Default(),
         depthStencil = DepthStencilStateDescription.Default(),
         blend = BlendStateDescription.Default()
     });
 }
Example #16
0
        void DefineRasterizerState()
        {
            var desc = RasterizerStateDescription.Default();

            desc.IsFrontCounterClockwise = true;

            default_rasterizer_state = new RasterizerState(device, desc);
        }
Example #17
0
        void GetPipelineState()
        {

            DescriptorRange[] ranges = new DescriptorRange[] { new DescriptorRange() { RangeType = DescriptorRangeType.ConstantBufferView, BaseShaderRegister = 0, DescriptorCount = 1 } };
            RootParameter parameter = new RootParameter(ShaderVisibility.Vertex, ranges);

            // Create a root signature.
            RootSignatureDescription rootSignatureDesc = new RootSignatureDescription(RootSignatureFlags.AllowInputAssemblerInputLayout, new RootParameter[] { parameter });
            var rootSignature = device.CreateRootSignature(rootSignatureDesc.Serialize());

            // Create the pipeline state, which includes compiling and loading shaders.
            string filePath = @"E:\Code\ROE1\RoeHack-master\Forms\bin\Debug\DirectXHooker\shaders.hlsl";

#if DEBUG
            var vertexShader = new ShaderBytecode(SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile(filePath, "VSMain", "vs_5_0", SharpDX.D3DCompiler.ShaderFlags.Debug));
#else
            var vertexShader = new ShaderBytecode(SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile("filePath, "VSMain", "vs_5_0"));
#endif

#if DEBUG
            var pixelShader = new ShaderBytecode(SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile(filePath, "PSMain", "ps_5_0", SharpDX.D3DCompiler.ShaderFlags.Debug));
#else
            var pixelShader = new ShaderBytecode(SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile(filePath, "PSMain", "ps_5_0"));
#endif
           



            // Define the vertex input layout.
            InputElement[] inputElementDescs = new InputElement[]
            {
                    new InputElement("POSITION",0,Format.R32G32B32_Float,0,0),
                    new InputElement("COLOR",0,Format.R32G32B32A32_Float,12,0)
            };

            // Describe and create the graphics pipeline state object (PSO).
            GraphicsPipelineStateDescription psoDesc = new GraphicsPipelineStateDescription()
            {
                InputLayout = new InputLayoutDescription(inputElementDescs),
                RootSignature = rootSignature,
                VertexShader = vertexShader,
                PixelShader = pixelShader,
                RasterizerState = RasterizerStateDescription.Default(),
                BlendState = BlendStateDescription.Default(),
                DepthStencilFormat = SharpDX.DXGI.Format.D32_Float,
                DepthStencilState = DepthStencilStateDescription.Default(),
                SampleMask = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount = 1,
                Flags = PipelineStateFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                StreamOutput = new StreamOutputDescription()

            };
            psoDesc.DepthStencilState.IsDepthEnabled = false;
            psoDesc.RenderTargetFormats[0] = SharpDX.DXGI.Format.R8G8B8A8_UNorm;
            pipelineState = device.CreateGraphicsPipelineState(psoDesc);
        }
Example #18
0
        private void SetRasterizerState()
        {
            rasterizerState = new RasterizerState(device, RasterizerStateDescription.Default());
            var desc = rasterizerState.Description;

            desc.CullMode   = CullMode.None;
            rasterizerState = new RasterizerState(device, desc);
            deviceContext.Rasterizer.State = rasterizerState;
        }
Example #19
0
        /// <summary>
        /// Set current rasterizer state to default
        /// </summary>
        public void SetDefaultRasterState()
        {
            Utilities.Dispose(ref _rasterState);
            //Rasterize state
            RasterizerStateDescription rasterDescription = RasterizerStateDescription.Default();

            _rasterState = new RasterizerState(Device, rasterDescription);
            DeviceContext.Rasterizer.State = _rasterState;
        }
        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);
        }
Example #21
0
        /// <summary>
        /// Set current rasterizer state to wireframe
        /// </summary>
        public void SetWireframeRasterState()
        {
            _rasterState.Dispose();
            //Rasterize state
            RasterizerStateDescription rasterDescription = RasterizerStateDescription.Default();

            rasterDescription.FillMode = FillMode.Wireframe;
            _rasterState = new RasterizerState(Device, rasterDescription);

            DeviceContext.Rasterizer.State = _rasterState;
        }
Example #22
0
        internal static RasterizerState New(GraphicsDevice device, string name, CullMode mode)
        {
            var description = RasterizerStateDescription.Default();

            description.CullMode = mode;

            var state = New(device, description);

            state.Name = name;
            return(state);
        }
Example #23
0
        public SimpleRenderTask(RenderTargetGroup rt)
        {
            renderTarget = rt;

            vShader = Renderer.Instance.Shaders.LoadVertexShader("assets/shader/simple.hlsl", "VSMain");
            pShader = Renderer.Instance.Shaders.LoadPixelShader("assets/shader/simple.hlsl", "PSMain");

            var rasterizerStateDescription = RasterizerStateDescription.Default();

            rasterizerStateDescription.CullMode = CullMode.Back;
            rasterizerState = new RasterizerState(Renderer.Dev, rasterizerStateDescription);
        }
Example #24
0
        private RasterizerState CreateRasterizerState(bool isDepthEnabled, bool isScissorEnabled, bool isMultiSampleEnabled, bool isAntialiasedLineEnabled)
        {
            var rasterizerDescription = RasterizerStateDescription.Default();

            rasterizerDescription.CullMode                 = CullMode.ToSharpDX();
            rasterizerDescription.FillMode                 = FillMode.ToSharpDX();
            rasterizerDescription.IsDepthClipEnabled       = isDepthEnabled;
            rasterizerDescription.IsScissorEnabled         = isScissorEnabled;
            rasterizerDescription.IsMultisampleEnabled     = isMultiSampleEnabled;
            rasterizerDescription.IsAntialiasedLineEnabled = isAntialiasedLineEnabled;
            return(new RasterizerState(_graphicsDevice, rasterizerDescription));
        }
Example #25
0
        /// <summary>
        /// Whether to render solid or wireframe
        /// </summary>
        void SetRasterState(bool isWireframe = false)
        {
            // Dispose of old variable
            Utilities.Dispose(ref rasterState);

            RasterizerStateDescription description = RasterizerStateDescription.Default();

            description.FillMode             = isWireframe ? FillMode.Wireframe : FillMode.Solid;
            description.IsMultisampleEnabled = true;

            rasterState = new RasterizerState(device, description);
        }
Example #26
0
        internal static RasterizerState New(DirectXDevice device, string name, CullMode mode)
        {
            var description = RasterizerStateDescription.Default();

            description.CullMode = mode;
            description.IsFrontCounterClockwise = true;

            var state = New(device, description);

            state.Name = name;
            return(state);
        }
Example #27
0
        private void PlatformCreateShaders()
        {
            var inputElementDescs = new[]
            {
                new InputElement("POSITION", 0, Format.R32G32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.B8G8R8A8_UNorm, 8, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 8 + 4, 0)
            };

            var psoDesc = new GraphicsPipelineStateDescription()
            {
                InputLayout        = new InputLayoutDescription(inputElementDescs),
                RootSignature      = graphicsHost.RootSignature,
                VertexShader       = DXHelper.CompileShader(vertexShaderSource, "main", "vs_5_0"),
                PixelShader        = DXHelper.CompileShader(pixelShaderSource, "main", "ps_5_0"),
                RasterizerState    = RasterizerStateDescription.Default(),
                BlendState         = BlendStateDescription.Default(),
                DepthStencilFormat = SharpDX.DXGI.Format.D32_Float,
                DepthStencilState  = new DepthStencilStateDescription()
                {
                    IsDepthEnabled = false, IsStencilEnabled = false
                },
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                Flags             = PipelineStateFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                StreamOutput      = new StreamOutputDescription()
            };

            psoDesc.RenderTargetFormats[0] = SharpDX.DXGI.Format.R8G8B8A8_UNorm;

            pipelineState = graphicsHost.Device.CreateGraphicsPipelineState(psoDesc);

            // TODO: Move buffer
            var constantBufferDesc = ResourceDescription.Buffer(1024 * 64);

            constantBuffer      = graphicsHost.Device.CreateCommittedResource(new HeapProperties(HeapType.Upload), HeapFlags.None, constantBufferDesc, ResourceStates.GenericRead);
            constantBuffer.Name = "[SpriteRenderer] Constant Buffer";

            var cbvDesc = new ConstantBufferViewDescription()
            {
                BufferLocation = constantBuffer.GPUVirtualAddress,
                SizeInBytes    = (SharpDX.Utilities.SizeOf <ConstantBuffer>() + 255) & ~255,
            };

            graphicsHost.Device.CreateConstantBufferView(cbvDesc, graphicsHost.CBVHeap.CPUDescriptorHandleForHeapStart);

            mappedConstantBuffer = constantBuffer.Map(0);
            SharpDX.Utilities.Write(mappedConstantBuffer, ref constantBufferData);
        }
Example #28
0
        public void LoadShaders(string path)
        {
            BuildDescriptorHeaps();
            BuildConstantBuffers <Simple2DConst>();
            if (RootMake == null)
            {
                BuildRootSignature();
                Root = _rootSignature;
            }

            else
            {
                RootMake?.Invoke();
            }



            VertexCode = LoadVertex(path);
            FragCode   = LoadFrag(path);
            SetupShader();

            var psoDesc = new GraphicsPipelineStateDescription()
            {
                InputLayout        = new InputLayoutDescription(Input),
                RootSignature      = Root,
                VertexShader       = VertexCode,
                PixelShader        = FragCode,
                RasterizerState    = RasterizerStateDescription.Default(),
                BlendState         = BlendStateDescription.Default(),
                DepthStencilFormat = SharpDX.DXGI.Format.D32_Float,
                DepthStencilState  = new DepthStencilStateDescription()
                {
                    IsDepthEnabled = false, IsStencilEnabled = false
                },
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                Flags             = PipelineStateFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                StreamOutput      = new StreamOutputDescription()
            };


            psoDesc.RenderTargetFormats[0] = SharpDX.DXGI.Format.R8G8B8A8_UNorm;
            //psoDesc.

            pipelineState = DXGlobal.device.CreateGraphicsPipelineState(psoDesc);
            _pip          = pipelineState;
            // commandList = DXGlobal.device.CreateCommandList(CommandListType.Direct, DXGlobal.Display.DirectCmdListAlloc, pipelineState);
        }
Example #29
0
    public NormalMapRenderer(Device device, ShaderCache shaderCache,
                             Vector3[] hdNormals, Vector3[] ldNormals, Quad[] faces,
                             Vector2[] uvs, Vector3[] ldTangents, Quad[] uvFaces, int[] surfaceMap)
    {
        this.device     = device;
        this.hdNormals  = hdNormals;
        this.ldNormals  = ldNormals;
        this.faces      = faces;
        this.uvs        = uvs;
        this.ldTangents = ldTangents;
        this.uvFaces    = uvFaces;
        this.surfaceMap = surfaceMap;

        var vertexShaderAndByteCode = shaderCache.GetVertexShader <NormalMapRenderer>("morphing/hd/NormalMapRenderer");

        inputLayout  = new InputLayout(device, vertexShaderAndByteCode.Bytecode, InputElements);
        vertexShader = vertexShaderAndByteCode.Shader;
        pixelShader  = shaderCache.GetPixelShader <NormalMapRenderer>("morphing/hd/NormalMapRenderer");

        var rasterizerStateDesc = RasterizerStateDescription.Default();

        rasterizerStateDesc.CullMode = CullMode.None;
        rasterizerState = new RasterizerState(device, rasterizerStateDesc);

        var textureDesc = new Texture2DDescription {
            Width             = 4096,
            Height            = 4096,
            MipLevels         = 1,
            ArraySize         = 1,
            Format            = Format.B8G8R8A8_UNorm,
            SampleDescription = new SampleDescription(8, 0),
            BindFlags         = BindFlags.RenderTarget
        };

        texture           = new Texture2D(device, textureDesc);
        textureTargetView = new RenderTargetView(device, texture);

        var resolveTextureDesc = textureDesc;

        resolveTextureDesc.SampleDescription = new SampleDescription(1, 0);
        resolveTexture = new Texture2D(device, resolveTextureDesc);

        var stagingTextureDesc = resolveTextureDesc;

        stagingTextureDesc.BindFlags      = BindFlags.None;
        stagingTextureDesc.Usage          = ResourceUsage.Staging;
        stagingTextureDesc.CpuAccessFlags = CpuAccessFlags.Read;
        stagingTexture = new Texture2D(device, stagingTextureDesc);
    }
Example #30
0
        private void Init()
        {
            vsRender = Renderer.ShaderLoader.LoadVertexShader("assets/shader/deferredRender.hlsl", "VSMain");
            psRender = Renderer.ShaderLoader.LoadPixelShader("assets/shader/deferredRender.hlsl", "PSMain");

            var rasterizerStateDescription = RasterizerStateDescription.Default();

            rasterizerStateDescription.CullMode = CullMode.Back;
            rasterizerStateDescription.FillMode = FillMode.Solid;
            rasterizerState = new RasterizerState(Renderer.Dev, rasterizerStateDescription);

            clearRenderTask   = new ClearRenderTask(renderTargets);
            lightRenderTask   = new LightRenderTask(renderTargets.RenderTargets[3], renderTargets.RenderTargets[1], renderTargets.RenderTargets[2]);
            combineRenderTask = new CombineRenderTask(renderTargets.RenderTargets[4], renderTargets.RenderTargets[0], renderTargets.RenderTargets[3]);
            fxaaRenderTask    = new PostProcessFXAA(swapChain.RenderTarget.RenderTargets[0], renderTargets.RenderTargets[4]);
        }