Game Development Community

Motion Blur v1.2

by Christian M Weber · 05/17/2004 (1:07 pm) · 45 comments

Download Code File

Updated motion blur effect to work with current HEAD and fixed stuff that was broken before.

Fixed:
No bitmap file needed.
No crash when switching resolution.
Works in camera mode now!


Back up your code before you start.

Download and unzip files to game/fx/

Add files (.cc & .h) to your project.


Open game/game.cc

Find: ConsoleFunction(screenShot
At the end of the function (after delete bitmap;)
add
glReadBuffer(GL_BACK);

Find: ConsoleFunction( panoramaScreenShot
At the end of the function (after delete [] pixels;)
add
glReadBuffer(GL_BACK);

Save & close.

We do this so that our motion blur don't blur the GUIs

Open gui/guiTSControl.cc

After the #includes near the top add

#include "game/fx/screenFXMgr.h"

and scroll down to the end of function GuiTSCtrl::onRender,
and replace

renderWorld(updateRect);
   renderChildControls(offset, updateRect);
   smFrameCount++;

with this
renderWorld(updateRect);
   gScreenFXMgr.render(updateRect); // Screen effects
   renderChildControls(offset, updateRect);
   smFrameCount++;

Save & close.


If you're using the starter.fps, you can see this effect in real-time when you're hit with an arrow.
Open game/fx/explosion.cc

After the #includes add
#include "game/fx/screenFXMgr.h"

Find: gCamFXMgr.addFX( camShake );
After that line, add this:
// Motion blur
		ScreenFXMotionBlur *newfx = new ScreenFXMotionBlur;

		newfx->setDuration(mDataBlock->camShakeDuration);
		newfx->setAlpha(0.80f);

		F32 timeToFade = mDataBlock->camShakeDuration - (mDataBlock->camShakeDuration/4);
		F32 Fade = 0.80f / (mDataBlock->camShakeDuration - timeToFade);

		newfx->setElapsedTimeToFade(timeToFade);
		newfx->setFade(Fade);

		gScreenFXMgr.addFX(newfx);
		//

Save & close.

Compile!


You can test the motion blur effect by typing in the console (press ~ while hosting a game)
testMotionBlur(0.8, 15);
That will blur your screen at 80% alpha and for 15 seconds.

Enjoy.
Page «Previous 1 2 3 Last »
#1
05/15/2004 (5:53 pm)
Nice to see this all cleaned up

However im having some problems, first i get extemely low fps even when nothing is happening
and when I do a testMotionBlur my screen flickers black rapidly.. the black fades off though to nothing (I assume the black is supposed to be a previous screencap) any idea?


Update:
Well that seemed to be a problem with having the guicommandermap resource on the screen at the same time.. after deleting that it all works fine...

However, im crashing when I exit torque, that I can't figure out

anyway I made this blur last a fraction of a second, and appears when you're shot
http://server5.uploadit.org/files/Helkus-moreblur.jpg
#2
05/17/2004 (4:07 am)
Hmmm, the commandor map gui renders using TS control, so thats why its going weird.

Also, the crashing part, thats odd, I don't crash at all..

I'm using a GF4 Ti, so I don't get a big hit, and even on my GF2 MMX I only lost 2-3 frames.

EDIT:

If you want to only copy when there is an effect replace your functions with these:

// Add new effect to currently running list
void ScreenFXManager::addFX(ScreenFX *newFX) {

	if(mFXList.size() == 0)
		mRefreshTexture = true;
	
	mFXList.link(newFX);
}
// Render effects
void ScreenFXManager::render(const RectI &updateRect) {

	if(mTextureHandle) {
		
		// Check if we changed resolution
		if(mLastWidth != updateRect.extent.x) {

			// Update next time
			mTextureHandle = NULL;
			mLastWidth = updateRect.extent.x;
			return;
		}

		// Set our texture active
		TextureObject* texture = (TextureObject *) mTextureHandle;
		glBindTexture(GL_TEXTURE_2D, texture->texGLName);

		if(mRefreshTexture) {

			// Copy our rendered scene to our texture
			glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
							updateRect.point.x, updateRect.point.y,
							updateRect.extent.x, updateRect.extent.y);

			mRefreshTexture = false;
			return;
		}

		mLastWidth = updateRect.extent.x;

		// Advance effects
		U32 curTime = Platform::getRealMilliseconds();

		advanceTime(((F32)(curTime - mLastTimeTick)) * 0.001f);

		mLastTimeTick = curTime;

		if(mFXList.size() == 0)
			return;

		ScreenFXPtr *cur = NULL;

		// preRender (before we copy screen)
		while((cur = mFXList.next(cur)))
			(*cur)->preRender(texture, updateRect);

		// Copy our rendered scene to our texture
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
							updateRect.point.x, updateRect.point.y,
							updateRect.extent.x, updateRect.extent.y);

		// render (after we copy screen)
		while((cur = mFXList.next(cur)))
			(*cur)->Render(texture, updateRect);

	}
	else {

		GBitmap *bitmap = new GBitmap(updateRect.extent.x, updateRect.extent.y, false, mFormat);

		if(bitmap) {

			dMemset(bitmap->pBits, 0x00, bitmap->byteSize);
			mTextureHandle = TextureHandle(NULL, bitmap, true);
		}
	}
}

Now in the header file, after U32 mLastTimeTick;
add
bool mRefreshTexture;


You should try a debug build and see what is making it crash, I still don't see why you would.
#3
05/17/2004 (4:35 am)
Ok, see if this code fixes your commander map bug.

Open gui/guiTSControl.h

find: F32 mForceFOV;
add after
bool mUpdateScreenEffects;

Save & close.

Open gui/guiTSControl.cc

find: mForceFOV = 0;
add after
mUpdateScreenEffects = false;

find: addField("forceFOV"
add after
addField("UpdateScreenEffects",   TypeBool, Offset(mUpdateScreenEffects,   GuiTSCtrl));

find: gScreenFXMgr.render(updateRect);
make it look like this:
renderWorld(updateRect);
   
   if(mUpdateScreenEffects)
      gScreenFXMgr.render(updateRect); // Screen effects
      
   renderChildControls(offset, updateRect);
   smFrameCount++;

Save & close.

Compile!
Now open starter.fps/client/ui/playGui.gui
(replace starter.fps with your mod folder name :)

Now, under new GameTSCtrl(PlayGui) {

after helpTag= "0";
add
UpdateScreenEffects = "1";

Save & close. Now only playGui will render/update the screen FX.
#4
05/17/2004 (4:48 am)
Ill definately be fixing my code up with this when I get the time

btw, I lose almost no fps either, as soon as I set the commandermap visible to 0 everything seemed to work ok

thanks for the update
#5
05/17/2004 (5:03 am)
Doh,

move
if(mFXList.size() == 0)
			return;

after
advanceTime(((F32)(curTime - mLastTimeTick)) * 0.001f);
      mLastTimeTick = curTime;

Or the effect will die when you try to make one, because the tick didn't update. Oops! :) I updated the post above too.
#6
05/29/2004 (4:11 am)
hmm.. so any info on how to throw this on a single being? Like so only ur player blurs? Btw, very nice effect too.. :D
#7
11/01/2004 (9:18 am)
Can this be used for specific items such as a sword? So the blur is just behind the sword?
#8
12/27/2004 (6:06 pm)
is it possible to add the resource to the Armor::Ondamage function?

thanks in advance
#9
12/30/2004 (4:01 pm)
This is a fullscreen effect, there is no way to limit this to specific objects, if you want to do that, keep a history of an entities previous location, and render the object x amount of times at those locations, lowering alpha with each render

regarding adding this to "Armor::onDamage" all you have to do is call
testMotionBlur(0.8, 15); anywhere
or if I were you I'd look at what actaully happens when testMotionBlur is called, and send the message yourself.
#10
02/17/2005 (10:56 am)
It's also crashing when I exit Torque.

Detail: it only crashes in release mode. Debug mode won't crash at all. (this is to hint that you should do release builds every so often to see if everything is going right there too).

When I commented gScreenFXMgr.render(updateRect) at guiTSControl.cc, it stopped crashing (I won't be using motion blur on this current project, I just added it to have a quick fun).

I think the render call is doing something that it shouldn't while Torque is being shut down, but I can't locate it in release mode.
#11
04/24/2005 (10:14 am)
We got the same problem about the crash.
Here's the stack at this time :

Memory::freeTreeNode()
Memory::disableLogging()
TextureManager::freeTexture()
TextureHandle::unlock()
ScreenFXManager::~ScreenFXManager()

We commented the TextureHandle = NULL; in the destructor.
It seems to work better for now, but maybe the is a side effect somewhere. Hope not ^^

Update : Commenting TextureHandle = NULL; doesn't change anything at all.
#12
05/24/2005 (1:44 pm)
this is probably a very simple problem, but i can't get past it:

i've implemented this resource several times and still get the message "unable to find function" when i type "testMotionBlur (0.8, 15); into the console.

any ideas?
#13
07/05/2005 (10:57 am)
Are you sure you added the two files to your project in VS6?
#14
08/04/2005 (7:01 pm)
i got both added in my project, before chris's comments it did the black flickering stuff.

after the comments, it couldn't find the function.

any ideas guys?
#15
08/15/2005 (7:36 am)
I have found why it was sometimes crashing the game.
It's a memory problem due to windows because the variable is global and there is a deletion problem.

So, the solution is changing this bit of code (in screenFXMgr.cc):
ScreenFXManager gScreenFXMgr;

to a pointer, like this.
ScreenFXManager *gScreenFXMgr;


and in main.cc, in the init() function, add
gScreenFXMgr = new ScreenFXManager();

and in the main.cc shutdowngame(), add :
delete gScreenFXMgr;
gScreenFXMgr = NULL;

And now, everything is perfect. Thanks for the resource.
#16
08/22/2005 (8:39 pm)
Does anyone know if this resource works with the SynapseGaming Lighting Pack?
#17
08/31/2005 (8:52 am)
Yes it works
#18
10/08/2005 (3:55 pm)
I had no problems integrating this resource as described. Thanks!
#19
11/25/2005 (8:20 am)
Works great! Cool resource
#20
12/02/2005 (6:52 pm)
Is this like bullet-time?
Page «Previous 1 2 3 Last »