From 2e666836c716ba99aa50c13b64e4cc5918dc4a8a Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 20 May 2019 13:42:53 -0700 Subject: [PATCH 1/2] add more options to render scripting interface --- interface/src/Menu.cpp | 50 ++-------- .../scripting/RenderScriptingInterface.cpp | 94 +++++++++++++++++-- .../src/scripting/RenderScriptingInterface.h | 52 +++++++++- .../render-utils/src/AntialiasingEffect.h | 2 - 4 files changed, 144 insertions(+), 54 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 9341b2316c..5880076358 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -49,16 +49,13 @@ #include "DeferredLightingEffect.h" #include "PickManager.h" -#include "LightingModel.h" -#include "AmbientOcclusionEffect.h" -#include "RenderShadowTask.h" -#include "AntialiasingEffect.h" - #include "scripting/SettingsScriptingInterface.h" #if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SpeechRecognizer.h" #endif +#include "scripting/RenderScriptingInterface.h" + extern bool DEV_DECIMATE_TEXTURES; Menu* Menu::getInstance() { @@ -367,45 +364,14 @@ Menu::Menu() { // Developer > Render >>> MenuWrapper* renderOptionsMenu = developerMenu->addMenu("Render"); - action = addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::AntiAliasing, 0, true); - connect(action, &QAction::triggered, [action] { - auto renderConfig = qApp->getRenderEngine()->getConfiguration(); - if (renderConfig) { - auto mainViewJitterCamConfig = renderConfig->getConfig("RenderMainView.JitterCam"); - auto mainViewAntialiasingConfig = renderConfig->getConfig("RenderMainView.Antialiasing"); - if (mainViewJitterCamConfig && mainViewAntialiasingConfig) { - if (action->isChecked()) { - mainViewJitterCamConfig->play(); - mainViewAntialiasingConfig->setDebugFXAA(false); - } else { - mainViewJitterCamConfig->none(); - mainViewAntialiasingConfig->setDebugFXAA(true); - } - } - } - }); + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::AntiAliasing, 0, RenderScriptingInterface::getInstance()->getAntialiasingEnabled(), + RenderScriptingInterface::getInstance(), SLOT(setAntialiasingEnabled(bool))); - action = addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Shadows, 0, true); - connect(action, &QAction::triggered, [action] { - auto renderConfig = qApp->getRenderEngine()->getConfiguration(); - if (renderConfig) { - auto lightingModelConfig = renderConfig->getConfig("RenderMainView.LightingModel"); - if (lightingModelConfig) { - lightingModelConfig->setShadow(action->isChecked()); - } - } - }); + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Shadows, 0, RenderScriptingInterface::getInstance()->getShadowsEnabled(), + RenderScriptingInterface::getInstance(), SLOT(setShadowsEnabled(bool))); - action = addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::AmbientOcclusion, 0, false); - connect(action, &QAction::triggered, [action] { - auto renderConfig = qApp->getRenderEngine()->getConfiguration(); - if (renderConfig) { - auto lightingModelConfig = renderConfig->getConfig("RenderMainView.LightingModel"); - if (lightingModelConfig) { - lightingModelConfig->setAmbientOcclusion(action->isChecked()); - } - } - }); + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::AmbientOcclusion, 0, RenderScriptingInterface::getInstance()->getAmbientOcclusionEnabled(), + RenderScriptingInterface::getInstance(), SLOT(setAmbientOcclusionEnabled(bool))); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::WorldAxes); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::DefaultSkybox, 0, true); diff --git a/interface/src/scripting/RenderScriptingInterface.cpp b/interface/src/scripting/RenderScriptingInterface.cpp index 8581c7527d..360a75b557 100644 --- a/interface/src/scripting/RenderScriptingInterface.cpp +++ b/interface/src/scripting/RenderScriptingInterface.cpp @@ -7,6 +7,9 @@ // #include "RenderScriptingInterface.h" +#include "LightingModel.h" +#include "AntialiasingEffect.h" + const QString DEFERRED = "deferred"; const QString FORWARD = "forward"; @@ -17,6 +20,9 @@ RenderScriptingInterface* RenderScriptingInterface::getInstance() { RenderScriptingInterface::RenderScriptingInterface() { setRenderMethod((render::Args::RenderMethod)_renderMethodSetting.get() == render::Args::RenderMethod::DEFERRED ? DEFERRED : FORWARD); + setShadowsEnabled(_shadowsEnabledSetting.get()); + setAmbientOcclusionEnabled(_ambientOcclusionEnabledSetting.get()); + setAntialiasingEnabled(_antialiasingEnabledSetting.get()); } QString RenderScriptingInterface::getRenderMethod() { @@ -24,6 +30,11 @@ QString RenderScriptingInterface::getRenderMethod() { } void RenderScriptingInterface::setRenderMethod(const QString& renderMethod) { + render::Args::RenderMethod newMethod = renderMethod == FORWARD ? render::Args::RenderMethod::FORWARD : render::Args::RenderMethod::DEFERRED; + if (_renderMethodSetting.get() == newMethod) { + return; + } + if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "setRenderMethod", Q_ARG(const QString&, renderMethod)); return; @@ -31,14 +42,81 @@ void RenderScriptingInterface::setRenderMethod(const QString& renderMethod) { auto config = dynamic_cast(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch")); if (config) { - if (renderMethod == DEFERRED) { - _renderMethodSetting.set(render::Args::RenderMethod::DEFERRED); - config->setBranch(render::Args::RenderMethod::DEFERRED); - emit config->dirtyEnabled(); - } else if (renderMethod == FORWARD) { - _renderMethodSetting.set(render::Args::RenderMethod::FORWARD); - config->setBranch(render::Args::RenderMethod::FORWARD); - emit config->dirtyEnabled(); + _renderMethodSetting.set(newMethod); + config->setBranch(newMethod); + emit config->dirtyEnabled(); + } +} + +bool RenderScriptingInterface::getShadowsEnabled() { + return _shadowsEnabledSetting.get(); +} + +void RenderScriptingInterface::setShadowsEnabled(bool enabled) { + if (_shadowsEnabledSetting.get() == enabled) { + return; + } + + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setShadowsEnabled", Q_ARG(bool, enabled)); + return; + } + + auto lightingModelConfig = qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.LightingModel"); + if (lightingModelConfig) { + Menu::getInstance()->setIsOptionChecked(MenuOption::Shadows, enabled); + _shadowsEnabledSetting.set(enabled); + lightingModelConfig->setShadow(enabled); + } +} + +bool RenderScriptingInterface::getAmbientOcclusionEnabled() { + return _ambientOcclusionEnabledSetting.get(); +} + +void RenderScriptingInterface::setAmbientOcclusionEnabled(bool enabled) { + if (_ambientOcclusionEnabledSetting.get() == enabled) { + return; + } + + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setAmbientOcclusionEnabled", Q_ARG(bool, enabled)); + return; + } + + auto lightingModelConfig = qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.LightingModel"); + if (lightingModelConfig) { + Menu::getInstance()->setIsOptionChecked(MenuOption::AmbientOcclusion, enabled); + _ambientOcclusionEnabledSetting.set(enabled); + lightingModelConfig->setAmbientOcclusion(enabled); + } +} + +bool RenderScriptingInterface::getAntialiasingEnabled() { + return _antialiasingEnabledSetting.get(); +} + +void RenderScriptingInterface::setAntialiasingEnabled(bool enabled) { + if (_antialiasingEnabledSetting.get() == enabled) { + return; + } + + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setAntialiasingEnabled", Q_ARG(bool, enabled)); + return; + } + + auto mainViewJitterCamConfig = qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.JitterCam"); + auto mainViewAntialiasingConfig = qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.Antialiasing"); + if (mainViewJitterCamConfig && mainViewAntialiasingConfig) { + Menu::getInstance()->setIsOptionChecked(MenuOption::AntiAliasing, enabled); + _antialiasingEnabledSetting.set(enabled); + if (enabled) { + mainViewJitterCamConfig->play(); + mainViewAntialiasingConfig->setDebugFXAA(false); + } else { + mainViewJitterCamConfig->none(); + mainViewAntialiasingConfig->setDebugFXAA(true); } } } \ No newline at end of file diff --git a/interface/src/scripting/RenderScriptingInterface.h b/interface/src/scripting/RenderScriptingInterface.h index 2aff3a08b6..329433fb60 100644 --- a/interface/src/scripting/RenderScriptingInterface.h +++ b/interface/src/scripting/RenderScriptingInterface.h @@ -26,6 +26,9 @@ class RenderScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(QString renderMethod READ getRenderMethod WRITE setRenderMethod) + Q_PROPERTY(bool shadowsEnabled READ getShadowsEnabled WRITE setShadowsEnabled) + Q_PROPERTY(bool ambientOcclusionEnabled READ getAmbientOcclusionEnabled WRITE setAmbientOcclusionEnabled) + Q_PROPERTY(bool antialiasingEnabled READ getAntialiasingEnabled WRITE setAntialiasingEnabled) public: RenderScriptingInterface(); @@ -37,8 +40,8 @@ public slots: * Get a config for a job by name * @function Render.getConfig * @param {string} name - Can be: - * - . Search for the first job named job_name traversing the the sub graph of task and jobs (from this task as root) - * - .[.]. Allows you to first look for the parent_name job (from this task as root) and then search from there for the + * - : Search for the first job named job_name traversing the the sub graph of task and jobs (from this task as root) + * - .[.]: Allows you to first look for the parent_name job (from this task as root) and then search from there for the * optional sub_parent_names and finally from there looking for the job_name (assuming every job in the path is found) * @returns {object} The sub job config. */ @@ -58,8 +61,53 @@ public slots: */ void setRenderMethod(const QString& renderMethod); + /**jsdoc + * Whether or not shadows are enabled + * @function Render.getShadowsEnabled + * @returns {bool} true if shadows are enabled, otherwise false + */ + bool getShadowsEnabled(); + + /**jsdoc + * Enables or disables shadows + * @function Render.setShadowsEnabled + * @param {bool} enabled - true to enable shadows, false to disable them + */ + void setShadowsEnabled(bool enabled); + + /**jsdoc + * Whether or not ambient occlusion is enabled + * @function Render.getAmbientOcclusionEnabled + * @returns {bool} true if ambient occlusion is enabled, otherwise false + */ + bool getAmbientOcclusionEnabled(); + + /**jsdoc + * Enables or disables ambient occlusion + * @function Render.setAmbientOcclusionEnabled + * @param {bool} enabled - true to enable ambient occlusion, false to disable it + */ + void setAmbientOcclusionEnabled(bool enabled); + + /**jsdoc + * Whether or not anti-aliasing is enabled + * @function Render.getAntialiasingEnabled + * @returns {bool} true if anti-aliasing is enabled, otherwise false + */ + bool getAntialiasingEnabled(); + + /**jsdoc + * Enables or disables anti-aliasing + * @function Render.setAntialiasingEnabled + * @param {bool} enabled - true to enable anti-aliasing, false to disable it + */ + void setAntialiasingEnabled(bool enabled); + private: Setting::Handle _renderMethodSetting { "renderMethod", RENDER_FORWARD ? render::Args::RenderMethod::FORWARD : render::Args::RenderMethod::DEFERRED }; + Setting::Handle _shadowsEnabledSetting { "shadowsEnabled", true }; + Setting::Handle _ambientOcclusionEnabledSetting { "ambientOcclusionEnabled", false }; + Setting::Handle _antialiasingEnabledSetting { "antialiasingEnabled", true }; }; #endif // hifi_RenderScriptingInterface_h diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h index 936ade043d..8057601317 100644 --- a/libraries/render-utils/src/AntialiasingEffect.h +++ b/libraries/render-utils/src/AntialiasingEffect.h @@ -107,8 +107,6 @@ public: AntialiasingConfig() : render::Job::Config(true) {} void setDebugFXAA(bool debug) { debugFXAAX = (debug ? 0.0f : 1.0f); emit dirty();} - bool debugFXAA() const { return (debugFXAAX == 0.0f ? true : false); } - float blend{ 0.25f }; float sharpen{ 0.05f }; From 43874fbfb39ed0e08219959e9db63b7db346a2b7 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 20 May 2019 17:21:10 -0700 Subject: [PATCH 2/2] fix AA toggle --- libraries/render-utils/src/AntialiasingEffect.cpp | 6 ++++-- libraries/render-utils/src/AntialiasingEffect.h | 1 + libraries/render-utils/src/RenderDeferredTask.cpp | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index a445ea2343..180e914d60 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -378,6 +378,8 @@ void JitterSample::configure(const Config& config) { } } else if (config.stop) { _sampleSequence.currentIndex = -1; + } else { + _sampleSequence.currentIndex = config.getIndex(); } _scale = config.scale; } @@ -392,10 +394,10 @@ void JitterSample::run(const render::RenderContextPointer& renderContext, Output } } - jitter.x = 0.0f; - jitter.y = 0.0f; if (current >= 0) { jitter = _sampleSequence.offsets[current]; + } else { + jitter = glm::vec2(0.0f); } } diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h index 8057601317..7d8bbb44d9 100644 --- a/libraries/render-utils/src/AntialiasingEffect.h +++ b/libraries/render-utils/src/AntialiasingEffect.h @@ -107,6 +107,7 @@ public: AntialiasingConfig() : render::Job::Config(true) {} void setDebugFXAA(bool debug) { debugFXAAX = (debug ? 0.0f : 1.0f); emit dirty();} + bool debugFXAA() const { return (debugFXAAX == 0.0f ? true : false); } float blend{ 0.25f }; float sharpen{ 0.05f }; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index d808823d0c..624869bbf5 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -248,7 +248,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Debugging task is happening in the "over" layer after tone mapping and just before HUD { // Debug the bounds of the rendered items, still look at the zbuffer - const auto extraDebugBuffers = RenderDeferredTaskDebug::ExtraBuffers(linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, ambientOcclusionFramebuffer, scatteringResource, velocityBuffer); + const auto extraDebugBuffers = RenderDeferredTaskDebug::ExtraBuffers(linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, ambientOcclusionUniforms, scatteringResource, velocityBuffer); const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, shadowTaskOutputs, lightingStageInputs, lightClusters, prepareDeferredOutputs, extraDebugBuffers, deferredFrameTransform, jitter, lightingModel).asVarying(); task.addJob("DebugRenderDeferredTask", debugInputs);