Default to diffuse/add mode, fix for interacting with ambient occlusion.

Unfortunately, I managed to break the diffusion somehow.
This commit is contained in:
Andrzej Kapolka 2013-08-20 16:07:12 -07:00
parent 11311f33ba
commit d5c66f6b67
3 changed files with 37 additions and 8 deletions

View file

@ -95,9 +95,9 @@ void AmbientOcclusionEffect::render() {
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, _rotationTextureID); glBindTexture(GL_TEXTURE_2D, _rotationTextureID);
// render with the occlusion shader to the secondary buffer // render with the occlusion shader to the secondary/tertiary buffer
QOpenGLFramebufferObject* secondaryFBO = Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject(); QOpenGLFramebufferObject* freeFBO = Application::getInstance()->getGlowEffect()->getFreeFramebufferObject();
secondaryFBO->bind(); freeFBO->bind();
float left, right, bottom, top, nearVal, farVal; float left, right, bottom, top, nearVal, farVal;
glm::vec4 nearClipPlane, farClipPlane; glm::vec4 nearClipPlane, farClipPlane;
@ -117,7 +117,7 @@ void AmbientOcclusionEffect::render() {
_occlusionProgram->release(); _occlusionProgram->release();
secondaryFBO->release(); freeFBO->release();
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
@ -128,7 +128,7 @@ void AmbientOcclusionEffect::render() {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFuncSeparate(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE); glBlendFuncSeparate(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE);
glBindTexture(GL_TEXTURE_2D, secondaryFBO->texture()); glBindTexture(GL_TEXTURE_2D, freeFBO->texture());
_blurProgram->bind(); _blurProgram->bind();

View file

@ -15,7 +15,13 @@
#include "ProgramObject.h" #include "ProgramObject.h"
#include "RenderUtil.h" #include "RenderUtil.h"
GlowEffect::GlowEffect() : _renderMode(BLUR_ADD_MODE) { GlowEffect::GlowEffect() : _renderMode(DIFFUSE_ADD_MODE) {
}
QOpenGLFramebufferObject* GlowEffect::getFreeFramebufferObject() const {
return (_renderMode == DIFFUSE_ADD_MODE && _isOddFrame) ?
Application::getInstance()->getTextureCache()->getTertiaryFramebufferObject() :
Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject();
} }
static ProgramObject* createProgram(const QString& name) { static ProgramObject* createProgram(const QString& name) {
@ -58,6 +64,7 @@ void GlowEffect::prepare() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_isEmpty = true; _isEmpty = true;
_isOddFrame = !_isOddFrame;
} }
void GlowEffect::begin(float intensity) { void GlowEffect::begin(float intensity) {
@ -109,7 +116,7 @@ void GlowEffect::render() {
Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject(); Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject();
QOpenGLFramebufferObject* newDiffusedFBO = QOpenGLFramebufferObject* newDiffusedFBO =
Application::getInstance()->getTextureCache()->getTertiaryFramebufferObject(); Application::getInstance()->getTextureCache()->getTertiaryFramebufferObject();
if ((_isOddFrame = !_isOddFrame)) { if (_isOddFrame) {
qSwap(oldDiffusedFBO, newDiffusedFBO); qSwap(oldDiffusedFBO, newDiffusedFBO);
} }
newDiffusedFBO->bind(); newDiffusedFBO->bind();
@ -204,5 +211,21 @@ void GlowEffect::render() {
} }
void GlowEffect::cycleRenderMode() { void GlowEffect::cycleRenderMode() {
_renderMode = (RenderMode)((_renderMode + 1) % RENDER_MODE_COUNT); switch(_renderMode = (RenderMode)((_renderMode + 1) % RENDER_MODE_COUNT)) {
case ADD_MODE:
qDebug() << "Glow mode: Add\n";
break;
case BLUR_ADD_MODE:
qDebug() << "Glow mode: Blur/add\n";
break;
case BLUR_PERSIST_ADD_MODE:
qDebug() << "Glow mode: Blur/persist/add\n";
break;
case DIFFUSE_ADD_MODE:
qDebug() << "Glow mode: Diffuse/add\n";
break;
}
} }

View file

@ -11,6 +11,8 @@
#include <QObject> #include <QObject>
class QOpenGLFramebufferObject;
class ProgramObject; class ProgramObject;
/// A generic full screen glow effect. /// A generic full screen glow effect.
@ -21,6 +23,10 @@ public:
GlowEffect(); GlowEffect();
/// Returns a pointer to the framebuffer object that the glow effect is *not* using for persistent state
/// (either the secondary or the tertiary).
QOpenGLFramebufferObject* getFreeFramebufferObject() const;
void init(); void init();
/// Prepares the glow effect for rendering the current frame. To be called before rendering the scene. /// Prepares the glow effect for rendering the current frame. To be called before rendering the scene.