• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

A recipe for motion blur?

Hey folks,

Does anyone have any pointers (or the actual code!) for applying motion blur to a layer?

I have some parallax background layers that are just being moved with the horizontal speed setting in the background layer itself and it would really benefit from some motion blur.

I assume this is achieved with a shader? I googled and found some but I have no idea how they are applied to a specific layer.
 

rIKmAN

Member
Hey folks,

Does anyone have any pointers (or the actual code!) for applying motion blur to a layer?

I have some parallax background layers that are just being moved with the horizontal speed setting in the background layer itself and it would really benefit from some motion blur.

I assume this is achieved with a shader? I googled and found some but I have no idea how they are applied to a specific layer.
You can use layer_script_begin() and layer_script_end() to run a shader for a specific layer/layers.

There are extended code examples on the manual pages I linked above which do exactly the process you are after.
Just amend the code to use your own layers/shader/uniforms etc as required.
 
You can use layer_script_begin() and layer_script_end() to run a shader for a specific layer/layers.

There are extended code examples on the manual pages I linked above which do exactly the process you are after.
Just amend the code to use your own layers/shader/uniforms etc as required.
Thanks. I found a motion blur shader on this page: https://github.com/GameMakerDiscord/blur-shaders

Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 pos;//x,y
const int Quality = 16;

void main()
{
    vec4 Color;
    for( float i=0.0;i<1.0;i+=1.0/float(Quality) )
    {
        Color += texture2D( gm_BaseTexture, v_vTexcoord+(0.5-pos)*i);
    }

    Color /= float(Quality);
    gl_FragColor =  Color *  v_vColour;
}

I have no idea about shaders! Do you just paste that into a shader? Is that the beginning? I see no mention in the shader tutorial about an end script.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You should read the entire page where you got that shader from instead of just copy/pasting what you think is appropriate. It does explain everything... Alternatively, check out this wonderful set of shader tutorials from @Xor (the same one user that made that github example you are copying from) then you'll know how that sample works: https://gmshaders.com/tutorials/gamemaker/ ;)
 
You should read the entire page where you got that shader from instead of just copy/pasting what you think is appropriate. It does explain everything... Alternatively, check out this wonderful set of shader tutorials from @Xor (the same one user that made that github example you are copying from) then you'll know how that sample works: https://gmshaders.com/tutorials/gamemaker/ ;)
Thanks for the link. This looks like a really nice explanation. I will read it (all the way through!). Cheers.
 
Top