I’m using sfml to make a 2D game with sprites and trying to get this effect:
I use Photoshop’s “Motion Blur” in the example. As you can see, the effect is directional.
My game uses paperdolled sprites so it would be much easier to have this as a post effect instead of blurring every single equipment combination on every sprite.
Would it be possible to get this effect with a shader? An example would be appreciated.
2
Answers
Generating points over a line
A little bit on the manual side but, I can suggest an approach.
Lets imagine a circle, crossed by a line on a determined angle. Over that line, we place some random points.
Something like this:
Circle with radius 100, angle 45ยบ (PI / 4 radians) and 100 random points
Then, wherever each one of that points are, we will draw a sprite of our texture, with some alpha (transparency). The result will look like so:
Changing the radius of the circle, and the number of points, the result may vary
Further explanation
In my example, I use a class, which represents the
BlurredSprite
. It will hold those points, and thesf::Texture
to draw.With
getPointOverLine
lambda, I create a random point over the line, but can be other options to do this. In fact, the way you spread those points will affect on the final result.I need to override the
draw
method, in order to make this class Drawable on the window. I also override thesetPosition
method (fromsf::Transformable
) because, if you move it, you should move all the points with it.Here I post the best result I could do in one night. I did it with shaders as you ask. I didn’t implement the angles but that something not too hard.
Here is part of the cpp file:
This is the fragment shader:
I upload the entire code to my repository so you can downloaded and try.
You can set x/Y direction, sample, and blur radius.
X/Y directions are from 0-1.
You can play with the number of samples.
The blur radius is very sensitive you can start try with 0.01
with my example would be:
Some pics: