Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
OVOAOVO committed Sep 14, 2023
2 parents af79411 + 0c49ac5 commit a96d7d5
Show file tree
Hide file tree
Showing 33 changed files with 674 additions and 219 deletions.
18 changes: 9 additions & 9 deletions Engine/Source/Editor/ECWorld/ECWorldConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ namespace editor
namespace Detail
{

const std::unordered_map<cd::MaterialTextureType, engine::Uber> materialTextureTypeToUber
const std::unordered_map<cd::MaterialTextureType, engine::ShaderFeature> materialTextureTypeToShaderFeature
{
{ cd::MaterialTextureType::BaseColor, engine::Uber::ALBEDO_MAP },
{ cd::MaterialTextureType::Normal, engine::Uber::NORMAL_MAP },
{ cd::MaterialTextureType::Occlusion, engine::Uber::ORM_MAP },
{ cd::MaterialTextureType::Roughness, engine::Uber::ORM_MAP },
{ cd::MaterialTextureType::Metallic, engine::Uber::ORM_MAP },
{ cd::MaterialTextureType::Emissive, engine::Uber::EMISSIVE_MAP },
{ cd::MaterialTextureType::BaseColor, engine::ShaderFeature::ALBEDO_MAP },
{ cd::MaterialTextureType::Normal, engine::ShaderFeature::NORMAL_MAP },
{ cd::MaterialTextureType::Occlusion, engine::ShaderFeature::ORM_MAP },
{ cd::MaterialTextureType::Roughness, engine::ShaderFeature::ORM_MAP },
{ cd::MaterialTextureType::Metallic, engine::ShaderFeature::ORM_MAP },
{ cd::MaterialTextureType::Emissive, engine::ShaderFeature::EMISSIVE_MAP },
};

CD_FORCEINLINE bool IsMaterialTextureTypeValid(cd::MaterialTextureType type)
{
return materialTextureTypeToUber.find(type) != materialTextureTypeToUber.end();
return materialTextureTypeToShaderFeature.find(type) != materialTextureTypeToShaderFeature.end();
}

} // namespace Detail
Expand Down Expand Up @@ -299,7 +299,7 @@ void ECWorldConsumer::AddMaterial(engine::Entity entity, const cd::Material* pMa

if (Detail::IsMaterialTextureTypeValid(optionalTextureType))
{
materialComponent.ActiveUberShaderOption(Detail::materialTextureTypeToUber.at(optionalTextureType));
materialComponent.ActiveShaderFeature(Detail::materialTextureTypeToShaderFeature.at(optionalTextureType));
}

uint8_t textureSlot = optTextureSlot.value();
Expand Down
65 changes: 39 additions & 26 deletions Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Rendering/BloomRenderer.h"
#include "Rendering/PostProcessRenderer.h"
#include "Rendering/RenderContext.h"
#include "Rendering/SkeletonRenderer.h"
#include "Rendering/SkyboxRenderer.h"
#include "Rendering/TerrainRenderer.h"
#include "Rendering/WorldRenderer.h"
Expand All @@ -39,6 +40,7 @@
#include "UILayers/MainMenu.h"
#include "UILayers/OutputLog.h"
#include "UILayers/SceneView.h"
#include "UILayers/SkeletonView.h"
#include "UILayers/Splash.h"
#include "UILayers/TestNodeEditor.h"
#include "Window/Input.h"
Expand Down Expand Up @@ -171,6 +173,7 @@ void EditorApp::InitEditorUILayers()
pSceneView->SetAABBRenderer(m_pAABBRenderer);
m_pEditorImGuiContext->AddDynamicLayer(cd::MoveTemp(pSceneView));

m_pEditorImGuiContext->AddDynamicLayer(std::make_unique<SkeletonView>("SkeletonView"));
m_pEditorImGuiContext->AddDynamicLayer(std::make_unique<Inspector>("Inspector"));

auto pAssetBrowser = std::make_unique<AssetBrowser>("AssetBrowser");
Expand Down Expand Up @@ -234,25 +237,18 @@ void EditorApp::InitECWorld()
{
m_pSceneWorld = std::make_unique<engine::SceneWorld>();

if (IsAtmosphericScatteringEnable())
{
m_pSceneWorld->CreatePBRMaterialType(true);
}
else
{
m_pSceneWorld->CreatePBRMaterialType(false);
}

m_pSceneWorld->CreatePBRMaterialType(IsAtmosphericScatteringEnable());
m_pSceneWorld->CreateAnimationMaterialType();
m_pSceneWorld->CreateTerrainMaterialType();
InitEditorCameraEntity();

InitSkyEntity();
InitShaderVariantCollectionEntity();

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

InitSkyEntity();
}

void EditorApp::InitEditorCameraEntity()
Expand Down Expand Up @@ -292,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 @@ -340,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 Expand Up @@ -410,6 +419,10 @@ void EditorApp::InitEngineRenderers()
pParticlerenderer->SetSceneWorld(m_pSceneWorld.get());
AddEngineRenderer(cd::MoveTemp(pParticlerenderer));

auto pSkeletonRenderer = std::make_unique<engine::SkeletonRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
pSkeletonRenderer->SetSceneWorld(m_pSceneWorld.get());
AddEngineRenderer(cd::MoveTemp(pSkeletonRenderer));

#ifdef ENABLE_DDGI
auto pDDGIRenderer = std::make_unique<engine::DDGIRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
pDDGIRenderer->SetSceneWorld(m_pSceneWorld.get());
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
6 changes: 3 additions & 3 deletions Engine/Source/Editor/Resources/ResourceBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool ResourceBuilder::AddTask(Process process)
return true;
}

bool ResourceBuilder::AddShaderBuildTask(ShaderType shaderType, const char* pInputFilePath, const char* pOutputFilePath, const char* pUberOptions)
bool ResourceBuilder::AddShaderBuildTask(ShaderType shaderType, const char* pInputFilePath, const char* pOutputFilePath, const char* pShaderFeatures)
{
if (s_SkipStatus & static_cast<uint8_t>(CheckFileStatus(pInputFilePath, pOutputFilePath)))
{
Expand Down Expand Up @@ -225,10 +225,10 @@ bool ResourceBuilder::AddShaderBuildTask(ShaderType shaderType, const char* pInp
assert("Unknown shader compile profile.");
}

if (pUberOptions && *pUberOptions != '\0')
if (pShaderFeatures && *pShaderFeatures != '\0')
{
commandArguments.push_back("--define");
commandArguments.push_back(shaderLanguageDefine + ";" + pUberOptions);
commandArguments.push_back(shaderLanguageDefine + ";" + pShaderFeatures);
}

process.SetCommandArguments(cd::MoveTemp(commandArguments));
Expand Down
2 changes: 1 addition & 1 deletion Engine/Source/Editor/Resources/ResourceBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ResourceBuilder final
bool AddTask(Process process);
bool AddIrradianceCubeMapBuildTask(const char* pInputFilePath, const char* pOutputFilePath);
bool AddRadianceCubeMapBuildTask(const char* pInputFilePath, const char* pOutputFilePath);
bool AddShaderBuildTask(ShaderType shaderType, const char* pInputFilePath, const char* pOutputFilePath, const char* pUberOptions = nullptr);
bool AddShaderBuildTask(ShaderType shaderType, const char* pInputFilePath, const char* pOutputFilePath, const char* pShaderFeatures = nullptr);
bool AddTextureBuildTask(cd::MaterialTextureType textureType, const char* pInputFilePath, const char* pOutputFilePath);

void Update(bool doPrintLog = true);
Expand Down
8 changes: 4 additions & 4 deletions Engine/Source/Editor/Resources/ShaderBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ void ShaderBuilder::BuildUberShader(engine::MaterialType* pMaterialType)
{
engine::ShaderSchema& shaderSchema = pMaterialType->GetShaderSchema();

// No uber option support for VS now.
// No shader feature support for VS now.
std::string outputVSFilePath = engine::Path::GetShaderOutputPath(shaderSchema.GetVertexShaderPath());
ResourceBuilder::Get().AddShaderBuildTask(ShaderType::Vertex,
shaderSchema.GetVertexShaderPath(), outputVSFilePath.c_str());

// Compile fragment shaders with uber options.
for (const auto& combine : shaderSchema.GetUberCombines())
// Compile fragment shaders with shader features.
for (const auto& combine : shaderSchema.GetFeatureCombines())
{
std::string outputFSFilePath = engine::Path::GetShaderOutputPath(shaderSchema.GetFragmentShaderPath(), combine);
ResourceBuilder::Get().AddShaderBuildTask(ShaderType::Fragment,
shaderSchema.GetFragmentShaderPath(), outputFSFilePath.c_str(), combine.c_str());
}

CD_ENGINE_INFO("Shader variant count of material type {0} : {1}", pMaterialType->GetMaterialName(), shaderSchema.GetUberCombines().size());
CD_ENGINE_INFO("Shader variant count of material type {0} : {1}", pMaterialType->GetMaterialName(), shaderSchema.GetFeatureCombines().size());
}

void ShaderBuilder::BuildNonUberShader(std::string folderPath)
Expand Down
24 changes: 15 additions & 9 deletions Engine/Source/Editor/UILayers/AssetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ void AssetBrowser::UpdateAssetFileView()
ImGui::SliderFloat(" ", &m_gridSize, 40.0f, 160.0f, " ", ImGuiSliderFlags_AlwaysClamp | ImGuiSliderFlags_Logarithmic);
}

bool AssetBrowser::UpdateOptionDialog(const char* pTitle, bool& active, bool& importMesh, bool& importMaterial, bool& importTexture, bool& importCamera, bool& importLight)
bool AssetBrowser::UpdateOptionDialog(const char* pTitle, bool& active, bool& importMesh, bool& importMaterial, bool& importTexture, bool& importAnimation, bool& importCamera, bool& importLight)
{
if (!active)
{
Expand Down Expand Up @@ -715,6 +715,7 @@ bool AssetBrowser::UpdateOptionDialog(const char* pTitle, bool& active, bool& im
ImGui::Separator();
if (isOtherOpen)
{
ImGuiUtils::ImGuiBoolProperty("Animation", importAnimation);
ImGuiUtils::ImGuiBoolProperty("Camera", importCamera);
ImGuiUtils::ImGuiBoolProperty("Light", importLight);
}
Expand Down Expand Up @@ -908,26 +909,31 @@ void AssetBrowser::ImportModelFile(const char* pFilePath)
if (0 == inputFileExtension.compare(".cdbin"))
{
cdtools::CDProducer cdProducer(pFilePath);
cdtools::Processor processor(&cdProducer, nullptr, pSceneDatabase);
cd::SceneDatabase newSceneDatabase;
cdtools::Processor processor(&cdProducer, nullptr, &newSceneDatabase);
processor.Run();
pSceneDatabase->Merge(cd::MoveTemp(newSceneDatabase));
}
else
{
#ifdef ENABLE_GENERIC_PRODUCER
cdtools::GenericProducer genericProducer(pFilePath);
genericProducer.SetSceneDatabaseIDs(pSceneDatabase->GetNodeCount(), pSceneDatabase->GetMeshCount(),
pSceneDatabase->GetMaterialCount(), pSceneDatabase->GetTextureCount(), pSceneDatabase->GetLightCount());
genericProducer.ActivateBoundingBoxService();
genericProducer.ActivateCleanUnusedService();
genericProducer.ActivateTangentsSpaceService();
genericProducer.ActivateTriangulateService();
genericProducer.ActivateSimpleAnimationService();
genericProducer.ActivateFlattenHierarchyService();
if (!m_importOptions.ImportAnimation)
{
genericProducer.ActivateFlattenHierarchyService();
}

cdtools::Processor processor(&genericProducer, nullptr, pSceneDatabase);
cd::SceneDatabase newSceneDatabase;
cdtools::Processor processor(&genericProducer, nullptr, &newSceneDatabase);
processor.SetDumpSceneDatabaseEnable(false);
processor.SetFlattenSceneDatabaseEnable(true);
//processor.SetFlattenSceneDatabaseEnable(true);
processor.Run();
pSceneDatabase->Merge(cd::MoveTemp(newSceneDatabase));
#else
assert("Unable to import this file format.");
#endif
Expand Down Expand Up @@ -1146,7 +1152,7 @@ void AssetBrowser::Update()
m_importOptions.Active = true;
}
if (UpdateOptionDialog("Import Options", m_importOptions.Active, m_importOptions.ImportMesh, m_importOptions.ImportMaterial, m_importOptions.ImportTexture,
m_importOptions.ImportCamera, m_importOptions.ImportLight))
m_importOptions.ImportAnimation, m_importOptions.ImportCamera, m_importOptions.ImportLight))
{
ImportAssetFile(m_pImportFileBrowser->GetSelected().string().c_str());
m_pImportFileBrowser->ClearSelected();
Expand All @@ -1159,7 +1165,7 @@ void AssetBrowser::Update()
}

if (UpdateOptionDialog("Export Options", m_exportOptions.Active, m_exportOptions.ExportMesh, m_exportOptions.ExportMaterial, m_exportOptions.ExportTexture,
m_exportOptions.ExportCamera, m_exportOptions.ExportLight))
m_importOptions.ImportAnimation, m_exportOptions.ExportCamera, m_exportOptions.ExportLight))
{
ExportAssetFile(m_pExportFileBrowser->GetSelected().string().c_str());
m_pExportFileBrowser->ClearSelected();
Expand Down
3 changes: 2 additions & 1 deletion Engine/Source/Editor/UILayers/AssetBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct AssetImportOptions
bool ImportMaterial = true;
bool ImportMesh = true;
bool ImportTexture = true;
bool ImportAnimation = false;
};

struct AssetExportOptions
Expand Down Expand Up @@ -129,7 +130,7 @@ class AssetBrowser : public engine::ImGuiBaseLayer

void UpdateAssetFolderTree();
void UpdateAssetFileView();
bool UpdateOptionDialog(const char* pTitle, bool& active, bool& importMesh, bool& importMaterial, bool& importTexture, bool& importCamera, bool& importLight);
bool UpdateOptionDialog(const char* pTitle, bool& active, bool& importMesh, bool& importMaterial, bool& importTexture, bool& importAnimation, bool& importCamera, bool& importLight);

private:
AssetImportOptions m_importOptions;
Expand Down
10 changes: 10 additions & 0 deletions Engine/Source/Editor/UILayers/EntityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ void EntityList::DrawEntity(engine::SceneWorld* pSceneWorld, engine::Entity enti
}
}
}
else
{
if (engine::TransformComponent* pTransform = pSceneWorld->GetTransformComponent(entity))
{
if (m_pCameraController)
{
m_pCameraController->CameraFocus(pTransform->GetTransform().GetTranslation());
}
}
}
}
}

Expand Down
Loading

0 comments on commit a96d7d5

Please sign in to comment.