• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
JoshKlint_34394

Per-pixel motion blur

6 posts in this topic

I implemented a velocity buffer for both moving and static objects. Once you have this data, how do you write a good per-pixel motion blur shader?

I wrote a shader that performs lookups along the reverse direction of velocity. So if a pixel is moving to the left, it will look up pixels to the right of it and blend these with the color at that pixel:
[code]#version 150

uniform sampler2D texture0;//color
uniform sampler2DMS texture1;//motion vector
uniform vec2 buffersize;
uniform vec4 drawcolor;

#define MOTIONBLURSAMPLES 64

in vec2 ex_texcoords0;

out vec4 out_Color;

void main(void)
{
vec4 color;
vec2 motion = -(texelFetch(texture1,ivec2(ex_texcoords0*buffersize),0).xy * 2.0 - 1.0);

vec2 motionblurtexcoord = ex_texcoords0;
float samples=0;
float strength=1;

for ( int i = 0; i < MOTIONBLURSAMPLES; i++ ) {
motionblurtexcoord += motion / buffersize * 0.5 * 10.0;
color += texture( texture0, motionblurtexcoord ) * strength;
samples += strength;
strength *= 0.98;
}

out_Color = color / samples;
}[/code]

This is not at all a realistic motion blur. Instead of moving objects leaving a trail, they take samples from the pixels behind their path of motion:
[attachment=1772:motionblur.png]

Imagine a truck driving by the camera, in front of a jungle. You would want the truck to leave a faint trail behind it as it moves to the left. Instead, you would see the rear bumper of the truck turning green as it picked up the color of the jungle in the background. The pixels of the jungle just behind the truck would be completely unaffected, because they are not in motion. Here's what my shader looks like when an object spins counterclockwise:
[attachment=1773:Image10.png]

The proper way to do this would be to look up the velocity at each pixel, and then copy that pixel's color to the pixel it "lands" on, by offsetting the coordinates by the velocity vector. But that isn't possible without scatter writing. Is there a way to do this properly?
0

Share this post


Link to post
Share on other sites
I highly recommend checking out Eric Lengyel's article in Game Engine Gems Vol. 1.
1

Share this post


Link to post
Share on other sites
Looking at chapter 17, I think he is using basically the same technique for the post-filter.

The proper way would be to sample an n x n grid and add pixel samples that have velocities that intersect with the pixel you are working on.
0

Share this post


Link to post
Share on other sites
Blurring both forward and backwards along the velocity might be an okay solution to this. There is still inherent error, but it's probably okay to do it like this, since it's impossible to improve without scatter write.
0

Share this post


Link to post
Share on other sites
It's a tricky problem, since like you said it's really a scatter problem that you're trying to solve through gathering. A few thing you can try...
[list=1][*]Stretch the vertices in the direction of opposite direction of velocity. This helps keep adjacent frames from looking too "separated", particularly for skinned meshes. However it can cause a lot of artifacts if you stretch along the vertex normal, since in some cases it can cause the triangles to "tear apart" (think a cube with normals that point in the direction of the face). What you really want is to stretch along a shared, averaged normal. It also doesn't really work for objects that just rotate, like a wheel. It can also help to only do this when rendering velocity separately from your main pass (or G-Buffer pass), since it makes the artifacts much less noticable.[*]"Dilate" your velocity either by blurring, or by pulling high velocities into adjacent pixels[*]Use the previous frame's velocity and/or color buffers. For objects that don't move really really fast, the previous frame's velocity or color buffer can give you information to "fill in the gaps" outside of the object's silhouette.[/list]You should check out the presentations for Lost Planet, Crysis, Little Big Planet, and Killzone 2. They all have information about their motion blur implementations.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0