Skip to content

Commit

Permalink
No more treating SVC as a component.
Browse files Browse the repository at this point in the history
  • Loading branch information
roeas committed Sep 14, 2023
1 parent 1353ac1 commit 8b6d9a3
Show file tree
Hide file tree
Showing 25 changed files with 103 additions and 132 deletions.
25 changes: 10 additions & 15 deletions Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Rendering/RenderContext.h"
#include "Rendering/SkeletonRenderer.h"
#include "Rendering/SkyboxRenderer.h"
#include "Rendering/ShaderVariantCollections.h"
#include "Rendering/TerrainRenderer.h"
#include "Rendering/WorldRenderer.h"
#include "Rendering/ParticleRenderer.h"
Expand Down Expand Up @@ -87,6 +88,8 @@ void EditorApp::Init(engine::EngineInitArgs initArgs)

// Init graphics backend
InitRenderContext(m_initArgs.backend, pSplashWindow->GetNativeHandle());
InitShaderVariantCollections();

pSplashWindow->OnResize.Bind<engine::RenderContext, &engine::RenderContext::OnResize>(m_pRenderContext.get());
AddWindow(cd::MoveTemp(pSplashWindow));

Expand Down Expand Up @@ -247,7 +250,6 @@ void EditorApp::InitECWorld()
InitEditorCameraEntity();

InitSkyEntity();
InitShaderVariantCollectionEntity();

#ifdef ENABLE_DDGI
m_pSceneWorld->InitDDGISDK();
Expand Down Expand Up @@ -325,19 +327,6 @@ void EditorApp::InitSkyEntity()
meshComponent.Build();
}

void EditorApp::InitShaderVariantCollectionEntity()
{
engine::World* pWorld = m_pSceneWorld->GetWorld();

engine::Entity shaderVariantCollectionEntity = pWorld->CreateEntity();
m_pSceneWorld->SetShaderVariantCollectionEntity(shaderVariantCollectionEntity);

auto& nameComponent = pWorld->CreateComponent<engine::NameComponent>(shaderVariantCollectionEntity);
nameComponent.SetName("ShaderVariantCollection");

auto& shaderVariantCollectionsComponent = pWorld->CreateComponent<engine::ShaderVariantCollectionsComponent>(shaderVariantCollectionEntity);
}

#ifdef ENABLE_DDGI
void EditorApp::InitDDGIEntity()
{
Expand All @@ -363,6 +352,12 @@ void EditorApp::InitRenderContext(engine::GraphicsBackend backend, void* hwnd)
engine::Renderer::SetRenderContext(m_pRenderContext.get());
}

void EditorApp::InitShaderVariantCollections()
{
m_pShaderVariantCollections = std::make_unique<engine::ShaderVariantCollections>();
engine::Renderer::SetShaderVariantCollections(m_pShaderVariantCollections.get());
}

void EditorApp::InitEditorRenderers()
{
AddEditorRenderer(std::make_unique<engine::ImGuiRenderer>(m_pRenderContext->CreateView()));
Expand Down Expand Up @@ -474,7 +469,7 @@ bool EditorApp::IsAtmosphericScatteringEnable() const

void EditorApp::InitShaderPrograms() const
{
ShaderBuilder::BuildShaders(m_pSceneWorld.get());
ShaderBuilder::BuildShaders(m_pShaderVariantCollections.get());

ShaderBuilder::BuildUberShader(m_pSceneWorld->GetPBRMaterialType());
ShaderBuilder::BuildUberShader(m_pSceneWorld->GetAnimationMaterialType());
Expand Down
6 changes: 5 additions & 1 deletion Engine/Source/Editor/EditorApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Renderer;
class AABBRenderer;
class RenderTarget;
class SceneWorld;
class ShaderVariantCollections;

}

Expand Down Expand Up @@ -50,6 +51,8 @@ class EditorApp final : public engine::IApplication
void RemoveWindow(size_t index);

void InitRenderContext(engine::GraphicsBackend backend, void* hwnd = nullptr);
void InitShaderVariantCollections();

void InitEditorRenderers();
void InitEngineRenderers();

Expand All @@ -75,7 +78,6 @@ class EditorApp final : public engine::IApplication
private:
void InitEditorCameraEntity();
void InitSkyEntity();
void InitShaderVariantCollectionEntity();

#ifdef ENABLE_DDGI
void InitDDGIEntity();
Expand Down Expand Up @@ -104,6 +106,8 @@ class EditorApp final : public engine::IApplication

// Rendering
std::unique_ptr<engine::RenderContext> m_pRenderContext;
std::unique_ptr<engine::ShaderVariantCollections> m_pShaderVariantCollections;

std::vector<std::unique_ptr<engine::Renderer>> m_pEditorRenderers;
std::vector<std::unique_ptr<engine::Renderer>> m_pEngineRenderers;

Expand Down
7 changes: 3 additions & 4 deletions Engine/Source/Editor/Resources/ShaderBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "ECWorld/SceneWorld.h"
#include "Log/Log.h"
#include "Path/Path.h"
#include "Rendering/RenderContext.h"
#include "Resources/ResourceLoader.h"
#include "Rendering/ShaderVariantCollections.h"

namespace editor
{
Expand All @@ -29,9 +28,9 @@ void ShaderBuilder::BuildUberShader(engine::MaterialType* pMaterialType)
CD_ENGINE_INFO("Shader variant count of material type {0} : {1}", pMaterialType->GetMaterialName(), shaderSchema.GetFeatureCombines().size());
}

void ShaderBuilder::BuildShaders(engine::SceneWorld* pSceneWorld)
void ShaderBuilder::BuildShaders(engine::ShaderVariantCollections* pCollections)
{
const auto& porgrams = pSceneWorld->GetShaderVariantCollectionsComponent(pSceneWorld->GetShaderVariantCollectionEntity())->GetShaderPrograms();
const auto& porgrams = pCollections->GetShaderPrograms();

for (const auto& [programName, pack] : porgrams)
{
Expand Down
4 changes: 2 additions & 2 deletions Engine/Source/Editor/Resources/ShaderBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace engine
{

class SceneWorld;
class ShaderVariantCollections;

}

Expand All @@ -24,7 +24,7 @@ class ShaderBuilder
public:
static void BuildUberShader(engine::MaterialType* pMaterialType);

static void BuildShaders(engine::SceneWorld* pSceneWorld);
static void BuildShaders(engine::ShaderVariantCollections* pCollections);

private:
static const ShaderType GetShaderType(const std::string& fileName);
Expand Down
23 changes: 0 additions & 23 deletions Engine/Source/Editor/UILayers/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,28 +510,6 @@ void UpdateComponentWidget<engine::ParticleComponent>(engine::SceneWorld* pScene
ImGui::PopStyleVar();
}

template<>
void UpdateComponentWidget<engine::ShaderVariantCollectionsComponent>(engine::SceneWorld* pSceneWorld, engine::Entity entity)
{
auto* pShaderVariantCollectionsComponent = pSceneWorld->GetShaderVariantCollectionsComponent(entity);
if (!pShaderVariantCollectionsComponent)
{
return;
}

bool isOpen = ImGui::CollapsingHeader("Shader Variant Collections Component", ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
ImGui::Separator();

if (isOpen)
{

}

ImGui::Separator();
ImGui::PopStyleVar();
}

}

namespace editor
Expand Down Expand Up @@ -571,7 +549,6 @@ void Inspector::Update()
details::UpdateComponentWidget<engine::SkyComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::TerrainComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::ParticleComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::ShaderVariantCollectionsComponent>(pSceneWorld, selectedEntity);

#ifdef ENABLE_DDGI
details::UpdateComponentWidget<engine::DDGIComponent>(pSceneWorld, selectedEntity);
Expand Down
1 change: 0 additions & 1 deletion Engine/Source/Runtime/ECWorld/AllComponentsHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "ECWorld/LightComponent.h"
#include "ECWorld/MaterialComponent.h"
#include "ECWorld/NameComponent.h"
#include "ECWorld/ShaderVariantCollectionsComponent.h"
#include "ECWorld/SkyComponent.h"
#include "ECWorld/StaticMeshComponent.h"
#include "ECWorld/TerrainComponent.h"
Expand Down
7 changes: 0 additions & 7 deletions Engine/Source/Runtime/ECWorld/SceneWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ SceneWorld::SceneWorld()
m_pLightComponentStorage = m_pWorld->Register<engine::LightComponent>();
m_pMaterialComponentStorage = m_pWorld->Register<engine::MaterialComponent>();
m_pNameComponentStorage = m_pWorld->Register<engine::NameComponent>();
m_pShaderVariantCollectionsComponentStorage = m_pWorld->Register<engine::ShaderVariantCollectionsComponent>();
m_pSkyComponentStorage = m_pWorld->Register<engine::SkyComponent>();
m_pStaticMeshComponentStorage = m_pWorld->Register<engine::StaticMeshComponent>();
m_pParticleComponentStorage = m_pWorld->Register<engine::ParticleComponent>();
Expand Down Expand Up @@ -171,12 +170,6 @@ void SceneWorld::SetSkyEntity(engine::Entity entity)
m_skyEntity = entity;
}

void SceneWorld::SetShaderVariantCollectionEntity(engine::Entity entity)
{
CD_TRACE("Setup Shader Variant Collection entity : {0}", entity);
m_shaderVariantCollectionEntity = entity;
}

void SceneWorld::AddCameraToSceneDatabase(engine::Entity entity)
{
engine::CameraComponent* pCameraComponent = GetCameraComponent(entity);
Expand Down
7 changes: 0 additions & 7 deletions Engine/Source/Runtime/ECWorld/SceneWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class SceneWorld
DEFINE_COMPONENT_STORAGE_WITH_APIS(Light);
DEFINE_COMPONENT_STORAGE_WITH_APIS(Material);
DEFINE_COMPONENT_STORAGE_WITH_APIS(Name);
DEFINE_COMPONENT_STORAGE_WITH_APIS(ShaderVariantCollections);
DEFINE_COMPONENT_STORAGE_WITH_APIS(Sky);
DEFINE_COMPONENT_STORAGE_WITH_APIS(StaticMesh);
DEFINE_COMPONENT_STORAGE_WITH_APIS(Particle);
Expand Down Expand Up @@ -71,9 +70,6 @@ class SceneWorld
void SetSkyEntity(engine::Entity entity);
CD_FORCEINLINE engine::Entity GetSkyEntity() const { return m_skyEntity; }

void SetShaderVariantCollectionEntity(engine::Entity entity);
CD_FORCEINLINE engine::Entity GetShaderVariantCollectionEntity() const { return m_shaderVariantCollectionEntity; }

void DeleteEntity(engine::Entity entity)
{
if (entity == m_mainCameraEntity)
Expand All @@ -98,7 +94,6 @@ class SceneWorld
DeleteLightComponent(entity);
DeleteMaterialComponent(entity);
DeleteNameComponent(entity);
DeleteShaderVariantCollectionsComponent(entity);
DeleteSkyComponent(entity);
DeleteStaticMeshComponent(entity);
DeleteParticleComponent(entity);
Expand Down Expand Up @@ -144,9 +139,7 @@ class SceneWorld
engine::Entity m_selectedEntity = engine::INVALID_ENTITY;
engine::Entity m_mainCameraEntity = engine::INVALID_ENTITY;

// TODO : wrap them to project data.
engine::Entity m_skyEntity = engine::INVALID_ENTITY;
engine::Entity m_shaderVariantCollectionEntity = engine::INVALID_ENTITY;

#ifdef ENABLE_DDGI
engine::Entity m_ddgiEntity = engine::INVALID_ENTITY;
Expand Down
6 changes: 3 additions & 3 deletions Engine/Source/Runtime/Rendering/AABBRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
#include "ECWorld/SceneWorld.h"
#include "ECWorld/StaticMeshComponent.h"
#include "ECWorld/TransformComponent.h"
#include "RenderContext.h"
#include "Rendering/RenderContext.h"
#include "Rendering/ShaderVariantCollections.h"
#include "Scene/Texture.h"

namespace engine
{

void AABBRenderer::Init()
{
auto* pShaderVariantCollectionsComponent = m_pCurrentSceneWorld->GetShaderVariantCollectionsComponent(m_pCurrentSceneWorld->GetShaderVariantCollectionEntity());
pShaderVariantCollectionsComponent->RegisterPragram("AABBProgram", { "vs_AABB", "fs_AABB" });
GetShaderVariantCollections()->RegisterPragram("AABBProgram", {"vs_AABB", "fs_AABB"});

bgfx::setViewName(GetViewID(), "AABBRenderer");
}
Expand Down
6 changes: 3 additions & 3 deletions Engine/Source/Runtime/Rendering/AnimationRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "ECWorld/SceneWorld.h"
#include "ECWorld/StaticMeshComponent.h"
#include "ECWorld/TransformComponent.h"
#include "RenderContext.h"
#include "Rendering/RenderContext.h"
#include "Rendering/ShaderVariantCollections.h"
#include "Scene/Texture.h"

#include <cmath>
Expand Down Expand Up @@ -135,8 +136,7 @@ void CalculateBoneTransform(std::vector<cd::Matrix4x4>& boneMatrices, const cd::

void AnimationRenderer::Init()
{
auto* pShaderVariantCollectionsComponent = m_pCurrentSceneWorld->GetShaderVariantCollectionsComponent(m_pCurrentSceneWorld->GetShaderVariantCollectionEntity());
pShaderVariantCollectionsComponent->RegisterPragram("AnimationProgram", { "vs_animation", "fs_animation" });
GetShaderVariantCollections()->RegisterPragram("AnimationProgram", { "vs_animation", "fs_animation" });

bgfx::setViewName(GetViewID(), "AnimationRenderer");
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/Source/Runtime/Rendering/BlitRenderTargetPass.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "BlitRenderTargetPass.h"

#include "RenderContext.h"
#include "Rendering/RenderContext.h"

namespace engine
{
Expand Down
18 changes: 9 additions & 9 deletions Engine/Source/Runtime/Rendering/BloomRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#include "BloomRenderer.h"

#include "RenderContext.h"
#include "Rendering/RenderContext.h"
#include "Rendering/ShaderVariantCollections.h"

namespace engine
{
void BloomRenderer::Init()
{
auto* pShaderVariantCollectionsComponent = m_pCurrentSceneWorld->GetShaderVariantCollectionsComponent(m_pCurrentSceneWorld->GetShaderVariantCollectionEntity());
pShaderVariantCollectionsComponent->RegisterPragram("CapTureBrightnessProgram", { "vs_fullscreen", "fs_captureBrightness" });
pShaderVariantCollectionsComponent->RegisterPragram("DownSampleProgram", { "vs_fullscreen", "fs_dowmsample" });
pShaderVariantCollectionsComponent->RegisterPragram("BlurVerticalProgram", { "vs_fullscreen", "fs_blurvertical" });
pShaderVariantCollectionsComponent->RegisterPragram("BlurHorizontalProgram", { "vs_fullscreen", "fs_blurhorizontal" });
pShaderVariantCollectionsComponent->RegisterPragram("UpSampleProgram", { "vs_fullscreen", "fs_upsample" });
pShaderVariantCollectionsComponent->RegisterPragram("KawaseBlurProgram", { "vs_fullscreen", "fs_kawaseblur" });
pShaderVariantCollectionsComponent->RegisterPragram("CombineProgram", { "vs_fullscreen", "fs_bloom" });
GetShaderVariantCollections()->RegisterPragram("CapTureBrightnessProgram", { "vs_fullscreen", "fs_captureBrightness" });
GetShaderVariantCollections()->RegisterPragram("DownSampleProgram", { "vs_fullscreen", "fs_dowmsample" });
GetShaderVariantCollections()->RegisterPragram("BlurVerticalProgram", { "vs_fullscreen", "fs_blurvertical" });
GetShaderVariantCollections()->RegisterPragram("BlurHorizontalProgram", { "vs_fullscreen", "fs_blurhorizontal" });
GetShaderVariantCollections()->RegisterPragram("UpSampleProgram", { "vs_fullscreen", "fs_upsample" });
GetShaderVariantCollections()->RegisterPragram("KawaseBlurProgram", { "vs_fullscreen", "fs_kawaseblur" });
GetShaderVariantCollections()->RegisterPragram("CombineProgram", { "vs_fullscreen", "fs_bloom" });

bgfx::setViewName(GetViewID(), "BloomRenderer");
}
Expand Down
6 changes: 3 additions & 3 deletions Engine/Source/Runtime/Rendering/DebugRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
#include "ECWorld/SceneWorld.h"
#include "ECWorld/StaticMeshComponent.h"
#include "ECWorld/TransformComponent.h"
#include "RenderContext.h"
#include "Rendering/RenderContext.h"
#include "Rendering/ShaderVariantCollections.h"
#include "Scene/Texture.h"

namespace engine
{

void DebugRenderer::Init()
{
auto* pShaderVariantCollectionsComponent = m_pCurrentSceneWorld->GetShaderVariantCollectionsComponent(m_pCurrentSceneWorld->GetShaderVariantCollectionEntity());
pShaderVariantCollectionsComponent->RegisterPragram("DebugProgram", { "vs_debug","fs_debug" });
GetShaderVariantCollections()->RegisterPragram("DebugProgram", { "vs_debug", "fs_debug" });

bgfx::setViewName(GetViewID(), "DebugRenderer");
}
Expand Down
3 changes: 3 additions & 0 deletions Engine/Source/Runtime/Rendering/ImGuiRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ImGuiRenderer.h"

#include "Rendering/RenderContext.h"
#include "Rendering/ShaderVariantCollections.h"

#include <imgui/imgui.h>

Expand All @@ -9,6 +10,8 @@ namespace engine

void ImGuiRenderer::Init()
{
GetShaderVariantCollections()->RegisterPragram("ImGuiProgram", { "vs_imgui", "fs_imgui" });

bgfx::setViewName(GetViewID(), "ImGuiRenderer");
}

Expand Down
20 changes: 10 additions & 10 deletions Engine/Source/Runtime/Rendering/PBRSkyRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "ECWorld/SkyComponent.h"
#include "Log/Log.h"
#include "Math/Box.hpp"
#include "RenderContext.h"
#include "Rendering/RenderContext.h"
#include "Rendering/ShaderVariantCollections.h"
#include "Scene/Mesh.h"
#include "Scene/VertexFormat.h"
#include "U_AtmophericScattering.sh"
Expand Down Expand Up @@ -49,15 +50,14 @@ constexpr uint16_t ScatteringOrders = 6;

void PBRSkyRenderer::Init()
{
auto* pShaderVariantCollectionsComponent = m_pCurrentSceneWorld->GetShaderVariantCollectionsComponent(m_pCurrentSceneWorld->GetShaderVariantCollectionEntity());
pShaderVariantCollectionsComponent->RegisterPragram(ProgramAtmosphericScatteringLUT, { "vs_atmSkyBox", "fs_PrecomputedAtmosphericScattering_LUT" });
pShaderVariantCollectionsComponent->RegisterPragram(ProgramSingleScatteringRayMarching, { "vs_atmSkyBox", "fs_SingleScattering_RayMarching" });
pShaderVariantCollectionsComponent->RegisterPragram(ProgramComputeTransmittance, { "cs_ComputeTransmittance" });
pShaderVariantCollectionsComponent->RegisterPragram(ProgramComputeDirectIrradiance, { "cs_ComputeDirectIrradiance" });
pShaderVariantCollectionsComponent->RegisterPragram(ProgramComputeSingleScattering, { "cs_ComputeSingleScattering" });
pShaderVariantCollectionsComponent->RegisterPragram(ProgramComputeScatteringDensity, { "cs_ComputeScatteringDensity" });
pShaderVariantCollectionsComponent->RegisterPragram(ProgramComputeIndirectIrradiance, { "cs_ComputeIndirectIrradiance" });
pShaderVariantCollectionsComponent->RegisterPragram(ProgramComputeMultipleScattering, { "cs_ComputeMultipleScattering" });
GetShaderVariantCollections()->RegisterPragram(ProgramAtmosphericScatteringLUT, { "vs_atmSkyBox", "fs_PrecomputedAtmosphericScattering_LUT" });
GetShaderVariantCollections()->RegisterPragram(ProgramSingleScatteringRayMarching, { "vs_atmSkyBox", "fs_SingleScattering_RayMarching" });
GetShaderVariantCollections()->RegisterPragram(ProgramComputeTransmittance, { "cs_ComputeTransmittance" });
GetShaderVariantCollections()->RegisterPragram(ProgramComputeDirectIrradiance, { "cs_ComputeDirectIrradiance" });
GetShaderVariantCollections()->RegisterPragram(ProgramComputeSingleScattering, { "cs_ComputeSingleScattering" });
GetShaderVariantCollections()->RegisterPragram(ProgramComputeScatteringDensity, { "cs_ComputeScatteringDensity" });
GetShaderVariantCollections()->RegisterPragram(ProgramComputeIndirectIrradiance, { "cs_ComputeIndirectIrradiance" });
GetShaderVariantCollections()->RegisterPragram(ProgramComputeMultipleScattering, { "cs_ComputeMultipleScattering" });

bgfx::setViewName(GetViewID(), "PBRSkyRenderer");
}
Expand Down
Loading

0 comments on commit 8b6d9a3

Please sign in to comment.