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.
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
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
Perfect Uniform Motion Blur v1.2
- xXxMoNkEyMaNxXx
- Party member
- Posts: 206
- Joined: Thu Jan 10, 2013 6:16 am
- Location: Canada
Perfect Uniform Motion Blur v1.2
- Attachments
-
- Motion Blur v1.1.love
- Old version
- (3.92 MiB) Downloaded 230 times
Last edited by xXxMoNkEyMaNxXx on Tue Feb 04, 2014 11:09 pm, edited 3 times in total.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Perfect Uniform Motion Blur
- 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.
When I write def I mean function.
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Perfect Uniform Motion Blur
.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.kikito wrote:
- Is *.frag the correct file extension for a shader? Shouldn't it be something like *.glsl or something similar?
- xXxMoNkEyMaNxXx
- Party member
- Posts: 206
- Joined: Thu Jan 10, 2013 6:16 am
- Location: Canada
Re: Perfect Uniform Motion Blur
I have never tried or even thought of doing that before, so I wouldn't know where to start.kikito wrote:You probably want to include a license of some kind somewhere.
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.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)
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Perfect Uniform Motion Blur
This may help: http://choosealicense.com/xXxMoNkEyMaNxXx wrote:I have never tried or even thought of doing that before, so I wouldn't know where to start.kikito wrote:You probably want to include a license of some kind somewhere.
Help us help you: attach a .love.
- xXxMoNkEyMaNxXx
- Party member
- Posts: 206
- Joined: Thu Jan 10, 2013 6:16 am
- Location: Canada
Re: Perfect Uniform Motion Blur v1.1
I made a simplification that: shortens the code, makes it more efficient, reduces texture look-ups, and is more difficult to follow.
Feeling like a genius level: >9000
Feeling like a genius level: >9000
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests