OpticalZDefocus v1.1


 
This location is for Registered Users Only.
Perhaps you need to login or register.
Contributor: Jed Smith
Website: jedypod.com
OpticalZDefocus is a physically accurate ZDefocus, which controls circle of confusion (coc) size based on lens geometry using the depth of field equation. Set your lens and film-back characteristics, your focus distance, and adjust the size of your bokeh with the aperture size, just like a real lens.
Requirements:
11.0, 10.5, 10.0, 9.0, 7.1, 7.0 or later
Linux, Mac, Windows
06 May 2018
6581

OpticalZDefocus screenshot

 

OpticalZDefocus is a physically accurate ZDefocus, which controls circle of confusion (coc) size based on lens geometry using the depth of field equation.

Set your lens and film-back characteristics, your focus distance, and adjust the size of your bokeh with the aperture size, just like a real lens.

Features

  • Unpremultiply your depth channel by the selected alpha
  • Sample the z-depth value at a given x/y coordinate
  • Supports multiple depth units: mm, cm, m, dm, inches, feet
  • Automatically snarf lens geometry data from a selected camera node
  • Min z-depth value to avoid long processing times on cg with transparent alphas
  • Fast constant defocus mode which will not calculate depth of field

The latest version will always be here: https://gist.github.com/jedypod/50a3b68f9b5bbe487e1a

There is also a video about depth of field which includes a section about how to use the tool here, for those that are curious: Simulating Physically Accurate Depth of Field

Please login in order to download these files.

Comments   

 
+1 # Warrachat Khamfun 2017-05-28 05:41
Very Nice script :-)
 
 
0 # Jorge M 2017-06-07 21:49
thanks man ! it's really impressive!
 
 
0 # Jorge M 2017-06-07 21:59
Do you know if it would be a difference if I use the depth from the deep data and plugin it into your OpticalZdefocus instead of a regular depth ?
 
 
0 # Jed Smith 2017-08-31 01:36
Sorry for the late reply.

Normally the deep.front and deep.back channels that are output from a DeepToImage or DeepHoldout will work as a depth channel. The distance values will be the same as an unfiltered depth.Z from a lighting render of the same objects, though the edges might vary since these channels represent the front and back samples of the edges of your fg objects.

The OpticalZDefocus tool expects distance in front of camera style z-depth (the "depth" type in the zdefocus node), there is currently no option for 1/z z-depth, though this would be easy to add.

In short it should work! Just need to point the tool to the right channel to use.
 
 
0 # Rich Bobo 2017-06-21 00:12
Jed,

Holy cow!! I can't even begin to say how *awesome* this is! I have been suffering with Nuke's ZDefocus for so long - and now there's a ZDepth tool that actually works the way it should! Thank you, thank you, thank you! If I ever see you, remind me that I owe you several drinks. I'm serious.

Already added it to our facility's toolset and I've been experimenting with it on a bunch of previous comps of all kinds. Our Head Creative Director even said we should go back and re-render one of our jobs, just so it looks better on our reel!

Thanks a ton,

Rich
 
 
0 # Jed Smith 2017-08-31 01:39
Thanks Rich, glad it's working well for you :)
 
 
0 # Rich Bobo 2017-12-04 19:36
Quoting Jed Smith:
Thanks Rich, glad it's working well for you :)


I have a question...

I have noticed that I am getting errors in the Nuke console like this:
ERROR: OpticalZDefocus .Generate_Direc t_Z.scale: Nothing is named "parent.scale"

I see the error inside the Group, I'm just wondering what knob the scale value is supposed to be linked to...? It looks like it is supposed to be linked to a multiplier for the depth values, so you can more easily switch units for the depth range?

Thanks,
Rich
 
 
0 # Jed Smith 2018-05-25 18:28
Thanks for the bug report, this should be fixed now with v1.1
 
 
0 # Mohamed Selim 2017-09-29 18:12
I was just thinking of attempting this. Thank you! Works great and gives very similar results to the pgBokeh plugin.
 
 
0 # Marvin Sprengel 2018-03-04 16:37
mhh it seems it doesn't repeat the edges for me. Not around Objects but around the whole Frame. Am i doing something wrong?
besides that great Gizmo!!
 
 
0 # Jed Smith 2018-03-15 03:12
Hey Marvin,
I would have to see an example to be able to help, but I would start by checking the values in your z-depth. Are they unpremultiplied ? Are there black or inf values? The ZDefocus node can do some weird stuff when driven in direct mode like this tool has to do as well... especially if there are fg objects over distant background objects.
 
 
0 # Vincent Langer 2018-03-14 15:24
really cool tool - thank you very much

GOOO MATH!!!!
 
 
0 # Jed Smith 2018-03-15 03:10
Thanks!
I won't mention how long it took me to solve the equation for coc size :P
 
 
0 # eden an 2018-05-08 09:23
Thank you for your ability!
I've already used this awesome gizmo.

What is different from the previous version v1.0?
 
 
0 # Jed Smith 2018-05-25 18:27
Hey Eden, thank you. Not much is changed, just some bug fixes and the ability to use a camera input to get focal length and haperture.
 
 
0 # Caroline Voglaire 2018-05-25 15:24
Seems really a nice one!
Easier and faster (and cheaper ;-)) than PGBokeh!

But I get an error message copying the gizmos :
_ZDEFOCUS_.legacy_resize_mode: no such knob
_ZDEFOCUS_.false: no such knob
_ZDEFOCUS_.show_legacy_resize_mode: no such knob
_ZDEFOCUS_.false: no such knob

In the other hand, I'm facing a concrete issue. After dealing with camera settings, focus distance etc... It seems to work really well (even with deep data rather than zdepth), but my supposed focused area is still a bit blurred. Actually, nothing is completely focused in the frame.
Do you have any idea of what is going on?
Do you thing that could be caused by the fact I am on Nuke 8.5?
That would be awesome if you could find something. That would help me a lot.
 
 
0 # Jed Smith 2018-05-25 18:26
Hey Caroline,
It looks like the legacy_resize_m ode and show_legacy_resize_m ode knobs were added after Nuke 9, and since this gizmo was created in Nuke 11, that's why they are showing up. Everything should still work as expected if you ignore this error message though.

I would have to see your setup to understand the problem you are describing. I would be happy to take a look if you want to send it over.

The ZDefocus will convolve every pixel in the image, so even if it is in perfect focus the pixel will be softened slightly. This is normal. But if you are seeing something different maybe something else is going on.
 
 
0 # Caroline Voglaire 2018-05-28 08:40
Thanks!
It's a bit more than just softened. It's really blurred.
I am setting up the pipe for a CG tv Show for kids, and i'm pretty sure the director won't allow too much soften on his characters.
I surely can send you my set up for you to take a look. How can we do that? Since it's a "in progress" production, I can't put images here obviously!
 
 
0 # Jed Smith 2018-05-29 01:34
I'll send you pm on linkedin.
 
 
0 # Ben Mossman 2019-03-28 19:59
Quoting Caroline Voglaire:
In the other hand, I'm facing a concrete issue. After dealing with camera settings, focus distance etc... It seems to work really well (even with deep data rather than zdepth), but my supposed focused area is still a bit blurred. Actually, nothing is completely focused in the frame.


In case anyone has this issue the sharpness was fixed for me by switching the filter type to "disc" or "image", I had it set to bladed which didn't look like anything was in focus.
 
 
0 # Ahmed omran 2018-09-30 15:58
how to install mac osx
 
 
0 # Ben Louden 2019-01-31 14:57
Amazing node, truly awesome.

Just one issue for me - it doesn't seem to defocus the alpha, even with all settings as you'd expect. has anyone come across this / any troubleshooting tips ?

Cheers!

Ben
 
 
0 # Ben Louden 2019-01-31 14:57
Amazing node, truly awesome.

Just one issue for me - it doesn't seem to defocus the alpha, even with all settings as you'd expect. has anyone come across this / any troubleshooting tips ?

Cheers!

Ben
 
 
0 # Kenedy Torcatt 2021-08-19 04:53
Hi, I am curious if this is cmpatible with nuke 13 considering is now pythion 3, or will you update it? is amazing this plugin!

Thnaks in advance"
 
 
0 # Kenedy Torcatt 2021-08-19 04:53
Hi, I am curious if this is cmpatible with nuke 13 considering is now pythion 3, or will you update it? is amazing this plugin!

Thnaks in advance"
 
 
+5 # Peter Jansen 2022-07-25 12:08
Thank you for this amazing tool! One small suggestion - it seems that zDefocus will happily accept negative values for the "direct" map, and these seem to inform zDefocus about values in between the camera and the focal plane (with positive values going out past the focal plane). These are useful because then the "fill foreground" checkbox on zDefocus can help to properly defocus foreground objects. All I did to modify the expression was remove the fabs() in "coc" and "coc_px", and then inverted by multiplying by -1. Here's an image showing the difference https://imgur.com/a/TSXfgk7
 
 
0 # Ross Anderson 2023-10-17 12:34
Hey Peter,
The fix you did looks great!
Possbile you could provide the expressions you adjusted to get this to work? I'm not clear on what you edited.
Thanks!
 
 
0 # darren coombes 2023-01-17 22:44
does this need a camera to work ?
I can't get it to work properly.
 
 
0 # Artem Marchuk 2023-05-07 16:43
Hi, any idea why OpticalZDefocus produces this kind of noise all over the comp?
Screenshot:
https://www.dropbox.com/s/ppxqum94rig5clj/Screenshot%202023-05-07%20at%2019.24.27.png?dl=0
 
 
0 # Jannik Walzer 2023-08-21 15:48
hey! i noticed that the defocus explodes when the focal distance gets close to the focal length/100. Lets say when we have a 24mm lens, and the focus ist set to 2,4 cm, the values explode. It makes sense looking at the formula, but has anyone found a workaround? Awesome tool by the way
 

You have no rights to post comments

We have 7082 guests and 64 members online