You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

  1. using System;
  2. namespace UnityEngine.PostProcessing
  3. {
  4. // Small wrapper on top of AnimationCurve to handle zero-key curves and keyframe looping
  5. [Serializable]
  6. public sealed class ColorGradingCurve
  7. {
  8. public AnimationCurve curve;
  9. [SerializeField]
  10. bool m_Loop;
  11. [SerializeField]
  12. float m_ZeroValue;
  13. [SerializeField]
  14. float m_Range;
  15. AnimationCurve m_InternalLoopingCurve;
  16. public ColorGradingCurve(AnimationCurve curve, float zeroValue, bool loop, Vector2 bounds)
  17. {
  18. this.curve = curve;
  19. m_ZeroValue = zeroValue;
  20. m_Loop = loop;
  21. m_Range = bounds.magnitude;
  22. }
  23. public void Cache()
  24. {
  25. if (!m_Loop)
  26. return;
  27. var length = curve.length;
  28. if (length < 2)
  29. return;
  30. if (m_InternalLoopingCurve == null)
  31. m_InternalLoopingCurve = new AnimationCurve();
  32. var prev = curve[length - 1];
  33. prev.time -= m_Range;
  34. var next = curve[0];
  35. next.time += m_Range;
  36. m_InternalLoopingCurve.keys = curve.keys;
  37. m_InternalLoopingCurve.AddKey(prev);
  38. m_InternalLoopingCurve.AddKey(next);
  39. }
  40. public float Evaluate(float t)
  41. {
  42. if (curve.length == 0)
  43. return m_ZeroValue;
  44. if (!m_Loop || curve.length == 1)
  45. return curve.Evaluate(t);
  46. return m_InternalLoopingCurve.Evaluate(t);
  47. }
  48. }
  49. }