YOUR ACCOUNT

Login or Register to post new topics or replies
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
Radial Blur by bertie
http://www.filterforge.com/filters/9442.html

--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
How did I miss this?

It's nice to see that a fast-rendering scripting solution is possible for radial blur... smile8)

A humble request: Could you simplify this and submit a "scrippet", with just the script map component and possibly some more detailed explanations of the script?
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
bertie
bertie
Posts: 19
Filters: 14
I'll upload a scrippet. In the meantime, here is a quick overview of how it works.

The prepare part of the script isn't doing much that's special so I'll skip over that. The radial part is done by this piece of script

Code
xd=x-xmid
yd=y-ymid
ang=math.atan2(yd,xd)
xs=-pixelstep*math.cos(ang)
ys=-pixelstep*math.sin(ang)
--here is where multiple pixels are samples to create the blur
   for s=1,Length do
   r,g,b,a    = get_sample_map(x+(s*xs), y+(s*ys), SOURCE)
ra=ra+r
ga=ga+g
ba=ba+b
aa=aa+a
end


xd and yd are calculating how far the point being rendered by the map script is fr om the centre of the blur. This gives the flexibility to reposition the centre of blur anywhere in the image.

Once these two distances are known the atan2 functions is used to calculate the angle to the point. Note the use of atan2 is very useful as it returns an angle based on positive and negative coordinates which atan doesn't.

So ang contains the angle from the centre to the point being rendered. It's the angular part of the polar coordinate of the point wh ere the centre is the origin. This angle is stored in radians not in degrees which might be important if anybody wanted to manipulate the angle in some way in a modified script.

Now the angle is known, it's possible to calculate the unit vector for the line that joins the sampled point to the centre of the blur. In the code this is done by:


diagram by RB_UK, on Flickr


Code
xs=-pixelstep*math.cos(ang)
ys=-pixelstep*math.sin(ang)


It's not quite a unit vector because it multiplies the result by pixelstep at the same time but hopefully you get the idea. If you are standing at the sample pixel and you add xs to the x coordinate and ys to the y coordinate you move an amount pixelstep towards the centre of blur.

This next bit does the sampling of multiple points. The picture helps to explain things better.

Code
   for s=1,Length do
   r,g,b,a    = get_sample_map(x+(s*xs), y+(s*ys), SOURCE)
ra=ra+r
ga=ga+g
ba=ba+b
aa=aa+a
end


You'll see the the loop runs from 1 to Length times and each time the point sampled is the location plus (s*xs). In other words, the loop samples along the line towards the centre in steps of xs (and ys for that matter). So you get a number of samples that are radially distributed. The result is the radial blur.

The full filter has some extra features. There is a 'deadzone' in the middle of the blur which makes it look more like a natural zoom blur. This is done with a simple elipse and transparence between the original and blured image. If you want to see a simpler implementation of this deadzone effect, see my filter 'spot focus'.

Fast mode just switches off most of the processing to enable the correct positioning of the centre and the radius of the deadzone.
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
Thank you, this is much appreciated! smile:)

Btw, do you realize you are setting a new standard for script filter documentation on this forum? smile;) smile:D
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
bertie
bertie
Posts: 19
Filters: 14
I'm working on another filter using similar ideas that produces realistic bokeh. I've uploaded some samples here at the link below.

See slideshow of the bokeh effect

It's not ready for publication. I've got a few things to tidy up but it works pretty well.
  Details E-Mail
bertie
bertie
Posts: 19
Filters: 14
Snippet of the script now available here
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,712 Registered Users
+19 new in 30 days!

153,533 Posts
+31 new in 30 days!

15,348 Topics
+73 new in year!

Create an Account

Online Users Last minute:

31 unregistered users.