DeepBlur: Plugin for Post Process Depth of Field

Hello!

This is my first plugin. I wrote it for use in my short film “Alchemy” and I thought that the community might find it useful.

It is based on zblur, but operates using a greyscale image instead of the zbuffer. This makes it easier to tweak. Also, imho, I think that my plugin gives more control and is easier to use than zblur.

source: http://cs.unm.edu/~sketch/gallery/resource/dof/deepblur.c
windows .dll: http://cs.unm.edu/~sketch/gallery/resource/dof/deepblur.dll
linux .so: http://cs.unm.edu/~sketch/gallery/resource/dof/deepblur.so

The plugin requires 2 input strips. The first should be the rendered images. The second should be greyscale images that indicate the depth of each pixel in the first strip. The second strip can easily be created using the zutilz plugin which can be found in the plugin repository.

User defined variables:
http://cs.unm.edu/~sketch/gallery/resource/dof/ui.jpg

Blur: Maximum radius of the blur effect.

Focus: Distance from camera to focal point.

Length: Distance from focal point that will remain in focus.

Fade: Distance for gradient between focused and blurred areas.

Show Weighting: Displays the greyscale image used to perform the weighted blur. Black areas will be in focus, while white will be blurred (and grey areas are everything in between).

For example:
Strip 1:
http://cs.unm.edu/~sketch/gallery/resource/dof/render.jpg

Strip 2 (created using zutilz plugin):
http://cs.unm.edu/~sketch/gallery/resource/dof/zinfo.jpg

Output (using default settings):
http://cs.unm.edu/~sketch/gallery/resource/dof/output.jpg

I hope you all find it useful.

Any chance of getting a quick step-by-step of what you did here. I have the zutilz plug-in but I can’t figure out how to use it to create the depth image used by the DOF plugin you created. Any help would be appreciated. Thanks.

I will write a full tutorial when I have time, but until then, hopefully this will help.

Here is a screenshot of the zutilz settings I used:
http://cs.unm.edu/~sketch/gallery/resource/dof/zutilz_settings.jpg

The output looks really great!

The only issue I’d have is that it is a plugin that needs the output of another plugin… Any chance that the zutils could be encapsulated by your plugin so that only the rendered images strip would be needed (and a link to the .blend of course)

Could a python script render the image, call the zutils plugin to render the depth info and pass both to your plugin for blurring?

So I create my scene, render it with RGBA turned on (is there anything special besides this that I need to do with the render). I import the image (will PNG do?) into the sequence editor, insert the zutilz plugin (how do I attached it to the image? Add?). Turn on “Do Sequnce” and render.

I’m probably missing a few steps or getting a few things wrong, any help would be great.

UglyMike: I don’t see why the zutilz code and deepblur code couldn’t be combined into 1 plugin. I will probably do that one day. This first release doesn’t have that functionality because I didn’t need it for my film at the moment :D.

kirpre: Here is a real quick and dirty step-by-step:
1.) Create your scene and render it. The plugin doesn’t support alpha channels yet, so it doesn’t matter if you use RGB or RGBA. Save the image (file format doesn’t matter).

2.) Add the scene to the sequence editor. Select the scene in the sequence editor and add the zutilz plugin. Make the settings look like the ones I posted above. Click “Do Sequence” in the render buttons and render. Save this image too. (for this second render you can turn off raytracing, delete lights, delete textures, etc to decrease your rendertime. All zutilz needs is the zbuffer)

3.) Delete the scene and zutilz from the sequence editor. Add both images that you just rendered to the sequence editor. Select them both images (select the depthmap last) and add the deepblur plugin.

Hopefully that made sense.

Perfect. Thanks for your help. I look forward to playing around with this some more.

Wow, thats a really nice blur!

I tested it, not with rendered images but just with a scene, and got some nice results.

the only thing I wish it had was the ablility to animate the focal point.

I don’t know if that’s limitation of the plugin as it’s written now or the sequence editor.

thanks for releasing this!

kirpre: Glad you got it working.

Phrangkk: Thanks for reminding me. I tried making the focal point animatable, but I was unable to get it to work. According to the online blender manual it should be possible to use an ipo to control the settings of a plugin. If anyone knows anything about doing this, I’d appreciate some pointers. An animatable focal point would be quite cool. ZBlur is supposed to be able to do this, but I never got it to work.

Also, I’m thinking about adding a feature similar to autofocus in zblur. It would focus on a certain area of the image, rather than on a certain depth. So that might be useful for animating the focal point.

Cool. This kind of job I always do it in postprocessing software like cinelerra or gimp. It is great to have the chance of applying depth masks in blender itself.

BTW Only bad thing about Zutils (or any other plugin using the zbuffer) is that objects that are partially transparent (objects with a texture to define transparent areas), will not be visible at all. In those cases, only workaround I found is using the “gradient technique” explained in these forums (using a white/black blend texture with global coordinates for all objects).

Kind regards

malefico.

malefico: Let me suggest another solution to you: Because the rgb render and the depth render are performed seperately, you can make your transparent objects opaque for the depth render. Halos, however, will still be a problem.

Also, using ray transparency instead of z transparency solves the problem as well. But often this is not ideal.

@sketchy: welcome to the world of seq plugin coding…It’s funny to see that you are using my first real plugin to support yours :slight_smile:

A better way to do it is to just render and save

add a scene (link objects)… I’d name it Z %|

in Z, turn off all the fancy rendering stuff like sketchy said…

ztransparent means what it says ;)… if you want it to show up in the depth map ya gotta turn off ztrans in the materials.

now go to the seq editor (go back to your origional scene)and add scene Z and then add zutilz to it & set it as above

add your image above zutilz

select the image, shift select zutilz, and add deepblur

The reason this is better is because now you can save your blend with all the plugins set up and not screw up your origional scene. you won’t have to start over from scratch if you decide to move or edit something and re-render, you can just turn off do squence and render and save. Since the objects in Z are linked to the original scene, your depth map will change with it and all you have to do is change the image (select the old image in the seq editor and hit c), and do sequence.

yeah, you can just use your origional scene strip instead of an rendered image if the rendertime isn’t too bad, but if you happen to accidentally change frames while in the seq editor you will have to wait for it to render again…that can get annoying

heh, like I said, zutilz was my first real plugin…Iv’e learned alot since then - I really need to completely recode it :expressionless:

Hi,
Thanks for this plugin :slight_smile: It work quite well. Any news about controlling plugin parameters with IPO?

sketchy,

Cool plugin, I was afraid to try it until someone compiled the source for me… and then I got frustrated waiting. So, I compiled it. Not sure where to place the linux deepblur.so file, so I’ll just post the instructions.

It was very easy. Took me a few seconds to read your source file, and realize that the compiling instructions were already there with the included zblur comments.

So…
A) copy the deepblur.c file code to $BLENDERDIR/plugins/

B) compile it with “./bmake deepblur.c”

C) this deepblur.so file is now in your plugins directory (or you could copy it off to a working plugins directory elsewhere if you like)

Yes, in fact. paprmh helped me figure it out. Once the school semester is over I will code it (this is the last week! :D).

DracoFodder: I pm’d you my email address. If you email the .so to me, I’ll make it available for download from my website. Thanks!

First post has been updated with DracoFodder’s linux build.

paprmh’s method is the only one that actually worked for me… As a sidenote, instead of using 2 plugins (too memory-intensive imo) you could just use the gradient method.

Sketchy: Would you mind explaining exactly where the focus (ie the completely un-blurred part) is, according to the script? I mean, do I have to figure out the exact distance from the camera to the focus, or is there some idiot-proof method?

[edit]
Nevermind, I figured it out. Or rather, messed around until I got something okay – I’d still appreciate an authorised answer :slight_smile:

~60kB DivX 5 avi

.blend file

Hi sketchy,very interesting plug in you have made!
I’m tryng to use it to help me faking subsurfacescattering and works very well.
But can you increase the maximun radius of the blur?For animation
it’s not a problem but for still at high resolution I think the radius should be increased,at least double the value(I know that in this way can be very slow but it’s not a problem for me.
Bye

Do you know why the z buffer has jagged edges?? :-?

bigbad,the zbuffer is not antialiased,it’s right having jagged edges(well,it’s not right but its make sense,for an antialiased zbuffer you should use the gradient method).
Bye