Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 86767d9

Browse files
committed
Fixed curve caching in volume; optimized curve CPU usage a bit
1 parent afe4b85 commit 86767d9

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

PostProcessing/Runtime/ParameterOverride.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,23 @@ protected internal override void OnEnable()
186186
value.Cache(int.MinValue);
187187
}
188188

189-
public override void Interp(Spline from, Spline to, float t)
189+
internal override void SetValue(ParameterOverride parameter)
190190
{
191-
int frameCount = Time.renderedFrameCount;
191+
base.SetValue(parameter);
192+
193+
if (value != null)
194+
value.Cache(Time.renderedFrameCount);
195+
}
192196

197+
public override void Interp(Spline from, Spline to, float t)
198+
{
193199
if (from == null || to == null)
194200
{
195201
base.Interp(from, to, t);
196202
return;
197203
}
198-
204+
205+
int frameCount = Time.renderedFrameCount;
199206
from.Cache(frameCount);
200207
to.Cache(frameCount);
201208

PostProcessing/Runtime/Utils/Spline.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public Spline(AnimationCurve curve, float zeroValue, bool loop, Vector2 bounds)
4040
cachedData = new float[k_Precision];
4141
}
4242

43+
// Note: it would be nice to have a way to check if a curve has changed in any way, that
44+
// would save quite a few CPU cycles instead of having to force cache it once per frame :/
4345
public void Cache(int frame)
4446
{
4547
// Only cache once per frame
@@ -63,22 +65,30 @@ public void Cache(int frame)
6365
}
6466

6567
for (int i = 0; i < k_Precision; i++)
66-
cachedData[i] = Evaluate((float)i * k_Step);
68+
cachedData[i] = Evaluate((float)i * k_Step, length);
6769

6870
frameCount = Time.renderedFrameCount;
6971
}
7072

71-
public float Evaluate(float t)
73+
public float Evaluate(float t, int length)
7274
{
73-
if (curve.length == 0)
75+
if (length == 0)
7476
return m_ZeroValue;
7577

76-
if (!m_Loop || curve.length == 1)
78+
if (!m_Loop || length == 1)
7779
return curve.Evaluate(t);
7880

7981
return m_InternalLoopingCurve.Evaluate(t);
8082
}
8183

84+
public float Evaluate(float t)
85+
{
86+
// Calling the length getter on a curve is expensive (!?) so it's better to cache its
87+
// length and call Evaluate(t, length) instead of getting the length for every call to
88+
// Evaluate(t)
89+
return Evaluate(t, curve.length);
90+
}
91+
8292
public override int GetHashCode()
8393
{
8494
unchecked

0 commit comments

Comments
 (0)