1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-25 23:43:58 +00:00

Enable radial blur post processing effect for spirit form.

Code for this existed, but it was wrong and never enabled.
This replaces most of the code, and makes it work on widescreen.
This commit is contained in:
fgenesis 2011-10-31 18:28:57 +01:00
parent 0ff37defc1
commit 7039f1d2cc
5 changed files with 87 additions and 171 deletions

View file

@ -1981,14 +1981,16 @@ void Continuity::applyWorldEffects(WorldType type, bool transition, bool affectM
if (!transition) time = 0; if (!transition) time = 0;
if (type == WT_SPIRIT) if (type == WT_SPIRIT)
{ {
/*
core->postProcessingFx.format = GL_LUMINANCE; if(dsq->user.video.blur)
core->postProcessingFx.blendType = 1; {
core->postProcessingFx.intensity = 0.2; core->postProcessingFx.blendType = 1;
core->postProcessingFx.layer = LR_AFTER_EFFECTS;//LR_AFTER_EFFECTS; core->postProcessingFx.intensity = 0.2f;
core->postProcessingFx.renderLayer = LR_AFTER_EFFECTS; core->postProcessingFx.layer = LR_AFTER_EFFECTS;//LR_AFTER_EFFECTS;
core->postProcessingFx.enable(FXT_RADIALBLUR); core->postProcessingFx.renderLayer = LR_AFTER_EFFECTS;
*/ core->postProcessingFx.enable(FXT_RADIALBLUR);
}
dsq->game->avatar->canWarp = false; dsq->game->avatar->canWarp = false;
/* /*
@ -2003,7 +2005,7 @@ void Continuity::applyWorldEffects(WorldType type, bool transition, bool affectM
{ {
dsq->game->avatar->canWarp = true; dsq->game->avatar->canWarp = true;
//core->postProcessingFx.disable(FXT_RADIALBLUR); core->postProcessingFx.disable(FXT_RADIALBLUR);
//worldType = WT_SPIRIT; //worldType = WT_SPIRIT;
/* /*
if (affectMusic) if (affectMusic)

View file

@ -1241,6 +1241,10 @@ This build is not yet final, and as such there are a couple things lacking. They
dsq->darkLayer.toggle(0); dsq->darkLayer.toggle(0);
debugLog("done"); debugLog("done");
debugLog("post FX init");
dsq->postProcessingFx.init();
debugLog("done");
#ifdef AQUARIA_BUILD_CONSOLE #ifdef AQUARIA_BUILD_CONSOLE
debugLog("Creating console"); debugLog("Creating console");

View file

@ -3947,6 +3947,15 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail)
afterEffectManager->render(); afterEffectManager->render();
} }
if (i == postProcessingFx.layer)
{
postProcessingFx.preRender();
}
if (i == postProcessingFx.renderLayer)
{
postProcessingFx.render();
}
if (darkLayer.isUsed() ) if (darkLayer.isUsed() )
{ {
/* /*
@ -3966,15 +3975,6 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail)
} }
} }
if (i == postProcessingFx.layer)
{
postProcessingFx.preRender();
}
if (i == postProcessingFx.renderLayer)
{
postProcessingFx.render();
}
RenderObjectLayer *r = &renderObjectLayers[i]; RenderObjectLayer *r = &renderObjectLayers[i];
RenderObject::rlayer = r; RenderObject::rlayer = r;
if (r->visible) if (r->visible)

View file

@ -23,113 +23,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Effects.h" #include "Effects.h"
#include "Core.h" #include "Core.h"
int quality = 64;
GLuint blurTexture;
GLuint emptyTexture() // Create An Empty Texture
{
GLuint txtnumber=0; // Texture ID
unsigned int* data; // Stored Data
// Create Storage Space For Texture Data (128x128x4)
data = (unsigned int*)new GLuint[((quality * quality)* 4 * sizeof(unsigned int))];
memset(data, 0, ((quality * quality)* 4 * sizeof(unsigned int))); // Clear Storage Memory
#ifdef BBGE_BUILD_OPENGL
glGenTextures(1, &txtnumber); // Create 1 Texture
glBindTexture(GL_TEXTURE_2D, txtnumber); // Bind The Texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 4, quality, quality, 0,
GL_RGBA, GL_UNSIGNED_BYTE, data); // Build Texture Using Information In data
#endif
delete [] data; // Release data
return txtnumber; // Return The Texture ID
}
PostProcessingFX::PostProcessingFX() PostProcessingFX::PostProcessingFX()
{ {
renderLayerStart = 1;
renderLayerEnd = 19;
#ifdef BBGE_BUILD_OPENGL
format = GL_LUMINANCE;
#endif
//GL_INTENSITY
//GL_RGB
//GL_LUMINANCE
blendType = 0; blendType = 0;
layer = renderLayer = 0; layer = renderLayer = 0;
intensity = 0.1; intensity = 0.1;
blurTimes = 12;
radialBlurColor = Vector(1,1,1); radialBlurColor = Vector(1,1,1);
for (int i = 0; i < FXT_MAX; i++) for (int i = 0; i < FXT_MAX; i++)
enabled[i] = false; enabled[i] = false;
} }
void PostProcessingFX::init(FXTypes type) void PostProcessingFX::init()
{ {
enabled[(int)type] = true;
if (type == FXT_RADIALBLUR)
blurTexture = emptyTexture();
} }
void PostProcessingFX::update(float dt) void PostProcessingFX::update(float dt)
{ {
} }
void PostProcessingFX::setRenderLayerRange(int start, int end)
{
renderLayerStart = start;
renderLayerEnd = end;
}
void PostProcessingFX::preRender() void PostProcessingFX::preRender()
{ {
for (int i = 0; i < FXT_MAX; i++)
{
if (enabled[i])
{
FXTypes type = (FXTypes)i;
switch(type)
{
case FXT_RADIALBLUR:
if (core->frameBuffer.isInited())
{
}
else
{
#ifdef BBGE_BUILD_OPENGL
glViewport(0,0,quality,quality); // Set Our Viewport (Match Texture Size;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And Depth Buffer
core->render(renderLayerStart, renderLayerEnd);
glBindTexture(GL_TEXTURE_2D,blurTexture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, format, 0, 0, quality, quality, 0);
glViewport(0, 0, core->width, core->height);
/*
glBindTexture(GL_TEXTURE_2D,blurTexture); // Bind To The Blur Texture
// Copy Our ViewPort To The Blur Texture (From 0,0 To 128,128... No Border)
glCopyTexImage2D(GL_TEXTURE_2D, 0, format, 0, 0, quality, quality, 0);
*/
//GL_INTENSITY
//GL_RGB
//GL_LUMINANCE
//glClearColor(0.0f, 0.0f, 0.5f, 0.5); // Set The Clear Color To Medium Blue
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And Depth Buffer
#endif
}
break;
}
}
}
} }
void PostProcessingFX::toggle(FXTypes type) void PostProcessingFX::toggle(FXTypes type)
@ -154,6 +69,9 @@ void PostProcessingFX::disable(FXTypes type)
void PostProcessingFX::render() void PostProcessingFX::render()
{ {
if(!core->frameBuffer.isEnabled())
return;
for (int i = 0; i < FXT_MAX; i++) for (int i = 0; i < FXT_MAX; i++)
{ {
if (enabled[i]) if (enabled[i])
@ -164,79 +82,73 @@ void PostProcessingFX::render()
switch(type) switch(type)
{ {
case FXT_RADIALBLUR: case FXT_RADIALBLUR:
/*
float percentX = (float)core->width/(float)quality;
float percentY = (float)core->height/(float)quality;
*/
/*
float percentX = (float)quality/(float)core->width;
float percentY = (float)quality/(float)core->height;
*/
float percentX = 1.0;
float percentY = 1.0;
/* float windowW = core->getWindowWidth();
std::ostringstream os; float windowH = core->getWindowHeight();
os << "p(" << percentX << ", " << percentY << ")"; float textureW = core->frameBuffer.getWidth();
debugLog(os.str()); float textureH = core->frameBuffer.getHeight();
*/
float alpha = intensity;
float offX = -(core->getVirtualOffX() * windowW / core->getVirtualWidth());
float offY = -(core->getVirtualOffY() * windowH / core->getVirtualHeight());
float width2 = windowW / 2;
float height2 = windowH / 2;
float pw = float(windowW)/float(textureW);
float ph = float(windowH)/float(textureH);
glLoadIdentity();
glTranslatef(width2 + offX, height2 + offY, 0);
glEnable(GL_TEXTURE_2D);
core->frameBuffer.bindTexture();
glEnable(GL_BLEND);
if (blendType == 1)
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
else
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
float percentX = pw, percentY = ph;
glLoadIdentity();
int times = 12;
float inc = 0.01; float inc = 0.01;
float spost = 0.0f; // Starting Texture Coordinate Offset float spost = 0.0f; // Starting Texture Coordinate Offset
float alphainc = 0.9f / times; // Fade Speed For Alpha Blending float alphadec = alpha / blurTimes;
//float alpha = 0.1f; // Starting Alpha Value
float alpha = intensity;
glEnable(GL_TEXTURE_2D); // Enable 2D Texture Mapping
if (blendType == 1)
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Set Blending Mode
else
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // Set Blending Mode
glEnable(GL_BLEND); // Enable Blending
if (core->frameBuffer.isInited())
core->frameBuffer.bindTexture();
else
glBindTexture(GL_TEXTURE_2D,blurTexture); // Bind To The Blur Texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
alphainc = alpha / times; // alphainc=0.2f / Times To Render Blur
glBegin(GL_QUADS); // Begin Drawing Quads glBegin(GL_QUADS); // Begin Drawing Quads
for (int num = 0;num < times;num++) // Number Of Times To Render Blur for (int num = 0;num < blurTimes; num++) // Number Of Times To Render Blur
{ {
glColor4f(radialBlurColor.x, radialBlurColor.y, radialBlurColor.z, alpha); // Set The Alpha Value (Starts At 0.2) glColor4f(radialBlurColor.x, radialBlurColor.y, radialBlurColor.z, alpha); // Set The Alpha Value (Starts At 0.2)
glTexCoord2f(0+spost,percentY-spost); // Texture Coordinate ( 0, 1 )
glVertex2f(0,0); // First Vertex ( 0, 0 )
glTexCoord2f(0+spost,0+spost); // Texture Coordinate ( 0, 0 ) glTexCoord2d(spost, spost);
glVertex2f(0,core->height); // Second Vertex ( 0, 480 ) glVertex3f(-width2, height2, 0.0);
glTexCoord2f(percentX-spost,0+spost); // Texture Coordinate ( 1, 0 ) glTexCoord2d(percentX-spost, spost);
glVertex2f(core->width,core->height); // Third Vertex ( 640, 480 ) glVertex3f( width2, height2, 0.0);
glTexCoord2f(percentX-spost,percentY-spost); // Texture Coordinate ( 1, 1 ) glTexCoord2d(percentX-spost, percentY-spost);
glVertex2f(core->width,0); // Fourth Vertex ( 640, 0 ) glVertex3f( width2, -height2, 0.0);
glTexCoord2d(spost, percentY-spost);
glVertex3f(-width2, -height2, 0.0);
spost += inc; // Gradually Increase spost (Zooming Closer To Texture Center) spost += inc; // Gradually Increase spost (Zooming Closer To Texture Center)
alpha = alpha - alphainc; // Gradually Decrease alpha (Gradually Fading Image Out) alpha -= alphadec; // Gradually Decrease alpha (Gradually Fading Image Out)
} }
glEnd(); glEnd();
glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D,0);
glColor4f(1,1,1,1);
//glDisable(GL_TEXTURE_2D);
// Done Drawing Quads glColor4f(1,1,1,1);
/* glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D); // Disable 2D Texture Mapping RenderObject::lastTextureApplied = 0;
glDisable(GL_BLEND); // Disable Blending
glBindTexture(GL_TEXTURE_2D,0); // Unbind The Blur Texture
*/
break; break;
} }
glPopMatrix(); glPopMatrix();

View file

@ -34,7 +34,7 @@ class PostProcessingFX
{ {
public: public:
PostProcessingFX(); PostProcessingFX();
void init(FXTypes type); void init();
void update(float dt); void update(float dt);
void preRender(); void preRender();
void render(); void render();
@ -42,20 +42,18 @@ public:
void enable(FXTypes type); void enable(FXTypes type);
void disable(FXTypes type); void disable(FXTypes type);
bool isEnabled(FXTypes type); bool isEnabled(FXTypes type);
void setRenderLayerRange(int start, int end);
// blur
/// misc
Vector radialBlurColor; Vector radialBlurColor;
#ifdef BBGE_BUILD_OPENGL int blurTimes;
GLenum format;
#endif /// misc
int renderLayer; int renderLayer;
int layer; int layer;
float intensity; float intensity;
int blendType; int blendType;
protected: protected:
int renderLayerStart, renderLayerEnd;
bool enabled[FXT_MAX]; bool enabled[FXT_MAX];
}; };