From 34048910d029cceeb51af7703772580c3b29b121 Mon Sep 17 00:00:00 2001 From: Hinageshi <2247001665@qq.com> Date: Tue, 12 Sep 2023 12:01:49 +0800 Subject: [PATCH] Renderer::CreateGraphicsResources --- Engine/Source/Editor/EditorApp.cpp | 25 +++- Engine/Source/Editor/EditorApp.h | 4 + .../Editor/ImGui/EditorImGuiViewport.cpp | 6 +- .../Source/Editor/UILayers/AssetBrowser.cpp | 2 +- Engine/Source/Editor/UILayers/OutputLog.cpp | 2 +- .../Source/Runtime/ECWorld/TerrainComponent.h | 8 +- .../Runtime/ImGui/ImGuiContextInstance.cpp | 2 +- .../Source/Runtime/Rendering/AABBRenderer.cpp | 2 +- .../Source/Runtime/Rendering/AABBRenderer.h | 2 +- .../Runtime/Rendering/AnimationRenderer.cpp | 2 +- .../Runtime/Rendering/AnimationRenderer.h | 2 +- .../Rendering/BlitRenderTargetPass.cpp | 2 +- .../Runtime/Rendering/BlitRenderTargetPass.h | 2 +- .../Runtime/Rendering/BloomRenderer.cpp | 128 +++++++++++------- .../Source/Runtime/Rendering/BloomRenderer.h | 18 +-- .../Runtime/Rendering/DebugRenderer.cpp | 2 +- .../Source/Runtime/Rendering/DebugRenderer.h | 2 +- .../Runtime/Rendering/ImGuiRenderer.cpp | 11 +- .../Source/Runtime/Rendering/ImGuiRenderer.h | 2 +- .../Runtime/Rendering/PBRSkyRenderer.cpp | 10 +- .../Source/Runtime/Rendering/PBRSkyRenderer.h | 2 +- .../Runtime/Rendering/ParticleRenderer.cpp | 2 +- .../Runtime/Rendering/ParticleRenderer.h | 2 +- .../Runtime/Rendering/PostProcessRenderer.cpp | 8 +- .../Runtime/Rendering/PostProcessRenderer.h | 2 +- Engine/Source/Runtime/Rendering/Renderer.h | 2 +- .../Runtime/Rendering/SkeletonRenderer.cpp | 2 +- .../Runtime/Rendering/SkeletonRenderer.h | 2 +- .../Runtime/Rendering/SkyboxRenderer.cpp | 10 +- .../Source/Runtime/Rendering/SkyboxRenderer.h | 2 +- .../Runtime/Rendering/TerrainRenderer.cpp | 12 +- .../Runtime/Rendering/TerrainRenderer.h | 2 +- .../Runtime/Rendering/WorldRenderer.cpp | 12 +- .../Source/Runtime/Rendering/WorldRenderer.h | 2 +- 34 files changed, 167 insertions(+), 129 deletions(-) diff --git a/Engine/Source/Editor/EditorApp.cpp b/Engine/Source/Editor/EditorApp.cpp index 9e39459d..dc5882dd 100644 --- a/Engine/Source/Editor/EditorApp.cpp +++ b/Engine/Source/Editor/EditorApp.cpp @@ -91,6 +91,7 @@ void EditorApp::Init(engine::EngineInitArgs initArgs) AddWindow(cd::MoveTemp(pSplashWindow)); InitEditorRenderers(); + CreateEditorRendererGraphicsResources(); InitEditorImGuiContext(m_initArgs.language); InitECWorld(); @@ -446,6 +447,22 @@ void EditorApp::InitEngineRenderers() AddEngineRenderer(std::make_unique(m_pRenderContext->CreateView(), pSceneRenderTarget)); } +void EditorApp::CreateEditorRendererGraphicsResources() +{ + for (std::unique_ptr& pRenderer : m_pEditorRenderers) + { + pRenderer->CreateGraphicsResources(); + } +} + +void EditorApp::CreateEngineRendererGraphicsResources() +{ + for (std::unique_ptr& pRenderer : m_pEngineRenderers) + { + pRenderer->CreateGraphicsResources(); + } +} + bool EditorApp::IsAtmosphericScatteringEnable() const { engine::GraphicsBackend backend = engine::Path::GetGraphicsBackend(); @@ -502,18 +519,14 @@ bool EditorApp::Update(float deltaTime) { m_bInitEditor = true; - // Load compiled shaders. - for (std::unique_ptr& pRenderer : m_pEngineRenderers) - { - pRenderer->LoadShaders(); - } - engine::ShaderLoader::UploadUberShader(m_pSceneWorld->GetPBRMaterialType()); engine::ShaderLoader::UploadUberShader(m_pSceneWorld->GetAnimationMaterialType()); #ifdef ENABLE_DDGI engine::ShaderLoader::UploadUberShader(m_pSceneWorld->GetDDGIMaterialType()); #endif + CreateEngineRendererGraphicsResources(); + // Phase 2 - Project Manager // * TODO : Show project selector //GetMainWindow()->SetTitle("Project Manager"); diff --git a/Engine/Source/Editor/EditorApp.h b/Engine/Source/Editor/EditorApp.h index d28f2754..0932783e 100644 --- a/Engine/Source/Editor/EditorApp.h +++ b/Engine/Source/Editor/EditorApp.h @@ -52,6 +52,10 @@ class EditorApp final : public engine::IApplication void InitRenderContext(engine::GraphicsBackend backend, void* hwnd = nullptr); void InitEditorRenderers(); void InitEngineRenderers(); + + void CreateEditorRendererGraphicsResources(); + void CreateEngineRendererGraphicsResources(); + void InitShaderPrograms() const; void AddEditorRenderer(std::unique_ptr pRenderer); void AddEngineRenderer(std::unique_ptr pRenderer); diff --git a/Engine/Source/Editor/ImGui/EditorImGuiViewport.cpp b/Engine/Source/Editor/ImGui/EditorImGuiViewport.cpp index c3118ed2..92cc87d8 100644 --- a/Engine/Source/Editor/ImGui/EditorImGuiViewport.cpp +++ b/Engine/Source/Editor/ImGui/EditorImGuiViewport.cpp @@ -86,7 +86,7 @@ EditorImGuiViewport::EditorImGuiViewport(engine::RenderContext* pRenderContext) void EditorImGuiViewport::Update() { - //struct Rect { int left, top, width, height; }; + //struct Rect { int left, top, m_width, m_height; }; //struct Monitor { // Rect work_rect; // Rect monitor_rect; @@ -101,9 +101,9 @@ void EditorImGuiViewport::Update() // const os::Monitor& m = monitors[i]; // ImGuiPlatformMonitor im; // im.MainPos = ImVec2((float)m.monitor_rect.left, (float)m.monitor_rect.top); - // im.MainSize = ImVec2((float)m.monitor_rect.width, (float)m.monitor_rect.height); + // im.MainSize = ImVec2((float)m.monitor_rect.m_width, (float)m.monitor_rect.m_height); // im.WorkPos = ImVec2((float)m.work_rect.left, (float)m.work_rect.top); - // im.WorkSize = ImVec2((float)m.work_rect.width, (float)m.work_rect.height); + // im.WorkSize = ImVec2((float)m.work_rect.m_width, (float)m.work_rect.m_height); // // if (m.primary) { // pio.Monitors.push_front(im); diff --git a/Engine/Source/Editor/UILayers/AssetBrowser.cpp b/Engine/Source/Editor/UILayers/AssetBrowser.cpp index 7dd995f3..4313753b 100644 --- a/Engine/Source/Editor/UILayers/AssetBrowser.cpp +++ b/Engine/Source/Editor/UILayers/AssetBrowser.cpp @@ -1130,7 +1130,7 @@ void AssetBrowser::Update() // Column border size is fixed in ImGui // https://stackoverflow.com/questions/72068188/how-do-i-change-the-border-size-for-a-table-in-dear-imgui - // Colomn width doesn't have a flag to set only in the first frame. + // Colomn m_width doesn't have a flag to set only in the first frame. ImGui::SetColumnWidth(0, ImGui::GetWindowContentRegionMax().x * 0.3f); bFirstUpdate = false; } diff --git a/Engine/Source/Editor/UILayers/OutputLog.cpp b/Engine/Source/Editor/UILayers/OutputLog.cpp index 4b94fd10..8b3f011c 100644 --- a/Engine/Source/Editor/UILayers/OutputLog.cpp +++ b/Engine/Source/Editor/UILayers/OutputLog.cpp @@ -123,7 +123,7 @@ void OutputLog::Draw() { // If you have tens of thousands of items and their processing cost is non-negligible, coarse clipping them // on your side is recommended. Using ImGuiListClipper requires // - A) random access into your data - // - B) items all being the same height, + // - B) items all being the same m_height, // both of which we can handle since we have an array pointing to the beginning of each line of text. // When using the filter (in the block of code above) we don't have random access into the data to display // anymore, which is why we don't use the clipper. Storing or skimming through the search result would make diff --git a/Engine/Source/Runtime/ECWorld/TerrainComponent.h b/Engine/Source/Runtime/ECWorld/TerrainComponent.h index ff4213fd..2f571469 100644 --- a/Engine/Source/Runtime/ECWorld/TerrainComponent.h +++ b/Engine/Source/Runtime/ECWorld/TerrainComponent.h @@ -58,11 +58,11 @@ class TerrainComponent final private: //mesh - uint16_t m_meshWidth = 129U;//uint32_t is too big for width + uint16_t m_meshWidth = 129U;//uint32_t is too big for m_width uint16_t m_meshDepth = 129U; - //height map input - uint16_t m_texWidth = 129U;//uint32_t is too big for width + //m_height map input + uint16_t m_texWidth = 129U;//uint32_t is too big for m_width uint16_t m_texDepth = 129U;// float m_roughness = 1.55f; float m_minHeight = 0.0f; @@ -71,7 +71,7 @@ class TerrainComponent final //for patch wise generating //uint32_t m_PatchSize; - //height map output + //m_height map output std::vector m_elevationRawData; }; diff --git a/Engine/Source/Runtime/ImGui/ImGuiContextInstance.cpp b/Engine/Source/Runtime/ImGui/ImGuiContextInstance.cpp index 0f174135..be6f0e72 100644 --- a/Engine/Source/Runtime/ImGui/ImGuiContextInstance.cpp +++ b/Engine/Source/Runtime/ImGui/ImGuiContextInstance.cpp @@ -249,7 +249,7 @@ void ImGuiContextInstance::BeginDockSpace() ImGuiWindowFlags_NoBackground; // Place dock space window under static imgui layers. - // It is a hack now as only main menu bar is a static layer so we only need to adjust the height. + // It is a hack now as only main menu bar is a static layer so we only need to adjust the m_height. // If we have more static layers, we need to calculate their accurate areas. ImGuiViewport* pMainViewport = ImGui::GetMainViewport(); assert(pMainViewport && "The main viewport cannot be null"); diff --git a/Engine/Source/Runtime/Rendering/AABBRenderer.cpp b/Engine/Source/Runtime/Rendering/AABBRenderer.cpp index d2b3b957..5dccfdf3 100644 --- a/Engine/Source/Runtime/Rendering/AABBRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/AABBRenderer.cpp @@ -20,7 +20,7 @@ void AABBRenderer::Init() bgfx::setViewName(GetViewID(), "AABBRenderer"); } -void AABBRenderer::LoadShaders() +void AABBRenderer::CreateGraphicsResources() { GetRenderContext()->CreateProgram("AABBProgram", "vs_AABB.bin", "fs_AABB.bin"); } diff --git a/Engine/Source/Runtime/Rendering/AABBRenderer.h b/Engine/Source/Runtime/Rendering/AABBRenderer.h index 435243cc..075e2e33 100644 --- a/Engine/Source/Runtime/Rendering/AABBRenderer.h +++ b/Engine/Source/Runtime/Rendering/AABBRenderer.h @@ -15,7 +15,7 @@ class AABBRenderer final : public Renderer using Renderer::Renderer; virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; diff --git a/Engine/Source/Runtime/Rendering/AnimationRenderer.cpp b/Engine/Source/Runtime/Rendering/AnimationRenderer.cpp index 9f49e6ac..cf124221 100644 --- a/Engine/Source/Runtime/Rendering/AnimationRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/AnimationRenderer.cpp @@ -143,7 +143,7 @@ void AnimationRenderer::Init() bgfx::setViewName(GetViewID(), "AnimationRenderer"); } -void AnimationRenderer::LoadShaders() +void AnimationRenderer::CreateGraphicsResources() { #ifdef VISUALIZE_BONE_WEIGHTS m_pRenderContext->CreateUniform("u_debugBoneIndex", bgfx::UniformType::Vec4, 1); diff --git a/Engine/Source/Runtime/Rendering/AnimationRenderer.h b/Engine/Source/Runtime/Rendering/AnimationRenderer.h index dc4a25fa..25cecb7a 100644 --- a/Engine/Source/Runtime/Rendering/AnimationRenderer.h +++ b/Engine/Source/Runtime/Rendering/AnimationRenderer.h @@ -15,7 +15,7 @@ class AnimationRenderer final : public Renderer using Renderer::Renderer; virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; diff --git a/Engine/Source/Runtime/Rendering/BlitRenderTargetPass.cpp b/Engine/Source/Runtime/Rendering/BlitRenderTargetPass.cpp index 0b6a9a4d..d22d3c35 100644 --- a/Engine/Source/Runtime/Rendering/BlitRenderTargetPass.cpp +++ b/Engine/Source/Runtime/Rendering/BlitRenderTargetPass.cpp @@ -14,7 +14,7 @@ BlitRenderTargetPass::~BlitRenderTargetPass() { } -void BlitRenderTargetPass::LoadShaders() +void BlitRenderTargetPass::CreateGraphicsResources() { } diff --git a/Engine/Source/Runtime/Rendering/BlitRenderTargetPass.h b/Engine/Source/Runtime/Rendering/BlitRenderTargetPass.h index 72e46ff7..a4387c26 100644 --- a/Engine/Source/Runtime/Rendering/BlitRenderTargetPass.h +++ b/Engine/Source/Runtime/Rendering/BlitRenderTargetPass.h @@ -12,7 +12,7 @@ class BlitRenderTargetPass final : public Renderer virtual ~BlitRenderTargetPass(); virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; diff --git a/Engine/Source/Runtime/Rendering/BloomRenderer.cpp b/Engine/Source/Runtime/Rendering/BloomRenderer.cpp index d91672f4..7477aa45 100644 --- a/Engine/Source/Runtime/Rendering/BloomRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/BloomRenderer.cpp @@ -16,6 +16,39 @@ namespace engine pShaderVariantCollectionsComponent->AddShader("fs_upsample"); pShaderVariantCollectionsComponent->AddShader("fs_kawaseblur"); pShaderVariantCollectionsComponent->AddShader("fs_bloom"); + + bgfx::setViewName(GetViewID(), "BloomRenderer"); + } + + void BloomRenderer::CreateGraphicsResources() + { + for (int i = 0; i < TEX_CHAIN_LEN; i++) + { + m_sampleChainFB[i] = BGFX_INVALID_HANDLE; + } + for (int i = 0; i < 2; i++) + { + m_blurChainFB[i] = BGFX_INVALID_HANDLE; + } + m_combineFB = BGFX_INVALID_HANDLE; + m_startDowmSamplePassID = GetRenderContext()->CreateView(); + for (int i = 0; i < TEX_CHAIN_LEN - 2; i++) + { + GetRenderContext()->CreateView(); + } + m_startVerticalBlurPassID = GetRenderContext()->CreateView(); + m_startHorizontalBlurPassID = GetRenderContext()->CreateView(); + for (int i = 0; i < 40 - 2; i++) + { + GetRenderContext()->CreateView(); + } + m_startUpSamplePassID = GetRenderContext()->CreateView(); + for (int i = 0; i < TEX_CHAIN_LEN - 2; i++) + { + GetRenderContext()->CreateView(); + } + m_CombinePassID = GetRenderContext()->CreateView(); + m_blitColorPassID = GetRenderContext()->CreateView(); GetRenderContext()->CreateUniform("s_texture", bgfx::UniformType::Sampler); GetRenderContext()->CreateUniform("s_bloom", bgfx::UniformType::Sampler); @@ -24,25 +57,6 @@ namespace engine GetRenderContext()->CreateUniform("u_bloomIntensity", bgfx::UniformType::Vec4); GetRenderContext()->CreateUniform("u_luminanceThreshold", bgfx::UniformType::Vec4); - bgfx::setViewName(GetViewID(), "BloomRenderer"); - - for (int i = 0; i < TEX_CHAIN_LEN; i++) m_sampleChainFB[i] = BGFX_INVALID_HANDLE; - for (int i = 0; i < 2; i++) m_blurChainFB[i] = BGFX_INVALID_HANDLE; - m_combineFB = BGFX_INVALID_HANDLE; - - start_dowmSamplePassID = GetRenderContext()->CreateView(); - for (int i = 0; i < TEX_CHAIN_LEN - 2; i++) GetRenderContext()->CreateView(); - start_verticalBlurPassID = GetRenderContext()->CreateView(); - start_horizontalBlurPassID = GetRenderContext()->CreateView(); - for (int i = 0; i < 40 - 2; i++) GetRenderContext()->CreateView(); - start_upSamplePassID = GetRenderContext()->CreateView(); - for (int i = 0; i < TEX_CHAIN_LEN - 2; i++) GetRenderContext()->CreateView(); - combinePassID = GetRenderContext()->CreateView(); - blit_colorPassID = GetRenderContext()->CreateView(); - } - - void BloomRenderer::LoadShaders() - { GetRenderContext()->CreateProgram("CapTureBrightnessProgram", "vs_fullscreen.bin", "fs_captureBrightness.bin"); GetRenderContext()->CreateProgram("DownSampleProgram", "vs_fullscreen.bin", "fs_dowmsample.bin"); GetRenderContext()->CreateProgram("BlurVerticalProgram", "vs_fullscreen.bin", "fs_blurvertical.bin"); @@ -86,19 +100,26 @@ namespace engine tempH = GetRenderContext()->GetBackBufferHeight(); } - if (width != tempW || height != tempH) { - width = tempW; - height = tempH; + if (m_width != tempW || m_height != tempH) + { + m_width = tempW; + m_height = tempH; - const uint64_t tsFlags = 0 | BGFX_TEXTURE_RT | BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP; + constexpr uint64_t tsFlags = 0 | BGFX_TEXTURE_RT | BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP; for (int ii = 0; ii < TEX_CHAIN_LEN; ++ii) { - if (bgfx::isValid(m_sampleChainFB[ii])) bgfx::destroy(m_sampleChainFB[ii]); - if ((height >> ii) < 2 || (width >> ii) < 2) break; - m_sampleChainFB[ii] = bgfx::createFrameBuffer(width >> ii, height >> ii, bgfx::TextureFormat::RGBA32F, tsFlags); + if (bgfx::isValid(m_sampleChainFB[ii])) + { + bgfx::destroy(m_sampleChainFB[ii]); + } + if ((m_height >> ii) < 2 || (m_width >> ii) < 2) + { + break; + } + m_sampleChainFB[ii] = bgfx::createFrameBuffer(m_width >> ii, m_height >> ii, bgfx::TextureFormat::RGBA32F, tsFlags); } - m_combineFB = bgfx::createFrameBuffer(width, height, bgfx::TextureFormat::RGBA32F, tsFlags); + m_combineFB = bgfx::createFrameBuffer(m_width, m_height, bgfx::TextureFormat::RGBA32F, tsFlags); } } @@ -130,9 +151,9 @@ namespace engine cd::Matrix4x4 orthoMatrix = cd::Matrix4x4::Orthographic(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1000.0f, 0.0f, bgfx::getCaps()->homogeneousDepth); - //capture + // capture bgfx::setViewFrameBuffer(GetViewID(), m_sampleChainFB[0]); - bgfx::setViewRect(GetViewID(), 0, 0, width, height); + bgfx::setViewRect(GetViewID(), 0, 0, m_width, m_height); bgfx::setViewTransform(GetViewID(), nullptr, orthoMatrix.Begin()); constexpr StringCrc luminanceThresholdUniformName("u_luminanceThreshold"); @@ -153,19 +174,23 @@ namespace engine for (int i = 0; i < sampleTimes; ++i) { int shift = i + 1; - if ((width >> shift) < 2 || (height >> shift) < 2) break; + if ((m_width >> shift) < 2 || (m_height >> shift) < 2) + { + break; + } + tempshift = shift; const float pixelSize[4] = { - 1.0f / static_cast(width >> shift), - 1.0f / static_cast(height >> shift), + 1.0f / static_cast(m_width >> shift), + 1.0f / static_cast(m_height >> shift), 0.0f, 0.0f, }; - bgfx::setViewFrameBuffer(start_dowmSamplePassID + i, m_sampleChainFB[shift]); - bgfx::setViewRect(start_dowmSamplePassID + i, 0, 0, width >> shift, height >> shift); - bgfx::setViewTransform(start_dowmSamplePassID + i, nullptr, orthoMatrix.Begin()); + bgfx::setViewFrameBuffer(m_startDowmSamplePassID + i, m_sampleChainFB[shift]); + bgfx::setViewRect(m_startDowmSamplePassID + i, 0, 0, m_width >> shift, m_height >> shift); + bgfx::setViewTransform(m_startDowmSamplePassID + i, nullptr, orthoMatrix.Begin()); constexpr StringCrc textureSizeUniformName("u_textureSize"); bgfx::setUniform(GetRenderContext()->GetUniform(textureSizeUniformName), pixelSize); @@ -176,34 +201,34 @@ namespace engine Renderer::ScreenSpaceQuad(GetRenderTarget(), false); constexpr StringCrc DownSampleprogramName("DownSampleProgram"); - bgfx::submit(start_dowmSamplePassID + i, GetRenderContext()->GetProgram(DownSampleprogramName)); + bgfx::submit(m_startDowmSamplePassID + i, GetRenderContext()->GetProgram(DownSampleprogramName)); } if (pCameraComponent->GetIsBlurEnable() && pCameraComponent->GetBlurTimes() != 0) { - Blur(width >> tempshift, height >> tempshift, pCameraComponent->GetBlurTimes(), pCameraComponent->GetBlurSize(),pCameraComponent->GetBlurScaling(), orthoMatrix, bgfx::getTexture(m_sampleChainFB[tempshift])); + Blur(m_width >> tempshift, m_height >> tempshift, pCameraComponent->GetBlurTimes(), pCameraComponent->GetBlurSize(),pCameraComponent->GetBlurScaling(), orthoMatrix, bgfx::getTexture(m_sampleChainFB[tempshift])); } // upsample for (int i = 0; i < sampleTimes; ++i) { int shift = sampleTimes - i - 1; - if ((width >> shift) < 2 || (height >> shift) < 2) + if ((m_width >> shift) < 2 || (m_height >> shift) < 2) { continue; } const float pixelSize[4] = { - 1.0f / static_cast(width >> shift), - 1.0f / static_cast(height >> shift), + 1.0f / static_cast(m_width >> shift), + 1.0f / static_cast(m_height >> shift), 0.0f, 0.0f, }; - bgfx::setViewFrameBuffer(start_upSamplePassID + i, m_sampleChainFB[shift]); - bgfx::setViewRect(start_upSamplePassID + i, 0, 0, width >> shift, height >> shift); - bgfx::setViewTransform(start_upSamplePassID + i, nullptr, orthoMatrix.Begin()); + bgfx::setViewFrameBuffer(m_startUpSamplePassID + i, m_sampleChainFB[shift]); + bgfx::setViewRect(m_startUpSamplePassID + i, 0, 0, m_width >> shift, m_height >> shift); + bgfx::setViewTransform(m_startUpSamplePassID + i, nullptr, orthoMatrix.Begin()); constexpr StringCrc textureSizeUniformName("u_textureSize"); bgfx::setUniform(GetRenderContext()->GetUniform(textureSizeUniformName), pixelSize); @@ -224,13 +249,13 @@ namespace engine Renderer::ScreenSpaceQuad(GetRenderTarget(), false); constexpr StringCrc UpSampleprogramName("UpSampleProgram"); - bgfx::submit(start_upSamplePassID + i, GetRenderContext()->GetProgram(UpSampleprogramName)); + bgfx::submit(m_startUpSamplePassID + i, GetRenderContext()->GetProgram(UpSampleprogramName)); } // combine - bgfx::setViewFrameBuffer(combinePassID, m_combineFB); - bgfx::setViewRect(combinePassID, 0, 0, width, height); - bgfx::setViewTransform(combinePassID, nullptr, orthoMatrix.Begin()); + bgfx::setViewFrameBuffer(m_CombinePassID, m_combineFB); + bgfx::setViewRect(m_CombinePassID, 0, 0, m_width, m_height); + bgfx::setViewTransform(m_CombinePassID, nullptr, orthoMatrix.Begin()); constexpr StringCrc lightColorSampler("s_lightingColor"); bgfx::setTexture(0, GetRenderContext()->GetUniform(lightColorSampler), screenTextureHandle); @@ -242,9 +267,9 @@ namespace engine Renderer::ScreenSpaceQuad(GetRenderTarget(), false); constexpr StringCrc CombineprogramName("CombineProgram"); - bgfx::submit(combinePassID, GetRenderContext()->GetProgram(CombineprogramName)); + bgfx::submit(m_CombinePassID, GetRenderContext()->GetProgram(CombineprogramName)); - bgfx::blit(blit_colorPassID, screenTextureHandle, 0, 0, bgfx::getTexture(m_combineFB)); + bgfx::blit(m_blitColorPassID, screenTextureHandle, 0, 0, bgfx::getTexture(m_combineFB)); } void BloomRenderer::Blur(uint16_t width, uint16_t height, int iteration,float blursize, int blurscaling,cd::Matrix4x4 ortho,bgfx::TextureHandle texture) @@ -259,8 +284,8 @@ namespace engine m_blurChainFB[ii] = bgfx::createFrameBuffer(width, height, bgfx::TextureFormat::RGBA32F, tsFlags); } - uint16_t vertical = start_verticalBlurPassID; - uint16_t horizontal = start_horizontalBlurPassID; + uint16_t vertical = m_startVerticalBlurPassID; + uint16_t horizontal = m_startHorizontalBlurPassID; for (int i = 0; i < iteration; i++) { float pixelSize[4] = @@ -309,5 +334,4 @@ namespace engine horizontal += 2; } } - } diff --git a/Engine/Source/Runtime/Rendering/BloomRenderer.h b/Engine/Source/Runtime/Rendering/BloomRenderer.h index 51bb1c15..e1916fd3 100644 --- a/Engine/Source/Runtime/Rendering/BloomRenderer.h +++ b/Engine/Source/Runtime/Rendering/BloomRenderer.h @@ -17,7 +17,7 @@ namespace engine virtual ~BloomRenderer(); virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; @@ -35,15 +35,15 @@ namespace engine bgfx::FrameBufferHandle m_sampleChainFB[TEX_CHAIN_LEN]; bgfx::FrameBufferHandle m_combineFB; - uint16_t width; - uint16_t height; + uint16_t m_width; + uint16_t m_height; - uint16_t start_dowmSamplePassID; - uint16_t start_verticalBlurPassID; - uint16_t start_horizontalBlurPassID; - uint16_t start_upSamplePassID; - uint16_t blit_colorPassID; - uint16_t combinePassID; + uint16_t m_startDowmSamplePassID; + uint16_t m_startVerticalBlurPassID; + uint16_t m_startHorizontalBlurPassID; + uint16_t m_startUpSamplePassID; + uint16_t m_blitColorPassID; + uint16_t m_CombinePassID; }; } \ No newline at end of file diff --git a/Engine/Source/Runtime/Rendering/DebugRenderer.cpp b/Engine/Source/Runtime/Rendering/DebugRenderer.cpp index 5cd95e82..fe99f1ba 100644 --- a/Engine/Source/Runtime/Rendering/DebugRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/DebugRenderer.cpp @@ -20,7 +20,7 @@ void DebugRenderer::Init() bgfx::setViewName(GetViewID(), "DebugRenderer"); } -void DebugRenderer::LoadShaders() +void DebugRenderer::CreateGraphicsResources() { GetRenderContext()->CreateProgram("DebugProgram", "vs_debug.bin", "fs_debug.bin"); } diff --git a/Engine/Source/Runtime/Rendering/DebugRenderer.h b/Engine/Source/Runtime/Rendering/DebugRenderer.h index 3bc20389..28176b47 100644 --- a/Engine/Source/Runtime/Rendering/DebugRenderer.h +++ b/Engine/Source/Runtime/Rendering/DebugRenderer.h @@ -15,7 +15,7 @@ class DebugRenderer final : public Renderer using Renderer::Renderer; virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; diff --git a/Engine/Source/Runtime/Rendering/ImGuiRenderer.cpp b/Engine/Source/Runtime/Rendering/ImGuiRenderer.cpp index c693f409..75196585 100644 --- a/Engine/Source/Runtime/Rendering/ImGuiRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/ImGuiRenderer.cpp @@ -8,6 +8,11 @@ namespace engine { void ImGuiRenderer::Init() +{ + bgfx::setViewName(GetViewID(), "ImGuiRenderer"); +} + +void ImGuiRenderer::CreateGraphicsResources() { constexpr StringCrc imguiVertexLayoutName("imgui_vertex_layout"); if (0 == GetRenderContext()->GetVertexLayout(imguiVertexLayoutName).m_stride) @@ -22,12 +27,6 @@ void ImGuiRenderer::Init() } GetRenderContext()->CreateUniform("s_tex", bgfx::UniformType::Sampler); - - bgfx::setViewName(GetViewID(), "ImGuiRenderer"); -} - -void ImGuiRenderer::LoadShaders() -{ GetRenderContext()->CreateProgram("ImGuiProgram", "vs_imgui.bin", "fs_imgui.bin"); } diff --git a/Engine/Source/Runtime/Rendering/ImGuiRenderer.h b/Engine/Source/Runtime/Rendering/ImGuiRenderer.h index 49292f65..a0ccb866 100644 --- a/Engine/Source/Runtime/Rendering/ImGuiRenderer.h +++ b/Engine/Source/Runtime/Rendering/ImGuiRenderer.h @@ -12,7 +12,7 @@ class ImGuiRenderer final : public engine::Renderer virtual ~ImGuiRenderer(); virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; }; diff --git a/Engine/Source/Runtime/Rendering/PBRSkyRenderer.cpp b/Engine/Source/Runtime/Rendering/PBRSkyRenderer.cpp index 55bd2802..d22ad07f 100644 --- a/Engine/Source/Runtime/Rendering/PBRSkyRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/PBRSkyRenderer.cpp @@ -61,6 +61,11 @@ void PBRSkyRenderer::Init() pShaderVariantCollectionsComponent->AddShader("cs_ComputeIndirectIrradiance"); pShaderVariantCollectionsComponent->AddShader("cs_ComputeMultipleScattering"); + bgfx::setViewName(GetViewID(), "PBRSkyRenderer"); +} + +void PBRSkyRenderer::CreateGraphicsResources() +{ GetRenderContext()->CreateTexture(TextureTransmittance, TRANSMITTANCE_TEXTURE_WIDTH, TRANSMITTANCE_TEXTURE_HEIGHT, 1, bgfx::TextureFormat::RGBA32F, FlagTexture2D); GetRenderContext()->CreateTexture(TextureIrradiance, IRRADIANCE_TEXTURE_WIDTH, IRRADIANCE_TEXTURE_HEIGHT, 1, @@ -83,11 +88,6 @@ void PBRSkyRenderer::Init() GetRenderContext()->CreateUniform(HeightOffset, bgfx::UniformType::Enum::Vec4, 1); GetRenderContext()->CreateUniform(NumScatteringOrders, bgfx::UniformType::Enum::Vec4, 1); - bgfx::setViewName(GetViewID(), "PBRSkyRenderer"); -} - -void PBRSkyRenderer::LoadShaders() -{ GetRenderContext()->CreateProgram(ProgramAtmosphericScatteringLUT, "vs_atmSkyBox.bin", "fs_PrecomputedAtmosphericScattering_LUT.bin"); GetRenderContext()->CreateProgram(ProgramSingleScatteringRayMarching, "vs_atmSkyBox.bin", "fs_SingleScattering_RayMarching.bin"); diff --git a/Engine/Source/Runtime/Rendering/PBRSkyRenderer.h b/Engine/Source/Runtime/Rendering/PBRSkyRenderer.h index f12915a4..b6f648d6 100644 --- a/Engine/Source/Runtime/Rendering/PBRSkyRenderer.h +++ b/Engine/Source/Runtime/Rendering/PBRSkyRenderer.h @@ -15,7 +15,7 @@ class PBRSkyRenderer final : public Renderer using Renderer::Renderer; virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; virtual bool IsEnable() const override; diff --git a/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp b/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp index d60a1198..f3a243c4 100644 --- a/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/ParticleRenderer.cpp @@ -17,7 +17,7 @@ void ParticleRenderer::Init() bgfx::setViewName(GetViewID(), "ParticleRenderer"); } -void ParticleRenderer::LoadShaders() +void ParticleRenderer::CreateGraphicsResources() { } diff --git a/Engine/Source/Runtime/Rendering/ParticleRenderer.h b/Engine/Source/Runtime/Rendering/ParticleRenderer.h index cbbb499d..cc968611 100644 --- a/Engine/Source/Runtime/Rendering/ParticleRenderer.h +++ b/Engine/Source/Runtime/Rendering/ParticleRenderer.h @@ -13,7 +13,7 @@ class ParticleRenderer final : public Renderer using Renderer::Renderer; virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; diff --git a/Engine/Source/Runtime/Rendering/PostProcessRenderer.cpp b/Engine/Source/Runtime/Rendering/PostProcessRenderer.cpp index 70a46735..4be92dd3 100644 --- a/Engine/Source/Runtime/Rendering/PostProcessRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/PostProcessRenderer.cpp @@ -12,14 +12,14 @@ namespace engine pShaderVariantCollectionsComponent->AddShader("vs_fullscreen"); pShaderVariantCollectionsComponent->AddShader("fs_PBR_postProcessing"); - GetRenderContext()->CreateUniform("s_lightingColor", bgfx::UniformType::Sampler); - GetRenderContext()->CreateUniform("u_gamma", bgfx::UniformType::Vec4); - bgfx::setViewName(GetViewID(), "PostProcessRenderer"); } - void PostProcessRenderer::LoadShaders() + void PostProcessRenderer::CreateGraphicsResources() { + GetRenderContext()->CreateUniform("u_gamma", bgfx::UniformType::Vec4); + GetRenderContext()->CreateUniform("s_lightingColor", bgfx::UniformType::Sampler); + GetRenderContext()->CreateProgram("PostProcessProgram", "vs_fullscreen.bin", "fs_PBR_postProcessing.bin"); } diff --git a/Engine/Source/Runtime/Rendering/PostProcessRenderer.h b/Engine/Source/Runtime/Rendering/PostProcessRenderer.h index 768899f7..c090d95f 100644 --- a/Engine/Source/Runtime/Rendering/PostProcessRenderer.h +++ b/Engine/Source/Runtime/Rendering/PostProcessRenderer.h @@ -13,7 +13,7 @@ namespace engine virtual ~PostProcessRenderer(); virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; diff --git a/Engine/Source/Runtime/Rendering/Renderer.h b/Engine/Source/Runtime/Rendering/Renderer.h index 120ac8ed..1e562aed 100644 --- a/Engine/Source/Runtime/Rendering/Renderer.h +++ b/Engine/Source/Runtime/Rendering/Renderer.h @@ -24,7 +24,7 @@ class Renderer static RenderContext* GetRenderContext(); virtual void Init() = 0; - virtual void LoadShaders() = 0; + virtual void CreateGraphicsResources() = 0; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) = 0; virtual void Render(float deltaTime) = 0; diff --git a/Engine/Source/Runtime/Rendering/SkeletonRenderer.cpp b/Engine/Source/Runtime/Rendering/SkeletonRenderer.cpp index 89623fbc..6f67e3d9 100644 --- a/Engine/Source/Runtime/Rendering/SkeletonRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/SkeletonRenderer.cpp @@ -64,7 +64,7 @@ void SkeletonRenderer::Init() bgfx::setViewName(GetViewID(), "SkeletonRenderer"); } -void SkeletonRenderer::LoadShaders() +void SkeletonRenderer::CreateGraphicsResources() { GetRenderContext()->CreateProgram("SkeletonProgram", "vs_AABB.bin", "fs_AABB.bin"); } diff --git a/Engine/Source/Runtime/Rendering/SkeletonRenderer.h b/Engine/Source/Runtime/Rendering/SkeletonRenderer.h index 54606309..8dbc49b7 100644 --- a/Engine/Source/Runtime/Rendering/SkeletonRenderer.h +++ b/Engine/Source/Runtime/Rendering/SkeletonRenderer.h @@ -14,7 +14,7 @@ class SkeletonRenderer final : public Renderer using Renderer::Renderer; virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; void Build(); diff --git a/Engine/Source/Runtime/Rendering/SkyboxRenderer.cpp b/Engine/Source/Runtime/Rendering/SkyboxRenderer.cpp index 23c90ccd..dee5eca9 100644 --- a/Engine/Source/Runtime/Rendering/SkyboxRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/SkyboxRenderer.cpp @@ -26,16 +26,16 @@ void SkyboxRenderer::Init() pShaderVariantCollectionsComponent->AddShader("vs_skybox"); pShaderVariantCollectionsComponent->AddShader("fs_skybox"); + bgfx::setViewName(GetViewID(), "SkyboxRenderer"); +} + +void SkyboxRenderer::CreateGraphicsResources() +{ SkyComponent* pSkyComponent = m_pCurrentSceneWorld->GetSkyComponent(m_pCurrentSceneWorld->GetSkyEntity()); GetRenderContext()->CreateUniform(skyboxSampler, bgfx::UniformType::Sampler); GetRenderContext()->CreateTexture(pSkyComponent->GetRadianceTexturePath().c_str(), sampleFalg); - bgfx::setViewName(GetViewID(), "SkyboxRenderer"); -} - -void SkyboxRenderer::LoadShaders() -{ GetRenderContext()->CreateProgram(skyboxShader, "vs_skybox.bin", "fs_skybox.bin"); } diff --git a/Engine/Source/Runtime/Rendering/SkyboxRenderer.h b/Engine/Source/Runtime/Rendering/SkyboxRenderer.h index 18ab764e..cea457ac 100644 --- a/Engine/Source/Runtime/Rendering/SkyboxRenderer.h +++ b/Engine/Source/Runtime/Rendering/SkyboxRenderer.h @@ -13,7 +13,7 @@ class SkyboxRenderer final : public Renderer using Renderer::Renderer; virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; virtual bool IsEnable() const override; diff --git a/Engine/Source/Runtime/Rendering/TerrainRenderer.cpp b/Engine/Source/Runtime/Rendering/TerrainRenderer.cpp index 5f6ff12c..b52400b7 100644 --- a/Engine/Source/Runtime/Rendering/TerrainRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/TerrainRenderer.cpp @@ -59,8 +59,13 @@ void TerrainRenderer::Init() pShaderVariantCollectionsComponent->AddShader("vs_terrain"); pShaderVariantCollectionsComponent->AddShader("fs_terrain"); + bgfx::setViewName(GetViewID(), "TerrainRenderer"); +} + +void TerrainRenderer::CreateGraphicsResources() +{ SkyComponent* pSkyComponent = m_pCurrentSceneWorld->GetSkyComponent(m_pCurrentSceneWorld->GetSkyEntity()); - + GetRenderContext()->CreateUniform(snowSampler, bgfx::UniformType::Sampler); GetRenderContext()->CreateUniform(rockSampler, bgfx::UniformType::Sampler); GetRenderContext()->CreateUniform(grassSampler, bgfx::UniformType::Sampler); @@ -87,11 +92,6 @@ void TerrainRenderer::Init() GetRenderContext()->CreateTexture(elevationTexture, 129U, 129U, 1, bgfx::TextureFormat::Enum::R32F, samplerFlags, nullptr, 0); - bgfx::setViewName(GetViewID(), "TerrainRenderer"); -} - -void TerrainRenderer::LoadShaders() -{ GetRenderContext()->CreateProgram("TerrainProgram", "vs_terrain.bin", "fs_terrain.bin"); } diff --git a/Engine/Source/Runtime/Rendering/TerrainRenderer.h b/Engine/Source/Runtime/Rendering/TerrainRenderer.h index f172acde..4b946e9c 100644 --- a/Engine/Source/Runtime/Rendering/TerrainRenderer.h +++ b/Engine/Source/Runtime/Rendering/TerrainRenderer.h @@ -13,7 +13,7 @@ class TerrainRenderer final : public Renderer using Renderer::Renderer; virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override; diff --git a/Engine/Source/Runtime/Rendering/WorldRenderer.cpp b/Engine/Source/Runtime/Rendering/WorldRenderer.cpp index 428ee55c..07834b2b 100644 --- a/Engine/Source/Runtime/Rendering/WorldRenderer.cpp +++ b/Engine/Source/Runtime/Rendering/WorldRenderer.cpp @@ -52,6 +52,11 @@ void WorldRenderer::Init() pShaderVariantCollectionsComponent->AddShader("vs_PBR"); pShaderVariantCollectionsComponent->AddShader("fs_PBR"); + bgfx::setViewName(GetViewID(), "WorldRenderer"); +} + +void WorldRenderer::CreateGraphicsResources() +{ SkyComponent* pSkyComponent = m_pCurrentSceneWorld->GetSkyComponent(m_pCurrentSceneWorld->GetSkyEntity()); GetRenderContext()->CreateUniform(lutSampler, bgfx::UniformType::Sampler); @@ -74,13 +79,6 @@ void WorldRenderer::Init() GetRenderContext()->CreateUniform(LightDir, bgfx::UniformType::Vec4, 1); GetRenderContext()->CreateUniform(HeightOffsetAndshadowLength, bgfx::UniformType::Vec4, 1); - - bgfx::setViewName(GetViewID(), "WorldRenderer"); -} - -void WorldRenderer::LoadShaders() -{ - // TODO : Transfer controling of shader in material to SVC. } void WorldRenderer::UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) diff --git a/Engine/Source/Runtime/Rendering/WorldRenderer.h b/Engine/Source/Runtime/Rendering/WorldRenderer.h index 06ba6967..0725cf0b 100644 --- a/Engine/Source/Runtime/Rendering/WorldRenderer.h +++ b/Engine/Source/Runtime/Rendering/WorldRenderer.h @@ -13,7 +13,7 @@ class WorldRenderer final : public Renderer using Renderer::Renderer; virtual void Init() override; - virtual void LoadShaders() override; + virtual void CreateGraphicsResources() override; virtual void UpdateView(const float* pViewMatrix, const float* pProjectionMatrix) override; virtual void Render(float deltaTime) override;