Comments and answers for "The algorithm of curve in Shuriken Particle System"
http://answers.unity.com/questions/438407/the-algorithm-of-curve-in-shuriken-particle-system.html
The latest comments and answers for the question "The algorithm of curve in Shuriken Particle System"Answer by Varaughe
http://answers.unity.com/answers/1754901/view.html
If you want to know what is the exact equation behind an AnimationCurve,
you should check [Runtime Curve Editor][1] (from Unity Asset Store).
The package replicates 100% the equation by which the Animation Curve built-in editor plots the curve.
Also the package supports visually editing of pairs of curves, which is used in the particle editor.
[1]: https://assetstore.unity.com/packages/tools/gui/runtime-curve-editor-11835Sat, 25 Jul 2020 17:09:25 GMTVaraugheComment by keenanwoodall on keenanwoodall's comment
http://answers.unity.com/comments/1575944/view.html
Gotcha, thanks for pointing me in the right direction.Wed, 28 Nov 2018 21:20:18 GMTkeenanwoodallComment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1575872/view.html
If you have noticed my answer is 5 years old. The weighted tangents is a relatively new feature which didn't exist back then. However according to [the documentation][1] it seems that the weight simply takes place of the "1/3" factor. Though you have to check the [weighted mode][2] when to use which weight value. I haven't used the weighted curves yet, so i can't tell for sure. As you can read in example in the documentation the default weight is "1/3" Which would make sense, given how the slope is provided.
<br>
Since the used weight depends on the weighted mode setting it becomes a bit nasty. You need conditional code to choose the right weight for each tangent. Currently i don't have time to dive into this again.
[1]: https://docs.unity3d.com/ScriptReference/$$anonymous$$eyframe-inWeight.html
[2]: https://docs.unity3d.com/ScriptReference/$$anonymous$$eyframe-weighted$$anonymous$$ode.htmlWed, 28 Nov 2018 17:26:45 GMTBunny83Comment by keenanwoodall on keenanwoodall's answer
http://answers.unity.com/comments/1575835/view.html
I'm trying to reverse engineer the animation curve for use in the job system (to modify meshes). I got it working by using the equation from [this post][1] but it doesn't work when the keyframes are in weighted mode. The equation is insanely large, so I have no idea how to modify it to support keyframes with custom weights. That brought me to your post. If I can figure out the positions of the inner points I can evaluate the curve with the standard bezier equation ins$$anonymous$$d of dealing with tangents.
Here's my implementation of the other post.
var at = keyA.time;
var av = keyA.value;
var aot = keyA.outTangent;
var bt = keyB.time;
var bv = keyB.value;
var bit = keyB.inTangent;
var a = (at * aot + at * bit - bt * aot - bt * bit - 2 * av + 2 * bv) / (at * at * at - bt * bt * bt + 3 * at * bt * bt - 3 * at * at * bt);
var b = (-at * at * aot - 2 * at * at * bit + 2 * bt * bt * aot + bt * bt * bit - at * bt * aot + at * bt * bit + 3 * at * av - 3 * at * bv + 3 * av * bt - 3 * bt * bv) / (at * at * at - bt * bt * bt + 3 * at * bt * bt - 3 * at * at * bt);
var c = (at * at * at * bit - bt * bt * bt * aot - at * bt * bt * aot - 2 * at * bt * bt * bit + 2 * at * at * bt * aot + at * at * bt * bit - 6 * at * av * bt + 6 * at * bt * bv) / (at * at * at - bt * bt * bt + 3 * at * bt * bt - 3 * at * at * bt);
var d = (at * bt * bt * bt * aot - at * at * bt * bt * aot + at * at * bt * bt * bit - at * at * at * bt * bit - av * bt * bt * bt + at * at * at * bv + 3 * at * av * bt * bt - 3 * at * at * bt * bv) / (at * at * at - bt * bt * bt + 3 * at * bt * bt - 3 * at * at * bt);
var value = a * t * t * t + b * t * t + c * t + d;
As you can see, it works fine as long as keyframes don't have a custom weight.
![Working][2]
I tried implementing your version like so:
var p1 = float2 (keyA.time, keyA.value);
var p4 = float2 (keyB.time, keyB.value);
var w = (p4.x - p1.x) / 3f;
var p2 = p1 + float2 (w, w * keyA.outTangent);
var p3 = p4 - float2 (w, w * keyB.inTangent);
var a1 = lerp (p1, p2, t);
var b1 = lerp (p2, p3, t);
var c1 = lerp (p3, p4, t);
var a2 = lerp (a1, b1, t);
var b2 = lerp (b1, c1, t);
var value = lerp (a2, b2, t).y;
I'm not super fluent in making bezier curves, but I'm pretty sure I did it correctly. However, the evaluation is clearly incorrect.
![NotWorking][3]
This curve might be a little easier to analyse:
![alt text][4]
Anyways, I'm curious if you have any ideas as to what I'm doing wrong.
[1]: http://answers.unity.com/answers/1136791/view.html
[2]: https://imgur.com/evfiYwm.png
[3]: https://imgur.com/5ZlOoT4.png
[4]: https://imgur.com/6XnLEUH.pngWed, 28 Nov 2018 15:55:18 GMTkeenanwoodallComment by crtapps on crtapps's answer
http://answers.unity.com/comments/442746/view.html
Thanks a lot Bunny:)Mon, 22 Apr 2013 01:31:12 GMTcrtappsComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/441167/view.html
The value of 3 just divides the whole length into 3 equal segments. first segment start to cp1, cp1 to cp2, cp2 to end.
I first tried a value of 1.0, then the whole distance then half and finally 1/3 ;)Fri, 19 Apr 2013 07:00:02 GMTBunny83Comment by crtapps on crtapps's answer
http://answers.unity.com/comments/441117/view.html
Hi Bunny, I think I have understood the meaning of 3.0f that the distance on x-axis divided. The formula of tangent is tan = y / x, Now that you known the value of tangent, and the max value of x, you need a concrete value of x in [0, max_x],so the 3.0f is just a scalar to help you get a concrete value of y, The final curve is the same no matter what the scalar is, right?Fri, 19 Apr 2013 03:53:50 GMTcrtappsComment by crtapps on crtapps's answer
http://answers.unity.com/comments/441083/view.html
WoW!Thanks very much Bunny!:D
There is a place I don't quite understand, Why the distance from end point to start point on x-axis need to be divided by 3.0f? What's the meaning of that?Fri, 19 Apr 2013 02:20:15 GMTcrtappsComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/440992/view.html
I've updated my answer ;)Thu, 18 Apr 2013 21:38:29 GMTBunny83Comment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/440570/view.html
You will always use a cubic bezier which will connect your "curve points". The outTangent of the first point will be used to deter$$anonymous$$e the first control point and the inTangent of the second point will deter$$anonymous$$e the second control point. If i can find some time, when i'm home, i might try it myself.
I'm still extending my inApp editor features and a curve editor would be nice ;)Thu, 18 Apr 2013 09:30:33 GMTBunny83Comment by crtapps on crtapps's answer
http://answers.unity.com/comments/440375/view.html
Thanks Bunny. But how do I know the control point number of a curve? In other words, How do i know the curve is Quadratic Bezier or Cubic Bezier or higher degree?Thu, 18 Apr 2013 01:56:18 GMTcrtappsComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/439991/view.html
Well, i would suggest to use the tangent value directly ;) I would have to do some tests myself, but that should do it.
So just go from your curvepoint x units to the right and x*outTangent upwards to get the control point. What x is the right one is hard to say without testing ;)Wed, 17 Apr 2013 15:08:10 GMTBunny83Comment by crtapps on crtapps's answer
http://answers.unity.com/comments/439871/view.html
Thanks for your answer Bunny. I have understood the inTangent and outTanget in AnimationCurve. But how do I calculate the control points from tangent? I did not find the relevant information from google. Could you give me some tips or links about this area? Thanks.Wed, 17 Apr 2013 11:00:36 GMTcrtappsComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/439225/view.html
As i said you have to calculate the control points yourself. The in and out tangent is **not**, [like stated in the docs][1], an angle in degree but the tangent of the desired angle. InTangent is positive when co$$anonymous$$g in from below and outTangent is positive when going up. a value of 0 is flat positiveInfinity represents an immediate step.
[1]: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$eyframe-inTangent.htmlTue, 16 Apr 2013 11:24:48 GMTBunny83Comment by crtapps on crtapps's answer
http://answers.unity.com/comments/439200/view.html
Another question, If the curves in Shuriken Particle System is Bezier, How do I apply the tangent parameter to the curve? e.g, If I changed the inTangent and outTangent member variable of $$anonymous$$eyframes in AnimationCurve(AnimationCurve.keys), I watched the curve changed ,but why? the formula of Cubic Bezier curves does not have the parameter of tanget, right?
Thanks.Tue, 16 Apr 2013 10:22:53 GMTcrtappsComment by crtapps on crtapps's answer
http://answers.unity.com/comments/438651/view.html
Thanks Bunny.It's very helpful for me.Mon, 15 Apr 2013 15:03:24 GMTcrtappsAnswer by Bunny83
http://answers.unity.com/answers/438613/view.html
The Shuriken Particle System just uses Unity's AnimationCurve class and the built-in editor. Yes they are bezier curves, but the control points are calculated by the "tangent angle".
***edit***
Finally had some time and i quickly created an editor window with a CurveField. This is the result:
![Curve][1]
Here's the most important part of my sample code:
float w = R.width;
float h = R.height;
var keys = curve.keys;
for(int i = 0; i < keys.Length-1;i++)
{
Keyframe K1 = keys[i];
Keyframe K2 = keys[i+1];
Vector2 start = new Vector2(K1.time*w,K1.value*h);
Vector2 end = new Vector2(K2.time*w,K2.value*h);
float d = (end.x-start.x) / 3.0f;
float a = h / w;
Vector2 st = start + new Vector2(d,d*a*K1.outTangent);
Vector2 et = end + new Vector2(-d,-d*a*K2.inTangent);
Drawing.BezierLineGL(start,st,end, et,Color.red,20);
}
So basically you just take 1/3 of the distance between two points on the x-axis as the x position of the control point. When your viewing area's aspect ratio differs from 1.0 you have to correct the y value accordingly (like i did).
So at the end you have a start point (start) two control points (st, et) and the end point (end) for each segment to draw a cubic bezier between two KeyFrames.
ps: R is a Rect which represents the drawing area's size.
[1]: /storage/temp/185268-curvesample.pngMon, 15 Apr 2013 14:14:11 GMTBunny83Comment by crtapps
http://answers.unity.com/comments/438534/view.html
No one know?:(Mon, 15 Apr 2013 10:41:57 GMTcrtapps