Skip to content
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

[WIP] Fixed frustum culling debugger (and re-enabled frustum light culling) #327

Draft
wants to merge 3 commits into
base: feature/shadow_mapping
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace OvCore::Rendering
struct SceneDescriptor
{
OvCore::SceneSystem::Scene& scene;
std::optional<OvRendering::Data::Frustum> frustumOverride;
OvTools::Utils::OptRef<const OvRendering::Data::Frustum> frustumOverride;
OvTools::Utils::OptRef<OvRendering::Data::Material> overrideMaterial;
OvTools::Utils::OptRef<OvRendering::Data::Material> fallbackMaterial;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ void OvCore::Rendering::SceneRenderer::BeginFrame(const OvRendering::Data::Frame

auto& sceneDescriptor = GetDescriptor<SceneDescriptor>();

const bool frustumLightCulling = p_frameDescriptor.camera.value().HasFrustumLightCulling();

AddDescriptor<OvRendering::Features::LightingRenderFeature::LightingDescriptor>({
FindActiveLights(sceneDescriptor.scene),
frustumLightCulling ? sceneDescriptor.frustumOverride : std::nullopt
});

OvRendering::Core::CompositeRenderer::BeginFrame(p_frameDescriptor);
Expand Down Expand Up @@ -137,7 +140,8 @@ OvCore::Rendering::SceneRenderer::AllDrawables OvCore::Rendering::SceneRenderer:
auto& scene = sceneDescriptor.scene;
auto overrideMaterial = sceneDescriptor.overrideMaterial;
auto fallbackMaterial = sceneDescriptor.fallbackMaterial;
std::optional<OvRendering::Data::Frustum> frustum = std::nullopt;

OvTools::Utils::OptRef<const OvRendering::Data::Frustum> frustum;

if (camera.HasFrustumGeometryCulling())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ namespace OvEditor::Settings

inline static Property<bool> ShowGeometryBounds = { false };
inline static Property<bool> ShowLightBounds = { false };
inline static Property<bool> ShowGeometryFrustumCullingInSceneView = { false };
inline static Property<bool> ShowLightFrustumCullingInSceneView = { false };
inline static Property<bool> EditorFrustumGeometryCulling = { false };
inline static Property<bool> EditorFrustumLightCulling = { false };
inline static Property<bool> DebugFrustumCulling = { false };
inline static Property<float> LightBillboardScale = { 0.5f };
inline static Property<float> TranslationSnapUnit = { 1.0f };
inline static Property<float> RotationSnapUnit = { 15.0f };
Expand Down
3 changes: 3 additions & 0 deletions Sources/Overload/OvEditor/src/OvEditor/Panels/AView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "OvEditor/Panels/AView.h"
#include "OvEditor/Core/EditorActions.h"
#include "OvEditor/Settings/EditorSettings.h"

OvEditor::Panels::AView::AView
(
Expand Down Expand Up @@ -36,6 +37,8 @@ void OvEditor::Panels::AView::_Draw_Impl()

void OvEditor::Panels::AView::InitFrame()
{
auto camera = GetCamera();

m_renderer->AddDescriptor<OvCore::Rendering::SceneRenderer::SceneDescriptor>(
CreateSceneDescriptor()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "OvEditor/Rendering/DebugSceneRenderer.h"
#include "OvEditor/Rendering/GridRenderPass.h"
#include "OvEditor/Core/EditorActions.h"
#include "OvEditor/Settings/EditorSettings.h"

const OvMaths::FVector3 kDefaultGridColor{ 0.176f, 0.176f, 0.176f };
const OvMaths::FVector3 kDefaultClearColor{ 0.098f, 0.098f, 0.098f };
Expand Down Expand Up @@ -35,6 +36,9 @@ void OvEditor::Panels::AViewControllable::Update(float p_deltaTime)

void OvEditor::Panels::AViewControllable::InitFrame()
{
m_camera.SetFrustumGeometryCulling(Settings::EditorSettings::EditorFrustumGeometryCulling);
m_camera.SetFrustumLightCulling(Settings::EditorSettings::EditorFrustumLightCulling);

AView::InitFrame();

m_renderer->AddDescriptor<Rendering::GridRenderPass::GridDescriptor>({
Expand Down
6 changes: 3 additions & 3 deletions Sources/Overload/OvEditor/src/OvEditor/Panels/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ void OvEditor::Panels::MenuBar::InitializeSettingsMenu()
auto& debuggingMenu = m_settingsMenu->CreateWidget<MenuList>("Debugging");
debuggingMenu.CreateWidget<MenuItem>("Show geometry bounds", "", true, Settings::EditorSettings::ShowGeometryBounds).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::ShowGeometryBounds = p_value; };
debuggingMenu.CreateWidget<MenuItem>("Show lights bounds", "", true, Settings::EditorSettings::ShowLightBounds).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::ShowLightBounds = p_value; };
auto& subMenu = debuggingMenu.CreateWidget<MenuList>("Frustum culling visualizer...");
subMenu.CreateWidget<MenuItem>("For geometry", "", true, Settings::EditorSettings::ShowGeometryFrustumCullingInSceneView).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::ShowGeometryFrustumCullingInSceneView = p_value; };
subMenu.CreateWidget<MenuItem>("For lights", "", true, Settings::EditorSettings::ShowLightFrustumCullingInSceneView).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::ShowLightFrustumCullingInSceneView = p_value; };
debuggingMenu.CreateWidget<MenuItem>("Debug Frustum Culling", "", true, Settings::EditorSettings::DebugFrustumCulling).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::DebugFrustumCulling = p_value; };
debuggingMenu.CreateWidget<MenuItem>("Editor Frustum Geometry Culling", "", true, Settings::EditorSettings::EditorFrustumGeometryCulling).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::EditorFrustumGeometryCulling = p_value; };
debuggingMenu.CreateWidget<MenuItem>("Editor Frustum Light Culling", "", true, Settings::EditorSettings::EditorFrustumLightCulling).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::EditorFrustumLightCulling = p_value; };
}

void OvEditor::Panels::MenuBar::CreateFileMenu()
Expand Down
14 changes: 14 additions & 0 deletions Sources/Overload/OvEditor/src/OvEditor/Panels/SceneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ OvCore::Rendering::SceneRenderer::SceneDescriptor OvEditor::Panels::SceneView::C
{
auto descriptor = AViewControllable::CreateSceneDescriptor();
descriptor.fallbackMaterial = m_fallbackMaterial;

if (Settings::EditorSettings::DebugFrustumCulling)
{
auto& scene = *GetScene();

if (auto mainCameraComponent = scene.FindMainCamera())
{
auto& sceneCamera = mainCameraComponent->GetCamera();
m_camera.SetFrustumGeometryCulling(sceneCamera.HasFrustumGeometryCulling());
m_camera.SetFrustumLightCulling(sceneCamera.HasFrustumLightCulling());
descriptor.frustumOverride = sceneCamera.GetFrustum();
}
}

return descriptor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace OvRendering::Features
struct LightingDescriptor
{
LightSet lights;
OvTools::Utils::OptRef<const OvRendering::Data::Frustum> frustumOverride;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ void OvRendering::Features::LightingRenderFeature::OnBeginFrame(const Data::Fram
auto& frameDescriptor = m_renderer.GetFrameDescriptor();

std::vector<OvMaths::FMatrix4> lightMatrices;
auto frustum = frameDescriptor.camera->GetLightFrustum();
auto frustum = lightDescriptor.frustumOverride ?
lightDescriptor.frustumOverride :
frameDescriptor.camera->GetLightFrustum();

for (auto light : lightDescriptor.lights)
{
Expand Down