From df9791faaff2ca75b1e9dc36ab3500c983e1f8d7 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Thu, 14 Mar 2019 09:59:55 -0700 Subject: [PATCH] gltf_viewer: add stats and view controls. --- libs/gltfio/include/gltfio/SimpleViewer.h | 49 +++++++++++++++++------ samples/app/FilamentApp.cpp | 2 + samples/app/FilamentApp.h | 3 ++ samples/gltf_viewer.cpp | 8 ++++ 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/libs/gltfio/include/gltfio/SimpleViewer.h b/libs/gltfio/include/gltfio/SimpleViewer.h index 24b4abd6df..744e44dc98 100644 --- a/libs/gltfio/include/gltfio/SimpleViewer.h +++ b/libs/gltfio/include/gltfio/SimpleViewer.h @@ -102,6 +102,11 @@ public: */ int getSidebarWidth() const { return mSidebarWidth; } + /** + * Allows clients to inject custom UI. + */ + void setUiCallback(std::function callback) { mCustomUI = callback; } + static constexpr int INITIAL_SIDEBAR_WIDTH = 350; private: @@ -116,6 +121,7 @@ private: utils::NameComponentManager* mNames = nullptr; Animator* mAnimator = nullptr; filament::IndirectLight* mIndirectLight = nullptr; + std::function mCustomUI; // Properties that can be changed from the UI. int mCurrentAnimation = 1; @@ -125,6 +131,9 @@ private: bool mShowWireframe = false; bool mEnableSunlight = true; bool mEnableDithering = true; + bool mEnablePrepass = true; + bool mEnableFxaa = true; + bool mEnableMsaa = true; int mSidebarWidth = INITIAL_SIDEBAR_WIDTH; }; @@ -318,21 +327,35 @@ void SimpleViewer::updateUserInterface() { ImGui::SetNextWindowSizeConstraints(ImVec2(20, height), ImVec2(width, height)); ImGui::Begin("Filament", nullptr, ImGuiWindowFlags_NoTitleBar); + if (mCustomUI) { + mCustomUI(); + } + if (ImGui::CollapsingHeader("View")) { ImGui::Checkbox("Dithering", &mEnableDithering); - auto mode = mEnableDithering ? View::Dithering::TEMPORAL : View::Dithering::NONE; - mView->setDithering(mode); + ImGui::Checkbox("Depth prepass", &mEnablePrepass); + ImGui::Checkbox("FXAA", &mEnableFxaa); + ImGui::Checkbox("MSAA 4x", &mEnableMsaa); } + + mView->setDepthPrepass( + mEnablePrepass ? View::DepthPrepass::ENABLED : View::DepthPrepass::DISABLED); + mView->setDithering(mEnableDithering ? View::Dithering::TEMPORAL : View::Dithering::NONE); + mView->setAntiAliasing(mEnableFxaa ? View::AntiAliasing::FXAA : View::AntiAliasing::NONE); + mView->setSampleCount(mEnableMsaa ? 4 : 1); + if (ImGui::CollapsingHeader("Light")) { ImGui::SliderFloat("IBL intensity", &mIblIntensity, 0.0f, 100000.0f); ImGui::SliderAngle("IBL rotation", &mIblRotation); ImGui::Checkbox("Sunlight", &mEnableSunlight); - if (mEnableSunlight) { - mScene->addEntity(mSunlight); - } else { - mScene->remove(mSunlight); - } } + + if (mEnableSunlight) { + mScene->addEntity(mSunlight); + } else { + mScene->remove(mSunlight); + } + if (ImGui::CollapsingHeader("Model", ImGuiTreeNodeFlags_DefaultOpen)) { if (mAnimator->getAnimationCount() > 0) { intptr_t animationsNodeId = -1; @@ -343,13 +366,15 @@ void SimpleViewer::updateUserInterface() { } } ImGui::Checkbox("Wireframe", &mShowWireframe); - if (mShowWireframe) { - mScene->addEntity(mAsset->getWireframe()); - } else { - mScene->remove(mAsset->getWireframe()); - } treeNode(mAsset->getRoot()); } + + if (mShowWireframe) { + mScene->addEntity(mAsset->getWireframe()); + } else { + mScene->remove(mAsset->getWireframe()); + } + mSidebarWidth = ImGui::GetWindowWidth(); ImGui::End(); diff --git a/samples/app/FilamentApp.cpp b/samples/app/FilamentApp.cpp index c81c456271..200d2d2de9 100644 --- a/samples/app/FilamentApp.cpp +++ b/samples/app/FilamentApp.cpp @@ -365,6 +365,8 @@ void FilamentApp::run(const Config& config, SetupCallback setupCallback, renderer->render(view->getView()); } renderer->endFrame(); + } else { + ++mSkippedFrames; } if (postRender) { diff --git a/samples/app/FilamentApp.h b/samples/app/FilamentApp.h index 035b8770c1..dfa2474305 100644 --- a/samples/app/FilamentApp.h +++ b/samples/app/FilamentApp.h @@ -80,6 +80,8 @@ public: void setSidebarWidth(int width) { mSidebarWidth = width; } + size_t getSkippedFrameCount() const { return mSkippedFrames; } + FilamentApp(const FilamentApp& rhs) = delete; FilamentApp(FilamentApp&& rhs) = delete; FilamentApp& operator=(const FilamentApp& rhs) = delete; @@ -208,6 +210,7 @@ private: AnimCallback mAnimation; DropCallback mDropHandler; int mSidebarWidth = 0; + size_t mSkippedFrames = 0; }; #endif // TNT_FILAMENT_SAMPLE_FILAMENTAPP_H diff --git a/samples/gltf_viewer.cpp b/samples/gltf_viewer.cpp index 5258dfefd3..767e1982e9 100644 --- a/samples/gltf_viewer.cpp +++ b/samples/gltf_viewer.cpp @@ -199,6 +199,14 @@ int main(int argc, char** argv) { loadResources(filename); + app.viewer->setUiCallback([&app, scene] () { + if (ImGui::CollapsingHeader("Stats")) { + ImGui::Text("%zu entities in the asset", app.asset->getEntityCount()); + ImGui::Text("%zu renderables (excluding UI)", scene->getRenderableCount()); + ImGui::Text("%zu skipped frames", FilamentApp::get().getSkippedFrameCount()); + } + }); + // Leave FXAA enabled but we also enable MSAA for a nice result. The wireframe looks // much better with MSAA enabled. view->setSampleCount(4);