private void CreateLogicalInvert() { BlendStateDescription1 bs = new BlendStateDescription1() { AlphaToCoverageEnable = false, IndependentBlendEnable = false, }; for (int i = 0; i < 8; i++) { bs.RenderTarget[i] = new RenderTargetBlendDescription1() { IsBlendEnabled = false, IsLogicOperationEnabled = true, LogicOperation = SharpDX.Direct3D11.LogicOperation.Invert, RenderTargetWriteMask = ColorWriteMaskFlags.All, }; } //Some cards have partial dx11.1 support try { this.LogicalInvert = new BlendState1(this.device.Device, bs); this.AddState("LogicalInvert", this.LogicalInvert); } catch { } }
private void CreateD3D_rDto(string assetUrl) { RenderDTO rDto = new RenderDTO(); rDto.D3DPrimitiveDTO = new D3DPrimitiveDTO(); //SafeDispose(ref rDto.D3DPrimitiveDTO.VertexBuffer); //rDto.D3DPrimitiveDTO.IsRenderable = true; // Remove previous buffer //SafeDispose(ref rDto.D3DPrimitiveDTO.ConstantBuffer); // Setup local variables var d3dDevice = _deviceManager.DeviceDirect3D; var d3dContext = _deviceManager.ContextDirect3D; var d2dDevice = _deviceManager.DeviceDirect2D; var d2dContext = _deviceManager.ContextDirect2D; var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path; // Loads vertex shader bytecode var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_VS.fxo"); rDto.D3DPrimitiveDTO.VertexShader = new VertexShader(d3dDevice, vertexShaderByteCode); // Loads pixel shader bytecode rDto.D3DPrimitiveDTO.PixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_PS.fxo")); // Layout from VertexShader input signature rDto.D3DPrimitiveDTO.Layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0) }); // Instantiate Vertex buffer from vertex data float thicknessToUse = 0.15f; thicknessToUse = 1.0f; //project.Thickness; rDto.D3DPrimitiveDTO.VertexCount = 36; //6 * 6 rDto.D3DPrimitiveDTO.VertexBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, sizeof(float) * 6, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0)); rDto.D3DPrimitiveDTO.VertexBuffer = GenerateVertexBuffer6Sided(d3dDevice, thicknessToUse); //vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0); rDto.D3DPrimitiveDTO.VertexBufferBinding = new VertexBufferBinding(rDto.D3DPrimitiveDTO.VertexBuffer, sizeof(float) * 6, 0); // Create Constant Buffer rDto.D3DPrimitiveDTO.ConstantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0)); //TextureView RenderD3DDto(assetUrl, rDto); rDto.D3DPrimitiveDTO.Sampler = new SamplerState(d3dDevice, new SamplerStateDescription() { Filter = Filter.MinMagMipLinear, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = Color.Black, ComparisonFunction = Comparison.Never, MaximumAnisotropy = 16, MipLodBias = 0, MinimumLod = 0, MaximumLod = 16, }); BlendStateDescription1 blendDesc = new BlendStateDescription1(); blendDesc.AlphaToCoverageEnable = true; //set to true to get nice blending betweent sprites blendDesc.IndependentBlendEnable = false; blendDesc.RenderTarget[0].IsBlendEnabled = false; blendDesc.RenderTarget[0].IsLogicOperationEnabled = false; blendDesc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; blendDesc.RenderTarget[0].DestinationBlend = BlendOption.SourceAlphaSaturate; blendDesc.RenderTarget[0].BlendOperation = BlendOperation.Maximum; blendDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; blendDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; blendDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Maximum; // set to maximum to blend 2 sprites nicely over each other blendDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; rDto.D3DPrimitiveDTO.BlendState = new BlendState1(d3dDevice, blendDesc); _renderTree.Add(rDto); }
/// <summary> /// Constructs a new <see cref = "T:SharpDX.Direct3D10.BlendState1" /> based on the specified description. /// </summary> /// <param name = "device">The device with which to associate the state object.</param> /// <param name = "description">The state description.</param> /// <returns>The newly created object.</returns> public BlendState1(Device1 device, ref BlendStateDescription1 description) : base(IntPtr.Zero) { device.CreateBlendState1(ref description, this); }
public void Initialize(Device1 d3dDevice, DeviceContext1 d3dContext, int capacity = 1024) { m_d3dDevice = d3dDevice; m_d3dContext = d3dContext; m_capacity = capacity; var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path; var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\Assets\\SpriteBatch.vs.cso"); m_vertexShader = new VertexShader(m_d3dDevice, vertexShaderByteCode); m_pixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\Assets\\SpriteBatch.ps.cso")); // Layout from VertexShader input signature m_layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[] { new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 16, 0), new InputElement("COLOR", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 24, 0), }); SamplerStateDescription samplerDesc = SharpDX.Direct3D11.SamplerStateDescription.Default(); m_sampler = new SamplerState(d3dDevice, samplerDesc); //BlendStateDescription1 blendDesc = new BlendStateDescription1(); //blendDesc.AlphaToCoverageEnable = true; //set to true to get nice blending betweent sprites //blendDesc.IndependentBlendEnable = false; //blendDesc.RenderTarget[0].IsBlendEnabled = true; //blendDesc.RenderTarget[0].IsLogicOperationEnabled = false; //blendDesc.RenderTarget[0].SourceBlend = BlendOption.SourceColor; //blendDesc.RenderTarget[0].DestinationBlend = BlendOption.SourceAlphaSaturate; //blendDesc.RenderTarget[0].BlendOperation = BlendOperation.Add; //blendDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; //blendDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One //blendDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Maximum; // set to maximum to blend 2 sprites nicely over each other //blendDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; //m_blendStateAlpha = new BlendState1(d3dDevice, blendDesc); var description = BlendStateDescription1.Default(); description.RenderTarget[0].IsBlendEnabled = true; description.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; description.RenderTarget[0].DestinationBlend = BlendOption.One; description.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha; description.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; description.RenderTarget[0].BlendOperation = BlendOperation.Add; description.RenderTarget[0].IsLogicOperationEnabled = false; description.RenderTarget[0].AlphaBlendOperation = BlendOperation.Maximum; description.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; description.AlphaToCoverageEnable = true; //<==RT DOES NOT WORK description.IndependentBlendEnable = false; m_blendStateAlpha = new BlendState1(d3dDevice, description); //[BELOW] Windows RT this does not work //var description = BlendStateDescription1.Default(); //description.RenderTarget[0].IsBlendEnabled = true; //description.RenderTarget[0].SourceBlend = BlendOption.SourceColor; //description.RenderTarget[0].DestinationBlend = BlendOption.SourceAlphaSaturate; //description.RenderTarget[0].SourceAlphaBlend = BlendOption.One; //description.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; //description.RenderTarget[0].BlendOperation = BlendOperation.Add; //description.RenderTarget[0].IsLogicOperationEnabled = false; //description.RenderTarget[0].AlphaBlendOperation = BlendOperation.Maximum; //description.AlphaToCoverageEnable = true; //description.IndependentBlendEnable = false; //description.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; //m_blendStateAlpha = new BlendState1(d3dDevice, description); m_constantBufferVS = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0)); m_constantBufferPS = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0)); //======================= // Setup the pipeline //======================= m_vertices = ToDispose(BuildVerticesBuffer(d3dDevice, 1.0f, new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1))); m_vertexBufferBinding = new VertexBufferBinding(m_vertices, sizeof(float) * 10, 0); d3dContext.InputAssembler.SetVertexBuffers(0, m_vertexBufferBinding); d3dContext.InputAssembler.InputLayout = m_layout; d3dContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList; d3dContext.VertexShader.SetConstantBuffer(0, m_constantBufferVS); d3dContext.VertexShader.Set(m_vertexShader); d3dContext.PixelShader.SetConstantBuffer(0, m_constantBufferPS); d3dContext.PixelShader.SetSampler(0, m_sampler); d3dContext.PixelShader.Set(m_pixelShader); d3dContext.OutputMerger.BlendState = m_blendStateAlpha; // m_blendStateAlpha, m_blendStateAdditive; }