mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:44:01 +02:00
more GlowEctomy
This commit is contained in:
parent
819fa852b8
commit
c17794849d
4 changed files with 2 additions and 328 deletions
|
@ -98,8 +98,6 @@
|
|||
#include <UUID.h>
|
||||
#include <VrMenu.h>
|
||||
|
||||
#include <GlowEffect.h> // FIXME
|
||||
|
||||
#include "Application.h"
|
||||
#include "AudioClient.h"
|
||||
#include "DiscoverabilityManager.h"
|
||||
|
@ -270,7 +268,6 @@ bool setupEssentials(int& argc, char** argv) {
|
|||
auto geometryCache = DependencyManager::set<GeometryCache>();
|
||||
auto scriptCache = DependencyManager::set<ScriptCache>();
|
||||
auto soundCache = DependencyManager::set<SoundCache>();
|
||||
auto glowEffect = DependencyManager::set<GlowEffect>(); // FIXME
|
||||
auto faceshift = DependencyManager::set<Faceshift>();
|
||||
auto audio = DependencyManager::set<AudioClient>();
|
||||
auto audioScope = DependencyManager::set<AudioScope>();
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "AbstractViewStateInterface.h"
|
||||
#include "DeferredLightingEffect.h"
|
||||
#include "GeometryCache.h"
|
||||
#include "GlowEffect.h"
|
||||
#include "RenderUtil.h"
|
||||
#include "TextureCache.h"
|
||||
|
||||
|
@ -238,7 +237,7 @@ void DeferredLightingEffect::render(RenderArgs* args) {
|
|||
QSize framebufferSize = textureCache->getFrameBufferSize();
|
||||
|
||||
// binding the first framebuffer
|
||||
auto freeFBO = DependencyManager::get<GlowEffect>()->getFreeFramebuffer();
|
||||
auto freeFBO = DependencyManager::get<TextureCache>()->getSecondaryFramebuffer();
|
||||
batch.setFramebuffer(freeFBO);
|
||||
|
||||
batch.clearColorFramebuffer(freeFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
|
@ -547,7 +546,7 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) {
|
|||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
QSize framebufferSize = textureCache->getFrameBufferSize();
|
||||
|
||||
auto freeFBO = DependencyManager::get<GlowEffect>()->getFreeFramebuffer();
|
||||
auto freeFBO = DependencyManager::get<TextureCache>()->getSecondaryFramebuffer();
|
||||
|
||||
batch.setFramebuffer(textureCache->getPrimaryFramebuffer());
|
||||
batch.setPipeline(_blitLightBuffer);
|
||||
|
|
|
@ -1,225 +0,0 @@
|
|||
//
|
||||
// GlowEffect.cpp
|
||||
// interface/src/renderer
|
||||
//
|
||||
// Created by Andrzej Kapolka on 8/7/13.
|
||||
// Copyright 2013 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
|
||||
//
|
||||
|
||||
// include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL
|
||||
#include <gpu/GPUConfig.h>
|
||||
|
||||
#include <QOpenGLFramebufferObject>
|
||||
#include <QWindow>
|
||||
|
||||
#include <PathUtils.h>
|
||||
#include <PerfStat.h>
|
||||
|
||||
#include "GlowEffect.h"
|
||||
#include "ProgramObject.h"
|
||||
#include "RenderUtil.h"
|
||||
#include "TextureCache.h"
|
||||
#include "RenderUtilsLogging.h"
|
||||
|
||||
#include "gpu/GLBackend.h"
|
||||
|
||||
GlowEffect::GlowEffect()
|
||||
: _initialized(false),
|
||||
_isOddFrame(false),
|
||||
_isFirstFrame(true),
|
||||
_intensity(0.0f),
|
||||
_enabled(false) {
|
||||
}
|
||||
|
||||
GlowEffect::~GlowEffect() {
|
||||
if (_initialized) {
|
||||
delete _addProgram;
|
||||
delete _horizontalBlurProgram;
|
||||
delete _verticalBlurAddProgram;
|
||||
delete _verticalBlurProgram;
|
||||
delete _addSeparateProgram;
|
||||
delete _diffuseProgram;
|
||||
}
|
||||
}
|
||||
|
||||
gpu::FramebufferPointer GlowEffect::getFreeFramebuffer() const {
|
||||
return (_isOddFrame ?
|
||||
DependencyManager::get<TextureCache>()->getSecondaryFramebuffer():
|
||||
DependencyManager::get<TextureCache>()->getTertiaryFramebuffer());
|
||||
}
|
||||
|
||||
static ProgramObject* createProgram(const QString& name) {
|
||||
ProgramObject* program = new ProgramObject();
|
||||
program->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/" + name + ".frag");
|
||||
program->link();
|
||||
|
||||
program->bind();
|
||||
program->setUniformValue("originalTexture", 0);
|
||||
program->release();
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
void GlowEffect::init(bool enabled) {
|
||||
if (_initialized) {
|
||||
qCDebug(renderutils, "[ERROR] GlowEffeect is already initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
_addProgram = createProgram("glow_add");
|
||||
_horizontalBlurProgram = createProgram("horizontal_blur");
|
||||
_verticalBlurAddProgram = createProgram("vertical_blur_add");
|
||||
_verticalBlurProgram = createProgram("vertical_blur");
|
||||
_addSeparateProgram = createProgram("glow_add_separate");
|
||||
_diffuseProgram = createProgram("diffuse");
|
||||
|
||||
_verticalBlurAddProgram->bind();
|
||||
_verticalBlurAddProgram->setUniformValue("horizontallyBlurredTexture", 1);
|
||||
_verticalBlurAddProgram->release();
|
||||
|
||||
_addSeparateProgram->bind();
|
||||
_addSeparateProgram->setUniformValue("blurredTexture", 1);
|
||||
_addSeparateProgram->release();
|
||||
|
||||
_diffuseProgram->bind();
|
||||
_diffuseProgram->setUniformValue("diffusedTexture", 1);
|
||||
_diffuseProgram->release();
|
||||
|
||||
_diffusionScaleLocation = _diffuseProgram->uniformLocation("diffusionScale");
|
||||
|
||||
_initialized = true;
|
||||
_enabled = enabled;
|
||||
}
|
||||
|
||||
void GlowEffect::prepare(RenderArgs* renderArgs) {
|
||||
auto primaryFBO = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();
|
||||
GLuint fbo = gpu::GLBackend::getFramebufferID(primaryFBO);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
_isEmpty = true;
|
||||
_isOddFrame = !_isOddFrame;
|
||||
}
|
||||
|
||||
void GlowEffect::begin(RenderArgs* renderArgs, float intensity) {
|
||||
// store the current intensity and add the new amount
|
||||
_intensityStack.push(_intensity);
|
||||
glBlendColor(0.0f, 0.0f, 0.0f, _intensity += intensity);
|
||||
_isEmpty &= (_intensity == 0.0f);
|
||||
}
|
||||
|
||||
void GlowEffect::end(RenderArgs* renderArgs) {
|
||||
// restore the saved intensity
|
||||
glBlendColor(0.0f, 0.0f, 0.0f, _intensity = _intensityStack.pop());
|
||||
}
|
||||
|
||||
gpu::FramebufferPointer GlowEffect::render(RenderArgs* renderArgs) {
|
||||
PerformanceTimer perfTimer("glowEffect");
|
||||
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
|
||||
auto primaryFBO = gpu::GLBackend::getFramebufferID(textureCache->getPrimaryFramebuffer());
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textureCache->getPrimaryColorTextureID());
|
||||
auto framebufferSize = textureCache->getFrameBufferSize();
|
||||
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
gpu::FramebufferPointer destFBO = textureCache->getSecondaryFramebuffer();
|
||||
if (!_enabled || _isEmpty) {
|
||||
// copy the primary to the screen
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(destFBO));
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, primaryFBO);
|
||||
glBlitFramebuffer(
|
||||
0, 0, framebufferSize.width(), framebufferSize.height(),
|
||||
0, 0, framebufferSize.width(), framebufferSize.height(),
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
} else {
|
||||
// diffuse into the secondary/tertiary (alternating between frames)
|
||||
auto oldDiffusedFBO =
|
||||
textureCache->getSecondaryFramebuffer();
|
||||
auto newDiffusedFBO =
|
||||
textureCache->getTertiaryFramebuffer();
|
||||
if (_isOddFrame) {
|
||||
qSwap(oldDiffusedFBO, newDiffusedFBO);
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(newDiffusedFBO));
|
||||
|
||||
if (_isFirstFrame) {
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(oldDiffusedFBO->getRenderBuffer(0)));
|
||||
|
||||
_diffuseProgram->bind();
|
||||
|
||||
_diffuseProgram->setUniformValue(_diffusionScaleLocation, 1.0f / framebufferSize.width(), 1.0f / framebufferSize.height());
|
||||
|
||||
renderFullscreenQuad();
|
||||
|
||||
_diffuseProgram->release();
|
||||
}
|
||||
|
||||
destFBO = oldDiffusedFBO;
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
// add diffused texture to the primary
|
||||
glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(newDiffusedFBO->getRenderBuffer(0)));
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(destFBO));
|
||||
glViewport(0, 0, framebufferSize.width(), framebufferSize.height());
|
||||
_addSeparateProgram->bind();
|
||||
renderFullscreenQuad();
|
||||
_addSeparateProgram->release();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
_isFirstFrame = false;
|
||||
|
||||
return destFBO;
|
||||
}
|
||||
|
||||
void GlowEffect::toggleGlowEffect(bool enabled) {
|
||||
_enabled = enabled;
|
||||
}
|
||||
|
||||
Glower::Glower(float amount) {
|
||||
RenderArgs renderArgs;
|
||||
DependencyManager::get<GlowEffect>()->begin(&renderArgs, amount);
|
||||
}
|
||||
Glower::Glower(RenderArgs* renderArgs, float amount) : _renderArgs(renderArgs) {
|
||||
DependencyManager::get<GlowEffect>()->begin(_renderArgs, amount);
|
||||
}
|
||||
|
||||
Glower::~Glower() {
|
||||
DependencyManager::get<GlowEffect>()->end(_renderArgs);
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
//
|
||||
// GlowEffect.h
|
||||
// interface/src/renderer
|
||||
//
|
||||
// Created by Andrzej Kapolka on 8/7/13.
|
||||
// Copyright 2013 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_GlowEffect_h
|
||||
#define hifi_GlowEffect_h
|
||||
|
||||
#include <gpu/GPUConfig.h>
|
||||
#include <gpu/Framebuffer.h>
|
||||
|
||||
#include "RenderArgs.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QGLWidget>
|
||||
#include <QStack>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
|
||||
class ProgramObject;
|
||||
|
||||
/// A generic full screen glow effect.
|
||||
class GlowEffect : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
|
||||
public:
|
||||
|
||||
/// Returns a pointer to the framebuffer object that the glow effect is *not* using for persistent state
|
||||
/// (either the secondary or the tertiary).
|
||||
gpu::FramebufferPointer getFreeFramebuffer() const;
|
||||
|
||||
void init(bool enabled);
|
||||
|
||||
/// Prepares the glow effect for rendering the current frame. To be called before rendering the scene.
|
||||
void prepare(RenderArgs* renderArgs);
|
||||
|
||||
/// Starts using the glow effect.
|
||||
/// \param intensity the desired glow intensity, from zero to one
|
||||
void begin(RenderArgs* renderArgs, float intensity = 1.0f);
|
||||
|
||||
/// Stops using the glow effect.
|
||||
void end(RenderArgs* renderArgs);
|
||||
|
||||
/// Returns the current glow intensity.
|
||||
float getIntensity() const { return _intensity; }
|
||||
|
||||
/// Renders the glow effect. To be called after rendering the scene.
|
||||
/// \param toTexture whether to render to a texture, rather than to the frame buffer
|
||||
/// \return the framebuffer object to which we rendered, or NULL if to the frame buffer
|
||||
gpu::FramebufferPointer render(RenderArgs* renderArgs);
|
||||
|
||||
public slots:
|
||||
void toggleGlowEffect(bool enabled);
|
||||
|
||||
private:
|
||||
GlowEffect();
|
||||
virtual ~GlowEffect();
|
||||
|
||||
bool _initialized;
|
||||
|
||||
ProgramObject* _addProgram;
|
||||
ProgramObject* _horizontalBlurProgram;
|
||||
ProgramObject* _verticalBlurAddProgram;
|
||||
ProgramObject* _verticalBlurProgram;
|
||||
ProgramObject* _addSeparateProgram;
|
||||
ProgramObject* _diffuseProgram;
|
||||
int _diffusionScaleLocation;
|
||||
|
||||
bool _isEmpty; ///< set when nothing in the scene is currently glowing
|
||||
bool _isOddFrame; ///< controls the alternation between texture targets in diffuse add mode
|
||||
bool _isFirstFrame; ///< for persistent modes, notes whether this is the first frame rendered
|
||||
|
||||
float _intensity;
|
||||
QStack<float> _intensityStack;
|
||||
bool _enabled;
|
||||
};
|
||||
|
||||
/// RAII-style glow handler. Applies glow when in scope.
|
||||
class Glower {
|
||||
public:
|
||||
|
||||
Glower(float amount = 1.0f);
|
||||
Glower(RenderArgs* renderArgs, float amount = 1.0f);
|
||||
~Glower();
|
||||
|
||||
private:
|
||||
RenderArgs* _renderArgs;
|
||||
};
|
||||
|
||||
#endif // hifi_GlowEffect_h
|
Loading…
Reference in a new issue