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