Maya Depth of Field Viewport 2.0

Hi,
I was wondering if there was a way to access / modify the Viewport 2.0 Depth of Field effect. There is very little documentation about it. My first goal would be to make it more physically correct. ( Adjust blur amount to match an off-lline renderer ) Second make it work with transparent objects like in the attached image.


I have some OpenMaya 2 experience, though I assume this would be more a cpp override because of performance issues.
https://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__files_GUID_E171DC25_5750_4CA0_9A6C_A411EED1CE3E_htm This is what I found in the documentation. If any one has any tips / guides / articles how to approach this I would be really grateful.
Thanks!

Hey! I’m looking to do something very similar to this. Were you able to figure out how to achieve this?

Hi,
Kind of, I wrote a tool in python that picks up dof and jprototyped a physical dof node that recalculates the dof properly. I also found where maya stores the CoC values. I leanred some cpp so i`m rewriting it now since python sucks for viewport stuff :confused: Also maya has the near and close focus values totally off. They’re accessible thourh the api though. Regarding the per pixel dof - its a shader feature :confused: and maya straight-foward renderer is also quite limited in terms of post so the dof effect is… :slight_smile: yeah at least you can make it more responsive and physically accurate.
You can check my last reel:
https://vimeo.com/manage/videos/511273466

2 Likes

Ok so I rewrote the dofContext in c++ and merged the physicalDofNode into it.
You can check it out here:

Download:

Github:

Thanks!

2 Likes

Wow! That is cool ! and it is useful really

Will you sir release the source code of your DOF plugin helping to compile for elder version maya (like Maya 2018 / 2016)?

Hi MineClever,
Thank you for the kind words. I am not sure I am ready to release the source code yet since I did spent some time on this one - sorry. :frowning:
But I can compile for maya 2019 - 2018 if there is need for it.
Thanks

2 Likes

Hey, this is great. We’ve been trying to work out a good solution to viewport DOF ourselves and the documentation is pretty sparse. Can I clarify the current functionality of your plugin? I’ve downloaded it and tried it out and the depthOfFieldContext works as expected. I can click and set the focus distance for the camera, etc. But the plugin doesn’t appear to produce a visible difference in the viewport DOF compared Maya’s default DOF. Is this the expected functionality, or am I setting something incorrectly?

Hi Will,
So firstly yes, the difference is very subtle.
To work with dof you would need to have a textured scene with good lights to see it. Flat geo will not work well with this dof effect.
I`m recalculating the fStop value based on the simplified dof formula and coc setting.


You can find the math online. Also very important you need to work in cm so an average person will have around 185 maya units.
Then the math is a bit tricky since the dof equation has mm and cm you need to convert the distance to mm and afterwards back to cm when you want to set the values on the camera.

Then its just calculate the closes distance with MFnMesh.closestIntersection - check Chad’s APi videos for that (MPxContext).

Lastly I`m setting the MFnCamera setNearFocus and farFocusDistance which will change the camera fStop values to something like 0.238 which is below the GUI’s allowed values.

This was the easiest and most secure solution for my v.1.0.0 becasue I`m not messing with any internal settings - if you delete the keyframes on the camera everything will go back to stock settings.

Now from what I have researched maya viewport 2.0 is a straight - foward renderer so we will never have access to all the fancy stuff like render buffers so we have to stick to something like this:

image
This is what is happening and what I believe why the devs limitted the dof effect to what we have.

If you would like to get per pixel dof with alpha textures you would have to write your own shader for that i guess.
https://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_struct_m_h_w_render_1_1_m_frame_context_1_1_d_o_f_params_html
This is how they calculate it.

I’m also planning to release a small update to fix the edge inaccuracy which is driving me nuts X_x.

Hope that helps.

2 Likes

Hi Luky,

Yeah, that is really helpful, thanks. We’re really looking for a solution whereby the viewport DOF is reasonably representative of the final render DOF to allow previs/layout to set up cameras with some confidence. The limit on the DOF effect that you mention is, I think, what really gets in our way. We’re probably going to have to dig into Viewport 2 shader overrides. The “limitations” from the NVidia article aren’t really problems for use. We accept that the viewport doesn’t handle transparency well when it comes to DOF, also that extreme settings might cause the whole thing to fall apart.

Thanks again.

1 Like

Well , thank your implementation reference!