public void Render() { UpdatePerFrameBuffer(); UpdateLightBuffers(); //Clear targets deviceContext.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1, 0); deviceContext.ClearRenderTargetView(renderTargetView, Color.Gray); //Camera matrix calulcations Transform cameraTransform = engine.MainCamera.Transform; Matrix viewMatrix = Matrix.LookAtLH(cameraTransform.WorldPosition, (cameraTransform.Forward + cameraTransform.WorldPosition), Vector3.UnitY); Matrix projectionMatrix = Matrix.PerspectiveFovLH((float)((Math.PI / 4)), aspectRatio, 0.01f, 200f); IEnumerable <Shader> shaders = engine.ShaderMaterialGroupings.Keys; foreach (Shader shader in shaders) { shader.BeginRender(renderService); //Set per-frame and light buffers (camera position) renderService.SetConstantBuffer(Constants.ConstantBufferNames.PER_FRAME_CB, shader); renderService.SetConstantBuffer(Constants.ConstantBufferNames.POINT_LIGHT_CB, shader); renderService.SetConstantBuffer(Constants.ConstantBufferNames.DIRECTIONAL_LIGHT_CB, shader); IEnumerable <Material> materials = engine.MaterialRendererGroupings.Keys; foreach (Material material in materials) { material.BeginRender(renderService); IEnumerable <MeshRenderer> meshRenderers = engine.MaterialRendererGroupings[material]; foreach (MeshRenderer renderer in meshRenderers) { PerObjectCB perObjectCB = UpdateWorldMatrices(renderer.Transform.WorldMatrix, viewMatrix, projectionMatrix); renderService.SetConstantBuffer(Constants.ConstantBufferNames.PER_OBJECT_CB, shader); renderService.UpdateConstantBuffer(Constants.ConstantBufferNames.PER_OBJECT_CB, ref perObjectCB); deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(renderer.Mesh.VertexBuffer, shader.InputElementStride, 0)); deviceContext.InputAssembler.SetIndexBuffer(renderer.Mesh.IndexBuffer, Format.R32_UInt, 0); deviceContext.DrawIndexed(renderer.Mesh.Indices.Length, 0, 0); } } } swapChain.Present(1, PresentFlags.None); }
public override void BeginRender(RenderService RenderService) { RenderService.SetShader(this); RenderService.SetConstantBuffer(Constants.ConstantBufferNames.STANDARD_MATERIAL_CB, this); }