XNA Creators Club Online
community forums
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Motion blur

Last post 05-14-2008 12:10 PM by MJP. 3 replies.
  • 05-13-2008 1:33 PM

    Motion blur

    Hi all!

    I'm trying to make a motion blur effect, just as in the sample provided with the DirectX sdk. I've read it, but it's too complicated.

    I just want to blur every 2 frames. E.g.: if the order of the rendered frames would be 1,2,3,4,5 ... I need it to be 6,7,8,9 (6 is the blured frame resulted by overlapping frames 1 and 2; 7 is from 2 and 3; 8 is from 3 and 4..... and so on....)

    How do I do this?

  • 05-13-2008 7:58 PM In reply to

    Re: Motion blur

    Doing it that would way would effectively be super-sampling.  Basically for each "real" frame, you would need to render n sub-frames both before and after the "real" frame.  So let's say you're rendering at 30fps, and you wanted two sub-frames.  The "real" frame would be rendered at 33ms, then 66ms, and so forth.  So for the first frame, you would want render frames where your game world (simulation) thinks it's at time 16.6ms and 40ms.  You could just render these to full-size render targets.  Then as your last step, you would combine and filter your two sub-frames in a full-screen pixel shader.  The filtering is real simple, the generalizes equation is result = (sample1 + sample2 + ... + sampleN)/N where "N" is the number of sub-frames rendered.  So for two sub-frames, your equation would just be result = (sample1 + sample2) / 2, with sample1 being a texel sampled from the first render target and sample2 coming from the second. 

    Keep in mind that this is very expensive:  you're already doing double the work per frame you'd normally be doing without motion blur, and that's just for 2 samples.  Good anti-aliasing (motion blur is just a form of anti-aliasing) requires many samples to be effective, try comparing the difference between 2xMSAA and 4xMSAA to see what I mean.  
    Matt Pettineo | DirectX/XNA MVP


    Ride into The Danger Zone
  • 05-14-2008 8:17 AM In reply to

    Re: Motion blur

    K I got the idea... So what I need to do is to get the frame that should be rendered and combine it with the previous one then render the result.

    The problem: I don't know how to get the image that should be rendered. And I also don't know how to combine 2 images, both with 50% alpha.

    How I do this?

  • 05-14-2008 12:10 PM In reply to

    Re: Motion blur

    void PixelShader(in texCoord : TEXCOORD1, out output : COLOR)
    {
    float4 sample1 = tex2d(frame1Sampler, texCoord);
    float4 sample2 = tex2d(frame2Sampler, texCoord);
    output = (sample1 + sample2) / 2;
    }


    Just use something like this with a full-screen quad, as if you were doing a post-process.  If you don't know how to do that, check out the PostProcess sample or the PixelMotionBlur sample in the SDK.

    Also alternatively, you could render the first frame to the back-buffer and then render the second also the back-buffer using hardware alpha blending.  To this just set the correct alpha-blending states in your effect (AlphaBlendEnable = TRUE, SrcBlend = SRCALPHA, DestBlend = INVSRCALPHA) and set the alpha component of the output pixel color to be 0.5 in the pixel shader.



    Matt Pettineo | DirectX/XNA MVP


    Ride into The Danger Zone
Page 1 of 1 (4 items) Previous Next