public GrassRendrer(Form1 F) : base(F.Device) { this.P = F; this.CallFrequency = STDCallFrequencys.Always; E3 = new EffectWrapper("Grass_Mesh.fx", D); BlendStateDescription bsd = new BlendStateDescription() { AlphaToCoverageEnable = true, IndependentBlendEnable = false, }; RenderTargetBlendDescription rtbd = new RenderTargetBlendDescription() { BlendEnable = true, BlendOperation = BlendOperation.Add, BlendOperationAlpha = BlendOperation.Add, RenderTargetWriteMask = ColorWriteMaskFlags.All, DestinationBlend = BlendOption.InverseSourceAlpha, SourceBlend = BlendOption.SourceAlpha, SourceBlendAlpha = BlendOption.Zero, DestinationBlendAlpha = BlendOption.One }; bsd.RenderTargets[0] = rtbd; bsd0 = BlendState.FromDescription(D.HadrwareDevice(), bsd); StaticVertex[] vs = new StaticVertex[100]; mBuffer = new DynamicMeshBuffer<StaticVertex>(D, PrimitiveTopology.PointList); mBuffer.Write(vs); }
/// <summary> /// Create a label renderer. /// </summary> /// <param name="maxCharCount">Max char count to display for this label. Careful to set this value because greater <paramref name="maxCharCount"/> means more space ocupied in GPU nemory.</param> /// <param name="labelHeight">Label height(in pixels)</param> /// <param name="fontTexture">Use which font to render text?</param> /// <returns></returns> public static LabelRenderer Create(int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null) { if (fontTexture == null) { fontTexture = FontTexture.Default; } var model = new TextModel(maxCharCount); var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile( @"Resources\Label.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile( @"Resources\Label.frag"), ShaderType.FragmentShader); var map = new AttributeMap(); map.Add("in_Position", TextModel.strPosition); map.Add("in_UV", TextModel.strUV); var blendState = new BlendState(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.One); var renderer = new LabelRenderer(model, shaderCodes, map, blendState); renderer.blendState = blendState; renderer.fontTexture = fontTexture; renderer.LabelHeight = labelHeight; return renderer; }
public void Affect(GraphicsDevice device, BlendState currentState) { BlendState internalState = new BlendState(); // ColorSourceBlend internalState.ColorSourceBlend = ColorSourceBlend.HasValue ? ColorSourceBlend.Value : currentState.ColorSourceBlend; // ColorDestinationBlend internalState.ColorDestinationBlend = ColorDestinationBlend.HasValue ? ColorDestinationBlend.Value : currentState.ColorDestinationBlend; // ColorBlendFunction internalState.ColorBlendFunction = ColorBlendFunction.HasValue ? ColorBlendFunction.Value : currentState.ColorBlendFunction; // AlphaSourceBlend internalState.AlphaSourceBlend = AlphaSourceBlend.HasValue ? AlphaSourceBlend.Value : currentState.AlphaSourceBlend; // AlphaDestinationBlend internalState.AlphaDestinationBlend = AlphaDestinationBlend.HasValue ? AlphaDestinationBlend.Value : currentState.AlphaDestinationBlend; // AlphaBlendFunction internalState.AlphaBlendFunction = AlphaBlendFunction.HasValue ? AlphaBlendFunction.Value : currentState.AlphaBlendFunction; // ColorWriteChannels internalState.ColorWriteChannels = ColorWriteChannels.HasValue ? ColorWriteChannels.Value : currentState.ColorWriteChannels; // BlendFactor internalState.BlendFactor = BlendFactor.HasValue ? BlendFactor.Value : currentState.BlendFactor; // MultiSampleMask internalState.MultiSampleMask = MultiSampleMask.HasValue ? MultiSampleMask.Value : currentState.MultiSampleMask; // Finally apply the state device.BlendState = internalState; }
public static void Register() { style = Settings.GetChoice("style"); OnScreenInterface.Register(new OSIBossHPBar(),OnScreenInterface.LAYER_INTERFACE_SCREEN); if (style == "circular_bottomleft") { dss1 = new DepthStencilState { StencilEnable = true, StencilFunction = CompareFunction.Equal, StencilPass = StencilOperation.Increment, ReferenceStencil = 0, DepthBufferEnable = false, }; bs1 = new BlendState(); bs1.ColorWriteChannels = ColorWriteChannels.None; dss2 = new DepthStencilState { StencilEnable = true, StencilFunction = CompareFunction.NotEqual, StencilPass = StencilOperation.Keep, ReferenceStencil = 0, DepthBufferEnable = false, }; rt = new RenderTarget2D( Config.mainInstance.graphics.GraphicsDevice, 1920, 96, false,Config.mainInstance.graphics.GraphicsDevice.DisplayMode.Format,DepthFormat.Depth24Stencil8 ); sb = new SpriteBatch(Config.mainInstance.graphics.GraphicsDevice); } }
public SpriteBatch(BlendState state) { texDst = new Rectangle(); texSrc = new Rectangle(); origin = new Vector2(); lastBlendState = state; }
public void UpdateBlendState(BlendState state) { if (state == BlendState) return; mContext.Context.OutputMerger.BlendState = state.Native; BlendState = state; }
public Mesh(GxContext context) { mContext = context; VertexBuffer = new VertexBuffer(context); IndexBuffer = new IndexBuffer(context); DepthState = new DepthState(context); RasterizerState = new RasterState(context); BlendState = new BlendState(context); }
public BlendStateChangeCommand(RenderTargetBlendDescription bStateDesc) : base(CommandType.BlendStateChange) { CommandAttributes |= CommandAttributes.MonoRendering; Description = bStateDesc; blendStateDescription = new BlendStateDescription(); blendStateDescription.RenderTargets[0] = Description; blendState = BlendState.FromDescription(Game.Context.Device, blendStateDescription); }
public void Begin(TextureAtlas atlas, Camera camera) { if (_beginCalled) throw new Exception("Begin called twice without a call to end."); _atlas = atlas; _camera = camera; _blendState = BlendState.AlphaBlend; _sortMode = SpriteSortMode.None; _beginCalled = true; }
/// <summary> /// Initializes a new instance of the <see cref="SpriteBatchState"/> structure. /// </summary> /// <param name="sortMode">The sprite batch's sort mode.</param> /// <param name="blendState">The sprite batch's blend state.</param> /// <param name="samplerState">The sprite batch's sampler state.</param> /// <param name="rasterizerState">The sprite batch's rasterizer state.</param> /// <param name="depthStencilState">The sprite batch's depth/stencil state.</param> /// <param name="effect">The sprite batch's custom effect.</param> /// <param name="transformMatrix">The sprite batch's transformation matrix.</param> public SpriteBatchState(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, RasterizerState rasterizerState, DepthStencilState depthStencilState, Effect effect, Matrix transformMatrix) { this.sortMode = sortMode; this.blendState = blendState; this.samplerState = samplerState; this.rasterizerState = rasterizerState; this.depthStencilState = depthStencilState; this.customEffect = effect; this.transformMatrix = transformMatrix; }
internal EffectPass(Effect effect, EffectPass cloneSource) { this._effect = effect; this.Name = cloneSource.Name; this._blendState = cloneSource._blendState; this._depthStencilState = cloneSource._depthStencilState; this._rasterizerState = cloneSource._rasterizerState; this.Annotations = cloneSource.Annotations; this._vertexShader = cloneSource._vertexShader; this._pixelShader = cloneSource._pixelShader; }
internal EffectPass(Effect effect, string name, Shader vertexShader, Shader pixelShader, BlendState blendState, DepthStencilState depthStencilState, RasterizerState rasterizerState, EffectAnnotationCollection annotations) { this._effect = effect; this.Name = name; this._vertexShader = vertexShader; this._pixelShader = pixelShader; this._blendState = blendState; this._depthStencilState = depthStencilState; this._rasterizerState = rasterizerState; this.Annotations = annotations; this.Initialize(); }
/// <summary> /// Initializes a new instance of the StateFactory /// </summary> /// <param name="device"></param> /// <param name="ubershader"></param> private StateFactory ( Ubershader ubershader, Type enumType, Primitive primitive, VertexInputElement[] vertexInputElements, BlendState blendState, RasterizerState rasterizerState ) : base(ubershader.GraphicsDevice) { this.ubershader = ubershader; Enumerate( enumType, ubershader, (ps,i) => { ps.Primitive = primitive; ps.VertexInputElements = vertexInputElements; ps.BlendState = blendState; ps.RasterizerState = rasterizerState; } ); }
static BlendState() { Opaque = Create(); NoWrite = Create( ColorChannels.None ); AlphaBlend = Create( ColorChannels.All, Blend.SrcAlpha, Blend.InvSrcAlpha ); AlphaBlendPremul = Create( ColorChannels.All, Blend.One, Blend.InvSrcAlpha ); AlphaMaskWrite = Create( ColorChannels.Alpha ); AlphaOnly = Create( ColorChannels.Alpha ); Additive = Create( ColorChannels.All, Blend.One, Blend.One, Blend.One, Blend.One ); Screen = Create( ColorChannels.All, Blend.InvDstColor, Blend.One ); Multiply = Create( ColorChannels.All, Blend.Zero, Blend.SrcColor ); NegMultiply = Create( ColorChannels.All, Blend.Zero, Blend.InvSrcColor ); }
public void Finish() { BlendState blendState = new BlendState(); blendState.AlphaDestinationBlend = Blend.SourceColor; blendState.ColorDestinationBlend = Blend.SourceColor; blendState.AlphaSourceBlend = Blend.Zero; blendState.ColorSourceBlend = Blend.Zero; //Draw the additional RenderTarget2D on top of the back buffer. spriteBatch.Begin(SpriteSortMode.Deferred, blendState, null, null, null); spriteBatch.Draw(this.lightTarget, Vector2.Zero, Color.White); //spriteBatch.Draw(this.debugTarget, Vector2.Zero, Color.White); spriteBatch.End(); }
/// <summary> /// Creates new instance of blend state /// </summary> /// <param name="mask"></param> /// <param name="src"></param> /// <param name="dst"></param> /// <param name="srcA"></param> /// <param name="dstA"></param> public static BlendState Create ( ColorChannels mask=ColorChannels.All, Blend src = Blend.One, Blend dst = Blend.Zero, Blend srcA = Blend.One, Blend dstA = Blend.Zero ) { BlendState bs = new BlendState(); bs.SrcColor = src; bs.DstColor = dst; bs.SrcAlpha = srcA; bs.DstAlpha = dstA; bs.ColorOp = BlendOp.Add; bs.AlphaOp = BlendOp.Add; bs.WriteMask = mask; bs.MultiSampleMask = -1; bs.BlendFactor = new Color4(0,0,0,0); return bs; }
/// <summary> /// Initializes device dependant resources. /// </summary> private void Initialize() { var device = m_directCanvasFactory.DeviceContext.Device; /* Here we create a new sampler for sampling input within * our pixel shader */ var sampDesc = new SamplerDescription(); sampDesc.AddressU = TextureAddressMode.Clamp; sampDesc.AddressV = TextureAddressMode.Clamp; sampDesc.AddressW = TextureAddressMode.Clamp; sampDesc.BorderColor = new Color4(0, 0, 0, 0).InternalColor4; sampDesc.ComparisonFunction = Comparison.Never; sampDesc.Filter = Filter.MinMagMipLinear; sampDesc.MaximumAnisotropy = 10; sampDesc.MaximumLod = float.MaxValue; sampDesc.MinimumLod = 0; sampDesc.MipLodBias = 0; m_linearSamplerState = SamplerState.FromDescription(device, sampDesc); sampDesc.Filter = Filter.MinMagMipPoint; m_pointSamplerState = SamplerState.FromDescription(device, sampDesc); /* Here we have a hard coded blend state. This should be configurable in * the future. Like the composer has */ var blendDesc = new BlendStateDescription(); blendDesc.IsAlphaToCoverageEnabled = false; blendDesc.BlendOperation = BlendOperation.Add; blendDesc.AlphaBlendOperation = BlendOperation.Add; blendDesc.DestinationBlend = BlendOption.InverseSourceAlpha; blendDesc.DestinationAlphaBlend = BlendOption.One; blendDesc.SourceBlend = BlendOption.One; blendDesc.SourceAlphaBlend = BlendOption.One; for (uint i = 0; i < 8; i++) { blendDesc.SetWriteMask(i, ColorWriteMaskFlags.All); blendDesc.SetBlendEnable(i, true); } m_alphaBlendState = BlendState.FromDescription(device, blendDesc); }
public LNSprite(string fsName) : base() { this._ans = null; LNFrameStruct struc0 = LNDataCache.GetFrameStruct(fsName); if (struc0 == null) { throw new Exception(""); } this._texture = struc0._texture; base._left = struc0._textCoords.X(); base._top = struc0._textCoords.Y(); base._orig_width = struc0._orig_width; base._orig_height = struc0._orig_height; base.SetNodeSize(struc0._size_width, struc0._size_height); base._anchor.Set(struc0._anchor); blendState = struc0._state; if (!struc0._place.Equals(0, 0)) { SetPosition(struc0._place); } }
private void Submit(BlendState state,bool only) { if (idx == 0) { return; } lock (typeof(SpriteBatch)) { renderCalls++; totalRenderCalls++; int spritesInBatch = idx / 20; if (spritesInBatch > maxSpritesInBatch) { maxSpritesInBatch = spritesInBatch; } SetBlendState(state); if (only) { GLEx.GL.GLOnlyBind(lastTexture); } else { GLEx.GL.GLBind(lastTexture); } GLEx.GL.Submit(GL10.GL_TRIANGLE_FAN, idx, vertices, indices, null); System.Array.Clear(vertices, 0, idx); idx = 0; } }
public void CreateDeviceDependentResourcesAsync(DeviceResources deviceResources) { float scaleFactor = 0.00025f; var image = TextureLoader.LoadBitmap(new SharpDX.WIC.ImagingFactory2(), spriteImg); var height = image.Size.Height * scaleFactor; var width = image.Size.Width * scaleFactor; BlendStateDescription blendSdesc = new BlendStateDescription(); blendSdesc.IndependentBlendEnable = false; blendSdesc.AlphaToCoverageEnable = false; blendSdesc.RenderTarget[0].IsBlendEnabled = true; blendSdesc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; blendSdesc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; blendSdesc.RenderTarget[0].BlendOperation = BlendOperation.Maximum; blendSdesc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; blendSdesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; blendSdesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; blendSdesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; BlendState blendS = new BlendState(deviceResources.D3DDevice, blendSdesc); deviceResources.D3DDeviceContext.OutputMerger.SetBlendState(blendS); // Load mesh vertices. Each vertex has a position and a color. // Note that the cube size has changed from the default DirectX app // template. Windows Holographic is scaled in meters, so to draw the // cube at a comfortable size we made the cube width 0.2 m (20 cm). VertexPositionTexture[] cubeVertices = { new VertexPositionTexture(new Vector3(0f, -1f * height, -1f * width), new Vector2(0.0f, 1.0f)), new VertexPositionTexture(new Vector3(0f, -1f * height, 1f * width), new Vector2(1.0f, 1.0f)), new VertexPositionTexture(new Vector3(0f, 1f * height, -1f * width), new Vector2(0.0f, 0.0f)), new VertexPositionTexture(new Vector3(0f, 1f * height, 1f * width), new Vector2(1.0f, 0.0f)) }; vertexBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create( deviceResources.D3DDevice, SharpDX.Direct3D11.BindFlags.VertexBuffer, cubeVertices)); // Load mesh indices. Each trio of indices represents // a triangle to be rendered on the screen. // For example: 0,2,1 means that the vertices with indexes // 0, 2 and 1 from the vertex buffer compose the // first triangle of this mesh. ushort[] cubeIndices = { 2, 1, 0, // -x 2, 3, 1, //back face 2, 0, 1, // -x 2, 1, 3, }; indexCount = cubeIndices.Length; indexBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create( deviceResources.D3DDevice, SharpDX.Direct3D11.BindFlags.IndexBuffer, cubeIndices)); // Create a constant buffer to store the model matrix. modelConstantBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create( deviceResources.D3DDevice, SharpDX.Direct3D11.BindFlags.ConstantBuffer, ref modelConstantBufferData)); //Load the image var texture = TextureLoader.CreateTexture2DFromBitmap(deviceResources.D3DDevice, image); ShaderResourceView textureView = new ShaderResourceView(deviceResources.D3DDevice, texture); deviceResources.D3DDeviceContext.PixelShader.SetShaderResource(0, textureView); //Load the sampler SamplerStateDescription samplerDesc = new SamplerStateDescription(); samplerDesc.AddressU = TextureAddressMode.Wrap; samplerDesc.AddressV = TextureAddressMode.Wrap; samplerDesc.AddressW = TextureAddressMode.Wrap; samplerDesc.ComparisonFunction = Comparison.Never; samplerDesc.Filter = Filter.MinMagMipLinear; samplerDesc.MaximumLod = float.MaxValue; SamplerState sampler = new SamplerState(deviceResources.D3DDevice, samplerDesc); deviceResources.D3DDeviceContext.PixelShader.SetSampler(0, sampler); }
private void InitalizeGraphics() { if (Window.RenderCanvasHandle == IntPtr.Zero) throw new InvalidOperationException(); SwapChainDescription swapChainDesc = new SwapChainDescription() { BufferCount = 1, Flags = SwapChainFlags.None, IsWindowed = true, OutputHandle = Window.RenderCanvasHandle, SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput, ModeDescription = new ModeDescription() { Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm, //Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm, Width = (int)Window.RenderCanvasSize.Width, Height = (int)Window.RenderCanvasSize.Height, RefreshRate = new Rational(60, 1), Scaling = DisplayModeScaling.Unspecified, ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified }, SampleDescription = new SampleDescription(1, 0) }; var giFactory = new SlimDX.DXGI.Factory(); var adapter = giFactory.GetAdapter(0); Device device; SwapChain swapChain; Device.CreateWithSwapChain(adapter, DriverType.Hardware, DeviceCreationFlags.Debug, swapChainDesc, out device, out swapChain); _swapChain = swapChain; GraphicsDevice = device; // create a view of our render target, which is the backbuffer of the swap chain we just created using (var resource = SlimDX.Direct3D10.Resource.FromSwapChain<Texture2D>(swapChain, 0)) { _backBuffer = new RenderTargetView(device, resource); } // setting a viewport is required if you want to actually see anything var viewport = new Viewport(0, 0, (int)Window.RenderCanvasSize.Width, (int)Window.RenderCanvasSize.Height); device.OutputMerger.SetTargets(_backBuffer); device.Rasterizer.SetViewports(viewport); CreateDepthStencil(); LoadVisualizationEffect(); // Allocate a large buffer to write the PhysX visualization vertices into // There's more optimized ways of doing this, but for this sample a large buffer will do _userPrimitivesBuffer = new SlimDX.Direct3D10.Buffer(GraphicsDevice, VertexPositionColor.SizeInBytes * 50000, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None); var elements = new[] { new InputElement("Position", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("Color", 0, Format.R32G32B32A32_Float, 16, 0) }; _inputLayout = new InputLayout(GraphicsDevice, _visualizationEffect.RenderScenePass0.Description.Signature, elements); // States var blendDesc = new BlendStateDescription() { SourceBlend = BlendOption.One, DestinationBlend = BlendOption.Zero, BlendOperation = BlendOperation.Add, SourceAlphaBlend = BlendOption.One, DestinationAlphaBlend = BlendOption.Zero, AlphaBlendOperation = BlendOperation.Add }; blendDesc.SetBlendEnable(0, true); _blendState = BlendState.FromDescription(device, blendDesc); var rasterDesc = new RasterizerStateDescription() { IsAntialiasedLineEnabled = false, IsMultisampleEnabled = false, FillMode = FillMode.Solid, CullMode = CullMode.None }; _rasterizerState = RasterizerState.FromDescription(device, rasterDesc); }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ void PushRequest( CameraCtrl _cameraCtrl, float _weight, float _duration ) { BlendState blendState = null; for ( int i = 0; i < blendRequestList.Count; ++i ) { BlendState curBlendState = blendRequestList[i]; if ( curBlendState.target == _cameraCtrl ) { blendState = curBlendState; break; } } if ( blendState == null ) { blendState = new BlendState( _cameraCtrl, _weight, _duration ); blendRequestList.Add(blendState); } else { blendState.destWeight = _weight; blendState.duration = _duration; } }
public static void Initialize(GxContext context) { gDepthWriteState = new DepthState(context) { DepthEnabled = true, DepthWriteEnabled = true }; gDepthNoWriteState = new DepthState(context) { DepthEnabled = true, DepthWriteEnabled = false }; gMesh = new Mesh(context) { Stride = IO.SizeCache <M2Vertex> .Size, DepthState = gDepthNoWriteState }; gMesh.BlendState.Dispose(); gMesh.IndexBuffer.Dispose(); gMesh.VertexBuffer.Dispose(); gMesh.BlendState = null; gMesh.IndexBuffer = null; gMesh.VertexBuffer = null; gMesh.AddElement("POSITION", 0, 3); gMesh.AddElement("BLENDWEIGHT", 0, 4, DataType.Byte, true); gMesh.AddElement("BLENDINDEX", 0, 4, DataType.Byte); gMesh.AddElement("NORMAL", 0, 3); gMesh.AddElement("TEXCOORD", 0, 2); gMesh.AddElement("TEXCOORD", 1, 2); // all combinations are set in this one each time gCustomProgram = new ShaderProgram(context); gCustomProgram.SetVertexShader(Resources.Shaders.M2VertexSingle_VS_Diffuse_T1); gCustomProgram.SetPixelShader(Resources.Shaders.M2Pixel_PS_Combiners_Mod); gMesh.Program = gCustomProgram; gNoBlendProgram = new ShaderProgram(context); gNoBlendProgram.SetPixelShader(Resources.Shaders.M2PixelOld); gNoBlendProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); gBlendProgram = new ShaderProgram(context); gBlendProgram.SetPixelShader(Resources.Shaders.M2PixelBlendOld); gBlendProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); gBlendTestProgram = new ShaderProgram(context); gBlendTestProgram.SetPixelShader(Resources.Shaders.M2PixelBlendAlphaOld); gBlendTestProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); g2PassProgram = new ShaderProgram(context); g2PassProgram.SetPixelShader(Resources.Shaders.M2Pixel2PassOld); g2PassProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); g3PassProgram = new ShaderProgram(context); g3PassProgram.SetPixelShader(Resources.Shaders.M2Pixel3PassOld); g3PassProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); gPerDrawCallBuffer = new ConstantBuffer(context); gPerDrawCallBuffer.UpdateData(new PerDrawCallBuffer() { instanceMat = Matrix.Identity }); gPerPassBuffer = new ConstantBuffer(context); gPerPassBuffer.UpdateData(new PerModelPassBuffer() { uvAnimMatrix1 = Matrix.Identity, uvAnimMatrix2 = Matrix.Identity, uvAnimMatrix3 = Matrix.Identity, uvAnimMatrix4 = Matrix.Identity, modelPassParams = Vector4.Zero }); gSamplerWrapU = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressV = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16 }; gSamplerWrapV = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressV = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16 }; gSamplerWrapBoth = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressV = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16 }; gSamplerClampBoth = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressV = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16 }; for (var i = 0; i < BlendStates.Length; ++i) { BlendStates[i] = new BlendState(context); } BlendStates[0] = new BlendState(context) { BlendEnabled = false }; BlendStates[1] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.One, DestinationBlend = SharpDX.Direct3D11.BlendOption.Zero, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.One, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.Zero }; BlendStates[2] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha }; BlendStates[3] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceColor, DestinationBlend = SharpDX.Direct3D11.BlendOption.DestinationColor, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.DestinationAlpha }; BlendStates[4] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationBlend = SharpDX.Direct3D11.BlendOption.One, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.One }; BlendStates[5] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha }; BlendStates[6] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.DestinationColor, DestinationBlend = SharpDX.Direct3D11.BlendOption.SourceColor, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.DestinationAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha }; gNoCullState = new RasterState(context) { CullEnabled = false }; gCullState = new RasterState(context) { CullEnabled = true }; }
void Attach() { disposer = new DisposeGroup(); var device = Renderer.Device; string noteShaderData; var assembly = Assembly.GetExecutingAssembly(); using (var stream = assembly.GetManifestResourceStream("Iris.Previews.DX11.notes.fx")) using (var reader = new IO.StreamReader(stream)) noteShaderData = reader.ReadToEnd(); notesShader = disposer.Add(new ShaderManager( device, ShaderBytecode.Compile(noteShaderData, "VS_Note", "vs_4_0", ShaderFlags.None, EffectFlags.None), ShaderBytecode.Compile(noteShaderData, "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None), ShaderBytecode.Compile(noteShaderData, "GS_Note", "gs_4_0", ShaderFlags.None, EffectFlags.None) )); noteLayout = disposer.Add(new InputLayout(device, ShaderSignature.GetInputSignature(notesShader.vertexShaderByteCode), new[] { new InputElement("START", 0, Format.R32_Float, 0, 0), new InputElement("END", 0, Format.R32_Float, 4, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 8, 0), })); noteConstants = new NotesGlobalConstants() { NoteBorder = 0.002f, NoteLeft = -0.2f, NoteRight = 0.0f, ScreenAspect = 1f }; noteBuffer = new Buffer(device, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 40 * noteBufferLength, Usage = ResourceUsage.Dynamic, StructureByteStride = 0 }); globalNoteConstants = new Buffer(device, new BufferDescription() { BindFlags = BindFlags.ConstantBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 32, Usage = ResourceUsage.Dynamic, StructureByteStride = 0 }); var renderTargetDesc = new RenderTargetBlendDescription(); renderTargetDesc.IsBlendEnabled = true; renderTargetDesc.SourceBlend = BlendOption.SourceAlpha; renderTargetDesc.DestinationBlend = BlendOption.InverseSourceAlpha; renderTargetDesc.BlendOperation = BlendOperation.Add; renderTargetDesc.SourceAlphaBlend = BlendOption.One; renderTargetDesc.DestinationAlphaBlend = BlendOption.One; renderTargetDesc.AlphaBlendOperation = BlendOperation.Add; renderTargetDesc.RenderTargetWriteMask = ColorWriteMaskFlags.All; BlendStateDescription desc = new BlendStateDescription(); desc.AlphaToCoverageEnable = false; desc.IndependentBlendEnable = false; desc.RenderTarget[0] = renderTargetDesc; var blendStateEnabled = new BlendState(device, desc); device.ImmediateContext.OutputMerger.SetBlendState(blendStateEnabled); RasterizerStateDescription renderStateDesc = new RasterizerStateDescription { CullMode = CullMode.None, DepthBias = 0, DepthBiasClamp = 0, FillMode = FillMode.Solid, IsAntialiasedLineEnabled = false, IsDepthClipEnabled = false, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0 }; var rasterStateSolid = new RasterizerState(device, renderStateDesc); device.ImmediateContext.Rasterizer.State = rasterStateSolid; }
public override void DefinitionObjectDidReceiveString(string v) { base.DefinitionObjectDidReceiveString(v); List<string> result = GetResult(v); foreach (string list in result) { if (list.Length > 2) { string[] values = StringUtils.Split(list, "="); string name = values[0]; string value = values[1]; if ("imageid".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { this.uniqueID = value; } else if ("pos".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { this.pos = DefinitionObject.StrToVector2(value); } else if ("orig".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { this.orig = DefinitionObject.StrToVector2(value); } else if ("size".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { this.size = DefinitionObject.StrToVector2(value); } else if ("anchor".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { this.anchor = DefinitionObject.StrToVector2(value); } else if ("place".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { this.place = DefinitionObject.StrToVector2(value); } else if ("file".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { this.fileName = value; } else if ("name".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { this.uniqueID = value; } else if ("id".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { this.uniqueID = value; } else if ("mask".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { string[] colors = StringUtils.Split(value, ","); if (colors.Length == 3) { this.maskColor = new LColor(Convert.ToInt32(colors[0]), Convert.ToInt32(colors[1]), Convert.ToInt32(colors[2])); } else if (colors.Length == 4) { this.maskColor = new LColor(Convert.ToInt32(colors[0]), Convert.ToInt32(colors[1]), Convert.ToInt32(colors[2]), Convert.ToInt32(colors[4])); } } else if ("blend".Equals(name, System.StringComparison.InvariantCultureIgnoreCase)) { if ("non".Equals(value, System.StringComparison.InvariantCultureIgnoreCase) || "NonPremultiplied".Equals(value, System.StringComparison.InvariantCultureIgnoreCase)) { blend = BlendState.NonPremultiplied; } else if ("add".Equals(value, System.StringComparison.InvariantCultureIgnoreCase) || "Additive".Equals(value, System.StringComparison.InvariantCultureIgnoreCase)) { blend = BlendState.Additive; } else if ("alpha".Equals(value, System.StringComparison.InvariantCultureIgnoreCase) || "AlphaBlend".Equals(value, System.StringComparison.InvariantCultureIgnoreCase)) { blend = BlendState.AlphaBlend; } else if ("op".Equals(value, System.StringComparison.InvariantCultureIgnoreCase) || "Opaque".Equals(value, System.StringComparison.InvariantCultureIgnoreCase)) { blend = BlendState.Opaque; } } } } if (size == null && orig != null) { size = orig; } else if (orig == null && size != null) { orig = size; } if (anchor == null && size != null) { anchor = new Vector2f(size.x / 2, size.y / 2); } if (place == null) { place = new Vector2f(); } result.Clear(); }
public RenderObject(Device device) { cb.vp = Matrix.Identity; cb.world = Matrix.Identity; // load and compile the vertex shader using (var bytecode = ShaderBytecode.CompileFromFile("simple.fx", "VShader", "vs_4_0", ShaderFlags.None, EffectFlags.None)) { vsInputSignature = ShaderSignature.GetInputSignature(bytecode); vertexShader = new VertexShader(device, bytecode); } // load and compile the pixel shader using (var bytecode = ShaderBytecode.CompileFromFile("simple.fx", "PShader", "ps_4_0", ShaderFlags.None, EffectFlags.None)) pixelShader = new PixelShader(device, bytecode); // Old school style. /* vertexSize = 24; vertexCount = 3; var vertexStream = new DataStream(vertexSize * vertexCount, true, true); vertexStream.Write(new Vector3(0.0f, 5.0f, 0.5f)); vertexStream.Write(new Vector3(1, 0, 0)); // color vertexStream.Write(new Vector3(5.0f, -5.0f, 0.5f)); vertexStream.Write(new Vector3(0, 1, 0)); // color vertexStream.Write(new Vector3(-5.0f, -5.0f, 0.5f)); vertexStream.Write(new Vector3(0, 0, 1)); // color vertexStream.Position = 0; */ // Use struct Vertex[] vertices = new Vertex[] { new Vertex() { pos = new Vector3(0.0f, 50.0f, 0.5f), col = new Vector3(1, 0, 0), uv = new Vector2(0, 0) }, new Vertex() { pos = new Vector3(50.0f, -50.0f, 0.5f), col = new Vector3(1, 1, 0), uv = new Vector2(1, 0) }, new Vertex() { pos = new Vector3(-50.0f, -50.0f, 0.5f), col = new Vector3(0, 1, 1), uv = new Vector2(1, 1) }, }; vertexSize = Marshal.SizeOf(typeof(Vertex)); vertexCount = vertices.Length; var vertexStream = new DataStream(vertexSize * vertexCount, true, true); foreach (var vertex in vertices) { vertexStream.Write(vertex); } vertexStream.Position = 0; // create the vertex layout and buffer var elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0), new InputElement("COLOR", 0, Format.R32G32B32_Float, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0) }; vertexBufferLayout = new InputLayout(device, vsInputSignature, elements); vertexBuffer = new Buffer(device, vertexStream, vertexSize * vertexCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); vertexStream.Close(); // Setup Constant Buffers constantBuffer = new Buffer(device, Marshal.SizeOf(typeof(ConstantBuffer)), ResourceUsage.Dynamic, BindFlags.ConstantBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0); // http://asc-chalmers-project.googlecode.com/svn-history/r26/trunk/Source/AdvGraphicsProject/Program.cs // Try load a texture SamplerDescription samplerDescription = new SamplerDescription(); samplerDescription.AddressU = TextureAddressMode.Wrap; samplerDescription.AddressV = TextureAddressMode.Wrap; samplerDescription.AddressW = TextureAddressMode.Wrap; samplerDescription.Filter = Filter.MinPointMagMipLinear; samplerLinear = SamplerState.FromDescription(device, samplerDescription); texture = Texture2D.FromFile(device, "Data/cco.png"); textureView = new ShaderResourceView(device, texture); var desc = new BlendStateDescription() { AlphaToCoverageEnable = true, IndependentBlendEnable = true }; desc.RenderTargets[0].BlendEnable = false; desc.RenderTargets[0].BlendOperation = BlendOperation.Add; desc.RenderTargets[0].BlendOperationAlpha = BlendOperation.Add; desc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.Alpha; desc.RenderTargets[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTargets[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTargets[0].DestinationBlendAlpha = BlendOption.InverseSourceAlpha; desc.RenderTargets[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; blendState = BlendState.FromDescription(device, desc); }
public PongMaterials(IServiceProvider serviceProvider) : base(serviceProvider) { var addBs = new BlendState { AlphaBlendFunction = BlendFunction.Add, ColorBlendFunction = BlendFunction.Add, AlphaSourceBlend = Blend.One, ColorSourceBlend = Blend.One, AlphaDestinationBlend = Blend.One, ColorDestinationBlend = Blend.One }; var ds = new DepthStencilState { DepthBufferEnable = false }; // Set up various blending modes by changing render states var additiveBlend = new Action <DeviceManager>[] { (dm) => { dm.Device.BlendState = addBs; dm.Device.DepthStencilState = ds; } }; var subBs = new BlendState { AlphaBlendFunction = BlendFunction.ReverseSubtract, ColorBlendFunction = BlendFunction.ReverseSubtract, AlphaSourceBlend = Blend.One, ColorSourceBlend = Blend.One, AlphaDestinationBlend = Blend.One, ColorDestinationBlend = Blend.One }; var subtractiveBlend = new Action <DeviceManager>[] { (dm) => { dm.Device.BlendState = subBs; dm.Device.DepthStencilState = ds; } }; var alphaBs = new BlendState { AlphaBlendFunction = BlendFunction.Add, ColorBlendFunction = BlendFunction.Add, AlphaSourceBlend = Blend.SourceAlpha, ColorSourceBlend = Blend.SourceAlpha, AlphaDestinationBlend = Blend.InverseSourceAlpha, ColorDestinationBlend = Blend.InverseSourceAlpha }; var alphaBlend = new Action <DeviceManager>[] { (dm) => { dm.Device.BlendState = alphaBs; dm.Device.DepthStencilState = ds; } }; // Create a couple custom materials Trail = base.ScreenSpaceBitmap.WrapWithHandlers(additiveBlend); SubtractiveGeometry = base.ScreenSpaceGeometry.WrapWithHandlers(subtractiveBlend); // Replace the default materials with ones that set up our custom render states ScreenSpaceBitmap = base.ScreenSpaceBitmap.WrapWithHandlers(alphaBlend); ScreenSpaceGeometry = base.ScreenSpaceGeometry.WrapWithHandlers(alphaBlend); }
public void SetBlendState(BlendState state) { DXDeviceContext.OutputMerger.SetBlendState(state.NativeBlendState); }
public void Flush(BlendState state) { Submit(state,true); }
public void SetBlendState(BlendState state) { if (state != lastBlendState) { this.lastBlendState = state; switch (lastBlendState._code) { case 0: GL.XNA_BlendState = Microsoft.Xna.Framework.Graphics.BlendState.NonPremultiplied; break; case 1: GL.XNA_BlendState = Microsoft.Xna.Framework.Graphics.BlendState.Additive; break; case 2: GL.XNA_BlendState = Microsoft.Xna.Framework.Graphics.BlendState.AlphaBlend; break; case 3: GL.XNA_BlendState = Microsoft.Xna.Framework.Graphics.BlendState.Opaque; break; } } }
public void SetBlendState(BlendState state, Color4 color) { DXDeviceContext.OutputMerger.SetBlendState(state.NativeBlendState, color); }
/// <summary> /// Set the blend state of the output-merger stage. See <see cref="Render+states"/> to learn how to use it. /// </summary> /// <param name="blendState">a blend-state</param> /// <param name="blendFactor">Blend factors, one for each RGBA component. This requires a blend state object that specifies the <see cref="Blend.BlendFactor" /></param> /// <param name="multiSampleMask">32-bit sample coverage. The default value is 0xffffffff.</param> private void SetBlendStateImpl(BlendState blendState, Color4 blendFactor, int multiSampleMask = -1) { if (blendState == null) { NativeDeviceContext.OutputMerger.SetBlendState(null, ColorHelper.Convert(blendFactor), multiSampleMask); } else { NativeDeviceContext.OutputMerger.SetBlendState((SharpDX.Direct3D11.BlendState)blendState.NativeDeviceChild, ColorHelper.Convert(blendFactor), multiSampleMask); } }
internal CCGeometryInstanceAttributes() { BlendState = BlendState.AlphaBlend; AdditionalTransform = CCAffineTransform.Identity; PrimitiveType = PrimitiveType.TriangleList; }
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(); }
public void End() { CheckDrawing(); if (idx > 0) { batch.End(); } idx = 0; lastTexture = null; mode = -1; drawing = false; lastBlendState = BlendState.NonPremultiplied; }