Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to calculate the correct DOF focus distance?

Discussion in 'Image Effects' started by kankane, Apr 4, 2023.

  1. kankane

    kankane

    Joined:
    Feb 22, 2013
    Posts:
    23
    I have an AR project where I would like to use the DOF effect for capturing photos of the AR content. When the user taps the screen, I calculate the distance to the object, project it onto the
    camera.transform.forward
    vector and use that as the focus distance for the DOF effect. And everything is blurry. If I set the DOF focus distance to around 1.8x of the actual world distance, I get something that looks correct. The focal length of the DOF effect matches the MainCamera focal length, but the MainCamera isn't Physical though (AR library limitations).

    How can I match set the correct DOF focus distance?

    I am using Built-in render pipeline, PP 3.2.2, Unity 2021.3.21.