コード例 #1
0
		internal DepthStencilState(Device device, DepthStencilStateDescription description)
			: base(device)
		{
			_description = description;
		    _isDepthEnabled = description.IsDepthEnabled;
		    _depthComparison = description.DepthComparison;
		}
コード例 #2
0
 public void SetDefaultDepthStencil()
 {
     this.DepthStencil = new DepthStencilStateDescription()
     {
         DepthComparison = Comparison.LessEqual,
         DepthWriteMask = DepthWriteMask.All,
         IsDepthEnabled = true,
         IsStencilEnabled = false,
         StencilReadMask = 0xFF,
         StencilWriteMask = 0xFF
     };
 }
コード例 #3
0
        public override void GenerateShadowMaps(Device device, DeviceContext deviceContext, CRenderScene renderScene)
        {
            UserDefinedAnnotation annotation = deviceContext.QueryInterface <UserDefinedAnnotation>();

            annotation.BeginEvent("PointLightShadowMap");

            deviceContext.Rasterizer.SetViewport(0.0f, 0.0f, CStaticRendererCvars.ShadowMapSize, CStaticRendererCvars.ShadowMapSize);

            deviceContext.ClearDepthStencilView(ShadowMapTexture.GetRenderTarget(), DepthStencilClearFlags.Depth, 1.0f, 0);
            deviceContext.OutputMerger.SetRenderTargets(ShadowMapTexture.GetRenderTarget());

            DepthStencilStateDescription depthStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled  = true,
                DepthWriteMask  = DepthWriteMask.All,
                DepthComparison = Comparison.Less,

                IsStencilEnabled = false,
                StencilReadMask  = 0xFF,
                StencilWriteMask = 0xFF,
            };

            DepthStencilState depthState = new DepthStencilState(device, depthStateDesc);

            deviceContext.OutputMerger.SetDepthStencilState(depthState);

            SSceneViewInfo viewInfo = new SSceneViewInfo()
            {
                FitProjectionToScene = false,
                Fov          = MathUtil.Pi / 2.0f,
                ScreenFar    = Range,
                ScreenNear   = 0.1f,
                ScreenHeight = CStaticRendererCvars.ShadowMapSize,
                ScreenWidth  = CStaticRendererCvars.ShadowMapSize,
                ScreenLeft   = 0.0f,
                ScreenTop    = 0.0f,
                ViewLocation = Transform.WorldPosition
            };

            viewInfo.ProjectionMatrix = Matrix.PerspectiveFovLH(viewInfo.Fov, 1.0f, viewInfo.ScreenNear, viewInfo.ScreenFar);

            depthState.Dispose();
            renderScene.RenderSceneDepthCube(deviceContext, in viewInfo);

            DepthStencilView nullDepthView = null;

            deviceContext.OutputMerger.SetRenderTargets(nullDepthView);

            annotation.EndEvent();
            annotation.Dispose();
        }
コード例 #4
0
        // Define how the depth buffer will be used to filter out objects, based on their distance from the viewer.
        void DefineDepthStencilState()
        {
            var desc = DepthStencilStateDescription.Default();

            // NoDepthWriteState

            /*
             * desc.IsDepthEnabled = true;
             * desc.DepthWriteMask = DepthWriteMask.Zero;
             */
            desc.DepthComparison = Comparison.LessEqual;

            default_depth_stencil_state = new DepthStencilState(device, desc);
        }
コード例 #5
0
        public CompressToSwap(Device device, ShaderCache cache, float gamma = 2.2f)
        {
            Gamma                  = gamma;
            constants              = new ConstantsBuffer <float>(device, debugName: "CompressToSwap Constants");
            vertexShader           = new VertexShader(device, cache.GetShader(@"PostProcessing\CompressToSwap.hlsl.vshader"));
            vertexShader.DebugName = "CompressToSwapVS";
            pixelShader            = new PixelShader(device, cache.GetShader(@"PostProcessing\CompressToSwap.hlsl.pshader"));
            pixelShader.DebugName  = "CompressToSwapPS";
            var depthStateDescription = DepthStencilStateDescription.Default();

            depthStateDescription.DepthWriteMask = DepthWriteMask.Zero;
            depthStateDescription.IsDepthEnabled = false;
            depthState = new DepthStencilState(device, depthStateDescription);
        }
コード例 #6
0
ファイル: GraphicsCore.cs プロジェクト: Hiroky/CSharpRenderer
        /// <summary>
        /// デプスステンシルステート
        /// </summary>
        static void InitializeDepthStencilState()
        {
            var device = D3D11Device;

            depthStencilState_ = new DepthStencilState[(int)RenderState.DepthState.Max];

            // None
            DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = false,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.Zero,
                DepthComparison  = Comparison.Less,
            };

            depthStencilState_[(int)RenderState.DepthState.None] = DepthStencilState.FromDescription(device, dsStateDesc);

            // Normal
            dsStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = true,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Less,
            };
            depthStencilState_[(int)RenderState.DepthState.Normal] = DepthStencilState.FromDescription(device, dsStateDesc);

            // TestOnly
            dsStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = true,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.Zero,
                DepthComparison  = Comparison.Less,
            };
            depthStencilState_[(int)RenderState.DepthState.TestOnly] = DepthStencilState.FromDescription(device, dsStateDesc);

            // WriteOnly
            dsStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = false,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.Zero,
                DepthComparison  = Comparison.Less,
            };
            depthStencilState_[(int)RenderState.DepthState.WriteOnly] = DepthStencilState.FromDescription(device, dsStateDesc);

            // 初期値
            SetDepthState(RenderState.DepthState.Normal);
        }
コード例 #7
0
        public EffectPipelineState(
            RasterizerStateDescription rasterizerState,
            DepthStencilStateDescription depthStencilState,
            BlendStateDescription blendState,
            OutputDescription outputDescription)
        {
            RasterizerState   = rasterizerState;
            DepthStencilState = depthStencilState;
            BlendState        = blendState;

            OutputDescription = outputDescription;

            Handle = null;
            Handle = EffectPipelineStateFactory.GetHandle(this);
        }
コード例 #8
0
ファイル: GlobalRenderer.cs プロジェクト: 67-6f-64/HelloWorld
        private void Setup3dCamera(float partialStep)
        {
            Camera.Instance.Enable3d = true;
            DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = true,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Less,
            };
            DepthStencilState depthState = DepthStencilState.FromDescription(device, dsStateDesc);

            device.ImmediateContext.OutputMerger.DepthStencilState = depthState;
            Camera.Instance.Update(partialStep);
        }
コード例 #9
0
        public LeaDepthStencilState(NativeDevice nativeDevice, bool isDepthTestingEnable)
        {
            var depthStencilStateDesc = new DepthStencilStateDescription
            {
                IsDepthEnabled   = isDepthTestingEnable,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Less,
                IsStencilEnabled = false,
                StencilWriteMask = 0xff,
                StencilReadMask  = 0xff
            };


            depthStencilState = new DepthStencilState(nativeDevice.D3D11Device, depthStencilStateDesc);
        }
コード例 #10
0
        /// <summary>
        /// Creates a No depth, no stencil state
        /// </summary>
        /// <param name="graphics">Graphics</param>
        /// <returns>Creates the No depth, no stencil state</returns>
        public static EngineDepthStencilState None(Graphics graphics)
        {
            var desc = new DepthStencilStateDescription()
            {
                IsDepthEnabled  = false,
                DepthWriteMask  = DepthWriteMask.Zero,
                DepthComparison = Comparison.Never,

                IsStencilEnabled = false,
                StencilReadMask  = 0xFF,
                StencilWriteMask = 0xFF,
            };

            return(graphics.CreateDepthStencilState(desc, 0));
        }
コード例 #11
0
        internal static DepthStencilId CreateDepthStencil(DepthStencilStateDescription description)
        {
            var id = new DepthStencilId {
                Index = DepthStencilStates.Allocate()
            };

            MyArrayHelpers.Reserve(ref DepthStencilObjects, id.Index + 1);

            DepthStencilStates.Data[id.Index] = description;

            InitDepthStencilState(id);
            DepthStencilIndices.Add(id);

            return(id);
        }
コード例 #12
0
        public D3DDepthStencilState(Device device, bool isDepthEnabled, DepthComparison comparison, bool isDepthWriteEnabled)
        {
            _device             = device;
            IsDepthEnabled      = IsDepthEnabled;
            IsDepthWriteEnabled = isDepthWriteEnabled;
            DepthComparison     = comparison;

            DepthStencilStateDescription desc = DepthStencilStateDescription.Default();

            desc.DepthComparison = D3DFormats.ConvertDepthComparison(comparison);
            desc.IsDepthEnabled  = isDepthEnabled;
            desc.DepthWriteMask  = isDepthWriteEnabled ? DepthWriteMask.All : DepthWriteMask.Zero;

            _deviceState = new SharpDX.Direct3D11.DepthStencilState(device, desc);
        }
コード例 #13
0
        public static void CreateDepthStencil(ref DepthStencilId id, DepthStencilStateDescription description)
        {
            if (id == DepthStencilId.NULL)
            {
                id = new DepthStencilId(DepthStencilStates.Allocate());
                MyArrayHelpers.Reserve(ref DepthStencilObjects, id.Index + 1);
                DepthStencilIndices.Add(id);
            }
            else
            {
                DepthStencilObjects[id.Index].Dispose();
            }

            DepthStencilStates.Data[id.Index] = description;
            InitDepthStencilState(id);
        }
コード例 #14
0
        private DepthStencilState CreateNewDepthStencilState(ref DepthStencilStateDescription description)
        {
            SharpDX.Direct3D11.DepthStencilStateDescription dssDesc = new SharpDX.Direct3D11.DepthStencilStateDescription
            {
                DepthComparison  = D3D11Formats.VdToD3D11Comparison(description.DepthComparison),
                IsDepthEnabled   = description.DepthTestEnabled,
                DepthWriteMask   = description.DepthWriteEnabled ? DepthWriteMask.All : DepthWriteMask.Zero,
                IsStencilEnabled = description.StencilTestEnabled,
                FrontFace        = ToD3D11StencilOpDesc(description.StencilFront),
                BackFace         = ToD3D11StencilOpDesc(description.StencilBack),
                StencilReadMask  = description.StencilReadMask,
                StencilWriteMask = description.StencilWriteMask
            };

            return(new DepthStencilState(_device, dssDesc));
        }
コード例 #15
0
        private ID3D11DepthStencilState CreateNewDepthStencilState(ref DepthStencilStateDescription description)
        {
            DepthStencilDescription dssDesc = new DepthStencilDescription
            {
                DepthFunc        = D3D11Formats.VdToD3D11ComparisonFunc(description.DepthComparison),
                DepthEnable      = description.DepthTestEnabled,
                DepthWriteMask   = description.DepthWriteEnabled ? DepthWriteMask.All : DepthWriteMask.Zero,
                StencilEnable    = description.StencilTestEnabled,
                FrontFace        = ToD3D11StencilOpDesc(description.StencilFront),
                BackFace         = ToD3D11StencilOpDesc(description.StencilBack),
                StencilReadMask  = description.StencilReadMask,
                StencilWriteMask = description.StencilWriteMask
            };

            return(_device.CreateDepthStencilState(dssDesc));
        }
コード例 #16
0
        public static void Initialize(Device device)
        {
            {
                var blendStateDescription = new BlendStateDescription();
                blendStateDescription.RenderTargets[0].BlendEnable           = false;
                blendStateDescription.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                blendStateDescription.RenderTargets[1].BlendEnable           = false;
                blendStateDescription.RenderTargets[1].RenderTargetWriteMask = ColorWriteMaskFlags.None;
                blendStateDescription.RenderTargets[2].BlendEnable           = false;
                blendStateDescription.RenderTargets[2].RenderTargetWriteMask = ColorWriteMaskFlags.None;
                blendStateDescription.RenderTargets[3].BlendEnable           = false;
                blendStateDescription.RenderTargets[3].RenderTargetWriteMask = ColorWriteMaskFlags.None;

                m_BlendStates[(int)BlendType.None] = BlendState.FromDescription(device, blendStateDescription);

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

                m_BlendStates[(int)BlendType.Additive] = BlendState.FromDescription(device, blendStateDescription);
            }

            {
                var depthStencilStateDescription = new DepthStencilStateDescription();
                depthStencilStateDescription.DepthComparison  = Comparison.Always;
                depthStencilStateDescription.DepthWriteMask   = DepthWriteMask.Zero;
                depthStencilStateDescription.IsDepthEnabled   = false;
                depthStencilStateDescription.IsStencilEnabled = false;

                m_DepthStencilStates[(int)DepthConfigurationType.NoDepth] = DepthStencilState.FromDescription(device, depthStencilStateDescription);

                depthStencilStateDescription.DepthComparison = Comparison.LessEqual;
                depthStencilStateDescription.DepthWriteMask  = DepthWriteMask.All;
                depthStencilStateDescription.IsDepthEnabled  = true;

                m_DepthStencilStates[(int)DepthConfigurationType.DepthWriteCompare] = DepthStencilState.FromDescription(device, depthStencilStateDescription);

                depthStencilStateDescription.DepthWriteMask = DepthWriteMask.Zero;

                m_DepthStencilStates[(int)DepthConfigurationType.DepthCompare] = DepthStencilState.FromDescription(device, depthStencilStateDescription);
            }
        }
コード例 #17
0
        private void CreateDepthStencilState()
        {
            DepthStencilStateDescription depthDescription = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = false,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Always,
                IsStencilEnabled = false
            };

            depthDescription.FrontFace.FailOperation      = StencilOperation.Keep;
            depthDescription.FrontFace.PassOperation      = StencilOperation.Keep;
            depthDescription.FrontFace.DepthFailOperation = StencilOperation.Keep;
            depthDescription.BackFace = depthDescription.FrontFace;

            m_depthStencilState = new DepthStencilState(m_d3Device, depthDescription);
        }
コード例 #18
0
        private void CreateDefaultRenderStates()
        {
            var blendStateDesc = new BlendStateDescription();

            blendStateDesc.IsAlphaToCoverageEnabled = false;
            blendStateDesc.BlendOperation           = BlendOperation.Add;
            blendStateDesc.AlphaBlendOperation      = BlendOperation.Add;
            blendStateDesc.SourceBlend           = BlendOption.One;
            blendStateDesc.DestinationBlend      = BlendOption.Zero;
            blendStateDesc.SourceAlphaBlend      = BlendOption.One;
            blendStateDesc.DestinationAlphaBlend = BlendOption.Zero;
            defaultBlendState = BlendState.FromDescription(device, blendStateDesc);

            var rasterizerStateDesc = new RasterizerStateDescription();

            rasterizerStateDesc.FillMode = FillMode.Solid;
            rasterizerStateDesc.CullMode = CullMode.Back;
            rasterizerStateDesc.IsFrontCounterclockwise = false;
            rasterizerStateDesc.DepthBias                = 0;
            rasterizerStateDesc.DepthBiasClamp           = 0;
            rasterizerStateDesc.SlopeScaledDepthBias     = 0;
            rasterizerStateDesc.IsDepthClipEnabled       = true;
            rasterizerStateDesc.IsScissorEnabled         = false;
            rasterizerStateDesc.IsMultisampleEnabled     = false;
            rasterizerStateDesc.IsAntialiasedLineEnabled = false;
            defaultRasterizerState = RasterizerState.FromDescription(device, rasterizerStateDesc);

            var depthStencilStateDesc = new DepthStencilStateDescription();

            depthStencilStateDesc.IsDepthEnabled   = true;
            depthStencilStateDesc.DepthWriteMask   = DepthWriteMask.All;
            depthStencilStateDesc.DepthComparison  = Comparison.LessEqual;
            depthStencilStateDesc.IsStencilEnabled = false;
            depthStencilStateDesc.StencilReadMask  = 0xff;
            depthStencilStateDesc.StencilWriteMask = 0xff;
            var depthStencilStateFaceDesk = new DepthStencilOperationDescription();

            depthStencilStateFaceDesk.Comparison         = Comparison.Always;
            depthStencilStateFaceDesk.DepthFailOperation = StencilOperation.Keep;
            depthStencilStateFaceDesk.FailOperation      = StencilOperation.Keep;
            depthStencilStateFaceDesk.PassOperation      = StencilOperation.Keep;
            depthStencilStateDesc.FrontFace = depthStencilStateFaceDesk;
            depthStencilStateDesc.BackFace  = depthStencilStateFaceDesk;
            defaultDepthStencilState        = DepthStencilState.FromDescription(device, depthStencilStateDesc);
        }
コード例 #19
0
        /// <summary>
        /// Конструктор
        /// </summary>
        /// <param name="dvContext">Контекст видеокарты</param>
        public DX11Drawer(DeviceContext dvContext)
        {
            _dx11DeviceContext = dvContext;
            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;
        }
コード例 #20
0
        protected override void OnResourceLoad()
        {
            CreatePrimaryRenderTarget();
            CreateDepthBuffer();

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

            var solidParentOp = new BlendStateDescription();

            solidParentOp.SetBlendEnable(0, false);
            solidParentOp.SetWriteMask(0, ColorWriteMaskFlags.All);

            var transParentOp = new BlendStateDescription {
                AlphaBlendOperation      = BlendOperation.Add,
                BlendOperation           = BlendOperation.Add,
                DestinationAlphaBlend    = BlendOption.Zero,
                DestinationBlend         = BlendOption.One,
                IsAlphaToCoverageEnabled = false,
                SourceAlphaBlend         = BlendOption.Zero,
                SourceBlend = BlendOption.One,
            };

            transParentOp.SetBlendEnable(0, true);
            transParentOp.SetWriteMask(0, ColorWriteMaskFlags.All);

            transBlendState = BlendState.FromDescription(Context10.Device, transParentOp);
            solidBlendState = BlendState.FromDescription(Context10.Device, solidParentOp);

            depthStencilState = DepthStencilState.FromDescription(Context10.Device, dssd);

            jupiterMesh = new SimpleModel(Context10.Device, "SimpleModel10.fx", "jupiter.SMD", "jupiter.jpg");

            view = Matrix.LookAtLH(new Vector3(0, 160, 0), new Vector3(0, -128.0f, 0), -Vector3.UnitZ);
            jupiterMesh.Effect.GetVariableByName("view").AsMatrix().SetMatrix(view);

            proj = Matrix.PerspectiveFovLH(45.0f, WindowWidth / (float)WindowHeight, 1.0f, 1000.0f);
            jupiterMesh.Effect.GetVariableByName("proj").AsMatrix().SetMatrix(proj);
        }
コード例 #21
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 sky.
            //

            GraphicsPipelineStateDescription skyPsoDesc = opaquePsoDesc.Copy();

            // The camera is inside the sky sphere, so just turn off culling.
            skyPsoDesc.RasterizerState.CullMode = CullMode.None;
            // Make sure the depth function is LESS_EQUAL and not just LESS.
            // Otherwise, the normalized depth values at z = 1 (NDC) will
            // fail the depth test if the depth buffer was cleared to 1.
            skyPsoDesc.DepthStencilState.DepthComparison = Comparison.LessEqual;
            skyPsoDesc.RootSignature = _rootSignature;
            skyPsoDesc.VertexShader  = _shaders["skyVS"];
            skyPsoDesc.PixelShader   = _shaders["skyPS"];
            _psos["sky"]             = Device.CreateGraphicsPipelineState(skyPsoDesc);
        }
コード例 #22
0
        /// <summary>
        /// Creates a default <see cref="DepthStencilState"/> object.
        /// </summary>
        /// <param name="device">The current <see cref="Device"/> being used.</param>
        /// <returns>The newly created <see cref="DepthStencilState"/> with the default options.</returns>
        public static DepthStencilState CreateDepthStencilState(Device device)
        {
            DepthStencilOperationDescription dsOperation = new DepthStencilOperationDescription();

            dsOperation.Comparison         = Comparison.Less;
            dsOperation.DepthFailOperation = StencilOperation.Keep;
            dsOperation.FailOperation      = StencilOperation.Keep;
            dsOperation.PassOperation      = StencilOperation.Replace;

            DepthStencilStateDescription dsDesc = new DepthStencilStateDescription();

            dsDesc.BackFace         = dsOperation;
            dsDesc.DepthComparison  = Comparison.Less;
            dsDesc.DepthWriteMask   = DepthWriteMask.All;
            dsDesc.FrontFace        = dsOperation;
            dsDesc.IsDepthEnabled   = true;
            dsDesc.IsStencilEnabled = false;

            return(DepthStencilState.FromDescription(device, dsDesc));
        }
コード例 #23
0
        private static GraphicsPipelineStateDescription BuildGraphicsPipelineStateDescription(RootSignature rootSignature, int msaaCount, int msaaQuality, Format depthStencilFormat)
        {
            var inputLayout = BuildInputLayout();

            return(new GraphicsPipelineStateDescription
            {
                InputLayout = inputLayout,
                RootSignature = rootSignature,
                VertexShader = ShaderHelper.CompileShader("Shaders\\Color.hlsl", "VS", "vs_5_0"),
                PixelShader = ShaderHelper.CompileShader("Shaders\\Color.hlsl", "PS", "ps_5_0"),
                RasterizerState = RasterizerStateDescription.Default(),
                BlendState = BlendStateDescription.Default(),
                DepthStencilState = DepthStencilStateDescription.Default(),
                SampleMask = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount = 1,
                SampleDescription = new SampleDescription(msaaCount, msaaQuality),
                DepthStencilFormat = depthStencilFormat
            });
        }
コード例 #24
0
 public void GetPipelineResources(
     ref BlendStateDescription blendDesc,
     ref DepthStencilStateDescription dssDesc,
     ref RasterizerStateDescription rasterDesc,
     bool multisample,
     VertexLayoutDescription[] vertexLayouts,
     byte[] vsBytecode,
     out BlendState blendState,
     out DepthStencilState depthState,
     out RasterizerState rasterState,
     out InputLayout inputLayout)
 {
     lock (_lock)
     {
         blendState  = GetBlendState(ref blendDesc);
         depthState  = GetDepthStencilState(ref dssDesc);
         rasterState = GetRasterizerState(ref rasterDesc, multisample);
         inputLayout = GetInputLayout(vertexLayouts, vsBytecode);
     }
 }
コード例 #25
0
        private void Update(EvaluationContext context)
        {
            DepthState.Value?.Dispose();

            try
            {
                var depthStencilStateDescription = new DepthStencilStateDescription()
                {
                    IsDepthEnabled  = EnableZTest.GetValue(context),
                    DepthWriteMask  = EnableZWrite.GetValue(context) ?  DepthWriteMask.All : DepthWriteMask.Zero,
                    DepthComparison = Comparison.GetValue(context),
                };

                DepthState.Value = new DepthStencilState(ResourceManager.Instance().Device, depthStencilStateDescription);
            }
            catch (SharpDXException e)
            {
                Log.Error("Failed to create DepthStencilState " + e.Message);
            }
        }
コード例 #26
0
ファイル: SimpleModel10Sample.cs プロジェクト: zhandb/slimdx
        protected override void OnResourceLoad() {
            CreatePrimaryRenderTarget();
            CreateDepthBuffer();

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

            var solidParentOp = new BlendStateDescription();
            solidParentOp.SetBlendEnable( 0, false );
            solidParentOp.SetWriteMask( 0, ColorWriteMaskFlags.All );

            var transParentOp = new BlendStateDescription {
                AlphaBlendOperation = BlendOperation.Add,
                BlendOperation = BlendOperation.Add,
                DestinationAlphaBlend = BlendOption.Zero,
                DestinationBlend = BlendOption.One,
                IsAlphaToCoverageEnabled = false,
                SourceAlphaBlend = BlendOption.Zero,
                SourceBlend = BlendOption.One,
            };

            transParentOp.SetBlendEnable( 0, true );
            transParentOp.SetWriteMask( 0, ColorWriteMaskFlags.All );

            transBlendState = BlendState.FromDescription( Context10.Device, transParentOp );
            solidBlendState = BlendState.FromDescription( Context10.Device, solidParentOp );

            depthStencilState = DepthStencilState.FromDescription( Context10.Device, dssd );

            jupiterMesh = new SimpleModel( Context10.Device, "SimpleModel10.fx", "jupiter.SMD", "jupiter.jpg" );

            view = Matrix.LookAtLH( new Vector3( 0, 160, 0 ), new Vector3( 0, -128.0f, 0 ), -Vector3.UnitZ );
            jupiterMesh.Effect.GetVariableByName( "view" ).AsMatrix().SetMatrix( view );

            proj = Matrix.PerspectiveFovLH( 45.0f, WindowWidth / (float)WindowHeight, 1.0f, 1000.0f );
            jupiterMesh.Effect.GetVariableByName( "proj" ).AsMatrix().SetMatrix( proj );
        }
コード例 #27
0
        private D3DRenderFlow()
        {
            tempVertexShader = VertexShaders.Instance.GetShaderIndex("test_vs");
            var vertexShaderBytecode = VertexShaders.Instance.GetByteCode(tempVertexShader);

            tempPixelShader = PixelShaders.Instance.GetShaderIndex("test_ps");
            tempInputLayout = new InputLayout(
                D3DSystem.Instance.Deivce,
                ShaderSignature.GetInputSignature(vertexShaderBytecode),
                new InputElement[] {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float, 0, 0),
                new InputElement("NORMAL", 0, SharpDX.DXGI.Format.R16G16B16A16_Float, 12, 0),
            });
            DepthStencilStateDescription depthStencilStateDescription = new DepthStencilStateDescription();

            depthStencilStateDescription.IsDepthEnabled   = true;
            depthStencilStateDescription.IsStencilEnabled = false;
            depthStencilStateDescription.DepthComparison  = Comparison.Less;
            depthStencilStateDescription.DepthWriteMask   = DepthWriteMask.All;
            depthState = new DepthStencilState(D3DSystem.Instance.Deivce, depthStencilStateDescription);
        }
コード例 #28
0
        //RasterizerStateDescription rasterizerStateDescription;
        //DepthStencilStateDescription depthStencilStateDescription;
        //BlendStateDescription blendStateDescription;

        public AminRenderTechniqueSystem()
            : base(new EntityHasSet(
                       typeof(D3DAnimRenderComponent),
                       typeof(CMOAnimateMeshComponent),
                       typeof(MeshAnimationComponent),
                       typeof(TransformComponent),
                       typeof(D3DTexturedMaterialSamplerComponent)))
        {
            rasterizerStateDescription = new RasterizerStateDescription()
            {
                FillMode = FillMode.Solid,
                CullMode = CullMode.Back,
            };
            depthStencilStateDescription = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = true, // enable depth?
                DepthComparison  = Comparison.Less,
                DepthWriteMask   = SharpDX.Direct3D11.DepthWriteMask.All,
                IsStencilEnabled = false, // enable stencil?
                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
                },
            };
            blendStateDescription = D3DBlendStateDescriptions.BlendStateDisabled;
        }
コード例 #29
0
        private static void InitializeDepthBuffer()
        {
            Format depthFormat = Format.D32_Float;

            depthBufferDesc = new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.DepthStencil,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = depthFormat,
                Height            = Form.Height,
                Width             = Form.Width,
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default
            };

            depthBuffer = new Texture2D(Device, depthBufferDesc);
            DepthView   = new DepthStencilView(Device, depthBuffer);

            dsStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = true,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Less,
            };
            dsStateDescOff = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = true,
                IsStencilEnabled = false,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparison  = Comparison.Less,
            };
            DepthStateOff = DepthStencilState.FromDescription(Device, dsStateDescOff);
            DepthState    = DepthStencilState.FromDescription(Device, dsStateDesc);

            DeviceContext.OutputMerger.DepthStencilState = DepthState;
        }
コード例 #30
0
        public void AddDepthStencil()
        {
            var depthBufferDescription = new Texture2DDescription {
                Format            = SharpDX.DXGI.Format.D32_Float_S8X24_UInt,
                ArraySize         = 1,
                MipLevels         = 1,
                Width             = Width,
                Height            = Height,
                SampleDescription = new SampleDescription(1, 0),
                BindFlags         = BindFlags.DepthStencil,
            };
            var depthStencilViewDescription = new DepthStencilViewDescription {
                Dimension = DepthStencilViewDimension.Texture2D
            };
            var depthStencilStateDescription = new DepthStencilStateDescription {
                IsDepthEnabled   = true,
                DepthComparison  = Comparison.Less,
                DepthWriteMask   = DepthWriteMask.All,
                IsStencilEnabled = false,
                StencilReadMask  = 0xff,
                StencilWriteMask = 0xff,
                FrontFace        = new DepthStencilOperationDescription {
                    Comparison         = Comparison.Always,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Increment
                },
                BackFace = new DepthStencilOperationDescription {
                    Comparison         = Comparison.Always,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Decrement
                }
            };

            using (var depthBuffer = new Texture2D(Renderer.Instance.Device, depthBufferDescription)) {
                DepthStencilState = new DepthStencilState(Renderer.Instance.Device, depthStencilStateDescription);
                DepthStencilView  = new DepthStencilView(Renderer.Instance.Device, depthBuffer, depthStencilViewDescription);
            }
        }
コード例 #31
0
        private static void MakeDepthEnabledState()
        {
            var depthDesc = new DepthStencilStateDescription
            {
                IsDepthEnabled   = true,
                DepthWriteMask   = DepthWriteMask.Zero,
                DepthComparison  = Comparison.LessEqual,
                IsStencilEnabled = false,
                StencilReadMask  = byte.MaxValue,
                StencilWriteMask = byte.MaxValue,
                FrontFace        =
                {
                    DepthFailOperation = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Replace,
                    Comparison         = Comparison.Always
                }
            };

            depthDesc.BackFace = depthDesc.FrontFace;
            DepthEnabled       = new DepthStencilState(Renderer.Device, depthDesc);
        }
コード例 #32
0
        private void CreateStencilGreater()
        {
            DepthStencilStateDescription ds = new DepthStencilStateDescription()
            {
                IsDepthEnabled   = false,
                IsStencilEnabled = true,
                DepthWriteMask   = DepthWriteMask.Zero,
                DepthComparison  = Comparison.Always,
                StencilReadMask  = 255,
                StencilWriteMask = 0,
                FrontFace        = new DepthStencilOperationDescription()
                {
                    Comparison         = Comparison.Greater,
                    DepthFailOperation = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Keep
                },
                BackFace = new DepthStencilOperationDescription()
                {
                    Comparison         = Comparison.Greater,
                    DepthFailOperation = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Keep
                }
            };

            this.StencilGreater = new DepthStencilState(device.Device, ds);

            ds.FrontFace.Comparison = Comparison.LessEqual;
            ds.BackFace.Comparison  = Comparison.LessEqual;

            this.StencilLessEqual = new DepthStencilState(device.Device, ds);

            this.AddState("StencilGreater", this.StencilGreater);

            ds.FrontFace.Comparison = Comparison.NotEqual;
            ds.BackFace.Comparison  = Comparison.NotEqual;
            this.StencilNotEqual    = new DepthStencilState(device.Device, ds);
        }
コード例 #33
0
        protected override void LoadContent()
        {
            base.LoadContent();

            // Create effects and geometric primitives
            Batch = new UIBatch(GraphicsDevice);

            // Create depth stencil states
            var depthStencilDescription = new DepthStencilStateDescription(depthEnable: true, depthWriteEnable: true)
            {
                StencilEnable = true,

                FrontFace = new DepthStencilStencilOpDescription
                {
                    StencilDepthBufferFail = StencilOperation.Keep,
                    StencilFail            = StencilOperation.Keep,
                    StencilPass            = StencilOperation.Keep,
                    StencilFunction        = CompareFunction.Equal
                },

                BackFace = new DepthStencilStencilOpDescription
                {
                    StencilDepthBufferFail = StencilOperation.Keep,
                    StencilFail            = StencilOperation.Keep,
                    StencilPass            = StencilOperation.Keep,
                    StencilFunction        = CompareFunction.Equal
                },
            };

            KeepStencilValueState = depthStencilDescription;

            depthStencilDescription.FrontFace.StencilPass = StencilOperation.Increment;
            depthStencilDescription.BackFace.StencilPass  = StencilOperation.Increment;
            IncreaseStencilValueState = depthStencilDescription;

            depthStencilDescription.FrontFace.StencilPass = StencilOperation.Decrement;
            depthStencilDescription.BackFace.StencilPass  = StencilOperation.Decrement;
            DecreaseStencilValueState = depthStencilDescription;
        }
コード例 #34
0
 public DepthStencilStateChangeCommand(DepthStencilStateDescription dStateDesc)
     : base(CommandType.DepthStencilStateChange)
 {
     CommandAttributes |= CommandAttributes.MonoRendering;
     Description = dStateDesc;
 }
コード例 #35
0
ファイル: GlobalRenderer.cs プロジェクト: samuto/HelloWorld
 private void Setup3dCamera(float partialStep)
 {
     Camera.Instance.Enable3d = true;
     DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
     {
         IsDepthEnabled = true,
         IsStencilEnabled = false,
         DepthWriteMask = DepthWriteMask.All,
         DepthComparison = Comparison.Less,
     };
     DepthStencilState depthState = DepthStencilState.FromDescription(device, dsStateDesc);
     device.ImmediateContext.OutputMerger.DepthStencilState = depthState;
     Camera.Instance.Update(partialStep);
 }
コード例 #36
0
ファイル: Window.cs プロジェクト: Christoph/ionfish
        private void CreateStencilState()
        {
            var depthStencilStateDescription = new DepthStencilStateDescription
            {
                IsDepthEnabled = true,
                IsStencilEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less
            };

            mDepthStencilState = DepthStencilState.FromDescription(Device, depthStencilStateDescription);
            Device.OutputMerger.DepthStencilState = mDepthStencilState;
        }
コード例 #37
0
        public TeapotScene(TeapotRenderer teapotRenderer)
        {
            // Create a description of the display mode
            ModeDescription modeDescription = new ModeDescription()
            {
                Format = Format.R8G8B8A8_UNorm,
                RefreshRate = new Rational(60, 1),
                
                Width = 512,
                Height = 512
            };

            // Create a description of the multisampler
            SampleDescription sampleDescription = new SampleDescription()
            {
                Count = 1,
                Quality = 0
            };

            // Create a description of the swap chain
            SwapChainDescription swapChainDescription = new SwapChainDescription()
            {
                ModeDescription = modeDescription,
                SampleDescription = sampleDescription,

                BufferCount = 1,
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput,

                IsWindowed = false
            };

            // Create a hardware accelarated rendering device
            renderingDevice = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport);

            // Create the shared texture
            Texture2DDescription colordesc = new Texture2DDescription();
            colordesc.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource;
            colordesc.Format = Format.B8G8R8A8_UNorm;
            colordesc.Width = 512;
            colordesc.Height = 512;
            colordesc.MipLevels = 1;
            colordesc.SampleDescription = new SampleDescription(1, 0);
            colordesc.Usage = ResourceUsage.Default;
            colordesc.OptionFlags = ResourceOptionFlags.Shared;
            colordesc.CpuAccessFlags = CpuAccessFlags.None;
            colordesc.ArraySize = 1;

            SharedTexture = new Texture2D(renderingDevice, colordesc);

            // Create the render target view
            renderTargetView = new RenderTargetView(renderingDevice, SharedTexture);

            // Creat the depth/stencil buffer
            DepthStencilStateDescription depthStencilStateDescription = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                IsStencilEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less,
            };

            depthStencilState = DepthStencilState.FromDescription(renderingDevice, depthStencilStateDescription);

            Texture2DDescription depthStencilTextureDescription = new Texture2DDescription()
            {
                Width = 512,
                Height = 512,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.D32_Float,
                SampleDescription = sampleDescription,
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None
            };

            DepthStencilViewDescription depthStencilViewDescription = new DepthStencilViewDescription()
            {
                Format = depthStencilTextureDescription.Format,
                Dimension = depthStencilTextureDescription.SampleDescription.Count > 1 ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D,
                MipSlice = 0
            };

            using (Texture2D depthStencilTexture = new Texture2D(renderingDevice, depthStencilTextureDescription))
            {
                depthStencilView = new DepthStencilView(renderingDevice, depthStencilTexture, depthStencilViewDescription);
            }

            // Setup the default output targets
            renderingDevice.ImmediateContext.OutputMerger.SetTargets(depthStencilView, renderTargetView);

            // Setup the viewport
            Viewport viewPort = new Viewport()
            {
                X = 0,
                Y = 0,
                Width = 512,
                Height = 512,
                MinZ = 0,
                MaxZ = 1
            };

            renderingDevice.ImmediateContext.Rasterizer.SetViewports(viewPort);

            // Create the teappot
            teapotObject = new TeapotObject(teapotRenderer, renderingDevice);

            // Create the camera
            camera = new ThirdPersonCamera(teapotObject);
            
        }
コード例 #38
0
        public static void CreateDepthStencil(ref DepthStencilId id, DepthStencilStateDescription description)
        {
            if (id == DepthStencilId.NULL)
            {
                id = new DepthStencilId(DepthStencilStates.Allocate());
                MyArrayHelpers.Reserve(ref DepthStencilObjects, id.Index + 1);
                DepthStencilIndices.Add(id);
            }
            else
            {
                DepthStencilObjects[id.Index].Dispose();
            }

            DepthStencilStates.Data[id.Index] = description;
            InitDepthStencilState(id);
        }
コード例 #39
0
        private void CreateStates()
        {
            var blendStateDesc = new BlendStateDescription();
            blendStateDesc.BlendOperation = BlendOperation.Add;
            blendStateDesc.AlphaBlendOperation = BlendOperation.Add;
            blendStateDesc.SourceBlend = BlendOption.One;
            blendStateDesc.DestinationBlend = BlendOption.One;
            blendStateDesc.SourceAlphaBlend = BlendOption.One;
            blendStateDesc.DestinationAlphaBlend = BlendOption.Zero;
            blendStateDesc.IsAlphaToCoverageEnabled = false;
            blendStateDesc.SetBlendEnable(0, true);
            visualEffectsBlendState = BlendState.FromDescription(renderer.Device, blendStateDesc);
            blendStateDesc.DestinationBlend = BlendOption.Zero;
            blenderBlendState = BlendState.FromDescription(renderer.Device, blendStateDesc);

            var rasterizerStateDesc = new RasterizerStateDescription();
            rasterizerStateDesc.CullMode = CullMode.None;
            rasterizerStateDesc.FillMode = FillMode.Solid;
            rasterizerStateDesc.IsAntialiasedLineEnabled = false;
            rasterizerStateDesc.IsMultisampleEnabled = false;
            // TODO: probably use scissor test
            rasterizerStateDesc.IsScissorEnabled = false;
            rasterizerState = RasterizerState.FromDescription(renderer.Device, rasterizerStateDesc);

            var depthStencilStateDesc = new DepthStencilStateDescription();
            depthStencilStateDesc.IsDepthEnabled = false;
            depthStencilStateDesc.IsStencilEnabled = false;
            depthStencilState = DepthStencilState.FromDescription(renderer.Device, depthStencilStateDesc);
        }
コード例 #40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DepthStencilState"/> class.
 /// </summary>
 /// <param name="graphicsDevice">The graphics device.</param>
 /// <param name="description">The description.</param>
 public static DepthStencilState New(GraphicsDevice graphicsDevice, DepthStencilStateDescription description)
 {
     return new DepthStencilState(graphicsDevice, description);
 }
コード例 #41
0
 /// <summary>
 /// Create a new fake depth-stencil state for serialization.
 /// </summary>
 /// <param name="description">The description of the depth-stencil state</param>
 /// <returns>The fake depth-stencil state</returns>
 public static DepthStencilState NewFake(DepthStencilStateDescription description)
 {
     return new DepthStencilState(description);
 }
コード例 #42
0
        /// <summary>
        /// Sets depth stencil view.
        /// </summary>
        private void SetDepthStencilView()
        {
            if (depthTexture != null)
                depthTexture.Dispose();

            Texture2DDescription depthBufferDescription = new Texture2DDescription()
            {
                ArraySize = 1,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.D24_UNorm_S8_UInt,
                Height = ClientSize.Height,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                Width = ClientSize.Width
            };

            depthTexture = new Texture2D(graphicsDevice, depthBufferDescription);

            DepthStencilStateDescription stencilDescription = new DepthStencilStateDescription()
            {
                BackFace = new DepthStencilOperationDescription()
                {
                    Comparison = Comparison.Always,
                    DepthFailOperation = StencilOperation.Decrement,
                    FailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Keep
                },
                DepthComparison = Comparison.Less,
                DepthWriteMask = DepthWriteMask.All,
                FrontFace = new DepthStencilOperationDescription()
                {
                    Comparison = Comparison.Always,
                    DepthFailOperation = StencilOperation.Increment,
                    FailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Keep
                },
                IsDepthEnabled = true,
                IsStencilEnabled = true,
                StencilReadMask = byte.MaxValue,
                StencilWriteMask = byte.MaxValue
            };

            DepthStencilState depthStencilState = DepthStencilState.FromDescription(graphicsDevice, stencilDescription);

            graphicsDevice.ImmediateContext.OutputMerger.DepthStencilState = depthStencilState;
            graphicsDevice.ImmediateContext.OutputMerger.DepthStencilReference = 1;

            DepthStencilViewDescription depthStencilViewDescription = new DepthStencilViewDescription()
            {
                ArraySize = 1,
                Dimension = DepthStencilViewDimension.Texture2D,
                FirstArraySlice = 0,
                Flags = DepthStencilViewFlags.None,
                Format = Format.D24_UNorm_S8_UInt,
                MipSlice = 0
            };

            if (depthStencilView != null)
                depthStencilView.Dispose();

            depthStencilView = new DepthStencilView(graphicsDevice, depthTexture, depthStencilViewDescription);
        }
コード例 #43
0
ファイル: GlobalRenderer.cs プロジェクト: samuto/HelloWorld
        internal void InitializeRenderer()
        {
            // setup directx
            var desc = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription = new ModeDescription(TheGame.Instance.Width, TheGame.Instance.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed = true,
                OutputHandle = TheGame.Instance.FormHandle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput,
            };
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);

            Factory factory = swapChain.GetParent<Factory>();
            factory.SetWindowAssociation(TheGame.Instance.FormHandle, WindowAssociationFlags.IgnoreAll);

            backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
            renderView = new RenderTargetView(device, backBuffer);

            // setup depth buffer
            Format depthFormat = Format.D32_Float;
            Texture2DDescription depthBufferDesc = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = depthFormat,
                Height = TheGame.Instance.Height,
                Width = TheGame.Instance.Width,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            };

            depthBuffer = new Texture2D(device, depthBufferDesc);

            DepthStencilViewDescription dsViewDesc = new DepthStencilViewDescription
            {
                ArraySize = 0,
                Format = depthFormat,
                Dimension = DepthStencilViewDimension.Texture2D,
                MipSlice = 0,
                Flags = 0,
                FirstArraySlice = 0
            };

            depthView = new DepthStencilView(device, depthBuffer, dsViewDesc);

            DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                IsStencilEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less,
            };

            DepthStencilState depthState = DepthStencilState.FromDescription(device, dsStateDesc);

            // setup render targets
            device.ImmediateContext.OutputMerger.DepthStencilState = depthState;
            device.ImmediateContext.OutputMerger.SetTargets(depthView, renderView);
            device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, TheGame.Instance.Width, TheGame.Instance.Height, 0.0f, 0.01f));

            t.Initialize(1024 * 1024 * 10, device);
            TileTextures.Instance.Initialize();
        }
コード例 #44
0
    public Direct3DRenderer()
    {
      _device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);
      _rasterizerStateDescription = new RasterizerStateDescription()
      {
        CullMode = SlimDX.Direct3D10.CullMode.None,
        FillMode = FillMode.Solid,
        IsFrontCounterclockwise = true
      };
      var rasterizerState = RasterizerState.FromDescription(_device, _rasterizerStateDescription);
      _device.Rasterizer.State = rasterizerState;

      _depthStencilStateDescription = new DepthStencilStateDescription()
      {
        IsDepthEnabled = true,
        DepthComparison = Comparison.Less,
        DepthWriteMask = DepthWriteMask.All
      };
      var depthStencilState = DepthStencilState.FromDescription(_device, _depthStencilStateDescription);
      _device.OutputMerger.DepthStencilState = depthStencilState;

      _semanticsTable.Add("inPosition", "POSITION");
      _semanticsTable.Add("inNormal", "NORMAL");
      _semanticsTable.Add("inTextureCoords", "TEXCOORD");
    }
コード例 #45
0
        public MenuEffect(Device device)
        {
            Device = device;
            ImmediateContext = Device.ImmediateContext;

            // Compile the shader...
            string compileErrors;
            var compiledShader = SlimDX.D3DCompiler.ShaderBytecode.CompileFromFile
            (
                "../../Effects/MenuEffect/MenuEffect.fx",
                null,
                "fx_5_0",
                SlimDX.D3DCompiler.ShaderFlags.None,
                SlimDX.D3DCompiler.EffectFlags.None,
                null,
                null,
                out compileErrors
            );

            if (compileErrors != null && compileErrors != "")
            {
                throw new EffectBuildException(compileErrors);
            }

            Effect = new Effect(Device, compiledShader);
            Technique = Effect.GetTechniqueByName("MenuTechnique");

            var vertexDesc = new[]
            {
                new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32_Float, 8, 0, InputClassification.PerVertexData, 0)
            };

            CPO_BlendColor = Effect.GetVariableByName("gBlendColor").AsVector();
            SRV_DiffuseMap = Effect.GetVariableByName("gDiffuseMap").AsResource();

            InputLayout = new InputLayout(Device, Technique.GetPassByIndex(0).Description.Signature, vertexDesc);

            Util.ReleaseCom(ref compiledShader);

            DepthStencilStateDescription dssd = new DepthStencilStateDescription()
            {
                IsDepthEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less,
                IsStencilEnabled = true,
                StencilReadMask = 0xFF,
                StencilWriteMask = 0xFF,
                FrontFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Increment,
                    Comparison = Comparison.Always
                },
                BackFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Keep,
                    Comparison = Comparison.Always,
                    DepthFailOperation = StencilOperation.Decrement
                }
            };
            DepthDisabledState = DepthStencilState.FromDescription(Device, dssd);
        }
コード例 #46
0
        private SharpDX.Direct3D12.DepthStencilStateDescription CreateDepthStencilState(DepthStencilStateDescription description)
        {
            SharpDX.Direct3D12.DepthStencilStateDescription nativeDescription;

            nativeDescription.IsDepthEnabled = description.DepthBufferEnable;
            nativeDescription.DepthComparison = (Comparison)description.DepthBufferFunction;
            nativeDescription.DepthWriteMask = description.DepthBufferWriteEnable ? SharpDX.Direct3D12.DepthWriteMask.All : SharpDX.Direct3D12.DepthWriteMask.Zero;

            nativeDescription.IsStencilEnabled = description.StencilEnable;
            nativeDescription.StencilReadMask = description.StencilMask;
            nativeDescription.StencilWriteMask = description.StencilWriteMask;

            nativeDescription.FrontFace.FailOperation = (SharpDX.Direct3D12.StencilOperation)description.FrontFace.StencilFail;
            nativeDescription.FrontFace.PassOperation = (SharpDX.Direct3D12.StencilOperation)description.FrontFace.StencilPass;
            nativeDescription.FrontFace.DepthFailOperation = (SharpDX.Direct3D12.StencilOperation)description.FrontFace.StencilDepthBufferFail;
            nativeDescription.FrontFace.Comparison = (SharpDX.Direct3D12.Comparison)description.FrontFace.StencilFunction;

            nativeDescription.BackFace.FailOperation = (SharpDX.Direct3D12.StencilOperation)description.BackFace.StencilFail;
            nativeDescription.BackFace.PassOperation = (SharpDX.Direct3D12.StencilOperation)description.BackFace.StencilPass;
            nativeDescription.BackFace.DepthFailOperation = (SharpDX.Direct3D12.StencilOperation)description.BackFace.StencilDepthBufferFail;
            nativeDescription.BackFace.Comparison = (SharpDX.Direct3D12.Comparison)description.BackFace.StencilFunction;

            return nativeDescription;
        }
コード例 #47
0
ファイル: ContextHelper.cs プロジェクト: shoff/CSharpRenderer
        public static void Initialize(Device device)
        {
            {
                var blendStateDescription = new BlendStateDescription();
                blendStateDescription.RenderTargets[0].BlendEnable = false;
                blendStateDescription.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                blendStateDescription.RenderTargets[1].BlendEnable = false;
                blendStateDescription.RenderTargets[1].RenderTargetWriteMask = ColorWriteMaskFlags.None;
                blendStateDescription.RenderTargets[2].BlendEnable = false;
                blendStateDescription.RenderTargets[2].RenderTargetWriteMask = ColorWriteMaskFlags.None;
                blendStateDescription.RenderTargets[3].BlendEnable = false;
                blendStateDescription.RenderTargets[3].RenderTargetWriteMask = ColorWriteMaskFlags.None;

                m_BlendStates[(int)BlendType.None] = BlendState.FromDescription(device, blendStateDescription);

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

                m_BlendStates[(int)BlendType.Additive] = BlendState.FromDescription(device, blendStateDescription);
            }

            {
                var depthStencilStateDescription = new DepthStencilStateDescription();
                depthStencilStateDescription.DepthComparison = Comparison.Always;
                depthStencilStateDescription.DepthWriteMask = DepthWriteMask.Zero;
                depthStencilStateDescription.IsDepthEnabled = false;
                depthStencilStateDescription.IsStencilEnabled = false;
                depthStencilStateDescription.DepthWriteMask = DepthWriteMask.Zero;

                m_DepthStencilStates[(int)DepthConfigurationType.NoDepth] = DepthStencilState.FromDescription(device, depthStencilStateDescription);

                depthStencilStateDescription.DepthComparison = Comparison.LessEqual;
                depthStencilStateDescription.DepthWriteMask = DepthWriteMask.All;
                depthStencilStateDescription.IsDepthEnabled = true;

                m_DepthStencilStates[(int)DepthConfigurationType.DepthWriteCompare] = DepthStencilState.FromDescription(device, depthStencilStateDescription);

                depthStencilStateDescription.DepthWriteMask = DepthWriteMask.Zero;

                m_DepthStencilStates[(int)DepthConfigurationType.DepthCompare] = DepthStencilState.FromDescription(device, depthStencilStateDescription);
            }

            {
                var rasterizerStateDescription = new RasterizerStateDescription();
                rasterizerStateDescription.DepthBias = 0;
                rasterizerStateDescription.DepthBiasClamp = 0;
                rasterizerStateDescription.FillMode = FillMode.Solid;
                rasterizerStateDescription.IsAntialiasedLineEnabled = false;
                rasterizerStateDescription.IsDepthClipEnabled = true;
                rasterizerStateDescription.IsMultisampleEnabled = false;
                rasterizerStateDescription.IsScissorEnabled = false;
                rasterizerStateDescription.SlopeScaledDepthBias = 0;
                rasterizerStateDescription.CullMode = CullMode.None;
                m_RasterizerStates[(int)RasterizerStateType.CullNone] = RasterizerState.FromDescription(device, rasterizerStateDescription);

                rasterizerStateDescription.CullMode = CullMode.Front;
                m_RasterizerStates[(int)RasterizerStateType.CullFront] = RasterizerState.FromDescription(device, rasterizerStateDescription);

                rasterizerStateDescription.CullMode = CullMode.Back;
                m_RasterizerStates[(int)RasterizerStateType.CullBack] = RasterizerState.FromDescription(device, rasterizerStateDescription);
            }

        }
コード例 #48
0
        /// <summary>
        /// Creates a new instance of the SpriteRenderer
        /// </summary>
        /// <param name="device">The device to use</param>
        /// <param name="maxSpriteInstances">The maximum sprite instances that can be cached before a flush happens</param>
        public SpriteRenderer(Device device, int maxSpriteInstances = 10000)
        {
            /* Initialize our arrays to hold our sprite data */
            m_spriteRenderData = new SpriteRenderData[maxSpriteInstances];
            m_spriteDrawData = new SpriteDrawData[maxSpriteInstances];

            /* Initialize all the items in the array */
            for (int i = 0; i < maxSpriteInstances; i++)
            {
                m_spriteRenderData[i] = new SpriteRenderData();
            }

            m_maxSpriteInstances = maxSpriteInstances;
            m_device = device;

            /* Create our default blend states using our helper */
            m_blendStates = SpriteRendererBlendStateHelper.InitializeDefaultBlendStates(m_device);

            /* Create our vertex shader */
            m_vertexShaderInstanced10 = new VertexShader10(device,
                                                           SHADER_RESOURCE_NAME, Assembly.GetExecutingAssembly(),
                                                           "SpriteInstancedVS", 
                                                           ShaderVersion.Vs_4_0);

            /* Create our pixel shader */
            m_pixelShader10 = new PixelShader10(device,
                                                SHADER_RESOURCE_NAME, Assembly.GetExecutingAssembly(),
                                                "SpritePS", 
                                                ShaderVersion.Ps_4_0,ShaderFlags.Debug);
            
            /* Create a new sprite quad that holds our GPU buffers */
            m_spriteQuad = new SpriteQuad(device, maxSpriteInstances);

            m_spriteQuadShaderBinding = new GeometryInputShaderBinding(m_spriteQuad, 
                                                                       m_vertexShaderInstanced10, 
                                                                       m_pixelShader10);

            var rastDesc = new RasterizerStateDescription();
            rastDesc.IsAntialiasedLineEnabled = false;
            rastDesc.CullMode = CullMode.None;
            rastDesc.DepthBias = 0;
            rastDesc.DepthBiasClamp = 1.0f;
            rastDesc.IsDepthClipEnabled = false;
            rastDesc.FillMode = FillMode.Solid;
            rastDesc.IsFrontCounterclockwise = false;
            rastDesc.IsMultisampleEnabled = false;
            rastDesc.IsScissorEnabled = false;
            rastDesc.SlopeScaledDepthBias = 0;
            m_rasterizerState = RasterizerState.FromDescription(m_device, rastDesc);
            
            var dsDesc = new DepthStencilStateDescription();
            dsDesc.IsDepthEnabled = false;
            dsDesc.DepthWriteMask = DepthWriteMask.All;
            dsDesc.DepthComparison = Comparison.Less;
            dsDesc.IsStencilEnabled = false;
            dsDesc.StencilReadMask = 0xff;
            dsDesc.StencilWriteMask = 0xff;
            dsDesc.FrontFace = new DepthStencilOperationDescription{ DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Replace, Comparison = Comparison.Always };
            dsDesc.BackFace = dsDesc.FrontFace;
            m_dsState = DepthStencilState.FromDescription(m_device, dsDesc);

            var sampDesc = new SamplerDescription();
            sampDesc.AddressU = TextureAddressMode.Wrap;
            sampDesc.AddressV = TextureAddressMode.Wrap;
            sampDesc.AddressW = TextureAddressMode.Wrap;
            sampDesc.BorderColor = new Color4(0, 0, 0, 0).InternalColor4;
            sampDesc.ComparisonFunction = Comparison.Never;
            sampDesc.Filter = Filter.MinMagMipLinear;
            sampDesc.MaximumAnisotropy = 1;
            sampDesc.MaximumLod = float.MaxValue;
            sampDesc.MinimumLod = 0;
            sampDesc.MipLodBias = 0;
            m_linearSamplerState = SamplerState.FromDescription(m_device, sampDesc);

            sampDesc.Filter = Filter.MinMagMipPoint;
            m_pointSamplerState = SamplerState.FromDescription(m_device, sampDesc);
        }
コード例 #49
0
ファイル: D3DScene.cs プロジェクト: treytomes/DirectCanvas
        private void LoadResources()
        {
            var imageLayer = m_presenter.Factory.CreateDrawingLayerFromFile(@".\Assets\Nature Mountains photo.jpg");
            m_brush = m_presenter.Factory.CreateDrawingLayerBrush(imageLayer);
            m_brushD3D = m_presenter.Factory.CreateDrawingLayerBrush(m_layer);
            lastStopwatchValue = Stopwatch.GetTimestamp();

            CreateDepthBuffer();

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

            var solidParentOp = new BlendStateDescription();
            solidParentOp.SetBlendEnable(0, false);
            solidParentOp.SetWriteMask(0, ColorWriteMaskFlags.All);

            var transParentOp = new BlendStateDescription
            {
                AlphaBlendOperation = BlendOperation.Add,
                BlendOperation = BlendOperation.Add,
                DestinationAlphaBlend = BlendOption.Zero,
                DestinationBlend = BlendOption.One,
                IsAlphaToCoverageEnabled = false,
                SourceAlphaBlend = BlendOption.Zero,
                SourceBlend = BlendOption.One,
            };

            transParentOp.SetBlendEnable(0, true);
            transParentOp.SetWriteMask(0, ColorWriteMaskFlags.All);

            transBlendState = BlendState.FromDescription(m_device, transParentOp);
            solidBlendState = BlendState.FromDescription(m_device, solidParentOp);

            depthStencilState = DepthStencilState.FromDescription(m_device, dssd);
            
            textTex = Texture2D.FromPointer(m_layerText.Texture2DComPointer);
            jupiterTex = Texture2D.FromFile(m_device, "jupiter.jpg");

            jupiterMesh = new SimpleModel(m_device, "SimpleModel10.fx", "jupiter.SMD", jupiterTex);

            view = Matrix.LookAtLH(new Vector3(0, 160, 0), new Vector3(0, -128.0f, 0), -Vector3.UnitZ);
            jupiterMesh.Effect.GetVariableByName("view").AsMatrix().SetMatrix(view);

            proj = Matrix.PerspectiveFovLH(45.0f, m_presenter.Width / (float)m_presenter.Height, 1.0f, 1000.0f);
            jupiterMesh.Effect.GetVariableByName("proj").AsMatrix().SetMatrix(proj);
        }
コード例 #50
0
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            this.renderTechnique = Techniques.RenderCubeMap;
            base.Attach(host);

            /// --- get variables               
            this.vertexLayout = EffectsManager.Instance.GetLayout(this.renderTechnique);
            this.effectTechnique = effect.GetTechniqueByName(this.renderTechnique.Name);
            this.effectTransforms = new EffectTransformVariables(this.effect);

            /// -- attach cube map 
            if (this.Filename != null)
            {
                /// -- attach texture
                using (var texture = Texture2D.FromFile<Texture2D>(this.Device, this.Filename))
                {
                    this.texCubeMapView = new ShaderResourceView(this.Device, texture);
                }
                this.texCubeMap = effect.GetVariableByName("texCubeMap").AsShaderResource();
                this.texCubeMap.SetResource(this.texCubeMapView);
                this.bHasCubeMap = effect.GetVariableByName("bHasCubeMap").AsScalar();
                this.bHasCubeMap.Set(true);

                /// --- set up geometry
                var sphere = new MeshBuilder(false,true,false);
                sphere.AddSphere(new Vector3(0, 0, 0));
                this.geometry = sphere.ToMeshGeometry3D();

                /// --- set up vertex buffer
                this.vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, CubeVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new CubeVertex() { Position = new Vector4(x, 1f) }).ToArray());

                /// --- set up index buffer
                this.indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), geometry.Indices.Array);

                /// --- set up rasterizer states
                var rasterStateDesc = new RasterizerStateDescription()
                {
                    FillMode = FillMode.Solid,
                    CullMode = CullMode.Back,
                    IsMultisampleEnabled = true,
                    IsAntialiasedLineEnabled = true,
                    IsFrontCounterClockwise = false,
                };
                this.rasterState = new RasterizerState(this.Device, rasterStateDesc);

                /// --- set up depth stencil state
                var depthStencilDesc = new DepthStencilStateDescription()
                {
                    DepthComparison = Comparison.LessEqual,
                    DepthWriteMask = global::SharpDX.Direct3D11.DepthWriteMask.All,
                    IsDepthEnabled = true,
                };
                this.depthStencilState = new DepthStencilState(this.Device, depthStencilDesc);
            }

            /// --- flush
            this.Device.ImmediateContext.Flush();
        }
コード例 #51
0
ファイル: Master.cs プロジェクト: catdawg/Ch0nkEngine
        private void InitializeGraphics()
        {
            // Creating device (we accept dx10 cards or greater)
            FeatureLevel[] levels = {
                                        FeatureLevel.Level_11_0,
                                        FeatureLevel.Level_10_1,
                                        FeatureLevel.Level_10_0
                                    };

            // Defining our swap chain
            SwapChainDescription desc = new SwapChainDescription();
            desc.BufferCount = 1;
            desc.Usage = Usage.RenderTargetOutput;
            desc.ModeDescription = new ModeDescription(0, 0, new Rational(0, 0), Format.R8G8B8A8_UNorm);
            desc.SampleDescription = new SampleDescription(1, 0);
            desc.OutputHandle = form.Handle;
            desc.IsWindowed = true;
            desc.SwapEffect = SwapEffect.Discard;

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, levels, desc, out device11, out swapChain);

            Format depthFormat = Format.D24_UNorm_S8_UInt;
            Texture2DDescription depthBufferDesc = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = depthFormat,
                Height = form.Height,
                Width = form.Width,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            };

            depthBuffer = new Texture2D(device11, depthBufferDesc);

            DepthStencilViewDescription dsViewDesc = new DepthStencilViewDescription
            {
                Format = depthFormat,
                Dimension = DepthStencilViewDimension.Texture2D,
                MipSlice = 0,
            };

            depthView = new DepthStencilView(device11, depthBuffer, dsViewDesc);

            DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less,

                IsStencilEnabled = true,
                StencilReadMask = 0xFF,
                StencilWriteMask = 0xFF,

                FrontFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Increment,
                    PassOperation = StencilOperation.Keep,
                    Comparison = Comparison.Always
                },
                BackFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Decrement,
                    PassOperation = StencilOperation.Keep,
                    Comparison = Comparison.Always
                },

            };

            depthState = DepthStencilState.FromDescription(device11, dsStateDesc);

            // Getting back buffer
            backBuffer = Resource.FromSwapChain<Texture2D>(swapChain, 0);

            // Defining render view
            renderTargetView = new RenderTargetView(device11, backBuffer);
            device11.ImmediateContext.OutputMerger.DepthStencilState = depthState;
            device11.ImmediateContext.OutputMerger.SetTargets(depthView, renderTargetView);

            // Setup the raster description which will determine how and what polygons will be drawn.
            RasterizerStateDescription rasterDesc = new RasterizerStateDescription(){
                IsAntialiasedLineEnabled = false,
                CullMode = CullMode.None,
                DepthBias = 0,
                DepthBiasClamp = 0.0f,
                IsDepthClipEnabled = true,
                FillMode = FillMode.Solid,
                IsFrontCounterclockwise = false,
                IsMultisampleEnabled = false,
                IsScissorEnabled = false,
                SlopeScaledDepthBias = 0.0f,
            };

            // Create the rasterizer state from the description we just filled out.
            rasterState = RasterizerState.FromDescription(device11, rasterDesc);

            // Now set the rasterizer state.
            device11.ImmediateContext.Rasterizer.State = rasterState;
            device11.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
        }
コード例 #52
0
 // For FakeDepthStencilState.
 private DepthStencilState(DepthStencilStateDescription description)
 {
     Description = description;
 }
コード例 #53
0
        /// <summary>
        /// Initialize everything D3D in here
        ///  Leave pretty empty for now.
        /// </summary>
        protected virtual void InitD3D()
        {
            // Set up rendering mode description (width, height, frame rate, color format)
            var modeDescription = new ModeDescription(0, 0, new SlimDX.Rational(60, 1), Format.R8G8B8A8_UNorm);

            // Set up swap chain description
            var swapChainDesc = new SwapChainDescription
            {
                BufferCount = 2,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = Handle,
                IsWindowed = true,
                ModeDescription = modeDescription,
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard
            };

            // Create our device and swap chain
            SlimDX.Direct3D11.Device.CreateWithSwapChain
            (
                DriverType.Hardware,
                DeviceCreationFlags.None,
                swapChainDesc,
                out Device,
                out SwapChain
            );

            // Obtain our device context (Immediate context)
            ImmediateContext = Device.ImmediateContext;

            // Prevent DXGI handling of alt+enter...
            using (var factory = SwapChain.GetParent<Factory>())
            {
                factory.SetWindowAssociation(Handle, WindowAssociationFlags.IgnoreAltEnter);
            }

            // Instead, handle the command ourselves
            KeyDown += (sender, e) =>
            {
                if (e.Alt && e.KeyCode == Keys.Enter)
                {
                    SwapChain.IsFullScreen = !SwapChain.IsFullScreen;
                }
            };

            // Add resize handling...
            UserResized += (sender, e) =>
            {
                OnResize(e);
            };

            // Set up viewport, render target (back buffer on swap chain), and render target view
            Viewport = new Viewport(0.0f, 0.0f, ClientSize.Width, ClientSize.Height, 0.0f, 1.0f);
            ImmediateContext.Rasterizer.SetViewports(Viewport);
            using (var resource = SlimDX.Direct3D11.Resource.FromSwapChain<Texture2D>(SwapChain, 0))
            {
                RenderTargetView = new RenderTargetView(Device, resource);
            }

            // Create the depth/stencil buffer and view
            // TODO KAM: On resize the window, do you need to resize the depth/stencil view?
            var depthBufferDesc = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.D32_Float,
                Height = ClientSize.Height,
                Width = ClientSize.Width,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            };

            DepthStencilBuffer = new Texture2D(Device, depthBufferDesc);

            var depthStencilViewDesc = new DepthStencilViewDescription
            {
                ArraySize = 0,
                Format = Format.D32_Float,
                Dimension = DepthStencilViewDimension.Texture2D,
                MipSlice = 0,
                Flags = 0,
                FirstArraySlice = 0
            };

            DepthStencilView = new DepthStencilView(Device, DepthStencilBuffer, depthStencilViewDesc);

            ImmediateContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView);

            // Set up the depth/stencil state description
            var dsStateDesc = new DepthStencilStateDescription
            {
                IsDepthEnabled = true,
                IsStencilEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less
            };

            DepthStencilState = DepthStencilState.FromDescription(Device, dsStateDesc);

            // Set depth/stencil state for the output merger
            ImmediateContext.OutputMerger.DepthStencilState = DepthStencilState;
        }
コード例 #54
0
 public static DepthStencilId CreateDepthStencil(DepthStencilStateDescription description)
 {
     DepthStencilId id = new DepthStencilId();
     CreateDepthStencil(ref id, description);
     return id;
 }
コード例 #55
0
        public void OnInitialise(InitialiseMessage msg)
        {
            // Initialise renderer
            Console.WriteLine("Initialising renderer...");
            rendermsg = new RenderMessage();
            updatemsg = new UpdateMessage();

            // Create the window
            window = new RenderForm("Castle Renderer - 11030062");
            window.Width = 1280;
            window.Height = 720;

            // Add form events
            window.FormClosed += window_FormClosed;

            // Defaults
            ClearColour = new Color4(1.0f, 0.0f, 0.0f, 1.0f);

            // Setup the device
            var description = new SwapChainDescription()
            {
                BufferCount = 1,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = window.Handle,
                IsWindowed = true,
                ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard
            };
            Device tmp;
            var result = Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out tmp, out swapchain);
            if (result.IsFailure)
            {
                Console.WriteLine("Failed to create Direct3D11 device (" + result.Code.ToString() + ":" + result.Description + ")");
                return;
            }
            Device = tmp;
            context = Device.ImmediateContext;
            using (var factory = swapchain.GetParent<Factory>())
                factory.SetWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAltEnter);

            // Check AA stuff
            int q = Device.CheckMultisampleQualityLevels(Format.R8G8B8A8_UNorm, 8);

            // Setup the viewport
            viewport = new Viewport(0.0f, 0.0f, window.ClientSize.Width, window.ClientSize.Height);
            viewport.MinZ = 0.0f;
            viewport.MaxZ = 1.0f;
            context.Rasterizer.SetViewports(viewport);

            // Setup the backbuffer
            using (var resource = Resource.FromSwapChain<Texture2D>(swapchain, 0))
                rtBackbuffer = new RenderTargetView(Device, resource);

            // Setup depth for backbuffer
            {
                Texture2DDescription texdesc = new Texture2DDescription()
                {
                    ArraySize = 1,
                    BindFlags = BindFlags.DepthStencil,
                    CpuAccessFlags = CpuAccessFlags.None,
                    Format = Format.D32_Float,
                    Width = (int)viewport.Width,
                    Height = (int)viewport.Height,
                    MipLevels = 1,
                    OptionFlags = ResourceOptionFlags.None,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage = ResourceUsage.Default
                };
                texDepthBuffer = new Texture2D(Device, texdesc);
                DepthStencilViewDescription viewdesc = new DepthStencilViewDescription()
                {
                    ArraySize = 0,
                    Format = Format.D32_Float,
                    Dimension = DepthStencilViewDimension.Texture2D,
                    MipSlice = 0,
                    Flags = 0,
                    FirstArraySlice = 0
                };
                vwDepthBuffer = new DepthStencilView(Device, texDepthBuffer, viewdesc);
            }

            // Setup states
            #region Depth States
            // Setup depth states
            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled = true,
                    IsStencilEnabled = false,
                    DepthWriteMask = DepthWriteMask.All,
                    DepthComparison = Comparison.Less
                };
                Depth_Enabled = DepthStencilState.FromDescription(Device, desc);
            }
            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled = false,
                    IsStencilEnabled = false,
                    DepthWriteMask = DepthWriteMask.Zero,
                    DepthComparison = Comparison.Less
                };
                Depth_Disabled = DepthStencilState.FromDescription(Device, desc);
            }
            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled = true,
                    IsStencilEnabled = false,
                    DepthWriteMask = DepthWriteMask.Zero,
                    DepthComparison = Comparison.Less
                };
                Depth_ReadOnly = DepthStencilState.FromDescription(Device, desc);
            }
            #endregion
            #region Sampler States
            Sampler_Clamp = SamplerState.FromDescription(Device, new SamplerDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                Filter = Filter.Anisotropic,
                MinimumLod = 0.0f,
                MaximumLod = float.MaxValue,
                MaximumAnisotropy = 16
            });
            Sampler_Clamp_Point = SamplerState.FromDescription(Device, new SamplerDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                Filter = Filter.MinMagMipPoint
            });
            Sampler_Clamp_Linear = SamplerState.FromDescription(Device, new SamplerDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                Filter = Filter.MinMagMipLinear
            });
            Sampler_Wrap = SamplerState.FromDescription(Device, new SamplerDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter = Filter.Anisotropic,
                MinimumLod = 0.0f,
                MaximumLod = float.MaxValue,
                MaximumAnisotropy = 16
            });
            #endregion
            #region Rasterizer States
            Culling_Backface = RasterizerState.FromDescription(Device, new RasterizerStateDescription()
            {
                CullMode = CullMode.Back,
                DepthBias = 0,
                DepthBiasClamp = 0.0f,
                IsDepthClipEnabled = true,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsFrontCounterclockwise = false,
                IsMultisampleEnabled = true,
                IsScissorEnabled = false,
                SlopeScaledDepthBias = 0.0f
            });
            Culling_Frontface = RasterizerState.FromDescription(Device, new RasterizerStateDescription()
            {
                CullMode = CullMode.Front,
                DepthBias = 0,
                DepthBiasClamp = 0.0f,
                IsDepthClipEnabled = true,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsFrontCounterclockwise = false,
                IsMultisampleEnabled = true,
                IsScissorEnabled = false,
                SlopeScaledDepthBias = 0.0f
            });
            Culling_None = RasterizerState.FromDescription(Device, new RasterizerStateDescription()
            {
                CullMode = CullMode.None,
                DepthBias = 0,
                DepthBiasClamp = 0.0f,
                IsDepthClipEnabled = true,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsFrontCounterclockwise = false,
                IsMultisampleEnabled = true,
                IsScissorEnabled = false,
                SlopeScaledDepthBias = 0.0f
            });
            #endregion
            #region Blend States
            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTargets[0].BlendEnable = true;
                desc.RenderTargets[0].BlendOperation = BlendOperation.Add;
                desc.RenderTargets[0].SourceBlend = BlendOption.One;
                desc.RenderTargets[0].DestinationBlend = BlendOption.Zero;
                desc.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add;
                desc.RenderTargets[0].SourceBlendAlpha = BlendOption.One;
                desc.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
                desc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                Blend_Opaque = BlendState.FromDescription(Device, desc);
            }
            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTargets[0].BlendEnable = true;
                desc.RenderTargets[0].BlendOperation = BlendOperation.Add;
                desc.RenderTargets[0].SourceBlend = BlendOption.SourceAlpha;
                desc.RenderTargets[0].DestinationBlend = BlendOption.InverseSourceAlpha;
                desc.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add;
                desc.RenderTargets[0].SourceBlendAlpha = BlendOption.One;
                desc.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
                desc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                Blend_Alpha = BlendState.FromDescription(Device, desc);
            }
            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTargets[0].BlendEnable = true;
                desc.RenderTargets[0].BlendOperation = BlendOperation.Add;
                desc.RenderTargets[0].SourceBlend = BlendOption.One;
                desc.RenderTargets[0].DestinationBlend = BlendOption.One;
                desc.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add;
                desc.RenderTargets[0].SourceBlendAlpha = BlendOption.One;
                desc.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
                desc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                Blend_Add = BlendState.FromDescription(Device, desc);
            }
            {
                BlendStateDescription desc = new BlendStateDescription();
                desc.RenderTargets[0].BlendEnable = true;
                desc.RenderTargets[0].BlendOperation = BlendOperation.Add;
                desc.RenderTargets[0].SourceBlend = BlendOption.DestinationColor;
                desc.RenderTargets[0].DestinationBlend = BlendOption.Zero;
                desc.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add;
                desc.RenderTargets[0].SourceBlendAlpha = BlendOption.One;
                desc.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
                desc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
                Blend_Multiply = BlendState.FromDescription(Device, desc);
            }
            #endregion

            // Setup default states
            Depth = Depth_Enabled;
            Culling = Culling_Backface;
            Blend = Blend_Opaque;

            // Setup other objects
            shaderresourcemap = new Dictionary<Resource, ShaderResourceView>();
            resourceviewslots = new ShaderResourceViewData[MaxPixelShaderResourceViewSlots];

            // Send the window created message
            WindowCreatedMessage windowcreatedmsg = new WindowCreatedMessage();
            windowcreatedmsg.Form = window;
            Owner.MessagePool.SendMessage(windowcreatedmsg);

            // Show the form
            window.Show();
        }
コード例 #56
0
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            Device device = context.Device;
            DeviceContext ctx = context.CurrentDeviceContext;

            if (!this.deviceshaderdata.ContainsKey(context))
            {
                this.deviceshaderdata.Add(context, new DX11ShaderData(context));
                this.deviceshaderdata[context].SetEffect(this.FShader);
            }

            DX11ShaderData shaderdata = this.deviceshaderdata[context];
            if (this.shaderupdated)
            {
                shaderdata.SetEffect(this.FShader);
                this.shaderupdated = false;
            }

            context.RenderStateStack.Push(new DX11RenderState());

            this.OnBeginQuery(context);

            //Clear shader stages
            shaderdata.ResetShaderStages(ctx);
            context.Primitives.ApplyFullTriVS();

            foreach (DX11ResourcePoolEntry<DX11RenderTarget2D> rt in this.lastframetargets)
            {
                rt.UnLock();
            }
            this.lastframetargets.Clear();

            DX11ObjectRenderSettings or = new DX11ObjectRenderSettings();

            int wi, he;
            bool preserve = false;
            DX11ResourcePoolEntry<DX11RenderTarget2D> preservedtarget = null;

            for (int i = 0; i < this.spmax; i++)
            {
                int passcounter = 0;

                if (this.FInEnabled[i])
                {
                    List<DX11ResourcePoolEntry<DX11RenderTarget2D>> locktargets = new List<DX11ResourcePoolEntry<DX11RenderTarget2D>>();

                    #region Manage size
                    DX11Texture2D initial;
                    if (this.FIn.PluginIO.IsConnected)
                    {
                        if (this.FInUseDefaultSize[0])
                        {
                            initial = context.DefaultTextures.WhiteTexture;
                            wi = (int)this.FInSize[0].X;
                            he = (int)this.FInSize[0].Y;
                        }
                        else
                        {
                            initial = this.FIn[i][context];
                            if (initial != null)
                            {
                                wi = initial.Width;
                                he = initial.Height;
                            }
                            else
                            {
                                initial = context.DefaultTextures.WhiteTexture;
                                wi = (int)this.FInSize[i].X;
                                he = (int)this.FInSize[i].Y;
                            }
                        }
                    }
                    else
                    {
                        initial = context.DefaultTextures.WhiteTexture;
                        wi = (int)this.FInSize[i].X;
                        he = (int)this.FInSize[i].Y;
                    }
                    #endregion

                    DX11RenderSettings r = new DX11RenderSettings();
                    r.RenderWidth = wi;
                    r.RenderHeight = he;
                    if (this.FInSemantics.PluginIO.IsConnected)
                    {
                        r.CustomSemantics.AddRange(this.FInSemantics.ToArray());
                    }
                    if (this.FInResSemantics.PluginIO.IsConnected)
                    {
                        r.ResourceSemantics.AddRange(this.FInResSemantics.ToArray());
                    }

                    this.varmanager.SetGlobalSettings(shaderdata.ShaderInstance, r);

                    this.varmanager.ApplyGlobal(shaderdata.ShaderInstance);

                    DX11Texture2D lastrt = initial;
                    DX11ResourcePoolEntry<DX11RenderTarget2D> lasttmp = null;

                    List<DX11Texture2D> rtlist = new List<DX11Texture2D>();

                    //Bind Initial (once only is ok)
                    this.BindTextureSemantic(shaderdata.ShaderInstance.Effect, "INITIAL", initial);

                    //Go trough all passes
                    EffectTechnique tech = shaderdata.ShaderInstance.Effect.GetTechniqueByIndex(tid);

                    for (int j = 0; j < tech.Description.PassCount; j++)
                    {
                        ImageShaderPass pi = this.varmanager.passes[j];
                        EffectPass pass = tech.GetPassByIndex(j);
                        bool isLastPass = j == tech.Description.PassCount - 1;

                        for (int kiter = 0; kiter < pi.IterationCount; kiter++)
                        {

                            if (passcounter > 0)
                            {
                                for (int pid = 0; pid < passcounter; pid++)
                                {
                                    string pname = "PASSRESULT" + pid;
                                    this.BindTextureSemantic(shaderdata.ShaderInstance.Effect, pname, rtlist[pid]);
                                }
                            }

                            Format fmt = initial.Format;
                            if (pi.CustomFormat)
                            {
                                fmt = pi.Format;
                            }
                            bool mips = pi.Mips || (isLastPass && FInMipLastPass[i]);

                            int w, h;
                            if (j == 0)
                            {
                                h = he;
                                w = wi;
                            }
                            else
                            {
                                h = pi.Reference == ImageShaderPass.eImageScaleReference.Initial ? he : lastrt.Height;
                                w = pi.Reference == ImageShaderPass.eImageScaleReference.Initial ? wi : lastrt.Width;
                            }

                            if (pi.DoScale)
                            {
                                if (pi.Absolute)
                                {
                                    w = Convert.ToInt32(pi.ScaleVector.X);
                                    h = Convert.ToInt32(pi.ScaleVector.Y);
                                }
                                else
                                {
                                    w = Convert.ToInt32((float)w * pi.ScaleVector.X);
                                    h = Convert.ToInt32((float)h * pi.ScaleVector.Y);
                                }

                                w = Math.Max(w, 1);
                                h = Math.Max(h, 1);
                            }

                            //Check format support for render target, and default to rgb8 if not
                            if (!context.IsSupported(FormatSupport.RenderTarget, fmt))
                            {
                                fmt = Format.R8G8B8A8_UNorm;
                            }

                            //Since device is not capable of telling us BGR not supported
                            if (fmt == Format.B8G8R8A8_UNorm) { fmt = Format.R8G8B8A8_UNorm; }

                            DX11ResourcePoolEntry<DX11RenderTarget2D> elem;
                            if (preservedtarget != null)
                            {
                                elem = preservedtarget;
                            }
                            else
                            {
                                elem = context.ResourcePool.LockRenderTarget(w, h, fmt, new SampleDescription(1, 0), mips, 0);
                                locktargets.Add(elem);
                            }
                            DX11RenderTarget2D rt = elem.Element;

                            if (this.FDepthIn.PluginIO.IsConnected && pi.UseDepth)
                            {
                                context.RenderTargetStack.Push(this.FDepthIn[0][context], true, elem.Element);
                            }
                            else
                            {
                                context.RenderTargetStack.Push(elem.Element);
                            }

                            if (pi.Clear)
                            {
                                elem.Element.Clear(new Color4(0, 0, 0, 0));
                            }

                            #region Check for depth/blend preset
                            bool validdepth = false;
                            bool validblend = false;

                            DepthStencilStateDescription ds = new DepthStencilStateDescription();
                            BlendStateDescription bs = new BlendStateDescription();

                            if (pi.DepthPreset != "")
                            {
                                try
                                {
                                    ds = DX11DepthStencilStates.Instance.GetState(pi.DepthPreset);
                                    validdepth = true;
                                }
                                catch
                                {

                                }
                            }

                            if (pi.BlendPreset != "")
                            {
                                try
                                {
                                    bs = DX11BlendStates.Instance.GetState(pi.BlendPreset);
                                    validblend = true;
                                }
                                catch
                                {

                                }
                            }
                            #endregion

                            if (validdepth || validblend)
                            {
                                DX11RenderState state = new DX11RenderState();
                                if (validdepth) { state.DepthStencil = ds; }
                                if (validblend) { state.Blend = bs; }
                                context.RenderStateStack.Push(state);
                            }

                            r.RenderWidth = w;
                            r.RenderHeight = h;
                            r.BackBuffer = elem.Element;
                            this.varmanager.ApplyGlobal(shaderdata.ShaderInstance);

                            //Apply settings (note that textures swap is handled later)
                            this.varmanager.ApplyPerObject(context, shaderdata.ShaderInstance, or, i);

                            //Bind last render target
                            this.BindTextureSemantic(shaderdata.ShaderInstance.Effect, "PREVIOUS", lastrt);

                            this.BindPassIndexSemantic(shaderdata.ShaderInstance.Effect, j);
                            this.BindPassIterIndexSemantic(shaderdata.ShaderInstance.Effect, kiter);

                            if (this.FDepthIn.PluginIO.IsConnected)
                            {
                                if (this.FDepthIn[0].Contains(context))
                                {
                                    this.BindTextureSemantic(shaderdata.ShaderInstance.Effect, "DEPTHTEXTURE", this.FDepthIn[0][context]);
                                }
                            }

                            //Apply pass and draw quad
                            pass.Apply(ctx);

                            if (pi.ComputeData.Enabled)
                            {
                                pi.ComputeData.Dispatch(context, w, h);
                                context.CleanUpCS();
                            }
                            else
                            {
                                ctx.ComputeShader.Set(null);
                                context.Primitives.FullScreenTriangle.Draw();
                                ctx.OutputMerger.SetTargets(this.nullrtvs);
                            }

                            //Generate mips if applicable
                            if (mips) { ctx.GenerateMips(rt.SRV); }

                            if (!pi.KeepTarget)
                            {
                                preserve = false;
                                rtlist.Add(rt);
                                lastrt = rt;
                                lasttmp = elem;
                                preservedtarget = null;
                                passcounter++;
                            }
                            else
                            {
                                preserve = true;
                                preservedtarget = elem;
                            }

                            context.RenderTargetStack.Pop();

                            if (validblend || validdepth)
                            {
                                context.RenderStateStack.Pop();
                            }

                            if (pi.HasState)
                            {
                                context.RenderStateStack.Apply();
                            }
                        }
                    }

                    //Set last render target
                    this.FOut[i][context] = lastrt;

                    //Unlock all resources
                    foreach (DX11ResourcePoolEntry<DX11RenderTarget2D> lt in locktargets)
                    {
                        lt.UnLock();
                    }

                    //Keep lock on last rt, since don't want it overidden
                    lasttmp.Lock();

                    this.lastframetargets.Add(lasttmp);
                }
                else
                {
                    this.FOut[i][context] = this.FIn[i][context];
                }
            }

            context.RenderStateStack.Pop();

            this.OnEndQuery(context);

            //UnLock previous frame in applicable
            //if (previoustarget != null) { context.ResourcePool.Unlock(previoustarget); }
        }
コード例 #57
0
ファイル: RenderStates.cs プロジェクト: amitprakash07/dx11
        public static void InitAll(Device device) {
            Debug.Assert(device != null);
            
            var wfDesc = new RasterizerStateDescription {
                FillMode = FillMode.Wireframe,
                CullMode = CullMode.Back,
                IsFrontCounterclockwise = false,
                IsDepthClipEnabled = true
            };
            WireframeRS = RasterizerState.FromDescription(device, wfDesc);

            var noCullDesc = new RasterizerStateDescription {
                FillMode = FillMode.Solid,
                CullMode = CullMode.None,
                IsFrontCounterclockwise = false,
                IsDepthClipEnabled = true
            };
            NoCullRS = RasterizerState.FromDescription(device, noCullDesc);

            var cullClockwiseDesc = new RasterizerStateDescription {
                FillMode = FillMode.Solid,
                CullMode = CullMode.Back,
                IsFrontCounterclockwise = true,
                IsDepthClipEnabled = true
            };
            CullClockwiseRS = RasterizerState.FromDescription(device, cullClockwiseDesc);

            var atcDesc = new BlendStateDescription {
                AlphaToCoverageEnable = true,
                IndependentBlendEnable = false,
            };
            atcDesc.RenderTargets[0].BlendEnable = false;
            atcDesc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            AlphaToCoverageBS = BlendState.FromDescription(device, atcDesc);

            var transDesc = new BlendStateDescription {
                AlphaToCoverageEnable = false,
                IndependentBlendEnable = false
            };
            transDesc.RenderTargets[0].BlendEnable = true;
            transDesc.RenderTargets[0].SourceBlend = BlendOption.SourceAlpha;
            transDesc.RenderTargets[0].DestinationBlend = BlendOption.InverseSourceAlpha;
            transDesc.RenderTargets[0].BlendOperation = BlendOperation.Add;
            transDesc.RenderTargets[0].SourceBlendAlpha = BlendOption.One;
            transDesc.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
            transDesc.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add;
            transDesc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;

            TransparentBS = BlendState.FromDescription(device, transDesc);

            var noRenderTargetWritesDesc = new BlendStateDescription {
                AlphaToCoverageEnable = false,
                IndependentBlendEnable = false
            };
            noRenderTargetWritesDesc.RenderTargets[0].BlendEnable = false;
            noRenderTargetWritesDesc.RenderTargets[0].SourceBlend = BlendOption.One;
            noRenderTargetWritesDesc.RenderTargets[0].DestinationBlend = BlendOption.Zero;
            noRenderTargetWritesDesc.RenderTargets[0].BlendOperation = BlendOperation.Add;
            noRenderTargetWritesDesc.RenderTargets[0].SourceBlendAlpha = BlendOption.One;
            noRenderTargetWritesDesc.RenderTargets[0].DestinationBlendAlpha = BlendOption.Zero;
            noRenderTargetWritesDesc.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add;
            noRenderTargetWritesDesc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.None;

            NoRenderTargetWritesBS = BlendState.FromDescription(device, noRenderTargetWritesDesc);

            var mirrorDesc = 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 = new DepthStencilOperationDescription {
                    FailOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Replace,
                    Comparison = Comparison.Always
                }
            };

            MarkMirrorDSS = DepthStencilState.FromDescription(device, mirrorDesc);

            var drawReflectionDesc = 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 = new DepthStencilOperationDescription {
                    FailOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Keep,
                    Comparison = Comparison.Equal
                }
            };
            DrawReflectionDSS = DepthStencilState.FromDescription(device, drawReflectionDesc);

            var noDoubleBlendDesc = 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 = new DepthStencilOperationDescription {
                    FailOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Increment,
                    Comparison = Comparison.Equal
                }
            };
            NoDoubleBlendDSS = DepthStencilState.FromDescription(device, noDoubleBlendDesc);

            var lessEqualDesc = new DepthStencilStateDescription {
                IsDepthEnabled = true,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.LessEqual,
                IsStencilEnabled = false
            };
            LessEqualDSS = DepthStencilState.FromDescription(device, lessEqualDesc);

            var equalsDesc = new DepthStencilStateDescription() {
                IsDepthEnabled = true,
                DepthWriteMask = DepthWriteMask.Zero,
                DepthComparison = Comparison.LessEqual,
                
            };
            EqualsDSS = DepthStencilState.FromDescription(device, equalsDesc);

            var noDepthDesc = new DepthStencilStateDescription() {
                IsDepthEnabled = false,
                DepthComparison = Comparison.Always,
                DepthWriteMask = DepthWriteMask.Zero
            };
            NoDepthDSS = DepthStencilState.FromDescription(device, noDepthDesc);
        }
コード例 #58
0
        private void createDepthBuffer()
        {
            Texture2DDescription depthdesc = new Texture2DDescription();
            depthdesc.BindFlags = BindFlags.DepthStencil;
            depthdesc.Format = Format.D32_Float_S8X24_UInt;
            depthdesc.Width = WindowWidth;
            depthdesc.Height = WindowHeight;
            depthdesc.MipLevels = 1;
            depthdesc.SampleDescription = new SampleDescription(1, 0);
            depthdesc.Usage = ResourceUsage.Default;
            depthdesc.OptionFlags = ResourceOptionFlags.None;
            depthdesc.CpuAccessFlags = CpuAccessFlags.None;
            depthdesc.ArraySize = 1;

            DepthTexture = new Texture2D(D3DDevice, depthdesc);

            SampleDepthView = new DepthStencilView(D3DDevice, DepthTexture);

            DepthStencilStateDescription depthStencilDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less,

                IsStencilEnabled = true,
                StencilReadMask = 0xFF,
                StencilWriteMask = 0xFF,

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

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

            depthStencilState = DepthStencilState.FromDescription(D3DDevice, depthStencilDesc);

            DepthStencilStateDescription disabledDepthStencilDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = false,
                DepthWriteMask = DepthWriteMask.All,
                DepthComparison = Comparison.Less,

                IsStencilEnabled = true,
                StencilReadMask = 0xFF,
                StencilWriteMask = 0xFF,

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

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

            disabledDepthStencilState = DepthStencilState.FromDescription(D3DDevice, disabledDepthStencilDesc);
        }
コード例 #59
0
        public override void Initialize()
        {
            base.Initialize();
            plStruct = new PointLightStruct[maxLights];
            pLightBuffer = new StructuredBuffer<PointLightStruct>(maxLights, false, true);
            cBuffer = new ConstantBufferWrapper(Renderer, sizeof(float) * 32, ShaderType.PixelShader, 0);
            cBuffer.Semantics.Add(Semantic.Projection);
            cBuffer.Semantics.Add(Semantic.CameraNearFar);
            GBuffer = new GBuffer(Renderer);

            BlendStateDescription disabledBlendDesc = States.BlendDefault();
            BlendStateDescription additiveDesc = States.BlendDefault();
            additiveDesc.RenderTargets[0] = new RenderTargetBlendDescription()
            {
                BlendEnable = true,
                SourceBlend = BlendOption.One,
                DestinationBlend = BlendOption.One,
                BlendOperation = BlendOperation.Add,
                SourceBlendAlpha = BlendOption.One,
                DestinationBlendAlpha = BlendOption.One,
                BlendOperationAlpha = BlendOperation.Add,
                RenderTargetWriteMask = ColorWriteMaskFlags.All,
            };
            DepthStencilStateDescription defaultDepthDesc = States.DepthDefault();
            defaultDepthDesc.DepthComparison = Comparison.GreaterEqual;
            DepthStencilStateDescription equalDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = true,
                DepthWriteMask = DepthWriteMask.Zero,
                DepthComparison = Comparison.GreaterEqual,
                IsStencilEnabled = true,
                StencilWriteMask = 0xFF,
                StencilReadMask = 0xFF,
                FrontFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Keep,
                    Comparison = Comparison.Equal,
                },
                BackFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Keep,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation = StencilOperation.Keep,
                    Comparison = Comparison.Equal,
                }
            };
            DepthStencilStateDescription writeDesc = new DepthStencilStateDescription()
            {
                IsDepthEnabled = false,
                DepthWriteMask = DepthWriteMask.Zero,
                DepthComparison = Comparison.GreaterEqual,
                IsStencilEnabled = true,
                StencilWriteMask = 0xFF,
                StencilReadMask = 0xFF,
                FrontFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Replace,
                    DepthFailOperation = StencilOperation.Replace,
                    PassOperation = StencilOperation.Replace,
                    Comparison = Comparison.Always,
                },
                BackFace = new DepthStencilOperationDescription()
                {
                    FailOperation = StencilOperation.Replace,
                    DepthFailOperation = StencilOperation.Replace,
                    PassOperation = StencilOperation.Replace,
                    Comparison = Comparison.Always,
                }
            };
            RasterizerStateDescription rsDesc = States.RasterizerDefault();

            mGeometryBlendState = BlendState.FromDescription(Renderer.Device, disabledBlendDesc);
            mLightingBlendState = BlendState.FromDescription(Renderer.Device, additiveDesc);
            mDepthState = DepthStencilState.FromDescription(Renderer.Device, defaultDepthDesc);
            mEqualStencilState = DepthStencilState.FromDescription(Renderer.Device, equalDesc);
            mWriteStencilState = DepthStencilState.FromDescription(Renderer.Device, writeDesc);
            mRasterizerState = RasterizerState.FromDescription(Renderer.Device, rsDesc);

            InitializeBuffers();
            InitializeShaders();
        }
コード例 #60
0
        public static RenderTargetSet CreateRenderTargetSet( Device device, int width, int height, Format format, int numSurfaces, bool needsDepth )
        {
            RenderTargetSet rt = new RenderTargetSet();

            rt.m_Descriptor = new RenderTargetDescriptor()
            {
                m_Format = format,
                m_HasDepth = needsDepth,
                m_Height = height,
                m_NumSurfaces = numSurfaces,
                m_Width = width
            };

            rt.m_NumRTs = numSurfaces;
            for (int i = 0; i < numSurfaces; ++i)
            {
                rt.m_RenderTargets[i] = TextureObject.CreateTexture(device, width, height, 1, format, false, true);
            }
            
            if (needsDepth)
            {
                rt.m_DepthStencil = TextureObject.CreateTexture(device, width, height, 1, Format.R32_Typeless, true, false);
            }

            rt.m_Viewport = new Viewport(0, 0, width, height, 0.0f, 1.0f);

            if (m_DepthStencilState == null)
            {
                DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled = true,
                    IsStencilEnabled = false,
                    DepthWriteMask = DepthWriteMask.All,
                    DepthComparison = Comparison.Less,
                };

                m_DepthStencilState = DepthStencilState.FromDescription(device, dsStateDesc);

                dsStateDesc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled = false,
                    IsStencilEnabled = false,
                    DepthWriteMask = DepthWriteMask.Zero,
                    DepthComparison = Comparison.Always,
                };

                m_DepthStencilStateNoDepth = DepthStencilState.FromDescription(device, dsStateDesc);
            }
            

            return rt;
        }