diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7dcb863049..a6eaf4d42d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -95,6 +95,7 @@ #include #include #include +#include #include #include #include @@ -672,6 +673,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : initializeGL(); // Start rendering + _renderEngine->addTask(make_shared()); _renderEngine->addTask(make_shared()); _renderEngine->registerScene(_main3DScene); @@ -3825,9 +3827,10 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se renderContext.setArgs(renderArgs); bool occlusionStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugAmbientOcclusion); + bool shadowStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugShadows); bool antialiasingStatus = Menu::getInstance()->isOptionChecked(MenuOption::Antialiasing); bool showOwnedStatus = Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned); - renderContext.setOptions(occlusionStatus, antialiasingStatus, showOwnedStatus); + renderContext.setOptions(occlusionStatus, antialiasingStatus, showOwnedStatus, shadowStatus); _renderEngine->setRenderContext(renderContext); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 377d97bc30..246a3c5bd1 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -326,6 +326,7 @@ Menu::Menu() { addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Atmosphere, 0, true); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::WorldAxes); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::DebugAmbientOcclusion); + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::DebugShadows); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Antialiasing); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Stars, 0, true); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 6bf66f1200..15cf118192 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -188,6 +188,7 @@ namespace MenuOption { const QString CoupleEyelids = "Couple Eyelids"; const QString CrashInterface = "Crash Interface"; const QString DebugAmbientOcclusion = "Debug Ambient Occlusion"; + const QString DebugShadows = "Debug Shadows"; const QString DecreaseAvatarSize = "Decrease Avatar Size"; const QString DeleteBookmark = "Delete Bookmark..."; const QString DisableActivityLogger = "Disable Activity Logger"; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 5af89e7afc..8d022c93ee 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -56,14 +56,21 @@ void DeferredLightingEffect::init() { _directionalAmbientSphereLightLocations = std::make_shared(); _directionalSkyboxLightLocations = std::make_shared(); + _directionalLightShadowLocations = std::make_shared(); + _directionalAmbientSphereLightShadowLocations = std::make_shared(); + _directionalSkyboxLightShadowLocations = std::make_shared(); + _pointLightLocations = std::make_shared(); _spotLightLocations = std::make_shared(); - // TODO: To use shadowmaps, replace directional_*_light_frag with directional_*_light_shadow_frag shaders. loadLightProgram(deferred_light_vert, directional_light_frag, false, _directionalLight, _directionalLightLocations); loadLightProgram(deferred_light_vert, directional_ambient_light_frag, false, _directionalAmbientSphereLight, _directionalAmbientSphereLightLocations); loadLightProgram(deferred_light_vert, directional_skybox_light_frag, false, _directionalSkyboxLight, _directionalSkyboxLightLocations); + loadLightProgram(deferred_light_vert, directional_light_shadow_frag, false, _directionalLightShadow, _directionalLightShadowLocations); + loadLightProgram(deferred_light_vert, directional_ambient_light_shadow_frag, false, _directionalAmbientSphereLightShadow, _directionalAmbientSphereLightShadowLocations); + loadLightProgram(deferred_light_vert, directional_skybox_light_shadow_frag, false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations); + loadLightProgram(deferred_light_limited_vert, point_light_frag, true, _pointLight, _pointLightLocations); loadLightProgram(deferred_light_spot_vert, spot_light_frag, true, _spotLight, _spotLightLocations); @@ -289,18 +296,27 @@ void DeferredLightingEffect::render(RenderArgs* args) { { bool useSkyboxCubemap = (_skybox) && (_skybox->getCubemap()); - auto& program = _directionalLight; - LightLocationsPtr locations = _directionalLightLocations; + auto& program = _shadowMapStatus ? _directionalLightShadow : _directionalLight; + LightLocationsPtr locations = _shadowMapStatus ? _directionalLightShadowLocations : _directionalLightLocations; - // TODO: At some point bring back the shadows... // Setup the global directional pass pipeline { - if (useSkyboxCubemap) { - program = _directionalSkyboxLight; - locations = _directionalSkyboxLightLocations; - } else if (_ambientLightMode > -1) { - program = _directionalAmbientSphereLight; - locations = _directionalAmbientSphereLightLocations; + if (_shadowMapStatus) { + if (useSkyboxCubemap) { + program = _directionalSkyboxLightShadow; + locations = _directionalSkyboxLightShadowLocations; + } else if (_ambientLightMode > -1) { + program = _directionalAmbientSphereLightShadow; + locations = _directionalAmbientSphereLightShadowLocations; + } + } else { + if (useSkyboxCubemap) { + program = _directionalSkyboxLight; + locations = _directionalSkyboxLightLocations; + } else if (_ambientLightMode > -1) { + program = _directionalAmbientSphereLight; + locations = _directionalAmbientSphereLightLocations; + } } if (locations->shadowTransformBuffer >= 0) { diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index d11dee7d49..b254052fb2 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -53,27 +53,37 @@ public: void setGlobalSkybox(const model::SkyboxPointer& skybox); const LightStage& getLightStage() { return _lightStage; } + void setShadowMapStatus(bool enable) { _shadowMapStatus = enable; }; private: LightStage _lightStage; + bool _shadowMapStatus{ false }; DeferredLightingEffect() = default; model::MeshPointer _spotLightMesh; model::MeshPointer getSpotLightMesh(); - + gpu::PipelinePointer _directionalSkyboxLight; - LightLocationsPtr _directionalSkyboxLightLocations; - gpu::PipelinePointer _directionalAmbientSphereLight; - LightLocationsPtr _directionalAmbientSphereLightLocations; - gpu::PipelinePointer _directionalLight; - LightLocationsPtr _directionalLightLocations; + + gpu::PipelinePointer _directionalSkyboxLightShadow; + gpu::PipelinePointer _directionalAmbientSphereLightShadow; + gpu::PipelinePointer _directionalLightShadow; gpu::PipelinePointer _pointLight; - LightLocationsPtr _pointLightLocations; gpu::PipelinePointer _spotLight; + + LightLocationsPtr _directionalSkyboxLightLocations; + LightLocationsPtr _directionalAmbientSphereLightLocations; + LightLocationsPtr _directionalLightLocations; + + LightLocationsPtr _directionalSkyboxLightShadowLocations; + LightLocationsPtr _directionalAmbientSphereLightShadowLocations; + LightLocationsPtr _directionalLightShadowLocations; + + LightLocationsPtr _pointLightLocations; LightLocationsPtr _spotLightLocations; using Lights = std::vector; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index dc3e5c652b..71313b5dc4 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -175,6 +175,9 @@ void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const Rend setToneMappingExposure(renderContext->getTone().exposure); setToneMappingToneCurve(renderContext->getTone().toneCurve); + // TODO: For now, lighting is controlled through a singleton, so it is distinct + DependencyManager::get()->setShadowMapStatus(renderContext->getShadowMapStatus()); + for (auto job : _jobs) { job.run(sceneContext, renderContext); } diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 4fe0c75198..96cc8d1329 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -131,15 +131,12 @@ public: void setDrawHitEffect(bool draw) { enableJob(_drawHitEffectJobIndex, draw); } bool doDrawHitEffect() const { return getEnableJob(_drawHitEffectJobIndex); } - void setOcclusionStatus(bool draw) { enableJob(_occlusionJobIndex, draw); } bool doOcclusionStatus() const { return getEnableJob(_occlusionJobIndex); } - void setAntialiasingStatus(bool draw) { enableJob(_antialiasingJobIndex, draw); } bool doAntialiasingStatus() const { return getEnableJob(_antialiasingJobIndex); } - void setToneMappingExposure(float exposure); float getToneMappingExposure() const; diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index b6b9f15f60..6f8940002a 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -120,6 +120,11 @@ void RenderShadowTask::run(const SceneContextPointer& sceneContext, const Render assert(sceneContext); RenderArgs* args = renderContext->getArgs(); + // This feature is in a debugging stage - it must be turned on explicitly + if (!renderContext->getShadowMapStatus()) { + return; + } + // sanity checks if (!sceneContext->_scene || !args) { return; diff --git a/libraries/render/src/render/Context.cpp b/libraries/render/src/render/Context.cpp index 8facaad1b2..0e07726eb4 100644 --- a/libraries/render/src/render/Context.cpp +++ b/libraries/render/src/render/Context.cpp @@ -21,9 +21,10 @@ RenderContext::RenderContext(ItemsConfig items, Tone tone, int drawStatus, bool { } -void RenderContext::setOptions(bool occlusion, bool fxaa, bool showOwned) { +void RenderContext::setOptions(bool occlusion, bool fxaa, bool showOwned, bool shadowMap) { _occlusionStatus = occlusion; _fxaaStatus = fxaa; + _shadowMapStatus = shadowMap; if (showOwned) { _drawStatus |= render::showNetworkStatusFlag; diff --git a/libraries/render/src/render/Context.h b/libraries/render/src/render/Context.h index 4eeba0ee08..c1d26d0ccb 100644 --- a/libraries/render/src/render/Context.h +++ b/libraries/render/src/render/Context.h @@ -83,7 +83,8 @@ public: bool getDrawHitEffect() { return _drawHitEffect; } bool getOcclusionStatus() { return _occlusionStatus; } bool getFxaaStatus() { return _fxaaStatus; } - void setOptions(bool occlusion, bool fxaa, bool showOwned); + bool getShadowMapStatus() { return _shadowMapStatus; } + void setOptions(bool occlusion, bool fxaa, bool showOwned, bool shadowMap); // Debugging int _deferredDebugMode; @@ -97,6 +98,7 @@ protected: bool _drawHitEffect; bool _occlusionStatus { false }; bool _fxaaStatus = { false }; + bool _shadowMapStatus = { false }; ItemsConfig _items; Tone _tone;