Unity-Technologies / com.unity.cinemachine

Smart camera tools for passionate creators
504 stars 117 forks source link

Changing vcam's FOV during a transition, there is a glitch #10

Open glabute opened 5 years ago

glabute commented 5 years ago

While transitioning from Vcam1 to Vcam2, and if changing Vcam1's FOV during that transition, there is a glitch in transition which happens at the time when FOVs of both cameras become equal.

LinkAgm commented 2 years ago

The interpolation of FOV is always wrong! Try to blend between two Vcams with different FOV; the values start to grow normally but do not reach the final weight and then abruptly change to the final result.

LinkAgm commented 2 years ago

I think the error is inside here https://github.com/Unity-Technologies/com.unity.cinemachine/blob/ab6e86a781ab7d1f25472a1fbef7ec21cc87aeca/Runtime/Core/CameraState.cs#L432

LinkAgm commented 2 years ago

https://user-images.githubusercontent.com/52554257/149371027-cdb79d42-e3eb-42f5-83dd-1df50d645784.mp4 One Vcam with FOV 50 and the other with FOV 60.

LinkAgm commented 2 years ago

I really appreciate the fact that is an open package. I temporarily changed that function with this:

   static float InterpolateFOV(float fovA, float fovB, float dA, float dB, float t)\n
    {
        // We interpolate shot height
        //float hA = dA * 2f * Mathf.Tan(fovA * Mathf.Deg2Rad / 2f);
        //float hB = dB * 2f * Mathf.Tan(fovB * Mathf.Deg2Rad / 2f);
        //float h = Mathf.Lerp(hA, hB, t);
        //float fov = 179f;
        //float d = Mathf.Lerp(dA, dB, t);
        //if (d > UnityVectorExtensions.Epsilon)
        //    fov = 2f * Mathf.Atan(h / (2 * d)) * Mathf.Rad2Deg;
        return Mathf.Lerp(fovA, fovB, t); /*return Mathf.Clamp(fov, Mathf.Min(fovA, fovB), Mathf.Max(fovA, fovB));*/
    }
glabute commented 2 years ago

Thanks for your remarks.

The reason that the FOV interpolation is not implemented as a simple lerp is that the visual effect of a linear lerp is nonlinear in appearance because the effect on image size is not linearly related to the FOV. Instead, we do a linear lerp on the target size, which gives a better result.

I can't repro the pop that you describe. When I blend vcams with different FOVs it always blends smoothly. I suspect that the change to CM that you made is compensating for an issue elsewhere in your project.