Advertisement
Zgragselus

Renderer.cpp

Jul 5th, 2024
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 35.53 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Renderer.cpp
  4. //
  5. ///////////////////////////////////////////////////////////////////////////////////////////////////
  6.  
  7. ///////////////////////////////////////////////////////////////////////////////////////////////////
  8. // Header section
  9.  
  10. #include "Game/Loader/Assimp.h"
  11. #include "Renderer.h"
  12. #include <Graphics/System/MaterialSystem.h>
  13.  
  14. ///////////////////////////////////////////////////////////////////////////////////////////////////
  15. // Declaration section
  16.  
  17. ///////////////////////////////////////////////////////////////////////////////////////////////////
  18. // Definition section
  19.  
  20. /// <summary>
  21. /// Parametric constructor.
  22. ///
  23. /// Builds renderer and sets everything up.
  24. /// </summary>
  25. /// <param name="engine">Pointer to Engine instance</param>
  26. /// <param name="eventSystem">Pointer to event system instance</param>
  27. /// <param name="options">Pointer to configuration instance</param>
  28. /// <param name="log">Pointer to logging system</param>
  29. /// <param name="renderer">Pointer to Direct3D 12 renderer</param>
  30. /// <param name="swapChain">Pointer to Swap chain for window</param>
  31. /// <param name="appState">Pointer to Scmdl class instance (holding state/values for application)</param>
  32. Renderer::Renderer(Engine::Core* engine, Engine::EventSystem* eventSystem, Engine::Constants* options, Engine::Log* log, Engine::D3DRenderer* renderer, Engine::D3DSwapChain* swapChain, Application* appState) :
  33.     Engine::System("Renderer", eventSystem),
  34.     mOptions(options),
  35.     mLog(log),
  36.     mRenderer(renderer),
  37.     mSwapChain(swapChain),
  38.     mAppState(appState)
  39. {
  40.     // Run in background
  41.     EnableUpdater(Engine::Task::BACKGROUND_SYNC_REPEATING);
  42.  
  43.     // Create compute/render pipeline
  44.     mPipeline = new Engine::ComputeGraph(engine);
  45.  
  46.     // Get whether to use HW ray tracing
  47.     mUseHardwareRaytracing = options->Get<int>("Renderer.RayTracing.Hardware") == 0 ? false : true;    
  48.     if (mUseHardwareRaytracing)
  49.     {
  50.         // Hardware ray tracer
  51.         mRaytraceHWNode = new Engine::ComputeGraphNode("Renderer::DXRPass", eventSystem, [&]() -> void
  52.             {
  53.                 Engine::GraphicsContext* context = mRenderer->GetGraphicsContext();
  54.  
  55.                 context->Begin();
  56.  
  57.                 mAppState->mGfxProfiler->BeginProfile(context, "DXRPass");
  58.                 mRaytracerPassHW->SetSources(mAppState->mScene);
  59.                 mRaytracerPassHW->Process(mRenderer->Heap(), context, mCamera.Read(), mAppState->mViewportWidth, mAppState->mViewportHeight);
  60.                 mAppState->mGfxProfiler->EndProfile(context, "DXRPass");
  61.  
  62.                 context->Finish();
  63.             });
  64.     }
  65.     else
  66.     {
  67.         // Compute ray tracer - acceleration structure generator
  68.         mAccelerationNode = new Engine::ComputeGraphNode("RayTracing::AccelerationStructure", eventSystem, [&]() -> void
  69.             {
  70.                 // TODO: Rebuild/refit TLAS here when needed (with re-initializing data from scene)
  71.             });
  72.  
  73.         // Compute ray tracer - ray generator
  74.         mRaygenNode = new Engine::ComputeGraphNode("RayTracing::Raygen", eventSystem, [&]() -> void
  75.             {
  76.                 Engine::ComputeContext* context = mRenderer->GetComputeContext();
  77.  
  78.                 context->Begin();
  79.  
  80.                 mAppState->mGfxProfiler->BeginProfile(context, "RayTracing::Raygen");
  81.                 mAppState->mRaytracer->GetRayGenerator()->InitPrimaryRaysDevice(mAppState->mRaytracer->GetRayBuffer(mAppState->mPrimaryRayBuffer), context, mRenderer->Heap(), mCamera.Read(), mAppState->mViewportWidth, mAppState->mViewportHeight);
  82.                 mAppState->mGfxProfiler->EndProfile(context, "RayTracing::Raygen");
  83.  
  84.                 context->Finish();
  85.             });
  86.  
  87.         // Compute ray tracer - trace rays
  88.         mRaytraceNode = new Engine::ComputeGraphNode("RayTracing::Trace", eventSystem, [&]() -> void
  89.             {
  90.                 Engine::ComputeContext* context = mRenderer->GetComputeContext();
  91.  
  92.                 context->Begin();
  93.  
  94.                 mAppState->mGfxProfiler->BeginProfile(context, "RayTracing::Trace");
  95.                 mRaytracerPass->SetSources(mAppState->mPrimaryRayBuffer);
  96.                 mRaytracerPass->Process(mRenderer->Heap(), context, mAppState->mRenderNodes->GetBounds());
  97.                 mAppState->mGfxProfiler->EndProfile(context, "RayTracing::Trace");
  98.  
  99.                 context->Finish();
  100.             });
  101.         mRaytraceNode->AddInput(mAccelerationNode);
  102.         mRaytraceNode->AddInput(mRaygenNode);
  103.     }
  104.  
  105.     // Prepare scenegraph render nodes into buffer (for rendering)
  106.     mRenderNodesNode = new Engine::ComputeGraphNode("Renderer::RenderNodesPass", eventSystem, [&]() -> void
  107.         {
  108.             Engine::ComputeContext* context = mRenderer->GetComputeContext();
  109.  
  110.             context->Begin();
  111.  
  112.             mAppState->mRenderNodes->Process(context);
  113.  
  114.             context->Finish();
  115.         });
  116.  
  117.     // Prepare material systems data into buffer (for rendering)
  118.     mMaterialNode = new Engine::ComputeGraphNode("Renderer::MaterialPass", eventSystem, [&]() -> void
  119.         {
  120.             Engine::ComputeContext* context = mRenderer->GetComputeContext();
  121.  
  122.             context->Begin();
  123.  
  124.             // If anything in editor was changed - check whether the object has material component, if it has - material system needs to be updated for this change
  125.             if (mAppState->mEditor->GetChangedFlag())
  126.             {
  127.                 std::set<int> ids = mAppState->mScene->GetState()->GetSelection();
  128.                 for (std::set<int>::iterator it = ids.begin(); it != ids.end(); it++)
  129.                 {
  130.                     Engine::Entity* entity = mAppState->mScene->GetEntity(*it);
  131.                     if (entity->GameObject().Has<Engine::MaterialComponent>())
  132.                     {
  133.                         Engine::MaterialComponent* materialComponent = entity->GameObject().Get<Engine::MaterialComponent>();
  134.                         int materialID = materialComponent->GetMaterialID();
  135.  
  136.                         SkyeCuillin::MaterialSystem::Material* material = mAppState->mMaterialSystem->GetMaterial(materialID);
  137.  
  138.                         material->mDiffuseMap = materialComponent->GetDiffuseMap()->GetSRVIndex();
  139.                         if (material->mDiffuseMap == (unsigned int)-1)
  140.                         {
  141.                             material->mDiffuseMap = mAppState->mDefault[(unsigned int)Application::DefaultTextures::DIFFUSE]->GetSRVIndex();
  142.                         }
  143.  
  144.                         material->mNormalsMap = materialComponent->GetNormalsMap()->GetSRVIndex();
  145.                         if (material->mNormalsMap == (unsigned int)-1)
  146.                         {
  147.                             material->mNormalsMap = mAppState->mDefault[(unsigned int)Application::DefaultTextures::NORMAL]->GetSRVIndex();
  148.                         }
  149.  
  150.                         material->mMetallicMap = materialComponent->GetMetallicMap()->GetSRVIndex();
  151.                         if (material->mMetallicMap == (unsigned int)-1)
  152.                         {
  153.                             material->mMetallicMap = mAppState->mDefault[(unsigned int)Application::DefaultTextures::METALLIC]->GetSRVIndex();
  154.                         }
  155.  
  156.                         material->mRoughnessMap = materialComponent->GetRoughnessMap()->GetSRVIndex();
  157.                         if (material->mRoughnessMap == (unsigned int)-1)
  158.                         {
  159.                             material->mRoughnessMap = mAppState->mDefault[(unsigned int)Application::DefaultTextures::ROUGHNESS]->GetSRVIndex();
  160.                         }
  161.  
  162.                         mAppState->mMaterialSystem->UpdateMaterial(materialID);
  163.                     }
  164.                 }
  165.             }
  166.  
  167.             mAppState->mMaterialSystem->Process(context);
  168.  
  169.             context->Finish();
  170.         });
  171.  
  172.     // Render all shadow maps in lighting system that need to be updated
  173.     mShadowRenderNode = new Engine::ComputeGraphNode("Renderer::ShadowPass", eventSystem, [&]() -> void
  174.         {
  175.             std::lock_guard<std::mutex> lock(mAppState->mRenderingMutex);
  176.  
  177.             Engine::GraphicsContext* context = mRenderer->GetGraphicsContext();
  178.  
  179.             context->Begin();
  180.  
  181.             mAppState->mGfxProfiler->BeginProfile(context, "ShadowPass");
  182.             switch (mAppState->GetViewportState())
  183.             {
  184.             case Application::ViewportState::WIREFRAME:
  185.                 break;
  186.  
  187.             case Application::ViewportState::TEXTURED:
  188.                 break;
  189.  
  190.             case Application::ViewportState::LIT_TEXTURED:
  191.             case Application::ViewportState::LIT:
  192.                 mLightingSystem->Process(mCamera.Read(), mRenderer->Heap(), context, mAppState->mRenderNodes, mAppState->mMaterialSystem->GetMaterialsBuffer(), mAppState->mRenderNodes->GetBounds());
  193.                 break;
  194.  
  195.             default:
  196.                 break;
  197.             }
  198.             mAppState->mGfxProfiler->EndProfile(context, "ShadowPass");
  199.  
  200.             context->Finish();
  201.         });
  202.     mShadowRenderNode->AddInput(mRenderNodesNode);
  203.     mShadowRenderNode->AddInput(mMaterialNode);
  204.  
  205.     mCullingNode = new Engine::ComputeGraphNode("Renderer::Culling", eventSystem, [&]() -> void
  206.         {
  207.             if (mCamera.Read() == nullptr)
  208.             {
  209.                 return;
  210.             }
  211.  
  212.             std::lock_guard<std::mutex> lock(mAppState->mRenderingMutex);
  213.  
  214.             Engine::GraphicsContext* context = mRenderer->GetGraphicsContext();
  215.  
  216.             context->Begin();
  217.  
  218.             mAppState->mGfxProfiler->BeginProfile(context, "CullPassHiZ");
  219.             mCulling->SetBuffers(mAppState->mRenderNodes, mCamera.Read()->GetFrustum(), Engine::Culling::DEFAULT_CULLING_BUFFER, mCamera.Read());
  220.             mCulling->Process(mRenderer->Heap(), context);
  221.             mAppState->mGfxProfiler->EndProfile(context, "CullPassHiZ");
  222.  
  223.             mAppState->mGfxProfiler->BeginProfile(context, "Hi-ZPass1");
  224.             //mHiZPass->Process(mCamera.Read(), mRenderer->Heap(), context, mAppState->mRenderNodes, mAppState->mMaterialSystem->GetMaterialsBuffer(), mCulling);
  225.             mAppState->mGfxProfiler->EndProfile(context, "Hi-ZPass1");
  226.  
  227.             mAppState->mGfxProfiler->BeginProfile(context, "Hi-ZPass2");
  228.             //mHiZPass->Process2(mCamera.Read(), mRenderer->Heap(), context, mAppState->mRenderNodes, mAppState->mMaterialSystem->GetMaterialsBuffer(), mCulling);
  229.             mAppState->mGfxProfiler->EndProfile(context, "Hi-ZPass2");
  230.  
  231.             mAppState->mGfxProfiler->BeginProfile(context, "CullPass");
  232.             // Occlusion culling
  233.             //mCulling->SetBuffers(mAppState->mRenderNodes, mCamera.Read()->GetFrustum(), Engine::Culling::DEFAULT_CULLING_BUFFER, mCamera.Read(), mHiZPass->GetWidth(), mHiZPass->GetHeight(), mHiZPass->GetNumMiplevels());
  234.             //mCulling->Process(mRenderer->Heap(), context, Engine::Culling::DEFAULT_CULLING_BUFFER, mHiZPass->GetBuffer());
  235.             // Uncomment for Frustum culling only
  236.             mCulling->SetBuffers(mAppState->mRenderNodes, mCamera.Read()->GetFrustum(), Engine::Culling::DEFAULT_CULLING_BUFFER);
  237.             mCulling->Process(mRenderer->Heap(), context);
  238.             mAppState->mGfxProfiler->EndProfile(context, "CullPass");
  239.  
  240.             context->Finish();
  241.         });
  242.     mCullingNode->AddInput(mRenderNodesNode);
  243.     mCullingNode->AddInput(mMaterialNode);
  244.  
  245.     mDrawNode = new Engine::ComputeGraphNode("Renderer::DrawPass", eventSystem, [&]() -> void
  246.         {
  247.             std::lock_guard<std::mutex> lock(mAppState->mRenderingMutex);
  248.  
  249.             Engine::GraphicsContext* context = mRenderer->GetGraphicsContext();
  250.  
  251.             context->Begin();
  252.  
  253.             mAppState->mGfxProfiler->BeginProfile(context, "DrawPass");
  254.  
  255.             switch (mAppState->GetViewportState())
  256.             {
  257.             case Application::ViewportState::WIREFRAME:
  258.                 mWireframePass->Process(mCamera.Read(), mRenderer->Heap(), context, mAppState->mRenderNodes, mCulling);
  259.                 break;
  260.  
  261.             case Application::ViewportState::TEXTURED:
  262.                 mTexturedPass->Process(mCamera.Read(), mRenderer->Heap(), context, mAppState->mRenderNodes, mAppState->mMaterialSystem->GetMaterialsBuffer(), mCulling);
  263.                 break;
  264.  
  265.             case Application::ViewportState::LIT_TEXTURED:
  266.             case Application::ViewportState::LIT:
  267.                 mGBufferPass->Process(mCamera.Read(), mRenderer->Heap(), context, mAppState->mRenderNodes, mAppState->mMaterialSystem->GetMaterialsBuffer(), mCulling);
  268.                 break;
  269.  
  270.             default:
  271.                 break;
  272.             }
  273.  
  274.             mAppState->mGfxProfiler->EndProfile(context, "DrawPass");
  275.  
  276.             context->Finish();
  277.         });
  278.     mDrawNode->AddInput(mRenderNodesNode);
  279.     mDrawNode->AddInput(mMaterialNode);
  280.     mDrawNode->AddInput(mCullingNode);
  281.  
  282.     mReductionNode = new Engine::ComputeGraphNode("Renderer::ReductionPass", eventSystem, [&]() -> void
  283.         {
  284.             Engine::GraphicsContext* context = mRenderer->GetGraphicsContext();
  285.  
  286.             context->Begin();
  287.  
  288.             mAppState->mGfxProfiler->BeginProfile(context, "ReductionPass");
  289.             switch (mAppState->GetViewportState())
  290.             {
  291.             case Application::ViewportState::WIREFRAME:
  292.                 mMultisampling->SetSources(mWireframePass->GetBuffer(), mWireframePass->GetDepthBuffer());
  293.                 break;
  294.  
  295.             case Application::ViewportState::TEXTURED:
  296.                 mMultisampling->SetSources(mTexturedPass->GetBuffer(), mTexturedPass->GetDepthBuffer());
  297.                 break;
  298.  
  299.             case Application::ViewportState::LIT_TEXTURED:
  300.             case Application::ViewportState::LIT:
  301.                 mMultisampling->SetSources(mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::NORMAL_BUFFER), mGBufferPass->GetDepthBuffer());
  302.                 break;
  303.  
  304.             default:
  305.                 break;
  306.             }
  307.             mMultisampling->Process(mCamera.Read(), mRenderer->Heap(), context);
  308.             mAppState->mGfxProfiler->EndProfile(context, "ReductionPass");
  309.  
  310.             context->Finish();
  311.         });
  312.     mReductionNode->AddInput(mDrawNode);
  313.  
  314.     mResolveNode = new Engine::ComputeGraphNode("Renderer::ResolvePass", eventSystem, [&]() -> void
  315.         {
  316.             Engine::GraphicsContext* context = mRenderer->GetGraphicsContext();
  317.  
  318.             context->Begin();
  319.  
  320.             mAppState->mGfxProfiler->BeginProfile(context, "ResolvePass");
  321.             switch (mAppState->GetViewportState())
  322.             {
  323.             case Application::ViewportState::WIREFRAME:
  324.                 mResolve->SetSources(mWireframePass->GetBuffer(), mMultisampling->GetTiles(), mMultisampling->GetTilesCount(), mMultisampling->GetTileRecords(), mMultisampling->GetTileSamples());
  325.                 break;
  326.  
  327.             case Application::ViewportState::TEXTURED:
  328.                 mResolve->SetSources(mTexturedPass->GetBuffer(), mMultisampling->GetTiles(), mMultisampling->GetTilesCount(), mMultisampling->GetTileRecords(), mMultisampling->GetTileSamples());
  329.                 break;
  330.  
  331.             case Application::ViewportState::LIT_TEXTURED:
  332.                 mLightingPass->SetSources(mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::COLOR_BUFFER),
  333.                     mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::NORMAL_BUFFER),
  334.                     mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::DEPTH_BUFFER),
  335.                     mMultisampling->GetTilesCount(),
  336.                     mMultisampling->GetTiles(),
  337.                     mMultisampling->GetTileRecords(),
  338.                     mMultisampling->GetTileSamples());
  339.                 mLightingPass->Process(mCamera.Read(), mRenderer->Heap(), context);
  340.  
  341.                 mAvgLuminance->SetSources(mLightingPass->GetOutput(), mMultisampling->GetTiles(), mMultisampling->GetTilesCount(), mMultisampling->GetTileRecords(), mMultisampling->GetTileSamples());
  342.                 mAvgLuminance->Process(mRenderer->Heap(), context, mAppState->mGfxProfiler->GetFrameTime());
  343.  
  344.                 mResolve->SetSources(mLightingPass->GetOutput(),
  345.                     mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::COLOR_BUFFER),
  346.                     mMultisampling->GetTiles(),
  347.                     mMultisampling->GetTilesCount(),
  348.                     mMultisampling->GetTileRecords(),
  349.                     mMultisampling->GetTileSamples(),
  350.                     mAvgLuminance->GetAvgLuminanceBuffer());
  351.                 break;
  352.  
  353.             case Application::ViewportState::LIT:
  354.                 mLightingPass->SetSources(mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::COLOR_BUFFER),
  355.                     mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::NORMAL_BUFFER),
  356.                     mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::DEPTH_BUFFER),
  357.                     mMultisampling->GetTilesCount(),
  358.                     mMultisampling->GetTiles(),
  359.                     mMultisampling->GetTileRecords(),
  360.                     mMultisampling->GetTileSamples());
  361.                 mLightingPass->Process(mCamera.Read(), mRenderer->Heap(), context, Engine::LightingPass::Mode::LIT);
  362.  
  363.                 mAvgLuminance->SetSources(mLightingPass->GetOutput(), mMultisampling->GetTiles(), mMultisampling->GetTilesCount(), mMultisampling->GetTileRecords(), mMultisampling->GetTileSamples());
  364.                 mAvgLuminance->Process(mRenderer->Heap(), context, mAppState->mGfxProfiler->GetFrameTime());
  365.  
  366.                 mResolve->SetSources(mLightingPass->GetOutput(),
  367.                     mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::COLOR_BUFFER),
  368.                     mMultisampling->GetTiles(),
  369.                     mMultisampling->GetTilesCount(),
  370.                     mMultisampling->GetTileRecords(),
  371.                     mMultisampling->GetTileSamples(),
  372.                     mAvgLuminance->GetAvgLuminanceBuffer());
  373.                 break;
  374.  
  375.             default:
  376.                 break;
  377.             }
  378.             mResolve->Process(mCamera.Read(), mRenderer->Heap(), context);
  379.             mAppState->mGfxProfiler->EndProfile(context, "ResolvePass");
  380.  
  381.             context->Finish();
  382.         });
  383.     mResolveNode->AddInput(mShadowRenderNode);
  384.     mResolveNode->AddInput(mReductionNode);
  385.  
  386.     mRenderNode = new Engine::ComputeGraphNode("Rendering", eventSystem, [&]() -> void
  387.         {
  388.             std::lock_guard<std::mutex> lock(mAppState->mRenderingMutex);
  389.             std::lock_guard<std::mutex> swapChainLock(mAppState->mSwapChainMutex);
  390.  
  391.             Engine::GraphicsContext* context = mRenderer->GetGraphicsContext();
  392.  
  393.             context->Begin();          
  394.  
  395.             mAppState->SetGraphicsContext(context);
  396.  
  397.             mAppState->mGfxProfiler->Reset(context);
  398.             mAppState->mGfxProfiler->BeginProfile(context, "Frame");
  399.  
  400.             // No native resolve pass
  401.             /*mAppState->mGfxProfiler->BeginProfile(context, "NativeResolve");
  402.             switch (mAppState->GetViewportState())
  403.             {
  404.             case Application::ViewportState::WIREFRAME:
  405.                 mNativeResolvePass->SetSources(mWireframePass->GetBuffer(), mWireframePass->GetDepthBuffer());
  406.                 break;
  407.  
  408.             case Application::ViewportState::TEXTURED:
  409.                 mNativeResolvePass->SetSources(mTexturedPass->GetBuffer(), mTexturedPass->GetDepthBuffer());
  410.                 break;
  411.  
  412.             case Application::ViewportState::LIT_TEXTURED:
  413.             case Application::ViewportState::LIT:
  414.                 mNativeResolvePass->SetSources(mGBufferPass->GetBuffer(Engine::GBuffer::Buffer::NORMAL_BUFFER), mGBufferPass->GetDepthBuffer());
  415.                 break;
  416.  
  417.             default:
  418.                 break;
  419.             }
  420.             mNativeResolvePass->Process(mCamera.Read(), mRenderer->Heap(), context);
  421.             mAppState->mGfxProfiler->EndProfile(context, "NativeResolve");*/
  422.  
  423.             // No gizmo pass
  424.             /*context->TransitionResource(mSwapChain->GetBackBuffer(), D3D12_RESOURCE_STATE_RENDER_TARGET, true);
  425.             context->SetRenderTargets(mSwapChain->GetBackBuffer(), mSwapChain->GetDepthBuffer());
  426.             context->SetViewport(0.0f, 0.0f, (float)mAppState->mWindowSize.x, (float)mAppState->mWindowSize.y);
  427.             context->SetScissorRect(0.0f, 0.0f, (float)mAppState->mWindowSize.x, (float)mAppState->mWindowSize.y);
  428.             context->ClearColor(mSwapChain->GetBackBuffer(), 0.0f, 0.0f, 0.0f, 1.0f);
  429.             context->ClearDepth(mSwapChain->GetDepthBuffer(), 1.0f, 0);
  430.  
  431.             std::set<int> ids;
  432.             Engine::float4 basis[3] = { Engine::float4(1.0f, 0.0f, 0.0f, 1.0f), Engine::float4(0.0f, 1.0f, 0.0f, 1.0f), Engine::float4(0.0f, 0.0f, 1.0f, 1.0f) };
  433.             mGizmoPass->Clear();
  434.             //mGizmoPass->Process(nodes, mAppState->mScene, mMatricesBuffer, ids);
  435.             //mGizmoPass->ProcessIcons(nodes);
  436.             mGizmoPass->AddTranslationAxis(Engine::float4(0.0f, 0.0f, 0.0f, 1.0f), basis, 10.0f, -1, -1);
  437.             mGizmoPass->Render(mCamera.Read(), mRenderer->Heap(), context);*/
  438.            
  439.             // Set output to back buffer - and perform imgui pass (output)
  440.             context->SetDescriptorHeap(Engine::DescriptorHeap::CBV_SRV_UAV, mRenderer->Heap());
  441.             context->TransitionResource(mSwapChain->GetBackBuffer(), D3D12_RESOURCE_STATE_RENDER_TARGET, true);
  442.             context->SetRenderTargets(mSwapChain->GetBackBuffer(), mSwapChain->GetDepthBuffer());
  443.             context->SetViewport(0.0f, 0.0f, (float)mAppState->mWindowSize.x, (float)mAppState->mWindowSize.y);
  444.             context->SetScissorRect(0.0f, 0.0f, (float)mAppState->mWindowSize.x, (float)mAppState->mWindowSize.y);
  445.             context->ClearColor(mSwapChain->GetBackBuffer(), 0.0f, 0.0f, 0.0f, 1.0f);
  446.             context->ClearDepth(mSwapChain->GetDepthBuffer(), 1.0f, 0);
  447.  
  448.             // Draw Imgui user interface
  449.             mImgui->Update(context, mAppState->mGfxProfiler->GetFrameTime() * 0.001f);
  450.             mImgui->NewFrame();
  451.  
  452.             mAppState->mMenuUI->Process(mAppState->mWindowSize);
  453.  
  454.  
  455.             // Create root imgui window for dockspace
  456.             ImGuiViewport* viewport = ImGui::GetMainViewport();
  457.             ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
  458.             ImGui::SetNextWindowSize(ImVec2((float)mAppState->mWindowSize.x, (float)mAppState->mWindowSize.y));
  459.             ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
  460.             ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
  461.             ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
  462.             ImGui::Begin("Viewport", nullptr, ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBackground);
  463.             ImGui::PopStyleVar();
  464.             ImGui::PopStyleVar();
  465.             ImGui::PopStyleVar();
  466.  
  467.             ImGuiID dockspace = ImGui::GetID("Dockspace");
  468.             ImGui::DockSpace(dockspace, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None | ImGuiDockNodeFlags_PassthruCentralNode);
  469.  
  470.             mAppState->mEditorSettingsDialog->Process();
  471.  
  472.             ImGui::End();
  473.  
  474.             unsigned int regionWidth = mAppState->mWindowSize.x;
  475.             unsigned int regionHeight = mAppState->mWindowSize.y;
  476.  
  477.             if (ImGui::Begin("Debug"))
  478.             {
  479.                 //ImGui::Image((ImTextureID)(mGBufferPass->GetBuffer(0)->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  480.                 //ImGui::Image((ImTextureID)(mWireframePass->GetBuffer()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  481.                 //ImGui::Image((ImTextureID)(mTexturedPass->GetBuffer()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  482.                 //ImGui::Image((ImTextureID)(mNativeResolvePass->GetBuffer()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  483.                 if (mAppState->GetViewportState() == Application::ViewportState::LIT_TEXTURED || mAppState->GetViewportState() == Application::ViewportState::LIT)
  484.                 {
  485.                     //ImGui::Image((ImTextureID)(mLightingSystem->GetShadowMap()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  486.                     ImGui::Image((ImTextureID)(mResolve->GetBuffer()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  487.                 }
  488.                 else
  489.                 {
  490.                     //ImGui::Image((ImTextureID)(mHiZPass->GetBuffer()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());             
  491.                     //ImGui::Image((ImTextureID)(mRaytracerPass->GetBuffer()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  492.                     ImGui::Image((ImTextureID)(mResolve->GetBuffer()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  493.                 }
  494.  
  495.                 ImVec2 regionMin = ImGui::GetWindowContentRegionMin();
  496.                 ImVec2 regionMax = ImGui::GetWindowContentRegionMax();
  497.  
  498.                 regionWidth = (unsigned int)(regionMax.x - regionMin.x);
  499.                 regionHeight = (unsigned int)(regionMax.y - regionMin.y);
  500.  
  501.                 if (regionWidth < 8)
  502.                 {
  503.                     regionWidth = 8;
  504.                 }
  505.  
  506.                 if (regionWidth > 4096)
  507.                 {
  508.                     regionWidth = 4096;
  509.                 }
  510.  
  511.                 if (regionHeight < 8)
  512.                 {
  513.                     regionHeight = 8;
  514.                 }
  515.  
  516.                 if (regionHeight > 4096)
  517.                 {
  518.                     regionHeight = 4096;
  519.                 }
  520.             }
  521.             ImGui::End();
  522.  
  523.             if (mUseHardwareRaytracing)
  524.             {
  525.                 if (ImGui::Begin("Debug2"))
  526.                 {
  527.                     ImGui::Image((ImTextureID)(mRaytracerPassHW->GetBuffer()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  528.                 }
  529.                 ImGui::End();
  530.             }
  531.             else
  532.             {
  533.                 if (ImGui::Begin("Debug2"))
  534.                 {
  535.                     ImGui::Image((ImTextureID)(mRaytracerPass->GetBuffer()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  536.                 }
  537.                 ImGui::End();
  538.             }
  539.  
  540.             if (ImGui::Begin("Debug3"))
  541.             {
  542.                 ImGui::Image((ImTextureID)(mLightingSystem->GetShadowMap()->GetSRV().mGpuHandle.ptr), ImGui::GetContentRegionAvail());
  543.             }
  544.             ImGui::End();
  545.  
  546.             if (ImGui::Begin("Histogram"))
  547.             {
  548.                 if (ImPlot::BeginPlot("Histogram"))
  549.                 {
  550.                     float data[256];
  551.                     for (int i = 0; i < 256; i++)
  552.                     {
  553.                         data[i] = (float)(mAvgLuminance->GetHistogramHostBuffer()[i]);
  554.                     }
  555.  
  556.                     ImPlot::SetupAxisScale(ImAxis_X1, ImPlotScale_Linear);
  557.                     ImPlot::SetupAxisLimits(ImAxis_X1, 0.0, 256.0);
  558.                     ImPlot::SetupAxisScale(ImAxis_Y1, ImPlotScale_Linear);
  559.                     ImPlot::SetupAxisLimits(ImAxis_Y1, 0.0, 1024.0);
  560.                     ImPlot::PlotLine("Buckets", data, 256);
  561.                     ImPlot::EndPlot();
  562.                 }
  563.             }
  564.             ImGui::End();
  565.  
  566.             if (ImGui::Begin("AverageLuminance"))
  567.             {
  568.                 ImGui::LabelText("Average Luminance", "%f", mAvgLuminance->GetAvgLuminanceHostBuffer()[0]);
  569.                 ImGui::LabelText("Exposure", "%f", mAvgLuminance->GetAvgLuminanceHostBuffer()[1]);
  570.             }
  571.             ImGui::End();
  572.  
  573.             ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
  574.             ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
  575.             ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
  576.             if (ImGui::Begin("Scenegraph", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus))
  577.             {
  578.                 mAppState->mEditorScenegraph->ImguiScenegraphEditor();
  579.             }
  580.             ImGui::End();
  581.             ImGui::PopStyleVar();
  582.             ImGui::PopStyleVar();
  583.             ImGui::PopStyleVar();
  584.  
  585.             ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
  586.             ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
  587.             ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
  588.             if (ImGui::Begin("Edit", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus))
  589.             {
  590.                 mAppState->mEditorComponent->ImguiSelectionEditor();
  591.             }
  592.             ImGui::End();
  593.             ImGui::PopStyleVar();
  594.             ImGui::PopStyleVar();
  595.             ImGui::PopStyleVar();
  596.  
  597.             ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
  598.             ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
  599.             ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
  600.             if (ImGui::Begin("Directory View", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus))
  601.             {
  602.                 mAppState->mDirTree->Imgui();
  603.             }
  604.             ImGui::End();
  605.             ImGui::PopStyleVar();
  606.             ImGui::PopStyleVar();
  607.             ImGui::PopStyleVar();
  608.  
  609.             if (Engine::ComponentStatic::mEditedComponent != nullptr)
  610.             {
  611.                 mAppState->mEditorManager->ImguiManagerList<Engine::Texture>("Select Texture", mAppState->mAssetManager->GetManager<Engine::Texture>());
  612.             }
  613.  
  614.             static bool showProfiler = true;
  615.             if (ImGui::Begin("Profile", &showProfiler))
  616.             {
  617.                 char tmp[255] = { 0 };
  618.                 snprintf(tmp, sizeof(tmp), "%f fps", mAppState->mGfxProfiler->GetFramesPerSecond()); ImGui::LabelText("FPS", tmp);
  619.  
  620.                 ImGui::Separator();
  621.  
  622.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("Frame")); ImGui::LabelText("Frame", tmp);
  623.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("ShadowPass")); ImGui::LabelText("ShadowPass", tmp);
  624.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("Hi-ZPass1")); ImGui::LabelText("Hi-ZPass1", tmp);
  625.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("Hi-ZPass2")); ImGui::LabelText("Hi-ZPass2", tmp);
  626.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("CullPass")); ImGui::LabelText("CullPass", tmp);
  627.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("CullPassHiZ")); ImGui::LabelText("CullPassHiZ", tmp);
  628.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("DrawPass")); ImGui::LabelText("DrawPass", tmp);
  629.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("ReductionPass")); ImGui::LabelText("ReductionPass", tmp);
  630.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("ResolvePass")); ImGui::LabelText("ResolvePass", tmp);
  631.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("NativeResolve")); ImGui::LabelText("NativeResolve", tmp);
  632.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("RayTracing::Raygen")); ImGui::LabelText("RayTracing::Raygen", tmp);
  633.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("RayTracing::Trace")); ImGui::LabelText("RayTracing::Trace", tmp);
  634.                 snprintf(tmp, sizeof(tmp), "%.2f ms", mAppState->mGfxProfiler->GetTime("DXRPass")); ImGui::LabelText("DXRPass", tmp);
  635.             }
  636.             ImGui::End();
  637.  
  638.             mImgui->Render();
  639.  
  640.             context->TransitionResource(mSwapChain->GetBackBuffer(), D3D12_RESOURCE_STATE_PRESENT, true);
  641.  
  642.             mAppState->mGfxProfiler->EndProfile(context, "Frame");
  643.             mAppState->mGfxProfiler->Resolve(context);
  644.  
  645.             mAppState->ReleaseGraphicsContext();
  646.  
  647.             // Finish recording command list, execute command list and wait for execution
  648.             uint64_t fence = context->Finish();
  649.  
  650.             if (mAppState->mEditorSettingsDialog->IsChanged())
  651.             {
  652.                 mAppState->mEditorSettingsDialog->ClearChanged();
  653.                 mImgui->SetupFonts(mRenderer);
  654.             }
  655.  
  656.             mAvgLuminance->Readback();
  657.  
  658.             mTexturedPass->Readback();
  659.  
  660.             if (mAppState->mViewportWidth != regionWidth && mAppState->mViewportHeight != regionHeight)
  661.             {
  662.                 mAppState->mViewportWidth = regionWidth;
  663.                 mAppState->mViewportHeight = regionHeight;
  664.  
  665.                 mAppState->mResizeFlag = true;
  666.  
  667.                 mWireframePass->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  668.                 mTexturedPass->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  669.                 mGBufferPass->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  670.                 //mNativeResolvePass->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  671.                 mMultisampling->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  672.                 mResolve->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  673.                 mLightingPass->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  674.                 if (mUseHardwareRaytracing)
  675.                 {
  676.                     mRaytracerPassHW->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  677.                 }
  678.                 else
  679.                 {
  680.                     mRaytracerPass->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  681.                 }
  682.                 mHiZPass->Resize(mAppState->mViewportWidth, mAppState->mViewportHeight);
  683.  
  684.                 if (mUseHardwareRaytracing == false)
  685.                 {
  686.                     mAppState->mRaytracer->ResizeRayBuffer(mAppState->mPrimaryRayBuffer, mAppState->mViewportWidth* mAppState->mViewportHeight);
  687.                 }
  688.             }
  689.             else
  690.             {
  691.                 mAppState->mResizeFlag = false;
  692.             }
  693.  
  694.             if (mAppState->mBaseSignatureChanged == true)
  695.             {
  696.                 mAppState->mBaseSignatureChanged = false;
  697.  
  698.                 delete mAppState->mRenderNodes;
  699.                 switch (mAppState->GetViewportState())
  700.                 {
  701.                 case Application::ViewportState::WIREFRAME:
  702.                     mAppState->mRenderNodes = new Engine::RenderNodeList(mRenderer, mOptions->Get<int>("Scene.MaxObjects"), std::vector<Engine::RootSignature*> { mWireframePass->GetRootSignature(), nullptr, mHiZPass->GetRootSignature() });
  703.                     break;
  704.  
  705.                 case Application::ViewportState::TEXTURED:
  706.                     mAppState->mRenderNodes = new Engine::RenderNodeList(mRenderer, mOptions->Get<int>("Scene.MaxObjects"), std::vector<Engine::RootSignature*> { mTexturedPass->GetRootSignature(), nullptr, mHiZPass->GetRootSignature() });
  707.                     break;
  708.  
  709.                 case Application::ViewportState::LIT_TEXTURED:
  710.                 case Application::ViewportState::LIT:
  711.                     mAppState->mRenderNodes = new Engine::RenderNodeList(mRenderer, mOptions->Get<int>("Scene.MaxObjects"), std::vector<Engine::RootSignature*> { mGBufferPass->GetRootSignature(), mLightingSystem->GetRootSignature(), mHiZPass->GetRootSignature() });
  712.                     break;
  713.  
  714.                 default:
  715.                     break;
  716.                 }
  717.             }
  718.  
  719.             mAppState->mGfxProfiler->Process("Frame");
  720.  
  721.             // Swap buffers in swap chain and present to screen
  722.             mSwapChain->SwapBuffers();
  723.  
  724.             if (mCamera.Read() != nullptr)
  725.             {
  726.                 mAppState->mScene->Render(mRenderer, mCamera.Read(), mAppState->mRenderNodes);
  727.             }
  728.  
  729.             mCamera.Write(mAppState->mScene->GetEntity("Camera")->GameObject().Get<Engine::CameraComponent>()->GetCamera());
  730.             mCamera.Swap();
  731.         });
  732.     mRenderNode->AddInput(mResolveNode);
  733.     if (mUseHardwareRaytracing)
  734.     {
  735.         mRenderNode->AddInput(mRaytraceHWNode);
  736.     }
  737.     else
  738.     {
  739.         mRenderNode->AddInput(mRaytraceNode);
  740.     }
  741.  
  742.     // Add render nodes into pipeline
  743.     if (mUseHardwareRaytracing)
  744.     {
  745.         mPipeline->AddNode(mRaytraceHWNode);
  746.     }
  747.     else
  748.     {
  749.         mPipeline->AddNode(mAccelerationNode);
  750.         mPipeline->AddNode(mRaygenNode);
  751.         mPipeline->AddNode(mRaytraceNode);
  752.     }
  753.     mPipeline->AddNode(mRenderNodesNode);
  754.     mPipeline->AddNode(mMaterialNode);
  755.     mPipeline->AddNode(mShadowRenderNode);
  756.     mPipeline->AddNode(mCullingNode);
  757.     mPipeline->AddNode(mDrawNode);
  758.     mPipeline->AddNode(mReductionNode);
  759.     mPipeline->AddNode(mResolveNode);
  760.     mPipeline->AddNode(mRenderNode);
  761.  
  762.     mPipeline->Start();
  763.  
  764.     // Register events implemented on this class
  765.     Engine::EventChannel chan(mEventSystem);
  766.     chan.Add<Engine::Window::Resize>(*this);
  767.     //chan.Add<Engine::Task::TaskCompleted>(*this);
  768. }
  769.  
  770.  
  771. /// <summary>
  772. /// Default virtual destructor
  773. /// </summary>
  774. Renderer::~Renderer()
  775. {
  776.     if (mUseHardwareRaytracing)
  777.     {
  778.         delete mRaytraceHWNode;
  779.     }
  780.     else
  781.     {
  782.         delete mAccelerationNode;
  783.         delete mRaygenNode;
  784.         delete mRaytraceNode;
  785.     }
  786.     delete mRenderNodesNode;
  787.     delete mMaterialNode;
  788.     delete mShadowRenderNode;
  789.     delete mCullingNode;
  790.     delete mDrawNode;
  791.     delete mReductionNode;
  792.     delete mResolveNode;
  793.     delete mRenderNode;
  794.  
  795.     delete mPipeline;
  796. }
  797.  
  798. /// <summary>
  799. /// Initialize system
  800. /// </summary>
  801. /// <returns>True on success, false otherwise</returns>
  802. bool Renderer::Init()
  803. {
  804.     mImgui = new Engine::RenderPassImgui(mOptions, mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y);
  805.     ImGui::GetStyle().WindowBorderSize = 0;
  806.     ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
  807.  
  808.     mGBufferPass = new Engine::GBuffer(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y, mOptions->Get<int>("Renderer.Antialiasing.SamplesMSAA"));
  809.     mWireframePass = new Engine::RenderPassWireframe(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y, mOptions->Get<int>("Renderer.Antialiasing.SamplesMSAA"));
  810.     mTexturedPass = new Engine::RenderPassTextured(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y, mOptions->Get<int>("Renderer.Antialiasing.SamplesMSAA"));
  811.     //mNativeResolvePass = new Engine::RenderPassResolveNative(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y, mOptions->Get<int>("Renderer.Antialiasing.SamplesMSAA"));
  812.     mMultisampling = new Engine::Multisample(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y, mOptions->Get<int>("Renderer.Antialiasing.SamplesMSAA"));
  813.     mResolve = new Engine::RenderPassResolveMultisample(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y, mOptions->Get<int>("Renderer.Antialiasing.SamplesMSAA"));
  814.     mCulling = new Engine::Culling(mRenderer, mOptions->Get<int>("Renderer.Culling.MaxBuffers"), mOptions->Get<int>("Scene.MaxObjects"));
  815.     mLightingSystem = new Engine::LightingSystem(mRenderer, mOptions->Get<int>("Renderer.Lighting.MaxLights"), mOptions->Get<int>("Renderer.Lighting.VirtualShadowMapResolution"), mCulling);
  816.     mLightingPass = new Engine::LightingPass(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y, mOptions->Get<int>("Renderer.Antialiasing.SamplesMSAA"), mLightingSystem);
  817.     if (mUseHardwareRaytracing)
  818.     {
  819.         mRaytracerPassHW = new Engine::RenderPassRaytracerHW(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y);
  820.     }
  821.     else
  822.     {
  823.         mRaytracerPass = new Engine::RenderPassRaytracer(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y, mAppState->mRaytracer);
  824.     }
  825.     mHiZPass = new Engine::RenderPassHiZ(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y);
  826.     mAvgLuminance = new Engine::RenderPassAvgLuminance(mRenderer, mAppState->mWindowSize.x, mAppState->mWindowSize.y, mOptions->Get<int>("Renderer.Antialiasing.SamplesMSAA"));
  827.  
  828.     mGizmoPass = new Engine::RenderGizmo(mRenderer, 1024);
  829.  
  830.     //mAppState->mRenderNodes = new Engine::RenderNodeList(mRenderer, mOptions->Get<int>("Scene.MaxObjects"), std::vector<Engine::RootSignature*> { mTexturedPass->GetRootSignature(), mLightingSystem->GetRootSignature(), mHiZPass->GetRootSignature() });
  831.     mAppState->mRenderNodes = new Engine::RenderNodeList(mRenderer, mOptions->Get<int>("Scene.MaxObjects"), std::vector<Engine::RootSignature*> { mTexturedPass->GetRootSignature() });
  832.  
  833.     mAppState->mEditorSettingsDialog = new Engine::EditorSettingsDialog(mLog, mOptions, mImgui, "../Data/Config/ConfigModel.conf");
  834.  
  835.     return true;
  836. }
  837.  
  838. /// <summary>
  839. /// Shutdown system
  840. /// </summary>
  841. void Renderer::Shutdown()
  842. {
  843.     mRenderer->Flush();
  844.  
  845.     delete mAppState->mEditorSettingsDialog;
  846.  
  847.     delete mImgui;
  848.     delete mHiZPass;
  849.     delete mGBufferPass;
  850.     delete mWireframePass;
  851.     delete mTexturedPass;
  852.     //delete mNativeResolvePass;
  853.     delete mMultisampling;
  854.     delete mResolve;
  855.     delete mLightingSystem;
  856.     delete mCulling;
  857.     delete mLightingPass;
  858.     delete mRaytracerPass;
  859.     delete mRaytracerPassHW;
  860.     delete mAvgLuminance;
  861.     delete mGizmoPass;
  862. }
  863.  
  864. /// <summary>
  865. /// Update call on system
  866. /// </summary>
  867. void Renderer::Update()
  868. {
  869.     mPipeline->Update();
  870. }
  871.  
  872. /// <summary>
  873. /// Window resize
  874. /// </summary>
  875. /// <param name="r">Window resize event parameter structure</param>
  876. void Renderer::Handle(const Engine::Window::Resize& r)
  877. {
  878.     // Resize render pass objects bound to window size
  879.     mImgui->Resize(r.mWidth, r.mHeight);
  880. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement