Skip to content

Commit

Permalink
cleanup ui for generating probes
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 27, 2024
1 parent 0c3ef56 commit 907af07
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/renderer/editor/render_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3616,10 +3616,18 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin {
, m_probes(app.getAllocator())
, m_model_plugin(model_plugin)
{
m_generate_action.init("Generate probes", "Generate probes", "generate_probes", "", Action::IMGUI_PRIORITY);
m_generate_action.func.bind<&EnvironmentProbePlugin::onGenerateProbes>(this);
m_add_bounce_action.init("Add bounce", "Add light bounce to probes", "probes_add_bounce", "", Action::IMGUI_PRIORITY);
m_add_bounce_action.func.bind<&EnvironmentProbePlugin::onAddBounce>(this);
m_app.addToolAction(&m_generate_action);
m_app.addToolAction(&m_add_bounce_action);
}

~EnvironmentProbePlugin()
{
m_app.removeAction(&m_generate_action);
m_app.removeAction(&m_add_bounce_action);
m_ibl_filter_shader->decRefCount();
}

Expand Down Expand Up @@ -3677,7 +3685,7 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin {
}


void generateCubemaps(bool bounce, World& world) {
void generateProbes(bool bounce, World& world) {
ASSERT(m_probes.empty());

m_pipeline->setIndirectLightMultiplier(bounce ? 1.f : 0.f);
Expand Down Expand Up @@ -3962,44 +3970,34 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin {
}
}

void onGenerateProbes() {
WorldEditor& editor = m_app.getWorldEditor();
World& world = *editor.getWorld();
generateProbes(false, world);
}

void onAddBounce() {
WorldEditor& editor = m_app.getWorldEditor();
World& world = *editor.getWorld();
generateProbes(true, world);
}

void onGUI(PropertyGrid& grid, Span<const EntityRef> entities, ComponentType cmp_type, const TextFilter& filter, WorldEditor& editor) override {
if (filter.isActive()) return;
if (entities.length() != 1) return;

World& world = *editor.getWorld();
const EntityRef e = entities[0];
auto* module = static_cast<RenderModule*>(world.getModule(cmp_type));
if (cmp_type == ENVIRONMENT_PROBE_TYPE) {
if (m_probe_counter) ImGui::Text("Generating...");
else {
if (ImGui::CollapsingHeader("Generator")) {
if (ImGui::Button("Generate")) generateCubemaps(false, world);
ImGui::SameLine();
if (ImGui::Button("Add bounce")) generateCubemaps(true, world);
}
}
}

if (cmp_type == REFLECTION_PROBE_TYPE) {
if (m_probe_counter) ImGui::Text("Generating...");
else {
const ReflectionProbe& probe = module->getReflectionProbe(e);
if (probe.flags & ReflectionProbe::ENABLED) {
const Path path("probes/", probe.guid, ".lbc");
ImGuiEx::Label("Path");
ImGuiEx::TextUnformatted(path);
if (ImGui::Button("View radiance")) m_app.getAssetBrowser().openEditor(path);
}
if (ImGui::CollapsingHeader("Generator")) {
if (ImGui::Button("Generate")) generateCubemaps(false, world);
ImGui::SameLine();
if (ImGui::Button("Add bounce")) generateCubemaps(true, world);
}
const ReflectionProbe& probe = module->getReflectionProbe(e);
if (probe.flags & ReflectionProbe::ENABLED) {
ImGuiEx::Label("GUID");
ImGuiEx::TextUnformatted(StaticString<64>(probe.guid));
}
}
}


StudioApp& m_app;
ModelPlugin& m_model_plugin;
UniquePtr<Pipeline> m_pipeline;
Expand All @@ -4010,6 +4008,8 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin {
Array<ProbeJob*> m_probes;
u32 m_done_counter = 0;
u32 m_probe_counter = 0;
Action m_generate_action;
Action m_add_bounce_action;
};

struct InstancedModelPlugin final : PropertyGrid::IPlugin, StudioApp::MousePlugin {
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/editor/scene_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ struct SceneView::RenderPlugin : Lumix::RenderPlugin {

RenderBufferHandle renderBeforeTonemap(const GBuffer& gbuffer, RenderBufferHandle input, Pipeline& pipeline) override {
if (m_scene_view.m_pipeline.get() != &pipeline) return input;
if (pipeline.m_debug_show == Pipeline::DebugShow::PLUGIN) return input;
Renderer& renderer = pipeline.getRenderer();

// selection
Expand Down Expand Up @@ -1017,6 +1018,7 @@ bool SceneView::onAction(const Action& action) {
for (u32 i = 0; i < lengthOf(m_debug_show_actions); ++i) {
if (&action == &m_debug_show_actions[i]) {
m_pipeline->m_debug_show = (Pipeline::DebugShow)i;
m_pipeline->m_debug_show_plugin = nullptr;
return true;
}
}
Expand Down

0 comments on commit 907af07

Please sign in to comment.