Skip to content

[WIP] Added a debug view system #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion Resources/Engine/Shaders/Standard.ovfx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#pass SHADOW_PASS
#pass ALBEDO_PASS
#pass METALLIC_PASS
#pass ROUGHNESS_PASS
#pass AO_PASS
#pass NORMAL_PASS
#pass UV_PASS
#pass DEPTH_PASS

#feature PARALLAX_MAPPING
#feature ALPHA_CLIPPING
Expand Down Expand Up @@ -129,6 +136,16 @@ void main()
}
#endif

#if defined(DEPTH_PASS)
const float near = 0.1;
const float far = 50.0;
const float depth = gl_FragCoord.z;
const float z = depth * 2.0 - 1.0; // back to NDC
float linearDepth = (2.0 * near * far) / (far + near - z * (far - near)) / far;
FRAGMENT_COLOR = vec4(vec3(linearDepth), 1.0);
return;
#endif

vec2 texCoords = TileAndOffsetTexCoords(fs_in.TexCoords, u_TextureTiling, u_TextureOffset);

#if defined(PARALLAX_MAPPING)
Expand Down Expand Up @@ -170,6 +187,18 @@ void main()
const vec3 normal = normalize(fs_in.Normal);
#endif

#if defined(NORMAL_PASS)
FRAGMENT_COLOR = vec4((normal + 1.0) / 2.0, 1.0);
return;
#endif

const float ao = texture(u_AmbientOcclusionMap, texCoords).r;

#if defined(AO_PASS)
FRAGMENT_COLOR = vec4(ao.rrr, 1.0);
return;
#endif

#if defined(SPECULAR_WORKFLOW)
const float specular = texture(u_SpecularMap, texCoords).r * u_Specular;
const float glossiness = texture(u_GlossinessMap, texCoords).r * u_Glossiness;
Expand All @@ -180,7 +209,25 @@ void main()
const float roughness = texture(u_RoughnessMap, texCoords).r * u_Roughness;
#endif

const float ao = texture(u_AmbientOcclusionMap, texCoords).r;
#if defined(ALBEDO_PASS)
FRAGMENT_COLOR = vec4(albedo.rgba);
return;
#endif

#if defined(METALLIC_PASS)
FRAGMENT_COLOR = vec4(metallic.rrr, 1.0);
return;
#endif

#if defined(ROUGHNESS_PASS)
FRAGMENT_COLOR = vec4(roughness.rrr, 1.0);
return;
#endif

#if defined(UV_PASS)
FRAGMENT_COLOR = vec4(texCoords.x, texCoords.y, 0.0, 1.0);
return;
#endif

vec3 pbr = PBRLightingModel(
albedo.rgb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace OvCore::Rendering
protected:
virtual void OnBeginFrame(const OvRendering::Data::FrameDescriptor& p_frameDescriptor) override;
virtual void OnEndFrame() override;
virtual void OnBeforeDraw(OvRendering::Data::PipelineState& p_pso, const OvRendering::Entities::Drawable& p_drawable) override;
virtual void OnBeforeDraw(OvRendering::Data::PipelineState& p_pso, OvRendering::Entities::Drawable& p_drawable) override;

protected:
std::chrono::high_resolution_clock::time_point m_startTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace OvCore::Rendering
ShadowRenderFeature(OvRendering::Core::CompositeRenderer& p_renderer);

protected:
virtual void OnBeforeDraw(OvRendering::Data::PipelineState& p_pso, const OvRendering::Entities::Drawable& p_drawable);
virtual void OnBeforeDraw(OvRendering::Data::PipelineState& p_pso, OvRendering::Entities::Drawable& p_drawable);
virtual void OnAfterDraw(OvRendering::Data::PipelineState& p_pso, const OvRendering::Entities::Drawable& p_drawable);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void OvCore::Rendering::EngineBufferRenderFeature::OnEndFrame()
m_engineBuffer->Unbind();
}

void OvCore::Rendering::EngineBufferRenderFeature::OnBeforeDraw(OvRendering::Data::PipelineState& p_pso, const OvRendering::Entities::Drawable& p_drawable)
void OvCore::Rendering::EngineBufferRenderFeature::OnBeforeDraw(OvRendering::Data::PipelineState& p_pso, OvRendering::Entities::Drawable& p_drawable)
{
OvTools::Utils::OptRef<const EngineDrawableDescriptor> descriptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ OvCore::Rendering::ShadowRenderFeature::ShadowRenderFeature(OvRendering::Core::C
{
}

void OvCore::Rendering::ShadowRenderFeature::OnBeforeDraw(OvRendering::Data::PipelineState& p_pso, const OvRendering::Entities::Drawable& p_drawable)
void OvCore::Rendering::ShadowRenderFeature::OnBeforeDraw(OvRendering::Data::PipelineState& p_pso, OvRendering::Entities::Drawable& p_drawable)
{
auto& material = p_drawable.material.value();

Expand Down
11 changes: 11 additions & 0 deletions Sources/Overload/OvEditor/include/OvEditor/Core/EditorActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ namespace tinyxml2
class XMLDocument;
}

namespace OvEditor::Rendering
{
enum class EDebugViewMode;
}

namespace OvEditor::Core
{
enum class EGizmoOperation;
Expand Down Expand Up @@ -162,6 +167,12 @@ namespace OvEditor::Core
* Returns the current gizmo operation
*/
EGizmoOperation GetGizmoOperation() const;

/**
* Sets the debug view mode to use
* @param p_mode
*/
void SetSceneViewDebugMode(OvEditor::Rendering::EDebugViewMode p_mode);
#pragma endregion

#pragma region ACTOR_CREATION_DESTRUCTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ namespace OvEditor::Panels { class AView; }

namespace OvEditor::Rendering
{
enum class EDebugViewMode
{
NONE,
ALBEDO,
METALLIC,
ROUGHNESS,
AO,
NORMAL,
UV,
DEPTH,
WIREFRAME
};

/**
* Provide a debug layer on top of the default scene renderer to see "invisible" entities such as
* lights, cameras,
Expand All @@ -44,5 +57,11 @@ namespace OvEditor::Rendering
* @param p_driver
*/
DebugSceneRenderer(OvRendering::Context::Driver& p_driver);

/**
* Set a debug view mode
* @param p_mode
*/
void SetDebugViewMode(EDebugViewMode p_mode) const;
};
}
8 changes: 8 additions & 0 deletions Sources/Overload/OvEditor/src/OvEditor/Core/EditorActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <OvEditor/Panels/MaterialEditor.h>
#include <OvEditor/Panels/ProjectSettings.h>
#include <OvEditor/Panels/SceneView.h>
#include <OvEditor/Rendering/DebugSceneRenderer.h>

#include <OvTools/Utils/PathParser.h>
#include <OvTools/Utils/String.h>
Expand Down Expand Up @@ -503,6 +504,13 @@ OvEditor::Core::EGizmoOperation OvEditor::Core::EditorActions::GetGizmoOperation
return sceneView.GetGizmoOperation();
}

void OvEditor::Core::EditorActions::SetSceneViewDebugMode(OvEditor::Rendering::EDebugViewMode p_mode)
{
auto& sceneView = m_panelsManager.GetPanelAs<OvEditor::Panels::SceneView>("Scene View");
const auto& debugSceneRenderer = static_cast<const OvEditor::Rendering::DebugSceneRenderer&>(sceneView.GetRenderer());
debugSceneRenderer.SetDebugViewMode(p_mode);
}

OvMaths::FVector3 OvEditor::Core::EditorActions::CalculateActorSpawnPoint(float p_distanceToCamera)
{
auto& sceneView = m_panelsManager.GetPanelAs<OvEditor::Panels::SceneView>("Scene View");
Expand Down
21 changes: 21 additions & 0 deletions Sources/Overload/OvEditor/src/OvEditor/Panels/Toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include <OvEditor/Core/EditorActions.h>
#include <OvEditor/Core/GizmoBehaviour.h>
#include <OvEditor/Panels/Toolbar.h>
#include <OvEditor/Rendering/DebugSceneRenderer.h>

#include <OvUI/Widgets/Layout/Spacing.h>
#include <OvUI/Widgets/Selection/ComboBox.h>

namespace
{
Expand Down Expand Up @@ -91,6 +93,25 @@ OvEditor::Panels::Toolbar::Toolbar
};

EDITOR_EXEC(SetEditorMode(OvEditor::Core::EditorActions::EEditorMode::EDIT));

using enum OvEditor::Rendering::EDebugViewMode;
auto& debugViewSelector = CreateWidget<OvUI::Widgets::Selection::ComboBox>();
debugViewSelector.lineBreak = false;
debugViewSelector.choices = {
{ static_cast<int>(NONE), "Default" },
{ static_cast<int>(ALBEDO), "Albedo" },
{ static_cast<int>(METALLIC), "Metallic" },
{ static_cast<int>(ROUGHNESS), "Roughness" },
{ static_cast<int>(AO), "Ambient Occlusion" },
{ static_cast<int>(NORMAL), "Normal"},
{ static_cast<int>(UV), "UV"},
{ static_cast<int>(DEPTH), "Depth"},
{ static_cast<int>(WIREFRAME), "Wireframe"}
};
debugViewSelector.currentChoice = 0;
debugViewSelector.ValueChangedEvent += [](int choice) {
EDITOR_EXEC(SetSceneViewDebugMode(static_cast<OvEditor::Rendering::EDebugViewMode>(choice)));
};
}

void OvEditor::Panels::Toolbar::_Draw_Impl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <OvCore/ECS/Components/CPointLight.h>
#include <OvCore/ECS/Components/CSpotLight.h>
#include <OvCore/Rendering/EngineDrawableDescriptor.h>
#include <OvCore/Rendering/PostProcessRenderPass.h>

#include <OvDebug/Assertion.h>

Expand Down Expand Up @@ -110,6 +111,63 @@ namespace
}
}

class DebugViewRenderFeature : public OvRendering::Features::ARenderFeature
{
public:
DebugViewRenderFeature(OvRendering::Core::CompositeRenderer& p_renderer) : ARenderFeature(p_renderer)
{
}

void SetDebugViewMode(OvEditor::Rendering::EDebugViewMode p_mode)
{
m_debugViewMode = p_mode;
}

protected:
void OnBeforeDraw(OvRendering::Data::PipelineState& p_pso, OvRendering::Entities::Drawable& p_drawable)
{
if (m_debugViewMode != OvEditor::Rendering::EDebugViewMode::NONE && !p_drawable.pass.has_value())
{
if (m_debugViewMode == OvEditor::Rendering::EDebugViewMode::WIREFRAME)
{
p_pso.rasterizationMode = OvRendering::Settings::ERasterizationMode::LINE;
}

const std::string pass = _GetCurrentPassName();

if (p_drawable.material->HasPass(pass))
{
p_drawable.pass = pass;
}
}
}

private:
std::string _GetCurrentPassName()
{
using enum OvEditor::Rendering::EDebugViewMode;

OVASSERT(m_debugViewMode != NONE, "Cannot retrieve current pass name if no debug view is set.");

switch (m_debugViewMode)
{
case ALBEDO: return "ALBEDO_PASS";
case METALLIC: return "METALLIC_PASS";
case ROUGHNESS: return "ROUGHNESS_PASS";
case AO: return "AO_PASS";
case NORMAL: return "NORMAL_PASS";
case UV: return "UV_PASS";
case DEPTH: return "DEPTH_PASS";
case WIREFRAME: return "ALBEDO_PASS";
}

return {};
}

private:
OvEditor::Rendering::EDebugViewMode m_debugViewMode = OvEditor::Rendering::EDebugViewMode::NONE;
};

class DebugCamerasRenderPass : public OvRendering::Core::ARenderPass
{
public:
Expand Down Expand Up @@ -643,10 +701,17 @@ OvEditor::Rendering::DebugSceneRenderer::DebugSceneRenderer(OvRendering::Context
AddFeature<OvEditor::Rendering::DebugModelRenderFeature>();
AddFeature<OvEditor::Rendering::OutlineRenderFeature>();
AddFeature<OvEditor::Rendering::GizmoRenderFeature>();
AddFeature<DebugViewRenderFeature>();

AddPass<GridRenderPass>("Grid", OvRendering::Settings::ERenderPassOrder::Debug);
AddPass<DebugCamerasRenderPass>("Debug Cameras", OvRendering::Settings::ERenderPassOrder::Debug);
AddPass<DebugLightsRenderPass>("Debug Lights", OvRendering::Settings::ERenderPassOrder::Debug);
AddPass<DebugActorRenderPass>("Debug Actor", OvRendering::Settings::ERenderPassOrder::Debug);
AddPass<PickingRenderPass>("Picking", OvRendering::Settings::ERenderPassOrder::Debug);
}

void OvEditor::Rendering::DebugSceneRenderer::SetDebugViewMode(EDebugViewMode p_mode) const
{
GetFeature<DebugViewRenderFeature>().SetDebugViewMode(p_mode);
GetPass<OvCore::Rendering::PostProcessRenderPass>("Post-Process").SetEnabled(p_mode == EDebugViewMode::NONE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace OvRendering::Features
* Invoked before drawing a drawable entity
* @param p_drawable
*/
virtual void OnBeforeDraw(Data::PipelineState& p_pso, const Entities::Drawable& p_drawable);
virtual void OnBeforeDraw(Data::PipelineState& p_pso, Entities::Drawable& p_drawable);

/**
* Invoked after drawing a drawable entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void OvRendering::Core::CompositeRenderer::DrawEntity(
{
ZoneScoped;

Entities::Drawable drawable = p_drawable;

// Ensure the drawable is valid.
// If not, skip the draw call and the attached features.
if (!IsDrawable(p_drawable))
Expand All @@ -102,17 +104,17 @@ void OvRendering::Core::CompositeRenderer::DrawEntity(
{
if (feature->IsEnabled())
{
feature->OnBeforeDraw(p_pso, p_drawable);
feature->OnBeforeDraw(p_pso, drawable);
}
}

ABaseRenderer::DrawEntity(p_pso, p_drawable);
ABaseRenderer::DrawEntity(p_pso, drawable);

for (const auto& [_, feature] : m_features)
{
if (feature->IsEnabled())
{
feature->OnAfterDraw(p_drawable);
feature->OnAfterDraw(drawable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void OvRendering::Features::ARenderFeature::OnEndFrame()
{
}

void OvRendering::Features::ARenderFeature::OnBeforeDraw(Data::PipelineState& p_pso, const Entities::Drawable& p_drawable)
void OvRendering::Features::ARenderFeature::OnBeforeDraw(Data::PipelineState& p_pso, Entities::Drawable& p_drawable)
{
}

Expand Down