Skip to content

Commit

Permalink
refact aabb modes
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw committed Sep 15, 2023
1 parent 8ab459b commit e715fb1
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 136 deletions.
6 changes: 6 additions & 0 deletions Engine/BuiltInShaders/shaders/fs_wireframe_line.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "../common/common.sh"

void main()
{
gl_FragColor = vec4(0.5, 1.0, 1.0, 1.0);
}
8 changes: 8 additions & 0 deletions Engine/BuiltInShaders/shaders/vs_wireframe_line.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$input a_position//, a_color1

#include "../common/common.sh"

void main()
{
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
}
26 changes: 16 additions & 10 deletions Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Rendering/DDGIRenderer.h"
#endif
#include "Rendering/WhiteModelRenderer.h"
#include "Rendering/WireframeRenderer.h"
#include "Rendering/ImGuiRenderer.h"
#include "Rendering/PBRSkyRenderer.h"
#include "Rendering/BloomRenderer.h"
Expand Down Expand Up @@ -170,6 +171,7 @@ void EditorApp::InitEditorUILayers()
pSceneView->SetCameraController(m_pViewportCameraController.get());
pSceneView->SetSceneRenderer(m_pSceneRenderer);
pSceneView->SetWhiteModelRenderer(m_pWhiteModelRenderer);
pSceneView->SetWireframeRenderer(m_pWireframeRenderer);
pSceneView->SetAABBRenderer(m_pAABBRenderer);
m_pEditorImGuiContext->AddDynamicLayer(cd::MoveTemp(pSceneView));

Expand Down Expand Up @@ -400,6 +402,10 @@ void EditorApp::InitEngineRenderers()
pTerrainRenderer->SetSceneWorld(m_pSceneWorld.get());
AddEngineRenderer(cd::MoveTemp(pTerrainRenderer));

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

auto pAnimationRenderer = std::make_unique<engine::AnimationRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
pAnimationRenderer->SetSceneWorld(m_pSceneWorld.get());
AddEngineRenderer(cd::MoveTemp(pAnimationRenderer));
Expand All @@ -410,26 +416,26 @@ void EditorApp::InitEngineRenderers()
pWhiteModelRenderer->SetEnable(false);
AddEngineRenderer(cd::MoveTemp(pWhiteModelRenderer));

auto pAABBRenderer = std::make_unique<engine::AABBRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
m_pAABBRenderer = pAABBRenderer.get();
pAABBRenderer->SetSceneWorld(m_pSceneWorld.get());
pAABBRenderer->SetEnable(false);
AddEngineRenderer(cd::MoveTemp(pAABBRenderer));

auto pParticlerenderer = std::make_unique<engine::ParticleRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
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());
AddEngineRenderer(cd::MoveTemp(pDDGIRenderer));
#endif

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

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

auto pBlitRTRenderPass = std::make_unique<engine::BlitRenderTargetPass>(m_pRenderContext->CreateView(), pSceneRenderTarget);
AddEngineRenderer(cd::MoveTemp(pBlitRTRenderPass));

Expand Down
1 change: 1 addition & 0 deletions Engine/Source/Editor/EditorApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class EditorApp final : public engine::IApplication
editor::SceneView* m_pSceneView = nullptr;
engine::Renderer* m_pSceneRenderer = nullptr;
engine::Renderer* m_pWhiteModelRenderer = nullptr;
engine::Renderer* m_pWireframeRenderer = nullptr;
engine::Renderer* m_pPBRSkyRenderer = nullptr;
engine::Renderer* m_pIBLSkyRenderer = nullptr;
engine::Renderer* m_pTerrainRenderer = nullptr;
Expand Down
27 changes: 25 additions & 2 deletions Engine/Source/Editor/UILayers/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ void UpdateComponentWidget(engine::SceneWorld* pSceneWorld, engine::Entity entit
{
}

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

bool isHeaderOpen = ImGui::CollapsingHeader("Collision Mesh Component", ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
ImGui::Separator();

if (isHeaderOpen)
{
ImGuiUtils::ImGuiBoolProperty("Debug Draw", pCollisionMesh->IsDebugDrawEnable());
}

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

template<>
void UpdateComponentWidget<engine::NameComponent>(engine::SceneWorld* pSceneWorld, engine::Entity entity)
{
Expand Down Expand Up @@ -564,13 +586,14 @@ void Inspector::Update()

details::UpdateComponentWidget<engine::NameComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::TransformComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::StaticMeshComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::MaterialComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::CameraComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::LightComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::SkyComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::TerrainComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::StaticMeshComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::ParticleComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::CollisionMeshComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::MaterialComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::ShaderVariantCollectionsComponent>(pSceneWorld, selectedEntity);

#ifdef ENABLE_DDGI
Expand Down
54 changes: 12 additions & 42 deletions Engine/Source/Editor/UILayers/SceneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "Log/Log.h"
#include "Material/ShaderSchema.h"
#include "Math/Ray.hpp"
#include "Rendering/AABBRenderer.h"
#include "Rendering/WireframeRenderer.h"
#include "Rendering/RenderContext.h"
#include "Rendering/Renderer.h"
#include "Rendering/RenderTarget.h"
Expand Down Expand Up @@ -104,49 +106,16 @@ void SceneView::UpdateOperationButtons()
}
}

void SceneView::UpdateAABBCombo()
{
ImGui::SetNextItemWidth(150);
if(ImGui::Combo("##AABBCombo", reinterpret_cast<int*>(&m_AABBMode), AABBModes, IM_ARRAYSIZE(AABBModes)))
{
if (AABBModeType::NoAABB == m_AABBMode)
{
m_pAABBRenderer->SetEnable(false);
}
else if (AABBModeType::AABBSelected == m_AABBMode)
{
m_pAABBRenderer->SetEnable(true);
static_cast<engine::AABBRenderer*>(m_pAABBRenderer)->SetIsRenderSelected(true);
}
else if (AABBModeType::AABBAll == m_AABBMode)
{
m_pAABBRenderer->SetEnable(true);
static_cast<engine::AABBRenderer*>(m_pAABBRenderer)->SetIsRenderSelected(false);
}
}
ImGui::PushItemWidth(150);
}

void SceneView::UpdateDebugCombo()
void SceneView::UpdateRenderModeCombo()
{
ImGui::SetNextItemWidth(130);
if (ImGui::Combo("##DebugCombo", reinterpret_cast<int*>(&m_debugMode), DebugModes, IM_ARRAYSIZE(DebugModes)))
if (ImGui::Combo("##DebugCombo", reinterpret_cast<int*>(&m_renderMode), RenderModes, IM_ARRAYSIZE(RenderModes)))
{
if (DebugModeType::NoDebug == m_debugMode)
{
m_pWhiteModelRenderer->SetEnable(false);
}
else if (DebugModeType::WhiteModel == m_debugMode)
{
m_pWhiteModelRenderer->SetEnable(true);
}
else if (DebugModeType::Wireframe == m_debugMode)
{

}
m_pSceneRenderer->SetEnable(RenderModeType::Rendered == m_renderMode);
m_pWhiteModelRenderer->SetEnable(RenderModeType::Solid == m_renderMode);

// white model
m_pSceneRenderer->SetEnable(!m_pWhiteModelRenderer->IsEnable());
auto* pWireframeRenderer = static_cast<engine::WireframeRenderer*>(m_pWireframeRenderer);
pWireframeRenderer->SetEnableGlobalWireframe(RenderModeType::Wireframe == m_renderMode);
}
ImGui::PushItemWidth(130);
}
Expand Down Expand Up @@ -198,7 +167,8 @@ void SceneView::UpdateSwitchAABBButton()

if (ImGui::Button(reinterpret_cast<const char*>(ICON_MDI_CUBE " AABB")))
{
GetRenderContext();
auto* pAABBRenderer = static_cast<engine::AABBRenderer*>(m_pAABBRenderer);
pAABBRenderer->SetEnableGlobalAABB(!pAABBRenderer->IsGlobalAABBEnable());
}

if (isAABBActive)
Expand Down Expand Up @@ -256,10 +226,10 @@ void SceneView::UpdateToolMenuButtons()
//ImGui::SameLine();

ImGui::SameLine();
UpdateAABBCombo();
UpdateRenderModeCombo();

ImGui::SameLine();
UpdateDebugCombo();
UpdateSwitchAABBButton();

ImGui::SameLine();
UpdateSwitchTerrainButton();
Expand Down
43 changes: 12 additions & 31 deletions Engine/Source/Editor/UILayers/SceneView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,24 @@ class RenderTarget;
namespace editor
{

enum class DebugModeType
enum class RenderModeType
{
NoDebug,
WhiteModel,
Rendered,
Solid,
Wireframe,

Count,
};

constexpr const char* DebugModes[] = {
"NoDebug",
"WhiteModel",
constexpr const char* RenderModes[] = {
"Rendered",
"Solid",
"Wireframe",
};

static_assert(static_cast<int>(DebugModeType::Count) == sizeof(DebugModes) / sizeof(char*),
static_assert(static_cast<int>(RenderModeType::Count) == sizeof(RenderModes) / sizeof(char*),
"Debug mode type and names mismatch.");

enum class AABBModeType
{
NoAABB,
AABBSelected,
AABBAll,

Count,
};

constexpr const char* AABBModes[] = {
"NoAABB",
"AABBSelected",
"AABBAll"
};

static_assert(static_cast<int>(AABBModeType::Count) == sizeof(AABBModes) / sizeof(char*),
"AABB mode type and names mismatch.");

class SceneView : public engine::ImGuiBaseLayer
{
public:
Expand All @@ -73,11 +55,11 @@ class SceneView : public engine::ImGuiBaseLayer
void PickSceneMesh(float regionWidth, float regionHeight);

ImGuizmo::OPERATION GetImGuizmoOperation() const { return m_currentOperation; }
DebugModeType GetDebugMode() const { return m_debugMode; }
AABBModeType GetAABBMode() const { return m_AABBMode; }
RenderModeType GetRenderMode() const { return m_renderMode; }

void SetSceneRenderer(engine::Renderer* pSceneRenderer) { m_pSceneRenderer = pSceneRenderer; }
void SetWhiteModelRenderer(engine::Renderer* pWhiteModelRenderer) { m_pWhiteModelRenderer = pWhiteModelRenderer; }
void SetWireframeRenderer(engine::Renderer* pWireframeRenderer) { m_pWireframeRenderer = pWireframeRenderer; }
void SetAABBRenderer(engine::Renderer* pAABBRenderer) { m_pAABBRenderer = pAABBRenderer; }

bool IsTerrainEditMode() const { return m_isTerrainEditMode; }
Expand All @@ -91,8 +73,7 @@ class SceneView : public engine::ImGuiBaseLayer
void UpdateSwitchAABBButton();
void UpdateSwitchTerrainButton();
void UpdateOperationButtons();
void UpdateDebugCombo();
void UpdateAABBCombo();
void UpdateRenderModeCombo();

private:
uint16_t m_lastContentWidth = 0;
Expand All @@ -103,11 +84,11 @@ class SceneView : public engine::ImGuiBaseLayer
bool m_is3DMode = true;
bool m_isIBLActive = false;
bool m_isTerrainEditMode = false;
DebugModeType m_debugMode = DebugModeType::NoDebug;
AABBModeType m_AABBMode = AABBModeType::NoAABB;
RenderModeType m_renderMode = RenderModeType::Rendered;

engine::Renderer* m_pSceneRenderer = nullptr;
engine::Renderer* m_pWhiteModelRenderer = nullptr;
engine::Renderer* m_pWireframeRenderer = nullptr;
engine::Renderer* m_pAABBRenderer = nullptr;

engine::RenderTarget* m_pRenderTarget = nullptr;
Expand Down
6 changes: 0 additions & 6 deletions Engine/Source/Game/GameApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,6 @@ void GameApp::InitEngineRenderers()
pAnimationRenderer->SetSceneWorld(m_pSceneWorld.get());
AddEngineRenderer(cd::MoveTemp(pAnimationRenderer));

auto pWhiteModelRenderer = std::make_unique<engine::WhiteModelRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
m_pWhiteModelRenderer = pWhiteModelRenderer.get();
pWhiteModelRenderer->SetSceneWorld(m_pSceneWorld.get());
pWhiteModelRenderer->SetEnable(false);
AddEngineRenderer(cd::MoveTemp(pWhiteModelRenderer));

#ifdef ENABLE_DDGI
auto pDDGIRenderer = std::make_unique<engine::DDGIRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
pDDGIRenderer->SetSceneWorld(m_pSceneWorld.get());
Expand Down
10 changes: 10 additions & 0 deletions Engine/Source/Runtime/ECWorld/CollisionMeshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class CollisionMeshComponent final
void Reset();
void Build();

#ifdef EDITOR_MODE
bool SetEnableDebugDraw(bool enable) { m_enableDebugDraw = enable; }
bool& IsDebugDrawEnable() { return m_enableDebugDraw; }
bool IsDebugDrawEnable() const { return m_enableDebugDraw; }
#endif

private:
CollisonMeshType m_collisionType = CollisonMeshType::AABB;
cd::AABB m_aabb;
Expand All @@ -51,6 +57,10 @@ class CollisionMeshComponent final
std::vector<std::byte> m_aabbIndexBuffer;
uint16_t m_aabbVBH = UINT16_MAX;
uint16_t m_aabbIBH = UINT16_MAX;

#ifdef EDITOR_MODE
bool m_enableDebugDraw = false;
#endif
};

}
Loading

0 comments on commit e715fb1

Please sign in to comment.