remove Application dependencies from AmbientOcclusion and DeferredLightingEffect

This commit is contained in:
ZappoMan 2014-12-16 10:32:03 -08:00
parent 5cba44fd5b
commit 4d79a08533
7 changed files with 78 additions and 24 deletions

View file

@ -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;

View file

@ -42,6 +42,7 @@
#include <ScriptEngine.h>
#include <TextureCache.h>
#include <ViewFrustum.h>
#include <ViewStateInterface.h>
#include <VoxelEditPacketSender.h>
#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; }

View file

@ -21,15 +21,15 @@
#include <ProgramObject.h>
#include <RenderUtil.h>
#include <SharedUtil.h>
#include "Application.h"
#include <TextureCache.h>
#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);

View file

@ -12,6 +12,8 @@
#ifndef hifi_AmbientOcclusionEffect_h
#define hifi_AmbientOcclusionEffect_h
#include <ViewStateInterface.h>
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

View file

@ -14,14 +14,17 @@
#include <QOpenGLFramebufferObject>
#include <GeometryCache.h>
#include <GLMHelpers.h>
#include <GlowEffect.h>
#include <PathUtils.h>
#include <RenderUtil.h>
#include <TextureCache.h>
#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<GeometryCache>();

View file

@ -16,6 +16,7 @@
#include <ProgramObject.h>
#include <SharedUtil.h>
#include <ViewStateInterface.h>
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<PointLight> _pointLights;
QVector<SpotLight> _spotLights;
QVector<PostLightingRenderable*> _postLightingRenderables;
ViewStateInterface* _viewState;
};
/// Simple interface for objects that require something to be rendered after deferred lighting.

View file

@ -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 <ViewFrustum.h>
/// 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