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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#ifndef SHURIKENCURVES_H
#define SHURIKENCURVES_H
#include "ParticleSystemParticle.h"
#include "PolynomialCurve.h"
#include "Runtime/Math/AnimationCurve.h"
struct MinMaxCurve;
// Some profile numbers from a run with 250,000 particles evaluating 3 velocity properties each on Intel i7-2600 CPU @ 3.4 GHz
// Scalar: 4.6 ms
// Optimized curve: 7.2 ms
// Random between 2 scalars: 9.5 ms
// Random between 2 curves: 9.5 ms
// Non-optimized curve: 10.0 ms
// Random between 2 non-optimized curves: 12.0 ms
enum ParticleSystemCurveEvalMode
{
kEMScalar,
kEMOptimized,
kEMOptimizedMinMax,
kEMSlow,
};
enum MinMaxCurveState
{
kMMCScalar = 0,
kMMCCurve = 1,
kMMCTwoCurves = 2,
kMMCTwoConstants = 3
};
struct MinMaxOptimizedPolyCurves
{
void Integrate();
void DoubleIntegrate();
Vector2f FindMinMaxIntegrated();
Vector2f FindMinMaxDoubleIntegrated();
OptimizedPolynomialCurve max;
OptimizedPolynomialCurve min;
};
inline float EvaluateIntegrated (const MinMaxOptimizedPolyCurves& curves, float t, float factor)
{
const float v0 = curves.min.EvaluateIntegrated (t);
const float v1 = curves.max.EvaluateIntegrated (t);
return Lerp (v0, v1, factor);
}
inline float EvaluateDoubleIntegrated (const MinMaxOptimizedPolyCurves& curves, float t, float factor)
{
const float v0 = curves.min.EvaluateDoubleIntegrated (t);
const float v1 = curves.max.EvaluateDoubleIntegrated (t);
return Lerp (v0, v1, factor);
}
struct MinMaxPolyCurves
{
void Integrate();
void DoubleIntegrate();
Vector2f FindMinMaxIntegrated();
Vector2f FindMinMaxDoubleIntegrated();
PolynomialCurve max;
PolynomialCurve min;
};
inline float EvaluateIntegrated (const MinMaxPolyCurves& curves, float t, float factor)
{
const float v0 = curves.min.EvaluateIntegrated (t);
const float v1 = curves.max.EvaluateIntegrated (t);
return Lerp (v0, v1, factor);
}
inline float EvaluateDoubleIntegrated (const MinMaxPolyCurves& curves, float t, float factor)
{
const float v0 = curves.min.EvaluateDoubleIntegrated (t);
const float v1 = curves.max.EvaluateDoubleIntegrated (t);
return Lerp (v0, v1, factor);
}
struct MinMaxAnimationCurves
{
bool SupportsProcedural ();
AnimationCurve max;
AnimationCurve min;
};
bool BuildCurves (MinMaxOptimizedPolyCurves& polyCurves, const MinMaxAnimationCurves& editorCurves, float scalar, short minMaxState);
void BuildCurves (MinMaxPolyCurves& polyCurves, const MinMaxAnimationCurves& editorCurves, float scalar, short minMaxState);
bool CurvesSupportProcedural (const MinMaxAnimationCurves& editorCurves, short minMaxState);
struct MinMaxCurve
{
MinMaxOptimizedPolyCurves polyCurves;
private:
float scalar; // Since scalar is baked into the optimized curve we use the setter function to modify it.
public:
short minMaxState; // see enum MinMaxCurveState
bool isOptimizedCurve;
MinMaxAnimationCurves editorCurves;
MinMaxCurve ();
inline float GetScalar() const { return scalar; }
inline void SetScalar(float value) { scalar = value; BuildCurves(polyCurves, editorCurves, scalar, minMaxState); }
bool IsOptimized () const { return isOptimizedCurve; }
bool UsesMinMax () const { return (minMaxState == kMMCTwoCurves) || (minMaxState == kMMCTwoConstants); }
DEFINE_GET_TYPESTRING (MinMaxCurve)
template<class TransferFunction>
void Transfer (TransferFunction& transfer);
Vector2f FindMinMax() const;
Vector2f FindMinMaxIntegrated() const;
Vector2f FindMinMaxDoubleIntegrated() const;
};
inline float EvaluateSlow (const MinMaxCurve& curve, float t, float factor)
{
const float v = curve.editorCurves.max.Evaluate(t) * curve.GetScalar ();
if (curve.minMaxState == kMMCTwoCurves)
return Lerp (curve.editorCurves.min.Evaluate(t) * curve.GetScalar (), v, factor);
else
return v;
}
template<ParticleSystemCurveEvalMode mode>
inline float Evaluate (const MinMaxCurve& curve, float t, float factor = 1.0F)
{
if(mode == kEMScalar)
{
return curve.GetScalar();
}
if(mode == kEMOptimized)
{
DebugAssert(curve.isOptimizedCurve);
return curve.polyCurves.max.Evaluate (t);
}
else if (mode == kEMOptimizedMinMax)
{
DebugAssert(curve.isOptimizedCurve);
const float v0 = curve.polyCurves.min.Evaluate (t);
const float v1 = curve.polyCurves.max.Evaluate (t);
return Lerp (v0, v1, factor);
}
else if (mode == kEMSlow)
{
return EvaluateSlow (curve, t, factor);
}
}
inline float Evaluate (const MinMaxCurve& curve, float t, float randomValue = 1.0F)
{
if (curve.minMaxState == kMMCScalar)
return curve.GetScalar ();
if (curve.minMaxState == kMMCTwoConstants)
return Lerp ( curve.editorCurves.min.GetKey(0).value * curve.GetScalar (),
curve.editorCurves.max.GetKey(0).value * curve.GetScalar (), randomValue);
DebugAssert(t <= 1.0F && t >= 0.0F);
if (curve.isOptimizedCurve)
return Evaluate<kEMOptimizedMinMax> (curve, t, randomValue);
else
return Evaluate<kEMSlow> (curve, t, randomValue);
}
struct DualMinMax3DPolyCurves
{
MinMaxOptimizedPolyCurves optX;
MinMaxOptimizedPolyCurves optY;
MinMaxOptimizedPolyCurves optZ;
MinMaxPolyCurves x;
MinMaxPolyCurves y;
MinMaxPolyCurves z;
};
#endif // SHURIKENCURVES_H
|