Skip to content

Commit

Permalink
Shader Variant Collections Component Frame (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
roeas authored Sep 8, 2023
1 parent 8e4bddf commit 780fded
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 26 deletions.
48 changes: 31 additions & 17 deletions Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,13 @@ void EditorApp::InitECWorld()
m_pSceneWorld->CreateTerrainMaterialType();
InitEditorCameraEntity();

InitSkyEntity();
InitShaderVariantCollectionEntity();

#ifdef ENABLE_DDGI
m_pSceneWorld->InitDDGISDK();
InitDDGIEntity();
#endif

InitSkyEntity();
}

void EditorApp::InitEditorCameraEntity()
Expand Down Expand Up @@ -287,21 +288,6 @@ void EditorApp::InitEditorCameraEntity()
cameraComponent.BuildViewMatrix(cameraTransform);
}

#ifdef ENABLE_DDGI
void EditorApp::InitDDGIEntity()
{
engine::World* pWorld = m_pSceneWorld->GetWorld();

engine::Entity ddgiEntity = pWorld->CreateEntity();
m_pSceneWorld->SetDDGIEntity(ddgiEntity);

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

pWorld->CreateComponent<engine::DDGIComponent>(ddgiEntity);
}
#endif

void EditorApp::InitSkyEntity()
{
engine::World* pWorld = m_pSceneWorld->GetWorld();
Expand Down Expand Up @@ -335,6 +321,34 @@ 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()
{
engine::World* pWorld = m_pSceneWorld->GetWorld();

engine::Entity ddgiEntity = pWorld->CreateEntity();
m_pSceneWorld->SetDDGIEntity(ddgiEntity);

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

pWorld->CreateComponent<engine::DDGIComponent>(ddgiEntity);
}
#endif

void EditorApp::InitRenderContext(engine::GraphicsBackend backend, void* hwnd)
{
CD_INFO("Init graphics backend : {}", nameof::nameof_enum(backend));
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 @@ -70,8 +70,12 @@ class EditorApp final : public engine::IApplication

private:
void InitEditorCameraEntity();
void InitDDGIEntity();
void InitSkyEntity();
void InitShaderVariantCollectionEntity();

#ifdef ENABLE_DDGI
void InitDDGIEntity();
#endif

bool m_bInitEditor = false;
engine::EngineInitArgs m_initArgs;
Expand Down
23 changes: 23 additions & 0 deletions Engine/Source/Editor/UILayers/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,28 @@ 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 @@ -551,6 +573,7 @@ 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: 1 addition & 0 deletions Engine/Source/Runtime/ECWorld/AllComponentsHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#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
13 changes: 10 additions & 3 deletions Engine/Source/Runtime/ECWorld/SceneWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ 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_pTerrainComponentStorage = m_pWorld->Register<engine::TerrainComponent>();
m_pTransformComponentStorage = m_pWorld->Register<engine::TransformComponent>();
m_pParticleComponentStorage = m_pWorld->Register<engine::ParticleComponent>();
m_pParticleEmitterComponentStorage = m_pWorld->Register<engine::ParticleEmitterComponent>();

m_pTerrainComponentStorage = m_pWorld->Register<engine::TerrainComponent>();
m_pTransformComponentStorage = m_pWorld->Register<engine::TransformComponent>();

#ifdef ENABLE_DDGI
CreateDDGIMaterialType();
#endif
Expand Down Expand Up @@ -170,6 +171,12 @@ 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
19 changes: 14 additions & 5 deletions Engine/Source/Runtime/ECWorld/SceneWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ 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(Terrain);
DEFINE_COMPONENT_STORAGE_WITH_APIS(Transform);
DEFINE_COMPONENT_STORAGE_WITH_APIS(Particle);
DEFINE_COMPONENT_STORAGE_WITH_APIS(ParticleEmitter);
DEFINE_COMPONENT_STORAGE_WITH_APIS(Terrain);
DEFINE_COMPONENT_STORAGE_WITH_APIS(Transform);

public:
SceneWorld();
Expand Down Expand Up @@ -70,6 +71,9 @@ 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 @@ -94,12 +98,13 @@ class SceneWorld
DeleteLightComponent(entity);
DeleteMaterialComponent(entity);
DeleteNameComponent(entity);
DeleteShaderVariantCollectionsComponent(entity);
DeleteSkyComponent(entity);
DeleteStaticMeshComponent(entity);
DeleteTerrainComponent(entity);
DeleteTransformComponent(entity);
DeleteParticleComponent(entity);
DeleteParticleEmitterComponent(entity);
DeleteTerrainComponent(entity);
DeleteTransformComponent(entity);
}

void CreatePBRMaterialType(bool isAtmosphericScatteringEnable = false);
Expand Down Expand Up @@ -138,10 +143,14 @@ class SceneWorld
// TODO : wrap them into another class?
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;
#endif
engine::Entity m_skyEntity = engine::INVALID_ENTITY;
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "ShaderVariantCollectionsComponent.h"

namespace engine
{



}
29 changes: 29 additions & 0 deletions Engine/Source/Runtime/ECWorld/ShaderVariantCollectionsComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "Base/Template.h"
#include "Core/StringCrc.h"

namespace engine
{

class ShaderVariantCollectionsComponent final
{
public:
static constexpr StringCrc GetClassName()
{
constexpr StringCrc className("ShaderVariantCollectionsComponent");
return className;
}

ShaderVariantCollectionsComponent() = default;
ShaderVariantCollectionsComponent(const ShaderVariantCollectionsComponent&) = default;
ShaderVariantCollectionsComponent& operator=(const ShaderVariantCollectionsComponent&) = default;
ShaderVariantCollectionsComponent(ShaderVariantCollectionsComponent&&) = default;
ShaderVariantCollectionsComponent& operator=(ShaderVariantCollectionsComponent&&) = default;
~ShaderVariantCollectionsComponent() = default;

private:

};

}

0 comments on commit 780fded

Please sign in to comment.