diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5f0f4a700a..57b3b57224 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1914,8 +1914,8 @@ void Application::init() { _environment.init(); - _deferredLightingEffect.init(); - _ambientOcclusionEffect.init(); + _deferredLightingEffect.init(this); + _ambientOcclusionEffect.init(this); // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager _avatarManager.init(); @@ -3235,6 +3235,14 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom } } +bool Application::getShadowsEnabled() { + return Menu::getInstance()->getShadowsEnabled(); +} + +bool Application::getCascadeShadowsEnabled() { + return Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows); +} + glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { float horizontalScale = _glWidget->getDeviceWidth() / 2.0f; float verticalScale = _glWidget->getDeviceHeight() / 2.0f; diff --git a/interface/src/Application.h b/interface/src/Application.h index 992d8d31d3..9ca363254a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "MainWindow.h" @@ -128,7 +129,7 @@ static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS static const QString INFO_HELP_PATH = "html/interface-welcome-allsvg.html"; static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-entities-commands.html"; -class Application : public QApplication { +class Application : public QApplication, public ViewStateInterface { Q_OBJECT friend class OctreePacketProcessor; @@ -276,12 +277,16 @@ public: void getModelViewMatrix(glm::dmat4* modelViewMatrix); void getProjectionMatrix(glm::dmat4* projectionMatrix); - const glm::vec3& getShadowDistances() const { return _shadowDistances; } + virtual const glm::vec3& getShadowDistances() const { return _shadowDistances; } /// Computes the off-axis frustum parameters for the view frustum, taking mirroring into account. - void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, + virtual void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const; + virtual ViewFrustum* getCurrentViewFrustum() { return getDisplayViewFrustum(); } + virtual bool getShadowsEnabled(); + virtual bool getCascadeShadowsEnabled(); + NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; } FileLogger* getLogger() { return _logger; } diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/interface/src/renderer/AmbientOcclusionEffect.cpp index bcae662085..4362d21645 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/interface/src/renderer/AmbientOcclusionEffect.cpp @@ -21,15 +21,15 @@ #include #include #include - -#include "Application.h" +#include #include "AmbientOcclusionEffect.h" const int ROTATION_WIDTH = 4; const int ROTATION_HEIGHT = 4; -void AmbientOcclusionEffect::init() { +void AmbientOcclusionEffect::init(ViewStateInterface* viewState) { + _viewState = viewState; // we will use this for view state services _occlusionProgram = new ProgramObject(); _occlusionProgram->addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() @@ -111,8 +111,7 @@ void AmbientOcclusionEffect::render() { float left, right, bottom, top, nearVal, farVal; glm::vec4 nearClipPlane, farClipPlane; - Application::getInstance()->computeOffAxisFrustum( - left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); + _viewState->computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); int viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); diff --git a/interface/src/renderer/AmbientOcclusionEffect.h b/interface/src/renderer/AmbientOcclusionEffect.h index 3b22c7629a..444b76a3c9 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.h +++ b/interface/src/renderer/AmbientOcclusionEffect.h @@ -12,6 +12,8 @@ #ifndef hifi_AmbientOcclusionEffect_h #define hifi_AmbientOcclusionEffect_h +#include + class ProgramObject; /// A screen space ambient occlusion effect. See John Chapman's tutorial at @@ -19,8 +21,7 @@ class ProgramObject; class AmbientOcclusionEffect { public: - void init(); - + void init(ViewStateInterface* viewState); void render(); private: @@ -38,6 +39,7 @@ private: int _blurScaleLocation; GLuint _rotationTextureID; + ViewStateInterface* _viewState; }; #endif // hifi_AmbientOcclusionEffect_h diff --git a/interface/src/renderer/DeferredLightingEffect.cpp b/interface/src/renderer/DeferredLightingEffect.cpp index 18a93aa042..d3145b9d5d 100644 --- a/interface/src/renderer/DeferredLightingEffect.cpp +++ b/interface/src/renderer/DeferredLightingEffect.cpp @@ -14,14 +14,17 @@ #include +#include +#include #include #include #include +#include -#include "Application.h" #include "DeferredLightingEffect.h" -void DeferredLightingEffect::init() { +void DeferredLightingEffect::init(ViewStateInterface* viewState) { + _viewState = viewState; _simpleProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/simple.vert"); _simpleProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/simple.frag"); _simpleProgram.link(); @@ -176,19 +179,18 @@ void DeferredLightingEffect::render() { ProgramObject* program = &_directionalLight; const LightLocations* locations = &_directionalLightLocations; - bool shadowsEnabled = Menu::getInstance()->getShadowsEnabled(); - if (shadowsEnabled) { + bool shadowsEnabled = _viewState->getShadowsEnabled(); + if (shadowsEnabled) { glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, textureCache->getShadowDepthTextureID()); program = &_directionalLightShadowMap; locations = &_directionalLightShadowMapLocations; - if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { + if (_viewState->getCascadeShadowsEnabled()) { program = &_directionalLightCascadedShadowMap; locations = &_directionalLightCascadedShadowMapLocations; _directionalLightCascadedShadowMap.bind(); - _directionalLightCascadedShadowMap.setUniform(locations->shadowDistances, - Application::getInstance()->getShadowDistances()); + _directionalLightCascadedShadowMap.setUniform(locations->shadowDistances, _viewState->getShadowDistances()); } else { program->bind(); @@ -202,8 +204,7 @@ void DeferredLightingEffect::render() { float left, right, bottom, top, nearVal, farVal; glm::vec4 nearClipPlane, farClipPlane; - Application::getInstance()->computeOffAxisFrustum( - left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); + _viewState->computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); program->setUniformValue(locations->nearLocation, nearVal); float depthScale = (farVal - nearVal) / farVal; program->setUniformValue(locations->depthScale, depthScale); @@ -238,8 +239,8 @@ void DeferredLightingEffect::render() { // enlarge the scales slightly to account for tesselation const float SCALE_EXPANSION = 0.05f; - const glm::vec3& eyePoint = Application::getInstance()->getDisplayViewFrustum()->getPosition(); - float nearRadius = glm::distance(eyePoint, Application::getInstance()->getDisplayViewFrustum()->getNearTopLeft()); + const glm::vec3& eyePoint = _viewState->getCurrentViewFrustum()->getPosition(); + float nearRadius = glm::distance(eyePoint, _viewState->getCurrentViewFrustum()->getNearTopLeft()); GeometryCache* geometryCache = DependencyManager::get(); diff --git a/interface/src/renderer/DeferredLightingEffect.h b/interface/src/renderer/DeferredLightingEffect.h index effcea27d2..40182e0917 100644 --- a/interface/src/renderer/DeferredLightingEffect.h +++ b/interface/src/renderer/DeferredLightingEffect.h @@ -16,6 +16,7 @@ #include #include +#include class PostLightingRenderable; @@ -23,7 +24,7 @@ class PostLightingRenderable; class DeferredLightingEffect { public: - void init(); + void init(ViewStateInterface* viewState); /// Returns a reference to a simple program suitable for rendering static /// untextured geometry (such as that generated by glutSolidSphere, etc.) @@ -118,6 +119,8 @@ private: QVector _pointLights; QVector _spotLights; QVector _postLightingRenderables; + + ViewStateInterface* _viewState; }; /// Simple interface for objects that require something to be rendered after deferred lighting. diff --git a/libraries/render-utils/src/ViewStateInterface.h b/libraries/render-utils/src/ViewStateInterface.h new file mode 100644 index 0000000000..decccdc401 --- /dev/null +++ b/libraries/render-utils/src/ViewStateInterface.h @@ -0,0 +1,36 @@ +// +// ViewStateInterface.h +// interface/src/renderer +// +// Created by Brad Hefta-Gaub on 12/16/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_ViewStateInterface_h +#define hifi_ViewStateInterface_h + +#include + +/// Interface provided by Application to other objects that need access to the current view state details +class ViewStateInterface { +public: + + /// Returns the shadow distances for the current view state + virtual const glm::vec3& getShadowDistances() const = 0; + + /// Computes the off-axis frustum parameters for the view frustum, taking mirroring into account. + virtual void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, + float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const = 0; + + /// gets the current view frustum for rendering the view state + virtual ViewFrustum* getCurrentViewFrustum() = 0; + + virtual bool getShadowsEnabled() = 0; + virtual bool getCascadeShadowsEnabled() = 0; +}; + + +#endif // hifi_ViewStateInterface_h