2011-08-03 20:05:33 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2007, 2010 - Bit-Blot
|
|
|
|
|
|
|
|
This file is part of Aquaria.
|
|
|
|
|
|
|
|
Aquaria is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "Effects.h"
|
|
|
|
#include "Core.h"
|
|
|
|
|
|
|
|
PostProcessingFX::PostProcessingFX()
|
|
|
|
{
|
|
|
|
blendType = 0;
|
|
|
|
layer = renderLayer = 0;
|
|
|
|
intensity = 0.1;
|
2011-11-20 14:44:17 +00:00
|
|
|
blurTimes = 12;
|
2011-08-03 20:05:33 +00:00
|
|
|
radialBlurColor = Vector(1,1,1);
|
|
|
|
for (int i = 0; i < FXT_MAX; i++)
|
|
|
|
enabled[i] = false;
|
|
|
|
}
|
|
|
|
|
2011-10-31 17:28:57 +00:00
|
|
|
void PostProcessingFX::init()
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-31 17:28:57 +00:00
|
|
|
void PostProcessingFX::update(float dt)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostProcessingFX::preRender()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostProcessingFX::toggle(FXTypes type)
|
|
|
|
{
|
|
|
|
enabled[int(type)] = !enabled[int(type)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostProcessingFX::enable(FXTypes type)
|
|
|
|
{
|
|
|
|
enabled[int(type)] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PostProcessingFX::isEnabled(FXTypes type)
|
|
|
|
{
|
|
|
|
return enabled[int(type)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostProcessingFX::disable(FXTypes type)
|
|
|
|
{
|
|
|
|
enabled[int(type)] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostProcessingFX::render()
|
|
|
|
{
|
2011-11-20 14:44:17 +00:00
|
|
|
if(!core->frameBuffer.isEnabled())
|
|
|
|
return;
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
for (int i = 0; i < FXT_MAX; i++)
|
|
|
|
{
|
|
|
|
if (enabled[i])
|
|
|
|
{
|
|
|
|
glPushMatrix();
|
|
|
|
FXTypes type = (FXTypes)i;
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FXT_RADIALBLUR:
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
float windowW = core->getWindowWidth();
|
|
|
|
float windowH = core->getWindowHeight();
|
|
|
|
float textureW = core->frameBuffer.getWidth();
|
|
|
|
float textureH = core->frameBuffer.getHeight();
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
float alpha = intensity;
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
float offX = -(core->getVirtualOffX() * windowW / core->getVirtualWidth());
|
|
|
|
float offY = -(core->getVirtualOffY() * windowH / core->getVirtualHeight());
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
float width2 = windowW / 2;
|
|
|
|
float height2 = windowH / 2;
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
float pw = float(windowW)/float(textureW);
|
|
|
|
float ph = float(windowH)/float(textureH);
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
glLoadIdentity();
|
2011-10-31 17:28:57 +00:00
|
|
|
|
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
glTranslatef(width2 + offX, height2 + offY, 0);
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
core->frameBuffer.bindTexture();
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
glEnable(GL_BLEND);
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
if (blendType == 1)
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
|
|
|
|
else
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
float percentX = pw, percentY = ph;
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
float inc = 0.01;
|
|
|
|
float spost = 0.0f; // Starting Texture Coordinate Offset
|
2011-10-31 17:28:57 +00:00
|
|
|
float alphadec = alpha / blurTimes;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
glBegin(GL_QUADS); // Begin Drawing Quads
|
2011-10-31 17:28:57 +00:00
|
|
|
for (int num = 0;num < blurTimes; num++) // Number Of Times To Render Blur
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
glColor4f(radialBlurColor.x, radialBlurColor.y, radialBlurColor.z, alpha); // Set The Alpha Value (Starts At 0.2)
|
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
glTexCoord2d(spost, spost);
|
|
|
|
glVertex3f(-width2, height2, 0.0);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
glTexCoord2d(percentX-spost, spost);
|
|
|
|
glVertex3f( width2, height2, 0.0);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
glTexCoord2d(percentX-spost, percentY-spost);
|
|
|
|
glVertex3f( width2, -height2, 0.0);
|
2011-10-31 17:28:57 +00:00
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
glTexCoord2d(spost, percentY-spost);
|
|
|
|
glVertex3f(-width2, -height2, 0.0);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
spost += inc; // Gradually Increase spost (Zooming Closer To Texture Center)
|
2011-10-31 17:28:57 +00:00
|
|
|
alpha -= alphadec; // Gradually Decrease alpha (Gradually Fading Image Out)
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2011-10-31 17:28:57 +00:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
|
2011-11-20 14:44:17 +00:00
|
|
|
glColor4f(1,1,1,1);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
RenderObject::lastTextureApplied = 0;
|
2011-10-31 17:28:57 +00:00
|
|
|
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|