Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: PostFX motion blur code snippets/tutorial  (Read 4587 times)

0 Members and 1 Guest are viewing this topic.

snowy2

  • Newbie
  • *
  • Posts: 2
    • View Profile
PostFX motion blur code snippets/tutorial
« on: May 29, 2010, 06:16:42 pm »
I'm trying to implement pixel motion blur. Does anyone have any code snippets or links to resources that demonstrate how to do this via PostFX? Any help much appreciated.

Just to clarify... I'm trying to do the quick and dirty 2d motion blur by saving the last frame's buffer, reducing the alpha and blending it with the current frame.

update:
Ah, found out a quick way to do it. I simply CopyScreen() the window contents and SetTexture() just before clearing the screen.  The fragment shader code just blends the two textures (framebuffer and last frame) together. Then Draw() the effect as usual.

K-Bal

  • Full Member
  • ***
  • Posts: 104
    • View Profile
    • pencilcase.bandcamp.com
    • Email
PostFX motion blur code snippets/tutorial
« Reply #1 on: June 03, 2010, 12:24:37 pm »
You can also do something like window.Clear(sf::Color(0,0,0,100));
Listen to my band: pencilcase.bandcamp.com

snowy2

  • Newbie
  • *
  • Posts: 2
    • View Profile
PostFX motion blur code snippets/tutorial
« Reply #2 on: June 04, 2010, 04:56:40 pm »
Hmmm motion blur occurs only in debug build. In release, the blur effect is not visible at all. However, if I temporarily hard code the sfx file by multiplying the blurred texture component with 1, the effect is seen albeit with full opacity. Any ideas? Maybe I'm clearing and copying the image in the wrong orders? Frame rate related?

Code: [Select]

sf::PostFX Effect;
if (!Effect.LoadFromFile("blur.sfx"))
return EXIT_SUCCESS;

// Setup the effect parameters
Effect.SetTexture("framebuffer", NULL);


// image for postfx motion blur blending
sf::Image image;
 
// Start game loop
while (App.IsOpened())
    {
// Game logic, moving stuff
...

        // First clear screen
App.Clear();

// Draw postfx motion blur first
App.Draw(Effect);

// Draw game stuff
...

// Copy window contents as image, set the texture and apply blurriness
image.CopyScreen(App);
Effect.SetTexture("blurred", &image);

// Draw hud overlays
...

      // Finally display window contents on screen
        App.Display();
}



blur.sfx
texture framebuffer
texture blurred

effect
{
vec4 c0 = framebuffer(_in);

_out = (c0 * 0.5f) + (blurred(_in) * 0.5f);
}