コード例 #1
0
ファイル: GL46CommandList.cs プロジェクト: deccer/Xacor
        public void SetDepthStencilState(IDepthStencilState depthStencilState)
        {
            var command = new GLCommand
            {
                Type = CommandType.SetDepthStencilState,
            };

            _commandList.Add(command);
        }
コード例 #2
0
        public void SetDepthStencilState(IDepthStencilState depthStencilState)
        {
            var command = new D3D11Command
            {
                Type = CommandType.SetDepthStencilState,
                DepthStencilState = (D3D11DepthStencilState)depthStencilState
            };

            _commandList.Add(command);
        }
コード例 #3
0
        internal void SetDepthStencilState(IDepthStencilState dss, int stencilRef = 0)
        {
            DepthStencilState dxstate = null;

            if (dss != null)
            {
                IDepthStencilStateInternal dssInternal = (IDepthStencilStateInternal)dss;
                dxstate = dssInternal.Resource;
            }
            m_state.SetDepthStencilState(dxstate, stencilRef);
            CheckErrors();
        }
コード例 #4
0
ファイル: D3D11Pipeline.cs プロジェクト: deccer/Xacor
 public D3D11Pipeline(Shader vertexShader, Shader pixelShader, IInputLayout inputLayout,
                      IBlendState blendState, IDepthStencilState depthStencilState, IRasterizerState rasterizerState,
                      Viewport viewport, PrimitiveTopology primitiveTopology)
 {
     VertexShader      = vertexShader;
     PixelShader       = pixelShader;
     InputLayout       = inputLayout;
     BlendState        = blendState;
     DepthStencilState = depthStencilState;
     RasterizerState   = rasterizerState;
     Viewport          = viewport;
     PrimitiveTopology = primitiveTopology;
 }
コード例 #5
0
 public void InitStandard(string cmFilepath, string ngFilepath, string extFilepath)
 {
     m_srvs = new ISrvBindable[]
     {
         MyManagers.FileTextures.GetTexture(cmFilepath, MyFileTextureEnum.COLOR_METAL),
         MyManagers.FileTextures.GetTexture(ngFilepath, MyFileTextureEnum.NORMALMAP_GLOSS),
         MyManagers.FileTextures.GetTexture(extFilepath, MyFileTextureEnum.EXTENSIONS)
     };
     m_depthStencilState    = MyDepthStencilStateManager.DefaultDepthState;
     m_blendState           = null;
     m_rasterizerState      = null;
     m_isFaceCullingEnabled = true;
 }
コード例 #6
0
        public static IDepthStencilState New(VideoTypes videoType, IDisposableResource parent, IDepthStencilStateDesc desc)
        {
            IDepthStencilState api = null;

                        #if WIN32
            if (videoType == VideoTypes.D3D9)
            {
                api = new D3D9.DepthStencilState(parent, desc);
            }
                        #endif

                        #if WIN32 || WINRT || WP8
            if (videoType == VideoTypes.D3D11)
            {
                api = new D3D11.DepthStencilState(parent, desc);
            }
                        #endif

                        #if WIN32 || OSX || LINUX || iOS || ANDROID || NaCl
            if (videoType == VideoTypes.OpenGL)
            {
                api = new OpenGL.DepthStencilState(parent, desc);
            }
                        #endif

                        #if XNA
            if (videoType == VideoTypes.XNA)
            {
                api = new XNA.DepthStencilState(parent, desc);
            }
                        #endif

                        #if VITA
            if (videoType == VideoTypes.Vita)
            {
                api = new Vita.DepthStencilState(parent, desc);
            }
                        #endif

            if (api == null)
            {
                Debug.ThrowError("DepthStencilStateAPI", "Unsuported InputType: " + videoType);
            }
            return(api);
        }
コード例 #7
0
ファイル: GBufferShader.cs プロジェクト: K0bin/DotGame
        public GBufferShader(Engine engine) : base(engine, @"Rendering\Passes\Shaders\gbuffer")
        {
            sampler        = engine.GraphicsDevice.Factory.CreateSampler(new SamplerInfo(TextureFilter.Linear));
            constantBuffer = shader.CreateConstantBuffer(ResourceUsage.Dynamic);

            rasterizerState = engine.GraphicsDevice.Factory.CreateRasterizerState(new RasterizerStateInfo()
            {
                CullMode = CullMode.None,
                FillMode = FillMode.Solid,
                IsFrontCounterClockwise = false,
            });

            depthStencil = engine.GraphicsDevice.Factory.CreateDepthStencilState(new DepthStencilStateInfo()
            {
                IsDepthEnabled  = true,
                DepthComparsion = Comparison.LessEqual,
                DepthWriteMask  = DepthWriteMask.All
            });
        }
コード例 #8
0
 public void InitDecal(string cmFilepath, string ngFilepath, string extFilepath, string alphamaskFilepath, bool isPremultipliedAlpha, bool isCutout)
 {
     m_srvs = new ISrvBindable[]
     {
         MyManagers.FileTextures.GetTexture(cmFilepath, MyFileTextureEnum.COLOR_METAL),
         MyManagers.FileTextures.GetTexture(ngFilepath, MyFileTextureEnum.NORMALMAP_GLOSS),
         MyManagers.FileTextures.GetTexture(extFilepath, MyFileTextureEnum.EXTENSIONS),
         MyManagers.FileTextures.GetTexture(alphamaskFilepath, MyFileTextureEnum.ALPHAMASK)
     };
     m_depthStencilState = MyDepthStencilStateManager.DepthTestReadOnly;
     if (isCutout)
     {
         m_blendState = null;
     }
     else
     {
         m_blendState = GetAlphamaskBlendState(cmFilepath, ngFilepath, extFilepath, isPremultipliedAlpha);
     }
     m_rasterizerState      = MyRasterizerStateManager.DecalRasterizerState;
     m_isFaceCullingEnabled = true;
 }
コード例 #9
0
        internal static void RunWithStencil(IRtvBindable destinationResource, ISrvBindable sourceResource, IBlendState blendState,
                                            IDepthStencilState depthStencilState = null, int stencilMask = 0x0, IDepthStencil depthStencil = null)
        {
            RC.SetBlendState(blendState);
            RC.SetRasterizerState(null);
            if (depthStencilState == null)
            {
                RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
                RC.SetRtv(null, MyDepthStencilAccess.ReadOnly, destinationResource);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilMask);
                RC.SetRtv(depthStencil ?? MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, destinationResource);
            }

            RC.PixelShader.SetSrv(0, sourceResource);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
コード例 #10
0
        internal static void RunWithStencil(IRtvBindable destinationResource, ISrvBindable sourceResource, IBlendState blendState,
            IDepthStencilState depthStencilState = null, int stencilMask = 0x0, IDepthStencil depthStencil = null)
        {
            RC.SetBlendState(blendState);
            RC.SetRasterizerState(null);
            if (depthStencilState == null)
            {
                RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
                RC.SetRtv(null, MyDepthStencilAccess.ReadOnly, destinationResource);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilMask);
                RC.SetRtv(depthStencil ?? MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, destinationResource);
            }

            RC.PixelShader.SetSrv(0, sourceResource);
            RC.PixelShader.Set(m_copyPixelShader);

            DrawFullscreenQuad();
            RC.SetBlendState(null);
        }
コード例 #11
0
ファイル: DemoGame.cs プロジェクト: deccer/Xacor
        protected override void Initialize()
        {
            base.Initialize();

            Window.Title = "Xacor.Demo";

            _viewMatrix       = Matrix.LookAtRH(new Vector3(0, 0, 10f), Vector3.Zero, Vector3.UnitY);
            _projectionMatrix = Matrix.PerspectiveFovRH(MathF.PI / 3.0f, _renderResolution.Width / (float)_renderResolution.Height, 0.1f, 4096f);
            _leftMvp          = new InputBuffer
            {
                ModelViewProjectionMatrix = Matrix.Translation(-1.5f, 1, -0.5f) * _viewMatrix * _projectionMatrix
            };

            _rightMvp = new InputBuffer
            {
                ModelViewProjectionMatrix = Matrix.Translation(1.5f, -1, 0.5f) * _viewMatrix * _projectionMatrix
            };

            _viewport                 = new Viewport(0, 0, _renderResolution.Width, _renderResolution.Height, 0.1f, 4096f);
            _defaultBlendState        = GraphicsFactory.CreateBlendState(true, Blend.SourceAlpha, Blend.InverseSourceAlpha, BlendOperation.Add, Blend.One, Blend.Zero, BlendOperation.Add);
            _defaultDepthStencilState = GraphicsFactory.CreateDepthStencilState();
            _defaultRasterizerState   = GraphicsFactory.CreateRasterizerState(CullMode.None, FillMode.Solid, true, false, false, false);

            var macros = new[] { ("TEST", "0") };
コード例 #12
0
        public RenderToTextureScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader);

            var meshFactory = new MeshFactory(Device, Handedness.Right, Winding.Clockwise);
            cubeMesh = meshFactory.CreateCube(2.0f);

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0),
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12),
                new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 24)
            });

            transformBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Transform.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            cameraVertexBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = CameraVertex.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            lightBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Light.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });

            var renderTargetFormats = Eye.Adapters[0]
                .GetSupportedFormats(FormatSupport.Texture2D | FormatSupport.RenderTarget | FormatSupport.MipAutogen)
                .Where(fi => fi.ColorBits <= 24);
            if (!renderTargetFormats.Any()) throw new NotSupportedException("Render target textures are not supported.");
            var renderTargetFormatInfo = renderTargetFormats
                .OrderByDescending(fi => fi.ColorBits)
                .ThenBy(fi => fi.TotalBits)
                .First();

            var renderTargetTexture = Device.Create.Texture2D(new Texture2DDescription
            {
                Width = TargetSize,
                Height = TargetSize,
                MipLevels = TextureHelper.MipLevels(TargetSize, TargetSize, 1),
                ArraySize = 1,
                FormatID = renderTargetFormatInfo.ID,
                Sampling = Sampling.NoMultisampling,
                Usage = Usage.Default,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                MiscFlags = MiscFlags.GenerateMips,
                ExtraFlags = ExtraFlags.None
            });
            targetRtv = renderTargetTexture.ViewAsRenderTarget(renderTargetFormatInfo.ID, 0);
            targetSrv = renderTargetTexture.ViewAsShaderResource(renderTargetFormatInfo.ID, 0, renderTargetTexture.MipLevels);

            var dsFormats = Eye.Adapters[0].GetSupportedFormats(FormatSupport.Texture2D | FormatSupport.DepthStencil);
            var dsFormatInfo = dsFormats
                .OrderBy(fi => (fi.ColorBits == 24 && fi.AlphaBits == 8) ? 0 : 1)
                .ThenByDescending(fi => fi.ColorBits)
                .ThenBy(fi => fi.TotalBits)
                .First();

            var depthStencilTexture = Device.Create.Texture2D(new Texture2DDescription
            {
                Width = TargetSize,
                Height = TargetSize,
                MipLevels = 1,
                ArraySize = 1,
                FormatID = dsFormatInfo.ID,
                Sampling = Sampling.NoMultisampling,
                Usage = Usage.Default,
                BindFlags = BindFlags.DepthStencil,
                MiscFlags = MiscFlags.None,
                ExtraFlags = ExtraFlags.None
            });
            targetDsv = depthStencilTexture.ViewAsDepthStencil(dsFormatInfo.ID, DepthStencilViewFlags.None, 0);

            var textureLoader = new TextureLoader(Device);

            var diffuseTexture = textureLoader.Load("../Textures/DiffuseTest.png");
            diffuseView = diffuseTexture.ViewAsShaderResource(diffuseTexture.FormatID, 0, diffuseTexture.MipLevels);

            samplerState = Device.Create.SamplerState(SamplerDescription.Anisotropic);
            depthStencilState = Device.Create.DepthStencilState(DepthStencilDescription.Enabled);
        }
コード例 #13
0
        public MyDepthStencilStateManager()
        {
            // Bits in stencil buffer: 76543210
            // bits 3-0 used in CSM
            // bit 4 used for stereo rendering mask
            // bit 6 used for outlines

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison  = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask   = DepthWriteMask.All;
                desc.IsDepthEnabled   = true;
                desc.IsStencilEnabled = false;
                MyDepthStencilStateManager.DepthTestWrite = CreateResource("DepthTestWrite", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison  = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask   = DepthWriteMask.Zero;
                desc.IsDepthEnabled   = true;
                desc.IsStencilEnabled = false;
                MyDepthStencilStateManager.DepthTestReadOnly = CreateResource("DepthTest", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison  = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask   = DepthWriteMask.Zero;
                desc.IsDepthEnabled   = false;
                desc.IsStencilEnabled = false;
                MyDepthStencilStateManager.IgnoreDepthStencil = CreateResource("IgnoreDepthStencil", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison             = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask              = DepthWriteMask.All;
                desc.IsDepthEnabled              = true;
                desc.IsStencilEnabled            = true;
                desc.StencilReadMask             = 0xFF;
                desc.StencilWriteMask            = 0xFF;
                desc.BackFace.Comparison         = Comparison.Always;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Replace;
                desc.BackFace.PassOperation      = StencilOperation.Replace;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.WriteDepthAndStencil = CreateResource("WriteDepthAndStencil", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.IsDepthEnabled              = false;
                desc.IsStencilEnabled            = true;
                desc.StencilReadMask             = 0xFF;
                desc.StencilWriteMask            = 0x80;
                desc.BackFace.Comparison         = Comparison.Always;
                desc.BackFace.DepthFailOperation = StencilOperation.Replace;
                desc.BackFace.FailOperation      = StencilOperation.Replace;
                desc.BackFace.PassOperation      = StencilOperation.Replace;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.MarkEdgeInStencil = CreateResource("MarkEdgeInStencil", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.IsDepthEnabled              = true;
                desc.DepthComparison             = Comparison.Equal;
                desc.DepthWriteMask              = DepthWriteMask.Zero;
                desc.IsStencilEnabled            = true;
                desc.StencilReadMask             = 0x00;
                desc.StencilWriteMask            = 0x40;
                desc.BackFace.Comparison         = Comparison.Always;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Replace;
                desc.BackFace.PassOperation      = StencilOperation.Replace;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.OutlineMesh = CreateResource("OutlineMesh", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.IsDepthEnabled              = false;
                desc.IsStencilEnabled            = true;
                desc.StencilReadMask             = 0x40;
                desc.StencilWriteMask            = 0x0;
                desc.BackFace.Comparison         = Comparison.NotEqual;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Keep;
                desc.BackFace.PassOperation      = StencilOperation.Keep;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.TestOutlineMeshStencil = CreateResource("TestOutlineMeshStencil", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.IsDepthEnabled              = false;
                desc.IsStencilEnabled            = true;
                desc.StencilReadMask             = 0x40;
                desc.StencilWriteMask            = 0x0;
                desc.BackFace.Comparison         = Comparison.Equal;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Keep;
                desc.BackFace.PassOperation      = StencilOperation.Keep;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.TestHighlightMeshStencil = CreateResource("TestHighlightMeshStencil", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison             = Comparison.Never;
                desc.IsDepthEnabled              = false;
                desc.DepthWriteMask              = DepthWriteMask.Zero;
                desc.IsStencilEnabled            = true;
                desc.StencilReadMask             = 0x80;
                desc.StencilWriteMask            = 0;
                desc.BackFace.Comparison         = Comparison.NotEqual;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Keep;
                desc.BackFace.PassOperation      = StencilOperation.Keep;
                desc.FrontFace       = desc.BackFace;
                TestSkipGrassStencil = CreateResource("TestSkipGrassStencil", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.IsDepthEnabled              = false;
                desc.IsStencilEnabled            = true;
                desc.StencilReadMask             = 0x80;
                desc.StencilWriteMask            = 0x00;
                desc.BackFace.Comparison         = Comparison.Equal;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Keep;
                desc.BackFace.PassOperation      = StencilOperation.Keep;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.TestEdgeStencil = CreateResource("TestEdgeStencil", ref desc);
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison             = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask              = DepthWriteMask.Zero;
                desc.IsDepthEnabled              = true;
                desc.IsStencilEnabled            = true;
                desc.StencilReadMask             = 0x80;
                desc.StencilWriteMask            = 0x00;
                desc.BackFace.Comparison         = Comparison.Equal;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Keep;
                desc.BackFace.PassOperation      = StencilOperation.Keep;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.TestDepthAndEdgeStencil = CreateResource("TestDepthAndEdgeStencil", ref desc);
            }

            MyDepthStencilStateManager.MarkIfInsideCascade = new MyDepthStencilState[8];

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.IsDepthEnabled  = true;
                desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Less : Comparison.Greater;
                desc.DepthWriteMask  = DepthWriteMask.Zero;

                for (int cascadeIndex = 0; cascadeIndex < MyDepthStencilStateManager.MarkIfInsideCascade.Length; ++cascadeIndex)
                {
                    desc.IsStencilEnabled            = true;
                    desc.StencilReadMask             = 0xF;
                    desc.StencilWriteMask            = (byte)(0xF - cascadeIndex);
                    desc.BackFace.Comparison         = cascadeIndex == 0 ? Comparison.Always : Comparison.GreaterEqual;
                    desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                    desc.BackFace.FailOperation      = StencilOperation.Keep;
                    desc.BackFace.PassOperation      = StencilOperation.Invert;
                    desc.FrontFace = desc.BackFace;
                    MyDepthStencilStateManager.MarkIfInsideCascade[cascadeIndex] = CreateResource("MarkIfInsideCascade_" + cascadeIndex, ref desc);
                }
            }

            MyDepthStencilStateManager.MarkIfInsideCascadeOld = new MyDepthStencilState[8];

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.IsDepthEnabled  = true;
                desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Less : Comparison.Greater;
                desc.DepthWriteMask  = DepthWriteMask.Zero;

                for (int cascadeIndex = 0; cascadeIndex < MyDepthStencilStateManager.MarkIfInsideCascadeOld.Length; ++cascadeIndex)
                {
                    desc.IsStencilEnabled            = true;
                    desc.StencilReadMask             = 0xF;
                    desc.StencilWriteMask            = (byte)(0xF - cascadeIndex);
                    desc.BackFace.Comparison         = cascadeIndex == 0 ? Comparison.Always : Comparison.GreaterEqual;
                    desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                    desc.BackFace.FailOperation      = StencilOperation.Keep;
                    desc.BackFace.PassOperation      = StencilOperation.Invert;
                    desc.FrontFace = desc.BackFace;
                    MyDepthStencilStateManager.MarkIfInsideCascadeOld[cascadeIndex] = CreateResource("MarkIfInsideCascade_" + cascadeIndex, ref desc);
                }
            }

            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison             = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask              = DepthWriteMask.All;
                desc.IsDepthEnabled              = true;
                desc.IsStencilEnabled            = true;
                desc.StencilWriteMask            = GetStereoMask();
                desc.StencilReadMask             = GetStereoMask();
                desc.BackFace.Comparison         = Comparison.GreaterEqual;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Keep;
                desc.BackFace.PassOperation      = StencilOperation.Replace;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.StereoDefaultDepthState = CreateResource("StereoDefaultDepthState", ref desc);
            }
            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison             = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask              = DepthWriteMask.Zero;
                desc.IsDepthEnabled              = false;
                desc.IsStencilEnabled            = true;
                desc.StencilWriteMask            = GetStereoMask();
                desc.StencilReadMask             = GetStereoMask();
                desc.BackFace.Comparison         = Comparison.Always;
                desc.BackFace.DepthFailOperation = StencilOperation.Replace;
                desc.BackFace.FailOperation      = StencilOperation.Replace;
                desc.BackFace.PassOperation      = StencilOperation.Replace;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.StereoStencilMask = CreateResource("StereoStencilMask", ref desc);
            }
            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison             = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask              = DepthWriteMask.Zero;
                desc.IsDepthEnabled              = true;
                desc.IsStencilEnabled            = true;
                desc.StencilWriteMask            = GetStereoMask();
                desc.StencilReadMask             = GetStereoMask();
                desc.BackFace.Comparison         = Comparison.GreaterEqual;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Keep;
                desc.BackFace.PassOperation      = StencilOperation.Replace;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.StereoDepthTestReadOnly = CreateResource("StereoDepthTestReadOnly", ref desc);
            }
            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison             = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask              = DepthWriteMask.All;
                desc.IsDepthEnabled              = true;
                desc.IsStencilEnabled            = true;
                desc.StencilWriteMask            = GetStereoMask();
                desc.StencilReadMask             = GetStereoMask();
                desc.BackFace.Comparison         = Comparison.GreaterEqual;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Keep;
                desc.BackFace.PassOperation      = StencilOperation.Replace;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.StereoDepthTestWrite = CreateResource("StereoDepthTestWrite", ref desc);
            }
            {
                DepthStencilStateDescription desc = new DepthStencilStateDescription();
                desc.DepthComparison             = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less;
                desc.DepthWriteMask              = DepthWriteMask.Zero;
                desc.IsDepthEnabled              = false;
                desc.IsStencilEnabled            = true;
                desc.StencilWriteMask            = GetStereoMask();
                desc.StencilReadMask             = GetStereoMask();
                desc.BackFace.Comparison         = Comparison.GreaterEqual;
                desc.BackFace.DepthFailOperation = StencilOperation.Keep;
                desc.BackFace.FailOperation      = StencilOperation.Keep;
                desc.BackFace.PassOperation      = StencilOperation.Replace;
                desc.FrontFace = desc.BackFace;
                MyDepthStencilStateManager.StereoIgnoreDepthStencil = CreateResource("StereoIgnoreDepthStencil", ref desc);
            }
        }
コード例 #14
0
 public IPipeline CreatePipeline(Shader vertexShader, Shader pixelShader, IInputLayout inputLayout, IBlendState blendState,
                                 IDepthStencilState depthStencilState, IRasterizerState rasterizerState, Viewport viewport,
                                 PrimitiveTopology primitiveTopology)
 {
     throw new System.NotImplementedException();
 }
コード例 #15
0
 public IPipeline CreatePipeline(Shader vertexShader, Shader pixelShader, IInputLayout inputLayout,
                                 IBlendState blendState, IDepthStencilState depthStencilState, IRasterizerState rasterizerState,
                                 Viewport viewport, PrimitiveTopology primitiveTopology)
 {
     return(new D3D11Pipeline(vertexShader, pixelShader, inputLayout, blendState, depthStencilState, rasterizerState, viewport, primitiveTopology));
 }
コード例 #16
0
ファイル: Stars.cs プロジェクト: Zulkir/Beholder
 public Stars(IDevice device, int starCount)
 {
     this.starCount = starCount;
     shaders = CreateShaders(device);
     timeUbuffer = CreateTimeUbuffer(device);
     vertexLayout = CreateVertexLayout(device, shaders.VertexShader);
     vertexBuffer = CreateVertexBuffer(device, starCount);
     indexBuffer = CreateIndexBuffer(device, starCount);
     rasterizerState = CreateRasterizerState(device);
     depthStencilState = CreateDepthStencilState(device);
     blendState = CreateBlendState(device);
 }
コード例 #17
0
ファイル: CubeScene.cs プロジェクト: Zulkir/Beholder
        public CubeScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader);

            var meshFactory = new MeshFactory(Device, Handedness.Right, Winding.Clockwise);
            cubeMesh = meshFactory.CreateCube(2.0f);

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0),
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12),
                new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 24)
            });

            transformBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Transform.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            cameraVertexBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = CameraVertex.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            cameraPixelBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = CameraPixel.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            lightBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Light.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });

            var textureLoader = new TextureLoader(Device);

            var diffuseTexture = textureLoader.Load("../Textures/DiffuseTest.png");
            diffuseView = diffuseTexture.ViewAsShaderResource(diffuseTexture.FormatID, 0, diffuseTexture.MipLevels);

            var specularTexture = textureLoader.Load("../Textures/SpecularTest.png");
            specualrView = specularTexture.ViewAsShaderResource(specularTexture.FormatID, 0, specularTexture.MipLevels);

            samplerState = Device.Create.SamplerState(SamplerDescription.Default);
            depthStencilState = Device.Create.DepthStencilState(DepthStencilDescription.Enabled);
        }
コード例 #18
0
ファイル: MyBlur.cs プロジェクト: viktorius/Viktor
        /// <param name="clearColor">Color used to clear render targets. Defaults to black</param>
        internal static void Run(IRtvBindable renderTarget, IRtvTexture intermediate, ISrvBindable initialResourceView,
                                 int maxOffset = 5, MyBlurDensityFunctionType densityFunctionType = MyBlurDensityFunctionType.Gaussian, float WeightParameter = 1.5f,
                                 IDepthStencilState depthStencilState = null, int stencilRef      = 0x0, Color4 clearColor = default(Color4),
                                 float depthDiscardThreshold          = 0.0f, MyViewport?viewport = null)
        {
            ProfilerShort.Begin("MyBlur.Run");
            MyGpuProfiler.IC_BeginBlock("MyBlur.Run");
            Debug.Assert(initialResourceView != null);
            Debug.Assert(intermediate != null);
            Debug.Assert(renderTarget != null);

            int shaderKey = InitShaders(densityFunctionType, maxOffset, depthDiscardThreshold);

            RC.PixelShader.SetConstantBuffer(5, m_blurConstantBuffer);

            BlurConstants constants = new BlurConstants
            {
                DistributionWeight = WeightParameter,
                StencilRef         = stencilRef,
            };
            var mapping = MyMapping.MapDiscard(m_blurConstantBuffer);

            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            // Horizontal pass
            // NOTE: DepthStencilState is not used here because the resulted target
            // would not be usable to perform vertical pass. DepthStencil is stil
            // bindinded as SRV since it is sampled in the shader
            RC.ClearRtv(intermediate, clearColor);
            RC.SetRtv(intermediate);
            RC.PixelShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth);
            RC.PixelShader.SetSrv(4, MyGBuffer.Main.DepthStencil.SrvStencil);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            RC.PixelShader.SetSrv(5, initialResourceView);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item1);
            MyScreenPass.DrawFullscreenQuad(viewport);
            RC.PixelShader.SetSrv(5, null);

            // Vertical pass
            RC.ClearRtv(renderTarget, clearColor);
            if (depthStencilState == null)
            {
                RC.SetRtv(renderTarget);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilRef);
                RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, renderTarget);
            }

            RC.PixelShader.SetSrv(5, intermediate);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item2);
            MyScreenPass.DrawFullscreenQuad(viewport);

            RC.PixelShader.SetSrv(0, null);
            RC.PixelShader.SetSrv(4, null);
            RC.PixelShader.SetSrv(5, null);
            RC.SetRtv(null);

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();
        }
コード例 #19
0
ファイル: DepthStencilState.cs プロジェクト: K0bin/DotGame
        internal void Apply(IDepthStencilState compareTo, int stencilReference)
        {
            if (compareTo != null || this.stencilReference != stencilReference)
            {
                //Depth
                if (compareTo.Info.IsDepthEnabled != Info.IsDepthEnabled)
                {
                    if (Info.IsDepthEnabled)
                        GL.Enable(EnableCap.DepthTest);
                    else
                        GL.Disable(EnableCap.DepthTest);
                }

                if (compareTo.Info.DepthWriteMask != Info.DepthWriteMask)
                    GL.DepthMask(Info.DepthWriteMask == DepthWriteMask.All);


                if (compareTo.Info.DepthComparsion != Info.DepthComparsion)
                    GL.DepthFunc(EnumConverter.Convert(Info.DepthComparsion));

                //Stencil
                if (compareTo.Info.IsStencilEnabled != Info.IsStencilEnabled)
                {
                    if (Info.IsStencilEnabled)
                        GL.Enable(EnableCap.StencilTest);
                    else
                        GL.Disable(EnableCap.StencilTest);
                }

                if (compareTo.Info.StencilWriteMask != Info.StencilWriteMask)
                    GL.StencilMask(Info.StencilWriteMask);


                if (compareTo.Info.FrontFace.Comparsion != Info.FrontFace.Comparsion)
                {
                    GL.StencilFuncSeparate(StencilFace.Front, (StencilFunction)EnumConverter.Convert(Info.FrontFace.Comparsion), stencilReference, Info.StencilWriteMask);
                }
                if (compareTo.Info.FrontFace.DepthFailOperation != Info.FrontFace.DepthFailOperation || compareTo.Info.FrontFace.FailOperation != Info.FrontFace.FailOperation || compareTo.Info.FrontFace.PassOperation != Info.FrontFace.PassOperation)
                {
                    GL.StencilOpSeparate(StencilFace.Front, EnumConverter.Convert(Info.FrontFace.FailOperation), EnumConverter.Convert(Info.FrontFace.DepthFailOperation), EnumConverter.Convert(Info.FrontFace.PassOperation));
                }

                if (compareTo.Info.BackFace.Comparsion != Info.BackFace.Comparsion)
                {
                    GL.StencilFuncSeparate(StencilFace.Back, (StencilFunction)EnumConverter.Convert(Info.BackFace.Comparsion), stencilReference, Info.StencilWriteMask);
                }
                if (compareTo.Info.BackFace.DepthFailOperation != Info.BackFace.DepthFailOperation || compareTo.Info.BackFace.FailOperation != Info.BackFace.FailOperation || compareTo.Info.BackFace.PassOperation != Info.BackFace.PassOperation)
                {
                    GL.StencilOpSeparate(StencilFace.Back, EnumConverter.Convert(Info.BackFace.FailOperation), EnumConverter.Convert(Info.BackFace.DepthFailOperation), EnumConverter.Convert(Info.BackFace.PassOperation));
                }
            }
            else
            {
                //Depth
                if (Info.IsDepthEnabled)
                    GL.Enable(EnableCap.DepthTest);
                else
                    GL.Disable(EnableCap.DepthTest);

                GL.DepthMask(Info.DepthWriteMask == DepthWriteMask.All);

                GL.DepthFunc(EnumConverter.Convert(Info.DepthComparsion));

                //Stencil
                if (Info.IsStencilEnabled)
                    GL.Enable(EnableCap.StencilTest);
                else
                    GL.Disable(EnableCap.StencilTest);

                GL.StencilMask(Info.StencilWriteMask);

                GL.StencilFuncSeparate(StencilFace.Front, (StencilFunction)EnumConverter.Convert(Info.FrontFace.Comparsion), stencilReference, Info.StencilWriteMask);
                GL.StencilOpSeparate(StencilFace.Front, EnumConverter.Convert(Info.FrontFace.FailOperation), EnumConverter.Convert(Info.FrontFace.DepthFailOperation), EnumConverter.Convert(Info.FrontFace.PassOperation));
                GL.StencilFuncSeparate(StencilFace.Back, (StencilFunction)EnumConverter.Convert(Info.BackFace.Comparsion), stencilReference, Info.StencilWriteMask);
                GL.StencilOpSeparate(StencilFace.Back, EnumConverter.Convert(Info.BackFace.FailOperation), EnumConverter.Convert(Info.BackFace.DepthFailOperation), EnumConverter.Convert(Info.BackFace.PassOperation));
            }

            this.stencilReference = stencilReference;
        }
コード例 #20
0
ファイル: MyBlur.cs プロジェクト: rem02/SpaceEngineers
        /// <param name="clearColor">Color used to clear render targets. Defaults to black</param>
        internal static void Run(IRtvBindable renderTarget, IRtvTexture intermediate, ISrvBindable initialResourceView,
            int maxOffset = 5, MyBlurDensityFunctionType densityFunctionType = MyBlurDensityFunctionType.Gaussian, float WeightParameter = 1.5f,
            IDepthStencilState depthStencilState = null, int stencilRef = 0x0, Color4 clearColor = default(Color4),
            float depthDiscardThreshold = 0.0f, MyViewport? viewport = null)
        {
            ProfilerShort.Begin("MyBlur.Run");
            MyGpuProfiler.IC_BeginBlock("MyBlur.Run");
            Debug.Assert(initialResourceView != null);
            Debug.Assert(intermediate != null);
            Debug.Assert(renderTarget != null);

            int shaderKey = InitShaders(densityFunctionType, maxOffset, depthDiscardThreshold);

            RC.PixelShader.SetConstantBuffer(5, m_blurConstantBuffer);

            BlurConstants constants = new BlurConstants
            {
                DistributionWeight = WeightParameter,
                StencilRef = stencilRef,
            };
            var mapping = MyMapping.MapDiscard(m_blurConstantBuffer);
            mapping.WriteAndPosition(ref constants);
            mapping.Unmap();

            // Horizontal pass
            // NOTE: DepthStencilState is not used here because the resulted target
            // would not be usable to perform vertical pass. DepthStencil is stil
            // bindinded as SRV since it is sampled in the shader 
            RC.ClearRtv(intermediate, clearColor);
            RC.SetRtv(intermediate);
            RC.PixelShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth);
            RC.PixelShader.SetSrv(4, MyGBuffer.Main.DepthStencil.SrvStencil);
            RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil);
            RC.PixelShader.SetSrv(5, initialResourceView);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item1);
            MyScreenPass.DrawFullscreenQuad(viewport);
            RC.PixelShader.SetSrv(5, null);

            // Vertical pass
            RC.ClearRtv(renderTarget, clearColor);
            if (depthStencilState == null)
            {
                RC.SetRtv(renderTarget);
            }
            else
            {
                RC.SetDepthStencilState(depthStencilState, stencilRef);
                RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, renderTarget);
            }

            RC.PixelShader.SetSrv(5, intermediate);
            RC.PixelShader.Set(m_blurShaders[shaderKey].Item2);
            MyScreenPass.DrawFullscreenQuad(viewport);

            RC.PixelShader.SetSrv(0, null);
            RC.PixelShader.SetSrv(4, null);
            RC.PixelShader.SetSrv(5, null);
            RC.SetRtv(null);

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();
        }
コード例 #21
0
        /// <summary>
        /// OpenGL States auf DirectX11 default Werte setzen
        /// </summary>
        private void CreateDefaultState()
        {
            IBlendState defaultBlend = graphicsDevice.Factory.CreateBlendState(new BlendStateInfo()
            {
                AlphaToCoverageEnable  = false,
                IndependentBlendEnable = false,
                RenderTargets          = new RTBlendInfo[] {
                    new RTBlendInfo()
                    {
                        IsBlendEnabled        = false,
                        SrcBlend              = Blend.One,
                        DestBlend             = Blend.Zero,
                        BlendOp               = Graphics.BlendOp.Add,
                        SrcBlendAlpha         = Blend.One,
                        DestBlendAlpha        = Blend.Zero,
                        BlendOpAlpha          = BlendOp.Add,
                        RenderTargetWriteMask = ColorWriteMaskFlags.All,
                    }
                },
            });

            IRasterizerState defaultRasterizer = graphicsDevice.Factory.CreateRasterizerState(new RasterizerStateInfo()
            {
                FillMode = FillMode.Solid,
                CullMode = CullMode.None,
                IsFrontCounterClockwise = false,
                DepthBias                = 0,
                SlopeScaledDepthBias     = 0.0f,
                DepthBiasClamp           = 0.0f,
                IsDepthClipEnabled       = true,
                IsScissorEnabled         = true,
                IsMultisampleEnabled     = false,
                IsAntialiasedLineEnabled = false,
            });

            IDepthStencilState defaultDepthStencil = graphicsDevice.Factory.CreateDepthStencilState(new DepthStencilStateInfo()
            {
                IsDepthEnabled   = true,
                DepthWriteMask   = DepthWriteMask.All,
                DepthComparsion  = Comparison.Less,
                IsStencilEnabled = false,
                StencilReadMask  = 0x0,
                StencilWriteMask = 0x0,
                FrontFace        = new DepthStencilOperator()
                {
                    Comparsion         = Comparison.Always,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                },
                BackFace = new DepthStencilOperator()
                {
                    Comparsion         = Comparison.Always,
                    DepthFailOperation = StencilOperation.Keep,
                    PassOperation      = StencilOperation.Keep,
                    FailOperation      = StencilOperation.Keep,
                },
            });

            graphicsDevice.Cast <BlendState>(defaultBlend, "defaultBlend").Apply();
            graphicsDevice.Cast <RasterizerState>(defaultRasterizer, "defaultRasterizer").Apply();
            graphicsDevice.Cast <DepthStencilState>(defaultDepthStencil, "depthStencil").Apply(currentStencilReference);
        }