Integrating Post-Frame Buffering to PostFX
by Dave Calabrese · in Torque 3D Professional · 08/06/2010 (4:44 am) · 0 replies
I am working on a blur shader that is intended to cause a 'screen-trailing' effect. After doing a bit of research, it looks like the best way to do this will be to buffer the previous frame, then blend it with the current frame. The result should be a good trailing / onion-skinning effect. I've got what I believe should work coded into the engine, however it seems to be constantly storing the current frame, rather than the previous frame... or something is going on to prevent the effect from working right.
Here's some code to check out:
In postEffect.cpp, around line 738..
In postEffectManager.cpp, around line 76..
In postEffectmanager.cpp, around line 117..
In postEffectManager.h, around line 63..
In postEffectManager.h, around line 107..
Then on the script side, in my PostFX definition script file...
Then for the HLSL, I've tested it by just outputting the current frame, after running the above code. No matter what, it always shows the current frame and never onion skins.
Any help would be greatly appreciated. Thanks in advance!
Here's some code to check out:
In postEffect.cpp, around line 738..
else if ( texFilename.compare( "$previousFrameBuffer", 0, String::NoCase ) == 0 )
{
theTex = PFXMGR->getPreviousBufferTex();
if ( theTex )
viewport.set( 0, 0, theTex->getWidth(), theTex->getHeight() );
}In postEffectManager.cpp, around line 76..
// Store the current frame in the previousFrameBuffer storePreviousFrameBuffer();
In postEffectmanager.cpp, around line 117..
void PostEffectManager::storePreviousFrameBuffer()
{
GFXTarget *target = GFX->getActiveRenderTarget();
if ( mPreviousFrameBufferTex.isNull() ||
target != mPreviousFrameTarget )
{
const Point2I &targetSize = target->getSize();
GFXFormat targetFormat = target->getFormat();
mPreviousFrameBufferTex.set( targetSize.x, targetSize.y,
targetFormat,
&PostFxTargetProfile, "mPreviousFrameBufferTex" );
mPreviousFrameTarget = target;
}
}
GFXTextureObject* PostEffectManager::getPreviousBufferTex()
{
return mPreviousFrameBufferTex;
}In postEffectManager.h, around line 63..
// State for current frame and last frame bool mFrameStateSwitch; int mPrevFrameNoRenderCount;
In postEffectManager.h, around line 107..
/// Stores the previous frame buffer, so it can be requested in the next frame. void storePreviousFrameBuffer();
Then on the script side, in my PostFX definition script file...
singleton PostEffect( ScreenBlurPostFX )
{
isEnabled = false;
allowReflectPass = false;
renderTime = "PFXAfterDiffuse";
renderPriority = 1.0;
shader = ScreenBlurShader;
stateBlock = ScreenBlurStateBlock;
texture[0] = "$backBuffer";
texture[1] = "$previousFrameBuffer";
target = "$previousFrameBuffer";
targetFormat = "GFXFormatR16G16B16A16F";
};Then for the HLSL, I've tested it by just outputting the current frame, after running the above code. No matter what, it always shows the current frame and never onion skins.
Any help would be greatly appreciated. Thanks in advance!
About the author