protected override void OnExecuting(GraphicEntity entity, ref LightComponent light, ref ColorComponent color, ISceneSnapshot snapshot) { if (entity.Contains <FollowCameraDirectLightComponent>() && light.Direction != snapshot.Camera.LookDirection) { entity.UpdateComponent(light.ApplyDirection(snapshot.Camera.LookDirection)); } base.OnExecuting(entity, ref light, ref color, snapshot); }
public override bool IsAplicable(GraphicEntity entity) { return(entity.TryGetComponent <RenderableComponent>(out var ren) && ren.IsRenderable && ren.Technique == RenderTechniques.Lines && entity.Contains( typeof(GeometryPoolComponent), typeof(TransformComponent))); }
public override bool IsAplicable(GraphicEntity entity) { return(entity.TryGetComponent <RenderableComponent>(out var ren) && ren.IsRenderable && ren.Technique == RenderTechniques.Background && entity.Contains( typeof(BackgroundRenderComponent), typeof(MemoryTexturedMaterialComponent))); }
public override bool IsAplicable(GraphicEntity entity) { return(entity.TryGetComponent <RenderableComponent>(out var ren) && ren.IsRenderable && ren.Technique == RenderTechniques.OneFrameFlatWhite && entity.Contains( typeof(BlackAndWhiteRenderComponent), typeof(TransformComponent))); }
public void RenderEach(GraphicsDevice graphics, TProperties props, GraphicEntity en) { var device = graphics.D3DDevice; var context = graphics.ImmediateContext; if (!en.TryGetComponent <D3DRenderComponent>(out var render)) { render = new D3DRenderComponent(); en.AddComponent(render); } var renderable = en.GetComponent <RenderableComponent>(); var color = en.GetComponent <MaterialColorComponent>(); var geo = ContextState.GetGeometryPool().GetGeometry <IGeometryData>(en); if (!render.DepthStencilState.HasValue) { render.DepthStencilState.Set(new DepthStencilState(graphics.D3DDevice, renderable.DepthStencilStateDefinition.Description)); } if (!render.BlendingState.HasValue) { render.BlendingState.Set(new BlendState(graphics.D3DDevice, renderable.BlendStateDescription)); } { graphics.ClearAllShader(); context.VertexShader.Set(vertexShader.Get()); context.GeometryShader.Set(null); context.PixelShader.Set(pixelShader.Get()); if (en.Contains <FlatShadingGeometryComponent>()) { context.GeometryShader.Set(flatShadingGS.Get()); } else if (en.Contains <WireframeGeometryComponent>()) { context.GeometryShader.Set(wireframeGS.Get()); context.PixelShader.Set(wireframePS.Get()); } } var topology = renderable.PrimitiveTopology; if (geo.IsModified || (!render.VertexBuffer.HasValue && !render.IndexBuffer.HasValue)) { Vertex[] vertex = null; switch (geo.Topology) { case GeometryPrimitiveTopologies.TriangleList: topology = PrimitiveTopology.TriangleList; vertex = new Vertex[geo.Positions.Length]; for (var index = 0; index < vertex.Length; index++) { vertex[index] = new Vertex(geo.Positions[index], geo.Normals[index]); } break; } render.VertexBuffer.Set(graphics.CreateBuffer(BindFlags.VertexBuffer, vertex)); render.IndexBuffer.Set(graphics.CreateBuffer(BindFlags.IndexBuffer, geo.Indices.ToArray())); geo.IsModified = false; } if (!render.VertexBuffer.HasValue && !render.IndexBuffer.HasValue) { throw RenderTechniqueException.NoVertexAndIndexBuffers; } if (color.IsValid) { var material = MaterialStructBuffer.From(color); if (render.MaterialBuffer.HasValue) { var buff = render.MaterialBuffer.Get(); graphics.UpdateDynamicBuffer(ref material, buff); } else { var buff = graphics.CreateDynamicBuffer(ref material, Unsafe.SizeOf <MaterialStructBuffer>()); render.MaterialBuffer.Set(buff); } } UpdateTransformWorld(graphics, render, en); if (!render.TransformWorldBuffer.HasValue) { throw RenderTechniqueException.NoWorldTransformBuffers; } {//Update constant buffers context.VertexShader.SetConstantBuffer(GameStructBuffer.RegisterResourceSlot, props.Game); context.VertexShader.SetConstantBuffer(TransforStructBuffer.RegisterResourceSlot, render.TransformWorldBuffer.Get()); context.PixelShader.SetConstantBuffer(GameStructBuffer.RegisterResourceSlot, props.Game); context.PixelShader.SetConstantBuffer(LightStructBuffer.RegisterResourceSlot, props.Lights); if (render.MaterialBuffer.HasValue) { context.PixelShader.SetConstantBuffer(MaterialStructBuffer.RegisterResourceSlot, render.MaterialBuffer.Get()); } } { context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(render.VertexBuffer.Get(), layconst.VertexSize, 0)); context.InputAssembler.SetIndexBuffer(render.IndexBuffer.Get(), SharpDX.DXGI.Format.R32_UInt, 0); context.InputAssembler.InputLayout = inputLayout.Get(); context.InputAssembler.PrimitiveTopology = topology; context.OutputMerger.SetDepthStencilState( render.DepthStencilState.Get(), renderable.DepthStencilStateDefinition.StencilRef); context.OutputMerger.SetBlendState(render.BlendingState.Get(), new SharpDX.Mathematics.Interop.RawColor4(0, 0, 0, 0), -1); } var rasterizerDesc = renderable.RasterizerStateDescription; using (var rasterizerState = graphics.CreateRasterizerState(rasterizerDesc)) { context.Rasterizer.State = rasterizerState; graphics.ImmediateContext.DrawIndexed(geo.Indices.Length, 0, 0); } }
public override bool IsAplicable(GraphicEntity entity) { return(entity.Contains(typeof(BillboardTextComponent))); }
public void RenderEach(GraphicsDevice graphics, TProperties game, GraphicEntity en) { var device = graphics.D3DDevice; var context = graphics.ImmediateContext; if (!en.TryGetComponent <D3DRenderComponent>(out var render)) { render = new D3DRenderComponent(); en.AddComponent(render); } var renderable = en.GetComponent <RenderableComponent>(); var geo = ContextState.GetGeometryPool().GetGeometry <IGeometryData>(en); //optional var hasColor = en.TryGetComponent <MaterialColorComponent>(out var color); var hasTexture = en.TryGetComponent <D3DTexturedMaterialSamplerComponent>(out var texture); if (!render.DepthStencilState.HasValue) { render.DepthStencilState.Set(new DepthStencilState(graphics.D3DDevice, renderable.DepthStencilStateDefinition.Description)); } if (!render.BlendingState.HasValue) { render.BlendingState.Set(new BlendState(graphics.D3DDevice, renderable.BlendStateDescription)); } UpdateTransformWorld(graphics, render, en); if (geo.IsModified) { var vertex = new Vertex[geo.Positions.Length]; for (var index = 0; index < vertex.Length; index++) { vertex[index] = new Vertex( geo.Positions[index], geo.Normals[index], geo.TexCoor[index]); } render.VertexBuffer.Set(graphics.CreateBuffer(BindFlags.VertexBuffer, vertex)); render.IndexBuffer.Set(graphics.CreateBuffer(BindFlags.IndexBuffer, geo.Indices.ToArray())); geo.IsModified = false; } if (hasColor) { var material = MaterialStructBuffer.From(color); if (render.MaterialBuffer.HasValue) { var buff = render.MaterialBuffer.Get(); graphics.UpdateDynamicBuffer(ref material, buff); } else { var buff = graphics.CreateDynamicBuffer(ref material, Unsafe.SizeOf <MaterialStructBuffer>()); render.MaterialBuffer.Set(buff); } } if (hasTexture && texture.IsModified) { render.TextureResources.Set(ConvertToResources(texture, graphics.TexturedLoader)); render.SampleState.Set(graphics.CreateSampler(texture.SampleDescription)); texture.IsModified = false; } { graphics.ClearAllShader(); context.VertexShader.Set(vertexShader.Get()); if (en.Contains <FlatShadingGeometryComponent>()) { context.GeometryShader.Set(flatShadingGS.Get()); } context.PixelShader.Set(pixelShader.Get()); context.VertexShader.SetConstantBuffer(GameStructBuffer.RegisterResourceSlot, game.Game); context.VertexShader.SetConstantBuffer(TransforStructBuffer.RegisterResourceSlot, render.TransformWorldBuffer.Get()); context.PixelShader.SetConstantBuffer(GameStructBuffer.RegisterResourceSlot, game.Game); context.PixelShader.SetConstantBuffer(LightStructBuffer.RegisterResourceSlot, game.Lights); if (render.MaterialBuffer.HasValue) { context.PixelShader.SetConstantBuffer(MaterialStructBuffer.RegisterResourceSlot, render.MaterialBuffer.Get()); } if (render.TextureResources.HasValue && render.SampleState.HasValue) { context.PixelShader.SetShaderResources(0, render.TextureResources.Get()); context.PixelShader.SetSampler(0, render.SampleState.Get()); } } context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(render.VertexBuffer.Get(), layconst.VertexSize, 0)); context.InputAssembler.SetIndexBuffer(render.IndexBuffer.Get(), SharpDX.DXGI.Format.R32_UInt, 0); context.InputAssembler.InputLayout = inputLayout.Get(); context.InputAssembler.PrimitiveTopology = renderable.PrimitiveTopology; context.OutputMerger.SetDepthStencilState(render.DepthStencilState.Get(), 0); context.OutputMerger.SetBlendState(render.BlendingState.Get(), new SharpDX.Mathematics.Interop.RawColor4(0, 0, 0, 0), -1); using (var rasterizerState = graphics.CreateRasterizerState(renderable.RasterizerStateDescription)) { context.Rasterizer.State = rasterizerState; graphics.ImmediateContext.DrawIndexed(geo.Indices.Length, 0, 0); } }
public override bool IsAplicable(GraphicEntity entity) { return(entity.Contains <CameraViewsComponent>()); }
public bool HasComponents(GraphicEntity entity) { return(entity.Contains(types)); }