Search Unity

Question Cinemachine Focal Length to Camera fov inconsistency?

Discussion in 'Cinemachine' started by dfarjoun, Jul 15, 2020.

  1. dfarjoun

    dfarjoun

    Joined:
    Aug 6, 2017
    Posts:
    42
    Hi,
    I have a slider for focal length and should send these values to the "cinemachine" camera.

    I've seen lot's of print screens about cinemachine these days. All of them refer to field of view.

    When I keep cinemachine active, the slider is related to Focal Length.
    When I disable cinemachine vcam, the slider refers to Field of View.

    So if I setup the Focal Length slider to change the camera on start, it looks to get the field of view and not the focal length.
    Ex: 15mm lens will transfer to super narrow field of view (super zoomed camera).
    Later on, inside the game, it can get the normal Focal Length and loads normally.

    I tried to access via code and I see only the FOV option:

    Something like.. vcam.m_Lens.FieldOfView = ....

    Is there a way to pass without conversion the focal length value to the cinemachine focal length without these conversions?

    Thanks!!
     
    Last edited: Jul 16, 2020
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Hi @dfarjoun. The Cinemachine API only accepts FOV. You have to manually convert from focal length to FOV before sending the value to Cinemachine. Here is some code to make that conversion:
    Code (CSharp):
    1.     float FocalLengthToVerticalFOV(float _focalLength, float sensorSize)
    2.     {
    3.         if (_focalLength < 0.001f)
    4.             return 180f;
    5.         return Mathf.Rad2Deg * 2.0f * Mathf.Atan(sensorSize * 0.5f / _focalLength);
    6.     }
     
  3. dfarjoun

    dfarjoun

    Joined:
    Aug 6, 2017
    Posts:
    42
    Thank you very much! I'll give it a try soon.
    Now I'm facing with another problem with the quality settings of Depth of Field. I'll create a new post now.
     
  4. mauriciofelippe

    mauriciofelippe

    Joined:
    Aug 9, 2017
    Posts:
    28
    I'm struggling in the same problem, your code asks for sensorSize as float, but the sensorSize is a Vector2, how you calculate it?

    ps: aspect don't work as sensorSize.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    It's the vertical sensor size. Use SensorSize.y.
     
    mauriciofelippe likes this.