public override void Initialize() { _rasterStateId = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription { IsAntialiasedLineEnabled = false, CullMode = CullMode.None, DepthBias = 0, DepthBiasClamp = 1f, IsDepthClipEnabled = true, FillMode = FillMode.Solid, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0, }); var blendDescr = new BlendStateDescription { IndependentBlendEnable = false, AlphaToCoverageEnable = false }; for (var i = 0; i < 8; i++) { blendDescr.RenderTarget[i].IsBlendEnabled = false; blendDescr.RenderTarget[i].BlendOperation = BlendOperation.Add; blendDescr.RenderTarget[i].AlphaBlendOperation = BlendOperation.Add; blendDescr.RenderTarget[i].DestinationBlend = BlendOption.InverseSourceAlpha; blendDescr.RenderTarget[i].DestinationAlphaBlend = BlendOption.One; blendDescr.RenderTarget[i].SourceBlend = BlendOption.One; blendDescr.RenderTarget[i].SourceAlphaBlend = BlendOption.One; blendDescr.RenderTarget[i].RenderTargetWriteMask = ColorWriteMaskFlags.All; } _blendStateId = RenderStatesRepo.AddBlendStates(blendDescr); _depthStateId = RenderStatesRepo.AddDepthStencilStates(new DepthStencilStateDescription { IsDepthEnabled = false, DepthComparison = Comparison.Less, DepthWriteMask = DepthWriteMask.All, IsStencilEnabled = false, BackFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep }, FrontFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep } }); }
private void Initialize() { _spriteSamplerWrap = ToDispose(new SamplerState(_d3DEngine.Device, new SamplerStateDescription { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, //Filter = Filter.MinLinearMagMipPoint, Filter = Filter.MinMagMipPoint, // MinMagMipPoint, MaximumLod = float.MaxValue, MinimumLod = 0 })); _spriteSamplerClamp = ToDispose(new SamplerState(_d3DEngine.Device, new SamplerStateDescription { AddressU = TextureAddressMode.Clamp, AddressV = TextureAddressMode.Clamp, AddressW = TextureAddressMode.Clamp, Filter = Filter.MinMagMipPoint, MaximumLod = float.MaxValue, MinimumLod = 0 })); _rasterStateWithoutScissorId = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription { IsAntialiasedLineEnabled = false, CullMode = CullMode.None, DepthBias = 0, DepthBiasClamp = 1f, IsDepthClipEnabled = true, FillMode = FillMode.Solid, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0, }); _rasterStateWithScissorId = RenderStatesRepo.AddRasterStates(new RasterizerStateDescription { IsAntialiasedLineEnabled = false, CullMode = CullMode.None, DepthBias = 0, DepthBiasClamp = 1f, IsDepthClipEnabled = true, FillMode = FillMode.Solid, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = true, SlopeScaledDepthBias = 0, }); var blendDescr = new BlendStateDescription { IndependentBlendEnable = false, AlphaToCoverageEnable = false }; for (var i = 0; i < 8; i++) { blendDescr.RenderTarget[i].IsBlendEnabled = true; blendDescr.RenderTarget[i].BlendOperation = BlendOperation.Add; blendDescr.RenderTarget[i].AlphaBlendOperation = BlendOperation.Maximum; blendDescr.RenderTarget[i].DestinationBlend = BlendOption.InverseSourceAlpha; blendDescr.RenderTarget[i].DestinationAlphaBlend = BlendOption.One; blendDescr.RenderTarget[i].SourceBlend = BlendOption.SourceAlpha; blendDescr.RenderTarget[i].SourceAlphaBlend = BlendOption.One; blendDescr.RenderTarget[i].RenderTargetWriteMask = ColorWriteMaskFlags.All; } _blendStateId = RenderStatesRepo.AddBlendStates(blendDescr); _depthStateWithDepthId = RenderStatesRepo.AddDepthStencilStates(new DepthStencilStateDescription { IsDepthEnabled = true, DepthComparison = Comparison.Less, DepthWriteMask = DepthWriteMask.All, IsStencilEnabled = false, BackFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep }, FrontFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep } }); _depthStateWithoutDepthId = RenderStatesRepo.AddDepthStencilStates(new DepthStencilStateDescription { IsDepthEnabled = false, DepthComparison = Comparison.Less, DepthWriteMask = DepthWriteMask.All, IsStencilEnabled = false, BackFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep }, FrontFace = new DepthStencilOperationDescription { Comparison = Comparison.Always, DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Keep } }); //Create the effect and set the default texture sampler _effect = ToDispose(new HLSLSprites2(_d3DEngine.Device, _withAlphaClip, _shaderFilePath)); //Buffer creation _vb = ToDispose(new VertexBuffer <VertexSprite2>(_d3DEngine.Device, 16, SharpDX.Direct3D.PrimitiveTopology.TriangleList, "SpriteRenderer2 VB", ResourceUsage.Dynamic, 20)); _ib = ToDispose(new IndexBuffer <ushort>(_d3DEngine.Device, 24, "SpriteRenderer2 IB", 20, ResourceUsage.Dynamic)); //Sprite buffer creation _spriteBuffer = new SpriteDrawBuffer(); }
private static void CreateBlendStatesCollection() { BlendStateDescription BlendDescr; //Blender.Enabled BlendDescr = new BlendStateDescription(); BlendDescr.IndependentBlendEnable = false; BlendDescr.AlphaToCoverageEnable = false; for (int i = 0; i < 8; i++) { BlendDescr.RenderTarget[i].IsBlendEnabled = true; BlendDescr.RenderTarget[i].SourceBlend = BlendOption.SourceAlpha; BlendDescr.RenderTarget[i].DestinationBlend = BlendOption.InverseSourceAlpha; BlendDescr.RenderTarget[i].BlendOperation = BlendOperation.Add; BlendDescr.RenderTarget[i].SourceAlphaBlend = BlendOption.One; BlendDescr.RenderTarget[i].DestinationAlphaBlend = BlendOption.One; BlendDescr.RenderTarget[i].AlphaBlendOperation = BlendOperation.Add; BlendDescr.RenderTarget[i].RenderTargetWriteMask = ColorWriteMaskFlags.All; } Blenders.Enabled = RenderStatesRepo.AddBlendStates(BlendDescr); //Blender.Disabled BlendDescr = new BlendStateDescription(); BlendDescr.IndependentBlendEnable = false; BlendDescr.AlphaToCoverageEnable = false; for (int i = 0; i < 8; i++) { BlendDescr.RenderTarget[i].IsBlendEnabled = false; BlendDescr.RenderTarget[i].SourceBlend = BlendOption.SourceAlpha; BlendDescr.RenderTarget[i].DestinationBlend = BlendOption.InverseSourceAlpha; BlendDescr.RenderTarget[i].BlendOperation = BlendOperation.Add; BlendDescr.RenderTarget[i].SourceAlphaBlend = BlendOption.One; BlendDescr.RenderTarget[i].DestinationAlphaBlend = BlendOption.One; BlendDescr.RenderTarget[i].AlphaBlendOperation = BlendOperation.Add; BlendDescr.RenderTarget[i].RenderTargetWriteMask = ColorWriteMaskFlags.All; } Blenders.Disabled = RenderStatesRepo.AddBlendStates(BlendDescr); //Blender.Sprite BlendDescr = new BlendStateDescription(); BlendDescr.IndependentBlendEnable = false; BlendDescr.AlphaToCoverageEnable = false; for (int i = 0; i < 8; i++) { BlendDescr.RenderTarget[i].IsBlendEnabled = true; BlendDescr.RenderTarget[i].BlendOperation = BlendOperation.Add; BlendDescr.RenderTarget[i].AlphaBlendOperation = BlendOperation.Add; BlendDescr.RenderTarget[i].DestinationBlend = BlendOption.InverseSourceAlpha; BlendDescr.RenderTarget[i].DestinationAlphaBlend = BlendOption.One; BlendDescr.RenderTarget[i].SourceBlend = BlendOption.One; BlendDescr.RenderTarget[i].SourceAlphaBlend = BlendOption.One; BlendDescr.RenderTarget[i].RenderTargetWriteMask = ColorWriteMaskFlags.All; } Blenders.Sprite = RenderStatesRepo.AddBlendStates(BlendDescr); //Blender.AlphaToCoverage BlendDescr = new BlendStateDescription(); BlendDescr.IndependentBlendEnable = false; BlendDescr.AlphaToCoverageEnable = true; for (int i = 0; i < 8; i++) { BlendDescr.RenderTarget[i].IsBlendEnabled = false; BlendDescr.RenderTarget[i].SourceBlend = BlendOption.SourceAlpha; BlendDescr.RenderTarget[i].DestinationBlend = BlendOption.InverseSourceAlpha; BlendDescr.RenderTarget[i].BlendOperation = BlendOperation.Add; BlendDescr.RenderTarget[i].SourceAlphaBlend = BlendOption.One; BlendDescr.RenderTarget[i].DestinationAlphaBlend = BlendOption.One; BlendDescr.RenderTarget[i].AlphaBlendOperation = BlendOperation.Add; BlendDescr.RenderTarget[i].RenderTargetWriteMask = ColorWriteMaskFlags.All; } Blenders.AlphaToCoverage = RenderStatesRepo.AddBlendStates(BlendDescr); }