Showing the changes to interface/src/scripting/RenderScriptingInterface.cpp (1 of 746 files). Show all
Unified · Split
| @@ -9,12 +9,15 @@ · 8 unmodified lines | ||
| 9 | 9 | // |
| 10 | 10 | #include "RenderScriptingInterface.h" |
| 11 | 11 | |
| 12 | +#include <RenderCommonTask.h> | |
| 12 | 13 | #include <ScriptEngineCast.h> |
| 13 | 14 | |
| 14 | 15 | #include "LightingModel.h" |
| 15 | 16 | #include <QScreen> |
| 16 | 17 | #include "ScreenName.h" |
| 17 | 18 | |
| 19 | +#include <procedural/Procedural.h> | |
| 20 | + | |
| 18 | 21 | STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){ |
| 19 | 22 | auto scriptEngine = manager->engine().get(); |
| 20 | 23 | |
| @@ -42,16 +45,17 @@ RenderScriptingInterface::RenderScriptingInterface() { · 21 unmodified lines | ||
| 42 | 45 | }); |
| 43 | 46 | } |
| 44 | 47 | |
| 45 | − | |
| 46 | 48 | void RenderScriptingInterface::loadSettings() { |
| 47 | 49 | _renderSettingLock.withReadLock([&] { |
| 48 | − _renderMethod = (_renderMethodSetting.get()); | |
| 49 | − _shadowsEnabled = (_shadowsEnabledSetting.get()); | |
| 50 | − _ambientOcclusionEnabled = (_ambientOcclusionEnabledSetting.get()); | |
| 51 | − //_antialiasingMode = (_antialiasingModeSetting.get()); | |
| 50 | + _renderMethod = _renderMethodSetting.get(); | |
| 51 | + _shadowsEnabled = _shadowsEnabledSetting.get(); | |
| 52 | + _hazeEnabled = _hazeEnabledSetting.get(); | |
| 53 | + _bloomEnabled = _bloomEnabledSetting.get(); | |
| 54 | + _ambientOcclusionEnabled = _ambientOcclusionEnabledSetting.get(); | |
| 55 | + _proceduralMaterialsEnabled = _proceduralMaterialsEnabledSetting.get(); | |
| 52 | 56 | _antialiasingMode = static_cast<AntialiasingSetupConfig::Mode>(_antialiasingModeSetting.get()); |
| 53 | − _viewportResolutionScale = (_viewportResolutionScaleSetting.get()); | |
| 54 | − _fullScreenScreen = (_fullScreenScreenSetting.get()); | |
| 57 | + _viewportResolutionScale = _viewportResolutionScaleSetting.get(); | |
| 58 | + _fullScreenScreen = _fullScreenScreenSetting.get(); | |
| 55 | 59 | }); |
| 56 | 60 | |
| 57 | 61 | // If full screen screen is not initialized, or set to an invalid value, |
| @@ -64,7 +68,10 @@ void RenderScriptingInterface::loadSettings() { · 6 unmodified lines | ||
| 64 | 68 | |
| 65 | 69 | forceRenderMethod((RenderMethod)_renderMethod); |
| 66 | 70 | forceShadowsEnabled(_shadowsEnabled); |
| 71 | + forceHazeEnabled(_hazeEnabled); | |
| 72 | + forceBloomEnabled(_bloomEnabled); | |
| 67 | 73 | forceAmbientOcclusionEnabled(_ambientOcclusionEnabled); |
| 74 | + forceProceduralMaterialsEnabled(_proceduralMaterialsEnabled); | |
| 68 | 75 | forceAntialiasingMode(_antialiasingMode); |
| 69 | 76 | forceViewportResolutionScale(_viewportResolutionScale); |
| 70 | 77 | } |
| @@ -79,15 +86,37 @@ void RenderScriptingInterface::setRenderMethod(RenderMethod renderMethod) { · 8 unmodified lines | ||
| 79 | 86 | emit settingsChanged(); |
| 80 | 87 | } |
| 81 | 88 | } |
| 89 | + | |
| 90 | +void recursivelyUpdateMirrorRenderMethods(const QString& parentTaskName, int renderMethod, int depth) { | |
| 91 | + if (depth == RenderMirrorTask::MAX_MIRROR_DEPTH) { | |
| 92 | + return; | |
| 93 | + } | |
| 94 | + | |
| 95 | + auto renderConfig = qApp->getRenderEngine()->getConfiguration(); | |
| 96 | + for (size_t mirrorIndex = 0; mirrorIndex < RenderMirrorTask::MAX_MIRRORS_PER_LEVEL; mirrorIndex++) { | |
| 97 | + std::string mirrorTaskString = parentTaskName.toStdString() + ".RenderMirrorView" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth) + ".DeferredForwardSwitch"; | |
| 98 | + auto mirrorConfig = dynamic_cast<render::SwitchConfig*>(renderConfig->getConfig(QString::fromStdString(mirrorTaskString))); | |
| 99 | + if (mirrorConfig) { | |
| 100 | + mirrorConfig->setBranch((int)renderMethod); | |
| 101 | + recursivelyUpdateMirrorRenderMethods(QString::fromStdString(mirrorTaskString) + (renderMethod == 1 ? ".RenderForwardTask" : ".RenderShadowsAndDeferredTask.RenderDeferredTask"), | |
| 102 | + renderMethod, depth + 1); | |
| 103 | + } | |
| 104 | + } | |
| 105 | +} | |
| 106 | + | |
| 82 | 107 | void RenderScriptingInterface::forceRenderMethod(RenderMethod renderMethod) { |
| 83 | 108 | _renderSettingLock.withWriteLock([&] { |
| 84 | 109 | _renderMethod = (int)renderMethod; |
| 85 | 110 | _renderMethodSetting.set((int)renderMethod); |
| 86 | 111 | |
| 87 | 112 | auto renderConfig = qApp->getRenderEngine()->getConfiguration(); |
| 88 | − auto config = dynamic_cast<render::SwitchConfig*>(renderConfig->getConfig("RenderMainView.DeferredForwardSwitch")); | |
| 113 | + QString configName = "RenderMainView.DeferredForwardSwitch"; | |
| 114 | + auto config = dynamic_cast<render::SwitchConfig*>(renderConfig->getConfig(configName)); | |
| 89 | 115 | if (config) { |
| 90 | 116 | config->setBranch((int)renderMethod); |
| 117 | + | |
| 118 | + recursivelyUpdateMirrorRenderMethods(configName + (renderMethod == RenderMethod::FORWARD ? ".RenderForwardTask" : ".RenderShadowsAndDeferredTask.RenderDeferredTask"), | |
| 119 | + (int)renderMethod, 0); | |
| 91 | 120 | } |
| 92 | 121 | |
| 93 | 122 | auto secondaryConfig = dynamic_cast<render::SwitchConfig*>(renderConfig->getConfig("RenderSecondView.DeferredForwardSwitch")); |
| @@ -102,6 +131,34 @@ QStringList RenderScriptingInterface::getRenderMethodNames() const { · 8 unmodified lines | ||
| 102 | 131 | return refrenderMethodNames; |
| 103 | 132 | } |
| 104 | 133 | |
| 134 | +void recursivelyUpdateLightingModel(const QString& parentTaskName, std::function<void(MakeLightingModelConfig *)> updateLambda, int depth = -1) { | |
| 135 | + auto renderConfig = qApp->getRenderEngine()->getConfiguration(); | |
| 136 | + if (depth == -1) { | |
| 137 | + auto secondaryLightingModelConfig = renderConfig->getConfig<MakeLightingModel>("RenderSecondView.LightingModel"); | |
| 138 | + if (secondaryLightingModelConfig) { | |
| 139 | + updateLambda(secondaryLightingModelConfig); | |
| 140 | + } | |
| 141 | + | |
| 142 | + auto mainLightingModelConfig = renderConfig->getConfig<MakeLightingModel>("RenderMainView.LightingModel"); | |
| 143 | + if (mainLightingModelConfig) { | |
| 144 | + updateLambda(mainLightingModelConfig); | |
| 145 | + } | |
| 146 | + | |
| 147 | + recursivelyUpdateLightingModel("RenderMainView", updateLambda, depth + 1); | |
| 148 | + } else if (depth == RenderMirrorTask::MAX_MIRROR_DEPTH) { | |
| 149 | + return; | |
| 150 | + } | |
| 151 | + | |
| 152 | + for (size_t mirrorIndex = 0; mirrorIndex < RenderMirrorTask::MAX_MIRRORS_PER_LEVEL; mirrorIndex++) { | |
| 153 | + std::string mirrorTaskString = parentTaskName.toStdString() + ".RenderMirrorView" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth); | |
| 154 | + auto lightingModelConfig = renderConfig->getConfig<MakeLightingModel>(mirrorTaskString + ".LightingModel"); | |
| 155 | + if (lightingModelConfig) { | |
| 156 | + updateLambda(lightingModelConfig); | |
| 157 | + recursivelyUpdateLightingModel(QString::fromStdString(mirrorTaskString), updateLambda, depth + 1); | |
| 158 | + } | |
| 159 | + } | |
| 160 | +} | |
| 161 | + | |
| 105 | 162 | bool RenderScriptingInterface::getShadowsEnabled() const { |
| 106 | 163 | return _shadowsEnabled; |
| 107 | 164 | } |
| @@ -119,16 +176,47 @@ void RenderScriptingInterface::forceShadowsEnabled(bool enabled) { · 11 unmodified lines | ||
| 119 | 176 | _shadowsEnabledSetting.set(enabled); |
| 120 | 177 | Menu::getInstance()->setIsOptionChecked(MenuOption::Shadows, enabled); |
| 121 | 178 | |
| 122 | − auto renderConfig = qApp->getRenderEngine()->getConfiguration(); | |
| 123 | − assert(renderConfig); | |
| 124 | − auto lightingModelConfig = renderConfig->getConfig<MakeLightingModel>("RenderMainView.LightingModel"); | |
| 125 | − if (lightingModelConfig) { | |
| 126 | − lightingModelConfig->setShadow(enabled); | |
| 127 | − } | |
| 128 | − auto secondaryLightingModelConfig = renderConfig->getConfig<MakeLightingModel>("RenderSecondView.LightingModel"); | |
| 129 | − if (secondaryLightingModelConfig) { | |
| 130 | − secondaryLightingModelConfig->setShadow(enabled); | |
| 131 | − } | |
| 179 | + recursivelyUpdateLightingModel("", [enabled] (MakeLightingModelConfig *config) { config->setShadow(enabled); }); | |
| 180 | + }); | |
| 181 | +} | |
| 182 | + | |
| 183 | +bool RenderScriptingInterface::getHazeEnabled() const { | |
| 184 | + return _hazeEnabled; | |
| 185 | +} | |
| 186 | + | |
| 187 | +void RenderScriptingInterface::setHazeEnabled(bool enabled) { | |
| 188 | + if (_hazeEnabled != enabled) { | |
| 189 | + forceHazeEnabled(enabled); | |
| 190 | + emit settingsChanged(); | |
| 191 | + } | |
| 192 | +} | |
| 193 | + | |
| 194 | +void RenderScriptingInterface::forceHazeEnabled(bool enabled) { | |
| 195 | + _renderSettingLock.withWriteLock([&] { | |
| 196 | + _hazeEnabled = (enabled); | |
| 197 | + _hazeEnabledSetting.set(enabled); | |
| 198 | + | |
| 199 | + recursivelyUpdateLightingModel("", [enabled] (MakeLightingModelConfig *config) { config->setHaze(enabled); }); | |
| 200 | + }); | |
| 201 | +} | |
| 202 | + | |
| 203 | +bool RenderScriptingInterface::getBloomEnabled() const { | |
| 204 | + return _bloomEnabled; | |
| 205 | +} | |
| 206 | + | |
| 207 | +void RenderScriptingInterface::setBloomEnabled(bool enabled) { | |
| 208 | + if (_bloomEnabled != enabled) { | |
| 209 | + forceBloomEnabled(enabled); | |
| 210 | + emit settingsChanged(); | |
| 211 | + } | |
| 212 | +} | |
| 213 | + | |
| 214 | +void RenderScriptingInterface::forceBloomEnabled(bool enabled) { | |
| 215 | + _renderSettingLock.withWriteLock([&] { | |
| 216 | + _bloomEnabled = (enabled); | |
| 217 | + _bloomEnabledSetting.set(enabled); | |
| 218 | + | |
| 219 | + recursivelyUpdateLightingModel("", [enabled] (MakeLightingModelConfig *config) { config->setBloom(enabled); }); | |
| 132 | 220 | }); |
| 133 | 221 | } |
| 134 | 222 | |
| @@ -149,16 +237,28 @@ void RenderScriptingInterface::forceAmbientOcclusionEnabled(bool enabled) { · 14 unmodified lines | ||
| 149 | 237 | _ambientOcclusionEnabledSetting.set(enabled); |
| 150 | 238 | Menu::getInstance()->setIsOptionChecked(MenuOption::AmbientOcclusion, enabled); |
| 151 | 239 | |
| 152 | − auto renderConfig = qApp->getRenderEngine()->getConfiguration(); | |
| 153 | − auto lightingModelConfig = renderConfig->getConfig<MakeLightingModel>("RenderMainView.LightingModel"); | |
| 154 | − if (lightingModelConfig) { | |
| 155 | − lightingModelConfig->setAmbientOcclusion(enabled); | |
| 156 | − } | |
| 240 | + recursivelyUpdateLightingModel("", [enabled] (MakeLightingModelConfig *config) { config->setAmbientOcclusion(enabled); }); | |
| 241 | + }); | |
| 242 | +} | |
| 157 | 243 | |
| 158 | − auto secondaryLightingModelConfig = renderConfig->getConfig<MakeLightingModel>("RenderSecondView.LightingModel"); | |
| 159 | − if (secondaryLightingModelConfig) { | |
| 160 | − secondaryLightingModelConfig->setAmbientOcclusion(enabled); | |
| 161 | − } | |
| 244 | +bool RenderScriptingInterface::getProceduralMaterialsEnabled() const { | |
| 245 | + return _proceduralMaterialsEnabled; | |
| 246 | +} | |
| 247 | + | |
| 248 | +void RenderScriptingInterface::setProceduralMaterialsEnabled(bool enabled) { | |
| 249 | + if (_proceduralMaterialsEnabled != enabled) { | |
| 250 | + forceProceduralMaterialsEnabled(enabled); | |
| 251 | + emit settingsChanged(); | |
| 252 | + } | |
| 253 | +} | |
| 254 | + | |
| 255 | +void RenderScriptingInterface::forceProceduralMaterialsEnabled(bool enabled) { | |
| 256 | + _renderSettingLock.withWriteLock([&] { | |
| 257 | + _proceduralMaterialsEnabled = (enabled); | |
| 258 | + _proceduralMaterialsEnabledSetting.set(enabled); | |
| 259 | + | |
| 260 | + Menu::getInstance()->setIsOptionChecked(MenuOption::MaterialProceduralShaders, enabled); | |
| 261 | + Procedural::enableProceduralShaders = enabled; | |
| 162 | 262 | }); |
| 163 | 263 | } |
| 164 | 264 | |
| @@ -198,45 +298,52 @@ void setAntialiasingModeForView(AntialiasingSetupConfig::Mode mode, Antialiasing · 33 unmodified lines | ||
| 198 | 298 | } |
| 199 | 299 | } |
| 200 | 300 | |
| 201 | −void RenderScriptingInterface::forceAntialiasingMode(AntialiasingSetupConfig::Mode mode) { | |
| 202 | − _renderSettingLock.withWriteLock([&] { | |
| 203 | − _antialiasingMode = mode; | |
| 204 | − | |
| 205 | − auto renderConfig = qApp->getRenderEngine()->getConfiguration(); | |
| 206 | − auto mainViewJitterCamConfig = renderConfig->getConfig<AntialiasingSetup>("RenderMainView.JitterCam"); | |
| 207 | − auto mainViewAntialiasingConfig = renderConfig->getConfig<Antialiasing>("RenderMainView.Antialiasing"); | |
| 208 | − auto secondViewJitterCamConfig = renderConfig->getConfig<AntialiasingSetup>("RenderSecondView.JitterCam"); | |
| 301 | +void recursivelyUpdateAntialiasingMode(const QString& parentTaskName, AntialiasingSetupConfig::Mode mode, int depth = -1) { | |
| 302 | + auto renderConfig = qApp->getRenderEngine()->getConfiguration(); | |
| 303 | + if (depth == -1) { | |
| 304 | + auto secondViewJitterCamConfig = renderConfig->getConfig<AntialiasingSetup>("RenderSecondView.AntialiasingSetup"); | |
| 209 | 305 | auto secondViewAntialiasingConfig = renderConfig->getConfig<Antialiasing>("RenderSecondView.Antialiasing"); |
| 210 | − if (mode != AntialiasingSetupConfig::Mode::NONE | |
| 211 | − && mode != AntialiasingSetupConfig::Mode::TAA | |
| 212 | − && mode != AntialiasingSetupConfig::Mode::FXAA) { | |
| 213 | − _antialiasingMode = AntialiasingSetupConfig::Mode::NONE; | |
| 306 | + if (secondViewJitterCamConfig && secondViewAntialiasingConfig) { | |
| 307 | + setAntialiasingModeForView(mode, secondViewJitterCamConfig, secondViewAntialiasingConfig); | |
| 214 | 308 | } |
| 309 | + | |
| 310 | + auto mainViewJitterCamConfig = renderConfig->getConfig<AntialiasingSetup>("RenderMainView.AntialiasingSetup"); | |
| 311 | + auto mainViewAntialiasingConfig = renderConfig->getConfig<Antialiasing>("RenderMainView.Antialiasing"); | |
| 215 | 312 | if (mainViewJitterCamConfig && mainViewAntialiasingConfig) { |
| 216 | 313 | setAntialiasingModeForView( mode, mainViewJitterCamConfig, mainViewAntialiasingConfig); |
| 217 | 314 | } |
| 218 | − if (secondViewJitterCamConfig && secondViewAntialiasingConfig) { | |
| 219 | − setAntialiasingModeForView( mode, secondViewJitterCamConfig, secondViewAntialiasingConfig); | |
| 220 | − } | |
| 221 | − | |
| 222 | − _antialiasingModeSetting.set((int)_antialiasingMode); | |
| 223 | − }); | |
| 224 | −} | |
| 225 | 315 | |
| 316 | + recursivelyUpdateAntialiasingMode("RenderMainView", mode, depth + 1); | |
| 317 | + } else if (depth == RenderMirrorTask::MAX_MIRROR_DEPTH) { | |
| 318 | + return; | |
| 319 | + } | |
| 226 | 320 | |
| 227 | −float RenderScriptingInterface::getViewportResolutionScale() const { | |
| 228 | − return _viewportResolutionScale; | |
| 321 | + for (size_t mirrorIndex = 0; mirrorIndex < RenderMirrorTask::MAX_MIRRORS_PER_LEVEL; mirrorIndex++) { | |
| 322 | + std::string mirrorTaskString = parentTaskName.toStdString() + ".RenderMirrorView" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth); | |
| 323 | + auto jitterCamConfig = renderConfig->getConfig<AntialiasingSetup>(mirrorTaskString + ".AntialiasingSetup"); | |
| 324 | + auto antialiasingConfig = renderConfig->getConfig<Antialiasing>(mirrorTaskString + ".Antialiasing"); | |
| 325 | + if (jitterCamConfig && antialiasingConfig) { | |
| 326 | + setAntialiasingModeForView(mode, jitterCamConfig, antialiasingConfig); | |
| 327 | + recursivelyUpdateAntialiasingMode(QString::fromStdString(mirrorTaskString), mode, depth + 1); | |
| 328 | + } | |
| 329 | + } | |
| 229 | 330 | } |
| 230 | 331 | |
| 231 | −void RenderScriptingInterface::setViewportResolutionScale(float scale) { | |
| 232 | − if (_viewportResolutionScale != scale) { | |
| 233 | − forceViewportResolutionScale(scale); | |
| 234 | − emit settingsChanged(); | |
| 332 | +void RenderScriptingInterface::forceAntialiasingMode(AntialiasingSetupConfig::Mode mode) { | |
| 333 | + if ((int)mode < 0 || mode >= AntialiasingSetupConfig::Mode::MODE_COUNT) { | |
| 334 | + mode = AntialiasingSetupConfig::Mode::NONE; | |
| 235 | 335 | } |
| 336 | + | |
| 337 | + _renderSettingLock.withWriteLock([&] { | |
| 338 | + _antialiasingMode = mode; | |
| 339 | + _antialiasingModeSetting.set((int)_antialiasingMode); | |
| 340 | + | |
| 341 | + recursivelyUpdateAntialiasingMode("", _antialiasingMode); | |
| 342 | + }); | |
| 236 | 343 | } |
| 237 | 344 | |
| 238 | 345 | void RenderScriptingInterface::setVerticalFieldOfView(float fieldOfView) { |
| 239 | − if (getViewportResolutionScale() != fieldOfView) { | |
| 346 | + if (qApp->getFieldOfView() != fieldOfView) { | |
| 240 | 347 | qApp->setFieldOfView(fieldOfView); |
| 241 | 348 | emit settingsChanged(); |
| 242 | 349 | } |
| @@ -276,6 +383,16 @@ QString RenderScriptingInterface::getFullScreenScreen() const { · 33 unmodified lines | ||
| 276 | 383 | return _fullScreenScreen; |
| 277 | 384 | } |
| 278 | 385 | |
| 386 | +float RenderScriptingInterface::getViewportResolutionScale() const { | |
| 387 | + return _viewportResolutionScale; | |
| 388 | +} | |
| 389 | + | |
| 390 | +void RenderScriptingInterface::setViewportResolutionScale(float scale) { | |
| 391 | + if (_viewportResolutionScale != scale) { | |
| 392 | + forceViewportResolutionScale(scale); | |
| 393 | + emit settingsChanged(); | |
| 394 | + } | |
| 395 | +} | |
| 279 | 396 | |
| 280 | 397 | void RenderScriptingInterface::forceViewportResolutionScale(float scale) { |
| 281 | 398 | // just not negative values or zero |