Advertisement
Zgragselus

Untitled

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