Motion blur

What do you want to see in Armagetron soon? Any new feature ideas? Let's ponder these ground breaking ideas...
User avatar
Lucifer
Project Developer
Posts: 8750
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Motion blur

Post by Lucifer »

Ok, so I was editing the page on framerate on the wiki and read up a bit on framerates in movies compared to video games.

The upshot (which you all probably know), is that movies run at 24fps and look smoother than games that run at 80fps (just beyond the threshold of what the human eye can distinguish), but games still appear choppy compared to movies. This is because of the motion blur that is captured by the movie camera that a video game doesn't render.

So how can we go about rendering the motion blur? It seems to me like if we can render a motion blur, we can reduce the framerate needed from the GPU to get a good illusion of motion, and also probably reduce the resolution needed for the clearest possible picture (dvds are encoded at a surprisingly low resolution).

So I was thinking about double buffering, you know, you render the frame to some area of memory and then when you're finished you flip the display to use that new frame and go render the next frame somewhere else. The first thing you do in 2d gaming is copy parts of the background to the areas that changed in the last frame, then render your new stuff on top of that. If you don't, you get little bleeds of sprites moving across the screen.

So, to get a motion blur effect, it seems like the first thing to do is take advantage of double buffering. Instead of rendering one frame, though, we should render more than one frame before flipping the display. This means that each frame shown would have two or three frames rendered onto it, hopefully creating the motion blur effect.

So then we have two framerates to keep in mind. We have our rendering framerate and our display framerate. We could clamp the display framerate to something like 50fps and then clamp rendering based on a fancy formula that will put it somewhere around 80fps.

What do you think? Am I blowing smoke or is there a real possibility to create the motion blur effect seen in movies?
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

Yes and no. If your framerate is several times your refresh rate, you can get more fluid motion. Like shrinking an image of 4096 pixels to 1024 pixels based on averages if your screen can't display more. But otherwise you'd just pointlessly apply a block filter. Like, your source is 1024 pixels and you blend every 4 pixels together to get an effective 256 pixels. A single pixel of the result may look better than a single source pixel, but 4 individual source pixels are better than having them blended together.
ˌɑrməˈɡɛˌtrɑn
User avatar
hang3r
Core Dumper
Posts: 188
Joined: Fri Sep 16, 2005 9:05 pm
Location: Australia

Post by hang3r »

Limiting fps would have no benefit, there are many ways to achieve motion blur.

First of all though, there are two mainstream video formats, which are:

NTSC 23fps.
PAL 25fps.

As far as im aware, the blur is added later on, just because of the simple fact that everyone doesn’t want headaches watching there TV’s.

As for the double buffering, im not sure what you mean, armagetron is already double buffering.
User avatar
Lucifer
Project Developer
Posts: 8750
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

Actually, hanger, the blur is part of the filming process. The shutter is open for a certain amount of time (these days the shutter flickers 3 times per frame). To see how it works, just grab an old film camera (digital will probably still work), set a very low shutter speed and point it at a moving car. The resulting picture will have motion blur in it, and that's exactly what you have in movies.

There is some debate in the movie industry about moving to a higher framerate. Many directors like the lower framerate, they say it gives a more romantic view, more artistic, and getting a more accurate view of reality would destroy that feeling in the movie. Others, of course, want more realism, and having a faster shutter speed and more frames would accomplish that, at least as far as the filming process is concerned.

That doesn't mean directors don't add motion blur later on, all it means is there will always be a certain amount of motion blur in the movie. And it only really kicks in when the object is moving fast, of course.
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

hang3r wrote:As for the double buffering, im not sure what you mean, armagetron is already double buffering.
I think he meant something like the accum buffer.

OT: Some TV things I'm annoyed by:
- Low framerate
- Low resolution
- Flickering
- High-pitched tone
And that's just the technical part (i.e. ignoring content).
ˌɑrməˈɡɛˌtrɑn
User avatar
Lucifer
Project Developer
Posts: 8750
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

Get a better tv? ;)

I'd like a higher framerate too, I like more realistic video. The motion blur still has to be there, because the human eye will do motion blur in real life, but if there's no motion blur on the frames the human eye can't compensate for that.

I don't like the low resolution of tv either. :( That's something they're addressing in HDTV.

Flickering is entirely caused by your refresh rate, I think. My tv doesn't flicker, and since we only watch dvd's (and lately VHS tapes) there isn't a problem. I have noticed some flickering on regular tv programs, but the content of tv programs has already driven me away from tv so I no longer have a flickering problem. ;)

Same with high-pitched tone. I think HDTV is supposed to have digital sound that's at least CD quality. So it won't be perfect, but it'll beat the hell out of the previous analog signals. (not that digital is inherently superior to analog, just that digital audio technology is better than analog technology. If the only issue was audio quality, I'd prefer more advanced analog tech then digital tech, but since that's not the only issue, digital definitely kills analog)
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
hang3r
Core Dumper
Posts: 188
Joined: Fri Sep 16, 2005 9:05 pm
Location: Australia

Post by hang3r »

Lucifer wrote:Actually, hanger, the blur is part of the filming process. The shutter is open for a certain amount of time (these days the shutter flickers 3 times per frame).
Actually, lucifer, I wasnt aware of this trickery :(
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

Lucifer wrote:I'd like a higher framerate too, I like more realistic video. The motion blur still has to be there, because the human eye will do motion blur in real life, but if there's no motion blur on the frames the human eye can't compensate for that.
(about doing it in a game) You can sacrifice framerate for motion blur. If your framerate is below your refresh rate, it's as useful as a tile filter on an image.
Lucifer wrote:Flickering is entirely caused by your refresh rate, I think. My tv doesn't flicker, and since we only watch dvd's (and lately VHS tapes) there isn't a problem. I have noticed some flickering on regular tv programs, but the content of tv programs has already driven me away from tv so I no longer have a flickering problem. ;)
I have very good eyes, that "helps". Also, we have mostly 25 fps PAL here, not ~30 fps NTSC. One time when I hooked up my laptop to a TV, NTSC clearly gave less flickering (not that it's very good).
Lucifer wrote:Same with high-pitched tone. I think HDTV is supposed to have digital sound that's at least CD quality.<snip>
Um, I meant the tone of ~15 KHz caused by something related to the electron gun in the CRT. It will be gone with HDTV, but not because of better sound quality.
ˌɑrməˈɡɛˌtrɑn
User avatar
Lucifer
Project Developer
Posts: 8750
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

OH yeah. No, the double-buffering I'm talking about is a word that comes from 2d programming. I don't know how OpenGL refers to it, but in pygame an OpenGL surface has double-buffering along with it.

Basically, you have an area of memory that contains the screen you're going to display, right? If you put something in that area of memory, you overwrite was was previously there. So you have three areas of memory of the same size and configuration. One of those is the background of your screen, and the other two are used for the screen. During each timestep of your application, you copy from the background to one of the target screens to initialize it. Then you copy your objects (still called sprites, but they're not sprites anymore) into the area. When you're done, you flip the display to use the area you just drew. Now the other area is free, and in your next refresh you will update *that* area.

So each time, if you skip the initialization part where you copy from the background to the active screen buffer, you wind up with your sprite bleeding all over the place. So instead of drawing a ball you could easily wind up drawing a line of balls.

It's this last part that I was thinking could be used to create a motion blur effect. In essense you'd render fast-moving objects several times to the same frame before flipping the buffer, each in different positions. You might even apply an alpha effect or something--in 2d programming. I've never heard of anyone actually making a motion blur effect in gaming, I've only ever heard that it's a limitation of the medium. I'm challenging that idea right now, and probably someone will dig up links to show where someone else has already done it.

So, in OpenGL, then, how would we go about creating a motion blur effect? That obviously means the renderer has to run at a higher framerate, but theoretically it should only have to render fast-moving objects multiples of times. For slow-moving objects and scenery it should have to render those more than once per frame, so each frame would get an additional step, I guess. Or each game object would just render itself as many times as it determines necessary based on it's speed, so it would need to know it's speed in relation to the camera. A cycle pointing away from the camera moving at fast speed doesn't need to blur, but a cycle at a slower speed but going at right angles to the camera might need to blur.
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

The OpenGL way is using an accum buffer, but when I tested it it was very slow. There isn't really another way. :(
ˌɑrməˈɡɛˌtrɑn
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

Code: Select all

SDL_GL_SetAttribute( SDL_GL_RED_SIZE, singleCD_R );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, singleCD_G );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, singleCD_B );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, zDepth );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 8 );

Code: Select all

if (lastSuccess.useSDL) {
    static short maxcount = 4;
    static short count = 0;
    glAccum(count ? GL_ACCUM : GL_LOAD, 1.0 / maxcount);
    if(++count >= maxcount) {
        glAccum(GL_RETURN, 1);
        count = 0;
        SDL_GL_SwapBuffers();
    }
}
10 fps at 512x384. :(
ˌɑrməˈɡɛˌtrɑn
User avatar
Lucifer
Project Developer
Posts: 8750
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas

Post by Lucifer »

Hmm, I was thinking a bit more complex.

So, in each timestep, say a cycle, computes how far it's traveled, right? So have it also compute several steps based on its speed and render an alphad version of itself to each of those locations. Objects that don't move, right now that's everything else, don't need to do this at all.
Check out my YouTube channel: https://youtube.com/@davefancella?si=H--oCK3k_dQ1laDN

Be the devil's own, Lucifer's my name.
- Iron Maiden
User avatar
hang3r
Core Dumper
Posts: 188
Joined: Fri Sep 16, 2005 9:05 pm
Location: Australia

Post by hang3r »

Here is an interesting way of doing it, seems rather effective too :D
http://www.codeproject.com/opengl/MotionBlur.asp
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

If you could explain exactly how that's supposed to work, go ahead. Don't forget that motion relative to the camera is motion, i.e. almost everything is motion, and that we want motion blur, not objects drawn a few times on top of themselves which looks quite different.

Movie that hopefully works:
Attachments
motionblur.mp4.gz
16 rendered frames per displayed frame. The result is really only 3 displayed fps. Quicktime isn't that great for encoding MPEG-4, but it'll have to do.
(1.58 MiB) Downloaded 163 times
ˌɑrməˈɡɛˌtrɑn
User avatar
hang3r
Core Dumper
Posts: 188
Joined: Fri Sep 16, 2005 9:05 pm
Location: Australia

Post by hang3r »

Well, the link I posted was an alternative way to do full scene motion blur, it is affective as I saw the demo, as for explaining how it works??!? I thought that page explained it rather well.
Post Reply