Page 1 of 1

Perfect Uniform Motion Blur v1.2

Posted: Tue Feb 04, 2014 8:51 am
by xXxMoNkEyMaNxXx
This shader creates perfect uniform 2D motion blur! Feel free to use it for your own projects, with credit. For each pixel, the shader considers the colours from every pixel on the image that passes under the pixel on the screen. For this reason, the computation time is proportional to the Manhattan distance of the blur.
What it should look like
What it should look like
Motion Blur.png (1.18 MiB) Viewed 5457 times
In this demo, there's a 25 pixel radius safe zone in the centre of the screen where the blur effect demonstrates what happens if you set the Offset to 0. Use your mouse to control the blur. Notice that it is NOT IN ANY WAY calculated by summing identical copies of the image along the blur line, because that would never be perfect.

For love 0.9.0
Motion Blur v1.2.love
Tell me your thoughts!
(3.92 MiB) Downloaded 623 times
v1.1:
-At least 50% better performance!
-More commentary in the shader
-MIT Licence

v1.2:
-Changed variable names
-Uses texture coordinates
-More shader commentary

Re: Perfect Uniform Motion Blur

Posted: Tue Feb 04, 2014 9:31 am
by kikito
  • You probably want to include a license of some kind somewhere.
  • Is *.frag the correct file extension for a shader? Shouldn't it be something like *.glsl or something similar?
  • There is a lot of code repetition on the shader code. Isn't there a way to make it a bit more Don't Repeat Yourself? (I'm asking, I don't speak shader)
  • I like your humor.

Re: Perfect Uniform Motion Blur

Posted: Tue Feb 04, 2014 9:38 am
by slime
kikito wrote:
  • Is *.frag the correct file extension for a shader? Shouldn't it be something like *.glsl or something similar?
.glsl is usually used for generic shader code which can be used in vertex or pixel shaders. .vert and .frag (and .vs and .fs and .ps) are generally used for vertex shader and pixel/fragment shader code.

Re: Perfect Uniform Motion Blur

Posted: Tue Feb 04, 2014 9:56 am
by xXxMoNkEyMaNxXx
kikito wrote:You probably want to include a license of some kind somewhere.
I have never tried or even thought of doing that before, so I wouldn't know where to start.
kikito wrote:There is a lot of code repetition on the shader code. Isn't there a way to make it a bit more Don't Repeat Yourself? (I'm asking, I don't speak shader)
The shader is relatively short, and it also has the potential to get laggy with more extreme blurs. I think this justifies the code repetition. Rather than reduce the number of lines, I'd rather have it run faster. I don't know if all the choices I make actually benefit the speed, but there's always more ways to make a program faster. One choice I made was to transfer the colours already stored in the four colour values so that only half as many texture lookup operations had to be done.

Re: Perfect Uniform Motion Blur

Posted: Tue Feb 04, 2014 11:37 am
by Robin
xXxMoNkEyMaNxXx wrote:
kikito wrote:You probably want to include a license of some kind somewhere.
I have never tried or even thought of doing that before, so I wouldn't know where to start.
This may help: http://choosealicense.com/

Re: Perfect Uniform Motion Blur v1.1

Posted: Tue Feb 04, 2014 10:45 pm
by xXxMoNkEyMaNxXx
I made a simplification that: shortens the code, makes it more efficient, reduces texture look-ups, and is more difficult to follow. :awesome:
Feeling like a genius level: >9000