From 8a865e531ecf4bc30852e34d83b1fded321a21b4 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Thu, 1 Oct 2020 17:12:06 -0700 Subject: [PATCH] gltf_viewer: minor refactoring --- libs/viewer/include/viewer/SimpleViewer.h | 16 +++---- libs/viewer/src/SimpleViewer.cpp | 56 +++++++++++------------ samples/gltf_viewer.cpp | 16 +++---- 3 files changed, 43 insertions(+), 45 deletions(-) diff --git a/libs/viewer/include/viewer/SimpleViewer.h b/libs/viewer/include/viewer/SimpleViewer.h index 68b3e5e36a..b014eb8760 100644 --- a/libs/viewer/include/viewer/SimpleViewer.h +++ b/libs/viewer/include/viewer/SimpleViewer.h @@ -136,7 +136,7 @@ public: * Defaults to true. */ void enableDithering(bool b) { - mViewSettings.dithering = b ? Dithering::TEMPORAL : Dithering::NONE; + mSettings.view.dithering = b ? Dithering::TEMPORAL : Dithering::NONE; } /** @@ -144,26 +144,26 @@ public: * Defaults to true. */ void enableFxaa(bool b) { - mViewSettings.antiAliasing = b ? AntiAliasing::FXAA : AntiAliasing::NONE; + mSettings.view.antiAliasing = b ? AntiAliasing::FXAA : AntiAliasing::NONE; } /** * Enables hardware-based MSAA antialiasing. * Defaults to true. */ - void enableMsaa(bool b) { mViewSettings.sampleCount = b ? 4 : 1; } + void enableMsaa(bool b) { mSettings.view.sampleCount = b ? 4 : 1; } /** * Enables screen-space ambient occlusion in the post-process pipeline. * Defaults to true. */ - void enableSSAO(bool b) { mViewSettings.ssao.enabled = b; } + void enableSSAO(bool b) { mSettings.view.ssao.enabled = b; } /** * Enables Bloom. * Defaults to true. */ - void enableBloom(bool bloom) { mViewSettings.bloom.enabled = bloom; } + void enableBloom(bool bloom) { mSettings.view.bloom.enabled = bloom; } /** * Adjusts the intensity of the IBL. @@ -173,9 +173,9 @@ public: void setIBLIntensity(float brightness) { mIblIntensity = brightness; } /** - * Gets a modifiable reference to stashed View state. + * Gets a modifiable reference to stashed state. */ - ViewSettings& getViewSettings() { return mViewSettings; } + Settings& getSettings() { return mSettings; } private: void updateIndirectLight(); @@ -207,7 +207,7 @@ private: bool mEnableContactShadows = false; int mVsmMsaaSamplesLog2 = 1; std::array mSplitPositions = {0.25f, 0.50f, 0.75f}; - ViewSettings mViewSettings; + Settings mSettings; int mSidebarWidth; uint32_t mFlags; }; diff --git a/libs/viewer/src/SimpleViewer.cpp b/libs/viewer/src/SimpleViewer.cpp index c64745a9b5..4fd9260401 100644 --- a/libs/viewer/src/SimpleViewer.cpp +++ b/libs/viewer/src/SimpleViewer.cpp @@ -54,12 +54,12 @@ SimpleViewer::SimpleViewer(filament::Engine* engine, filament::Scene* scene, fil mSunlight(utils::EntityManager::get().create()), mSidebarWidth(sidebarWidth) { - mViewSettings.shadowType = ShadowType::PCF; - mViewSettings.dithering = Dithering::TEMPORAL; - mViewSettings.antiAliasing = AntiAliasing::FXAA; - mViewSettings.sampleCount = 4; - mViewSettings.ssao.enabled = true; - mViewSettings.bloom.enabled = true; + mSettings.view.shadowType = ShadowType::PCF; + mSettings.view.dithering = Dithering::TEMPORAL; + mSettings.view.antiAliasing = AntiAliasing::FXAA; + mSettings.view.sampleCount = 4; + mSettings.view.ssao.enabled = true; + mSettings.view.bloom.enabled = true; using namespace filament; LightManager::Builder(LightManager::Type::SUN) @@ -125,7 +125,7 @@ void SimpleViewer::removeAsset() { void SimpleViewer::setIndirectLight(filament::IndirectLight* ibl, filament::math::float3 const* sh3) { using namespace filament::math; - mViewSettings.fog.color = sh3[0]; + mSettings.view.fog.color = sh3[0]; mIndirectLight = ibl; if (ibl) { float3 d = filament::IndirectLight::getDirectionEstimate(sh3); @@ -271,31 +271,31 @@ void SimpleViewer::updateUserInterface() { if (ImGui::CollapsingHeader("View")) { ImGui::Indent(); - bool dither = mViewSettings.dithering == Dithering::TEMPORAL; + bool dither = mSettings.view.dithering == Dithering::TEMPORAL; ImGui::Checkbox("Dithering", &dither); enableDithering(dither); - bool msaa = mViewSettings.sampleCount != 1; + bool msaa = mSettings.view.sampleCount != 1; ImGui::Checkbox("MSAA 4x", &msaa); enableMsaa(msaa); - ImGui::Checkbox("TAA", &mViewSettings.taa.enabled); + ImGui::Checkbox("TAA", &mSettings.view.taa.enabled); // this clutters the UI and isn't that useful (except when working on TAA) //ImGui::Indent(); - //ImGui::SliderFloat("feedback", &mViewSettings.taa.feedback, 0.0f, 1.0f); - //ImGui::SliderFloat("filter", &mViewSettings.taa.filterWidth, 0.0f, 2.0f); + //ImGui::SliderFloat("feedback", &mSettings.view.taa.feedback, 0.0f, 1.0f); + //ImGui::SliderFloat("filter", &mSettings.view.taa.filterWidth, 0.0f, 2.0f); //ImGui::Unindent(); - bool fxaa = mViewSettings.antiAliasing == AntiAliasing::FXAA; + bool fxaa = mSettings.view.antiAliasing == AntiAliasing::FXAA; ImGui::Checkbox("FXAA", &fxaa); enableFxaa(fxaa); - ImGui::Checkbox("SSAO", &mViewSettings.ssao.enabled); - ImGui::Checkbox("Bloom", &mViewSettings.bloom.enabled); + ImGui::Checkbox("SSAO", &mSettings.view.ssao.enabled); + ImGui::Checkbox("Bloom", &mSettings.view.bloom.enabled); if (ImGui::CollapsingHeader("SSAO Options")) { - auto& ssao = mViewSettings.ssao; + auto& ssao = mSettings.view.ssao; int quality = (int) ssao.quality; int lowpass = (int) ssao.lowPassFilter; @@ -336,9 +336,9 @@ void SimpleViewer::updateUserInterface() { ImGui::Checkbox("Enable sunlight", &mEnableSunlight); ImGui::Checkbox("Enable shadows", &mEnableShadows); - bool enableVsm = mViewSettings.shadowType == ShadowType::VSM; + bool enableVsm = mSettings.view.shadowType == ShadowType::VSM; ImGui::Checkbox("Enable VSM", &enableVsm); - mViewSettings.shadowType = enableVsm ? ShadowType::VSM : ShadowType::PCF; + mSettings.view.shadowType = enableVsm ? ShadowType::VSM : ShadowType::PCF; char label[32]; snprintf(label, 32, "%d", 1 << mVsmMsaaSamplesLog2); @@ -356,21 +356,21 @@ void SimpleViewer::updateUserInterface() { if (ImGui::CollapsingHeader("Fog")) { ImGui::Indent(); - ImGui::Checkbox("Enable fog", &mViewSettings.fog.enabled); - ImGui::SliderFloat("Start", &mViewSettings.fog.distance, 0.0f, 100.0f); - ImGui::SliderFloat("Density", &mViewSettings.fog.density, 0.0f, 1.0f); - ImGui::SliderFloat("Height", &mViewSettings.fog.height, 0.0f, 100.0f); - ImGui::SliderFloat("Height falloff", &mViewSettings.fog.heightFalloff, 0.0f, 10.0f); - ImGui::SliderFloat("Scattering start", &mViewSettings.fog.inScatteringStart, 0.0f, 100.0f); - ImGui::SliderFloat("Scattering size", &mViewSettings.fog.inScatteringSize, 0.1f, 100.0f); - ImGui::Checkbox("Color from IBL", &mViewSettings.fog.fogColorFromIbl); - ImGui::ColorPicker3("Color", mViewSettings.fog.color.v); + ImGui::Checkbox("Enable fog", &mSettings.view.fog.enabled); + ImGui::SliderFloat("Start", &mSettings.view.fog.distance, 0.0f, 100.0f); + ImGui::SliderFloat("Density", &mSettings.view.fog.density, 0.0f, 1.0f); + ImGui::SliderFloat("Height", &mSettings.view.fog.height, 0.0f, 100.0f); + ImGui::SliderFloat("Height falloff", &mSettings.view.fog.heightFalloff, 0.0f, 10.0f); + ImGui::SliderFloat("Scattering start", &mSettings.view.fog.inScatteringStart, 0.0f, 100.0f); + ImGui::SliderFloat("Scattering size", &mSettings.view.fog.inScatteringSize, 0.1f, 100.0f); + ImGui::Checkbox("Color from IBL", &mSettings.view.fog.fogColorFromIbl); + ImGui::ColorPicker3("Color", mSettings.view.fog.color.v); ImGui::Unindent(); } // At this point, all View settings have been modified, // so we can now push them into the Filament View. - applySettings(mViewSettings, mView); + applySettings(mSettings.view, mView); if (mEnableSunlight) { mScene->addEntity(mSunlight); diff --git a/samples/gltf_viewer.cpp b/samples/gltf_viewer.cpp index 6671e7c95f..42b031f3cb 100644 --- a/samples/gltf_viewer.cpp +++ b/samples/gltf_viewer.cpp @@ -140,7 +140,7 @@ static void printUsage(char* name) { " --recompute-aabb, -r\n" " Ignore the min/max attributes in the glTF file\n\n" " --settings=, -t\n" - " Apply the settings in the given JSON file.\n\n" + " Apply the settings in the given JSON file\n\n" " --ubershader, -u\n" " Enable ubershaders (improves load time, adds shader complexity)\n\n" " --camera=, -c \n" @@ -332,7 +332,7 @@ static void createGroundPlane(Engine* engine, Scene* scene, App& app) { } static void computeRangePlot(App& app, float* rangePlot) { - float4& ranges = app.viewer->getViewSettings().colorGrading.ranges; + float4& ranges = app.viewer->getSettings().view.colorGrading.ranges; ranges.y = clamp(ranges.y, ranges.x + 1e-5f, ranges.w - 1e-5f); // darks ranges.z = clamp(ranges.z, ranges.x + 1e-5f, ranges.w - 1e-5f); // lights @@ -382,7 +382,7 @@ inline float3 curves(float3 v, float3 shadowGamma, float3 midPoint, float3 highl } static void computeCurvePlot(App& app, float* curvePlot) { - const auto& colorGradingOptions = app.viewer->getViewSettings().colorGrading; + const auto& colorGradingOptions = app.viewer->getSettings().view.colorGrading; for (size_t i = 0; i < 1024; i++) { float3 x{i / 1024.0f * 2.0f}; float3 y = curves(x, @@ -416,7 +416,7 @@ static void colorGradingUI(App& app) { const static ImVec2 plotLinesWideSize(350.0f, 120.0f); if (ImGui::CollapsingHeader("Color grading")) { - ColorGradingSettings& colorGrading = app.viewer->getViewSettings().colorGrading; + ColorGradingSettings& colorGrading = app.viewer->getSettings().view.colorGrading; ImGui::Indent(); ImGui::Checkbox("Enabled##colorGrading", &colorGrading.enabled); @@ -669,11 +669,9 @@ int main(int argc, char** argv) { app.viewer = new SimpleViewer(engine, scene, view, 410); if (app.settingsFile.size() > 0) { - Settings settings; - bool success = loadSettings(app.settingsFile.c_str(), &settings); + bool success = loadSettings(app.settingsFile.c_str(), &app.viewer->getSettings()); if (success) { std::cout << "Loaded settings from " << app.settingsFile << std::endl; - app.viewer->getViewSettings() = settings.view; } else { std::cerr << "Failed to load settings from " << app.settingsFile << std::endl; } @@ -721,7 +719,7 @@ int main(int argc, char** argv) { } if (ImGui::CollapsingHeader("Camera")) { - ViewSettings& settings = app.viewer->getViewSettings(); + ViewSettings& settings = app.viewer->getSettings().view; ImGui::Indent(); ImGui::SliderFloat("Focal length (mm)", &FilamentApp::get().getCameraFocalLength(), 16.0f, 90.0f); @@ -872,7 +870,7 @@ int main(int argc, char** argv) { .clear = true }); - ColorGradingSettings& options = app.viewer->getViewSettings().colorGrading; + ColorGradingSettings& options = app.viewer->getSettings().view.colorGrading; if (options.enabled) { // An inefficient but simple way of detecting change is to serialize to JSON, then // do a string comparison.