void Blend::Execute(RenderContext& context) { gxeng::GraphicsCommandList& commandList = context.AsGraphics(); auto* pRTV = &m_blendDest; commandList.SetResourceState(pRTV->GetResource(), gxapi::eResourceState::RENDER_TARGET); commandList.SetRenderTargets(1, &pRTV); gxapi::Rectangle rect{ 0, (int)pRTV->GetResource().GetHeight(), 0, (int)pRTV->GetResource().GetWidth() }; gxapi::Viewport viewport; viewport.width = (float)rect.right; viewport.height = (float)rect.bottom; viewport.topLeftX = 0; viewport.topLeftY = 0; viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; commandList.SetScissorRects(1, &rect); commandList.SetViewports(1, &viewport); commandList.SetPipelineState(m_PSO.get()); commandList.SetGraphicsBinder(&m_binder); commandList.SetPrimitiveTopology(gxapi::ePrimitiveTopology::TRIANGLELIST); commandList.SetResourceState(const_cast<Texture2D&>(m_blendSrc.GetResource()), { gxapi::eResourceState::PIXEL_SHADER_RESOURCE, gxapi::eResourceState::NON_PIXEL_SHADER_RESOURCE }); commandList.BindGraphics(m_tex0Param, m_blendSrc); commandList.SetPrimitiveTopology(gxapi::ePrimitiveTopology::TRIANGLESTRIP); commandList.DrawInstanced(4); }
void BrightLumPass::Execute(RenderContext& context) { GraphicsCommandList& commandList = context.AsGraphics(); Uniforms uniformsCBData; //DebugDrawManager::GetInstance().AddSphere(m_camera->GetPosition() + m_camera->GetLookDirection() * 5, 1, 1); //TODO get from somewhere uniformsCBData.bright_pass_threshold = 0.8f; //create single-frame only cb /*gxeng::VolatileConstBuffer cb = context.CreateVolatileConstBuffer(&uniformsCBData, sizeof(Uniforms)); cb.SetName("Bright Lum pass volatile CB"); gxeng::ConstBufferView cbv = context.CreateCbv(cb, 0, sizeof(Uniforms)); */ commandList.SetResourceState(m_bright_pass_rtv.GetResource(), gxapi::eResourceState::RENDER_TARGET); commandList.SetResourceState(m_luminance_rtv.GetResource(), gxapi::eResourceState::RENDER_TARGET); commandList.SetResourceState(m_inputTexSrv.GetResource(), { gxapi::eResourceState::PIXEL_SHADER_RESOURCE, gxapi::eResourceState::NON_PIXEL_SHADER_RESOURCE }); RenderTargetView2D* pRTV[] = { &m_bright_pass_rtv, &m_luminance_rtv }; commandList.SetRenderTargets(2, pRTV, 0); gxapi::Rectangle rect{ 0, (int)m_bright_pass_rtv.GetResource().GetHeight(), 0, (int)m_bright_pass_rtv.GetResource().GetWidth() }; gxapi::Viewport viewport; viewport.width = (float)rect.right; viewport.height = (float)rect.bottom; viewport.topLeftX = 0; viewport.topLeftY = 0; viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; commandList.SetScissorRects(1, &rect); commandList.SetViewports(1, &viewport); commandList.SetPipelineState(m_PSO.get()); commandList.SetGraphicsBinder(&m_binder.value()); commandList.SetPrimitiveTopology(gxapi::ePrimitiveTopology::TRIANGLELIST); commandList.SetPipelineState(m_PSO.get()); commandList.SetGraphicsBinder(&m_binder.value()); commandList.BindGraphics(m_inputTexBindParam, m_inputTexSrv); commandList.BindGraphics(m_uniformsBindParam, &uniformsCBData, sizeof(Uniforms)); commandList.SetPrimitiveTopology(gxapi::ePrimitiveTopology::TRIANGLESTRIP); commandList.DrawInstanced(4); }
void DepthPrepass::Execute(RenderContext & context) { if (!m_entities) { return; } auto& commandList = context.AsGraphics(); commandList.SetResourceState(m_targetDsv.GetResource(), gxapi::eResourceState::DEPTH_WRITE); commandList.SetRenderTargets(0, nullptr, &m_targetDsv); gxapi::Rectangle rect{ 0, (int)m_targetDsv.GetResource().GetHeight(), 0, (int)m_targetDsv.GetResource().GetWidth() }; gxapi::Viewport viewport; viewport.width = (float)rect.right; viewport.height = (float)rect.bottom; viewport.topLeftX = 0; viewport.topLeftY = 0; viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; commandList.SetScissorRects(1, &rect); commandList.SetViewports(1, &viewport); commandList.SetResourceState(m_targetDsv.GetResource(), gxapi::eResourceState::DEPTH_WRITE); commandList.ClearDepthStencil(m_targetDsv, 1, 0, 0, nullptr, true, true); commandList.SetPipelineState(m_PSO.get()); commandList.SetGraphicsBinder(&m_binder.value()); commandList.SetPrimitiveTopology(gxapi::ePrimitiveTopology::TRIANGLELIST); Mat44 view = m_camera->GetViewMatrix(); Mat44 projection = m_camera->GetProjectionMatrix(); auto viewProjection = view * projection; std::vector<const gxeng::VertexBuffer*> vertexBuffers; std::vector<unsigned> sizes; std::vector<unsigned> strides; // Iterate over all entities for (const MeshEntity* entity : *m_entities) { // Get entity parameters Mesh* mesh = entity->GetMesh(); auto position = entity->GetPosition(); // Draw mesh if (!CheckMeshFormat(*mesh)) { assert(false); continue; } ConvertToSubmittable(mesh, vertexBuffers, sizes, strides); auto MVP = entity->GetTransform() * viewProjection; Mat44_Packed transformCBData; transformCBData = MVP; commandList.BindGraphics(m_transformBindParam, &transformCBData, sizeof(transformCBData)); for (auto& vb : vertexBuffers) { commandList.SetResourceState(*vb, gxapi::eResourceState::VERTEX_AND_CONSTANT_BUFFER); } commandList.SetResourceState(mesh->GetIndexBuffer(), gxapi::eResourceState::INDEX_BUFFER); commandList.SetVertexBuffers(0, (unsigned)vertexBuffers.size(), vertexBuffers.data(), sizes.data(), strides.data()); commandList.SetIndexBuffer(&mesh->GetIndexBuffer(), mesh->IsIndexBuffer32Bit()); commandList.DrawIndexedInstanced((unsigned)mesh->GetIndexBuffer().GetIndexCount()); } }