VFXExpressionMath.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. using System;
  2. using System.Linq;
  3. using System.Runtime.CompilerServices;
  4. using UnityEngine;
  5. using UnityEngine.VFX;
  6. namespace UnityEditor.VFX
  7. {
  8. class VFXExpressionCos : VFXExpressionUnaryFloatOperation
  9. {
  10. public VFXExpressionCos() : this(VFXValue<float>.Default) { }
  11. public VFXExpressionCos(VFXExpression parent) : base(parent, VFXExpressionOperation.Cos)
  12. {
  13. }
  14. sealed protected override string GetUnaryOperationCode(string x)
  15. {
  16. return string.Format("cos({0})", x);
  17. }
  18. sealed protected override float ProcessUnaryOperation(float input)
  19. {
  20. return Mathf.Cos(input);
  21. }
  22. }
  23. class VFXExpressionSin : VFXExpressionUnaryFloatOperation
  24. {
  25. public VFXExpressionSin() : this(VFXValue<float>.Default) { }
  26. public VFXExpressionSin(VFXExpression parent) : base(parent, VFXExpressionOperation.Sin)
  27. {
  28. }
  29. sealed protected override string GetUnaryOperationCode(string x)
  30. {
  31. return string.Format("sin({0})", x);
  32. }
  33. sealed protected override float ProcessUnaryOperation(float input)
  34. {
  35. return Mathf.Sin(input);
  36. }
  37. }
  38. class VFXExpressionTan : VFXExpressionUnaryFloatOperation
  39. {
  40. public VFXExpressionTan() : this(VFXValue<float>.Default) { }
  41. public VFXExpressionTan(VFXExpression parent) : base(parent, VFXExpressionOperation.Tan)
  42. {
  43. }
  44. sealed protected override string GetUnaryOperationCode(string x)
  45. {
  46. return string.Format("tan({0})", x);
  47. }
  48. sealed protected override float ProcessUnaryOperation(float input)
  49. {
  50. return Mathf.Tan(input);
  51. }
  52. }
  53. class VFXExpressionACos : VFXExpressionUnaryFloatOperation
  54. {
  55. public VFXExpressionACos() : this(VFXValue<float>.Default) { }
  56. public VFXExpressionACos(VFXExpression parent) : base(parent, VFXExpressionOperation.ACos)
  57. {
  58. }
  59. sealed protected override string GetUnaryOperationCode(string x)
  60. {
  61. return string.Format("acos({0})", x);
  62. }
  63. sealed protected override float ProcessUnaryOperation(float input)
  64. {
  65. return Mathf.Acos(input);
  66. }
  67. }
  68. class VFXExpressionASin : VFXExpressionUnaryFloatOperation
  69. {
  70. public VFXExpressionASin() : this(VFXValue<float>.Default) { }
  71. public VFXExpressionASin(VFXExpression parent) : base(parent, VFXExpressionOperation.ASin)
  72. {
  73. }
  74. sealed protected override string GetUnaryOperationCode(string x)
  75. {
  76. return string.Format("asin({0})", x);
  77. }
  78. sealed protected override float ProcessUnaryOperation(float input)
  79. {
  80. return Mathf.Asin(input);
  81. }
  82. }
  83. class VFXExpressionATan : VFXExpressionUnaryFloatOperation
  84. {
  85. public VFXExpressionATan() : this(VFXValue<float>.Default) { }
  86. public VFXExpressionATan(VFXExpression parent) : base(parent, VFXExpressionOperation.ATan)
  87. {
  88. }
  89. sealed protected override string GetUnaryOperationCode(string x)
  90. {
  91. return string.Format("atan({0})", x);
  92. }
  93. sealed protected override float ProcessUnaryOperation(float input)
  94. {
  95. return Mathf.Atan(input);
  96. }
  97. }
  98. class VFXExpressionLog2 : VFXExpressionUnaryFloatOperation
  99. {
  100. public VFXExpressionLog2() : this(VFXValue<float>.Default) { }
  101. public VFXExpressionLog2(VFXExpression parent) : base(parent, VFXExpressionOperation.Log2)
  102. {
  103. }
  104. sealed protected override string GetUnaryOperationCode(string x)
  105. {
  106. return string.Format("log2({0})", x);
  107. }
  108. sealed protected override float ProcessUnaryOperation(float input)
  109. {
  110. return Mathf.Log(input, 2.0f);
  111. }
  112. }
  113. class VFXExpressionAbs : VFXExpressionUnaryNumericOperation
  114. {
  115. public VFXExpressionAbs() : this(VFXValue<float>.Default) { }
  116. public VFXExpressionAbs(VFXExpression parent) : base(parent, VFXExpressionOperation.Abs)
  117. {
  118. if (parent.valueType == VFXValueType.Uint32)
  119. throw new NotImplementedException("Unexpected type for VFXExpressionAbs");
  120. }
  121. sealed protected override string GetUnaryOperationCode(string x, VFXValueType type)
  122. {
  123. if (type == VFXValueType.Uint32)
  124. throw new NotImplementedException("Unexpected type for VFXExpressionAbs");
  125. return string.Format("abs({0})", x);
  126. }
  127. protected override uint ProcessUnaryOperation(uint input)
  128. {
  129. throw new NotImplementedException();
  130. }
  131. protected override int ProcessUnaryOperation(int input)
  132. {
  133. return Mathf.Abs(input);
  134. }
  135. protected override bool ProcessUnaryOperation(bool input)
  136. {
  137. throw new NotImplementedException();
  138. }
  139. sealed protected override float ProcessUnaryOperation(float input)
  140. {
  141. return Mathf.Abs(input);
  142. }
  143. }
  144. class VFXExpressionSign : VFXExpressionUnaryNumericOperation
  145. {
  146. public VFXExpressionSign() : this(VFXValue<float>.Default) { }
  147. public VFXExpressionSign(VFXExpression parent) : base(parent, VFXExpressionOperation.Sign)
  148. {
  149. if (parent.valueType == VFXValueType.Uint32)
  150. throw new NotImplementedException("Unexpected type for VFXExpressionSign");
  151. }
  152. sealed protected override string GetUnaryOperationCode(string x, VFXValueType type)
  153. {
  154. if (type == VFXValueType.Uint32)
  155. throw new NotImplementedException("Unexpected type for VFXExpressionSign");
  156. return string.Format("sign({0})", x);
  157. }
  158. protected override uint ProcessUnaryOperation(uint input)
  159. {
  160. throw new NotImplementedException();
  161. }
  162. protected override int ProcessUnaryOperation(int input)
  163. {
  164. return (input > 0 ? 1 : 0) - (input < 0 ? 1 : 0);
  165. }
  166. sealed protected override float ProcessUnaryOperation(float input)
  167. {
  168. return (input > 0.0f ? 1.0f : 0.0f) - (input < 0.0f ? 1.0f : 0.0f);
  169. }
  170. protected override bool ProcessUnaryOperation(bool input)
  171. {
  172. throw new NotImplementedException();
  173. }
  174. }
  175. class VFXExpressionSaturate : VFXExpressionUnaryFloatOperation
  176. {
  177. public VFXExpressionSaturate() : this(VFXValue<float>.Default) { }
  178. public VFXExpressionSaturate(VFXExpression parent) : base(parent, VFXExpressionOperation.Saturate)
  179. {
  180. if (!IsFloatValueType(parent.valueType))
  181. throw new InvalidOperationException("Unexpected VFXExpressionSaturate type with parent " + parent.valueType);
  182. }
  183. sealed protected override string GetUnaryOperationCode(string x)
  184. {
  185. return string.Format("saturate({0})", x);
  186. }
  187. sealed protected override float ProcessUnaryOperation(float input)
  188. {
  189. return Mathf.Clamp01(input);
  190. }
  191. }
  192. class VFXExpressionCeil : VFXExpressionUnaryFloatOperation
  193. {
  194. public VFXExpressionCeil() : this(VFXValue<float>.Default) { }
  195. public VFXExpressionCeil(VFXExpression parent) : base(parent, VFXExpressionOperation.Ceil)
  196. {
  197. if (!IsFloatValueType(parent.valueType))
  198. throw new InvalidOperationException("Unexpected VFXExpressionCeil type with parent " + parent.valueType);
  199. }
  200. sealed protected override string GetUnaryOperationCode(string x)
  201. {
  202. return string.Format("ceil({0})", x);
  203. }
  204. sealed protected override float ProcessUnaryOperation(float input)
  205. {
  206. return Mathf.Ceil(input);
  207. }
  208. }
  209. class VFXExpressionRound : VFXExpressionUnaryFloatOperation
  210. {
  211. public VFXExpressionRound() : this(VFXValue<float>.Default) { }
  212. public VFXExpressionRound(VFXExpression parent) : base(parent, VFXExpressionOperation.Round)
  213. {
  214. if (!IsFloatValueType(parent.valueType))
  215. throw new InvalidOperationException("Unexpected VFXExpressionRound type with parent " + parent.valueType);
  216. }
  217. sealed protected override string GetUnaryOperationCode(string x)
  218. {
  219. return string.Format("round({0})", x);
  220. }
  221. sealed protected override float ProcessUnaryOperation(float input)
  222. {
  223. return Mathf.Round(input);
  224. }
  225. }
  226. class VFXExpressionFrac : VFXExpressionUnaryFloatOperation
  227. {
  228. public VFXExpressionFrac() : this(VFXValue<float>.Default) { }
  229. public VFXExpressionFrac(VFXExpression parent) : base(parent, VFXExpressionOperation.Frac)
  230. {
  231. if (!IsFloatValueType(parent.valueType))
  232. throw new InvalidOperationException("Unexpected VFXExpressionFrac type with parent " + parent.valueType);
  233. }
  234. sealed protected override string GetUnaryOperationCode(string x)
  235. {
  236. return string.Format("frac({0})", x);
  237. }
  238. sealed protected override float ProcessUnaryOperation(float input)
  239. {
  240. return Mathf.Repeat(input, 1.0f);
  241. }
  242. }
  243. class VFXExpressionFloor : VFXExpressionUnaryFloatOperation
  244. {
  245. public VFXExpressionFloor() : this(VFXValue<float>.Default) { }
  246. public VFXExpressionFloor(VFXExpression parent) : base(parent, VFXExpressionOperation.Floor)
  247. {
  248. if (!IsFloatValueType(parent.valueType))
  249. throw new InvalidOperationException("Unexpected VFXExpressionFloor type with parent " + parent.valueType);
  250. }
  251. sealed protected override string GetUnaryOperationCode(string x)
  252. {
  253. return string.Format("floor({0})", x);
  254. }
  255. sealed protected override float ProcessUnaryOperation(float input)
  256. {
  257. return Mathf.Floor(input);
  258. }
  259. }
  260. class VFXExpressionAdd : VFXExpressionBinaryNumericOperation
  261. {
  262. public VFXExpressionAdd() : this(VFXValue<float>.Default, VFXValue<float>.Default)
  263. {
  264. }
  265. public VFXExpressionAdd(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Add)
  266. {
  267. }
  268. protected override VFXExpression Reduce(VFXExpression[] reducedParents)
  269. {
  270. var zero = VFXOperatorUtility.ZeroExpression[reducedParents[0].valueType];
  271. if (zero.Equals(reducedParents[0]))
  272. return reducedParents[1];
  273. if (zero.Equals(reducedParents[1]))
  274. return reducedParents[0];
  275. return base.Reduce(reducedParents);
  276. }
  277. sealed protected override string GetBinaryOperationCode(string left, string right, VFXValueType type)
  278. {
  279. return string.Format("{0} + {1}", left, right);
  280. }
  281. sealed protected override float ProcessBinaryOperation(float left, float right)
  282. {
  283. return left + right;
  284. }
  285. sealed protected override int ProcessBinaryOperation(int left, int right)
  286. {
  287. return left + right;
  288. }
  289. sealed protected override uint ProcessBinaryOperation(uint left, uint right)
  290. {
  291. return left + right;
  292. }
  293. protected override bool ProcessBinaryOperation(bool left, bool right)
  294. {
  295. throw new NotImplementedException();
  296. }
  297. }
  298. class VFXExpressionMul : VFXExpressionBinaryNumericOperation
  299. {
  300. public VFXExpressionMul() : this(VFXValue<float>.Default, VFXValue<float>.Default)
  301. {
  302. }
  303. public VFXExpressionMul(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Mul)
  304. {
  305. }
  306. protected override VFXExpression Reduce(VFXExpression[] reducedParents)
  307. {
  308. var zero = VFXOperatorUtility.ZeroExpression[reducedParents[0].valueType];
  309. if (zero.Equals(reducedParents[0]) || zero.Equals(reducedParents[1]))
  310. return zero;
  311. var one = VFXOperatorUtility.OneExpression[reducedParents[0].valueType];
  312. if (one.Equals(reducedParents[0]))
  313. return reducedParents[1];
  314. if (one.Equals(reducedParents[1]))
  315. return reducedParents[0];
  316. return base.Reduce(reducedParents);
  317. }
  318. sealed protected override float ProcessBinaryOperation(float left, float right)
  319. {
  320. return left * right;
  321. }
  322. sealed protected override int ProcessBinaryOperation(int left, int right)
  323. {
  324. return left * right;
  325. }
  326. sealed protected override uint ProcessBinaryOperation(uint left, uint right)
  327. {
  328. return left * right;
  329. }
  330. protected override bool ProcessBinaryOperation(bool left, bool right)
  331. {
  332. throw new NotImplementedException();
  333. }
  334. sealed protected override string GetBinaryOperationCode(string left, string right, VFXValueType type)
  335. {
  336. return string.Format("{0} * {1}", left, right);
  337. }
  338. }
  339. class VFXExpressionDivide : VFXExpressionBinaryNumericOperation
  340. {
  341. public VFXExpressionDivide() : this(VFXValue<float>.Default, VFXValue<float>.Default)
  342. {
  343. }
  344. public VFXExpressionDivide(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Divide)
  345. {
  346. }
  347. protected override VFXExpression Reduce(VFXExpression[] reducedParents)
  348. {
  349. var zero = VFXOperatorUtility.ZeroExpression[reducedParents[0].valueType];
  350. if (zero.Equals(reducedParents[0]))
  351. return zero;
  352. var one = VFXOperatorUtility.OneExpression[reducedParents[0].valueType];
  353. if (one.Equals(reducedParents[1]))
  354. return reducedParents[0];
  355. return base.Reduce(reducedParents);
  356. }
  357. sealed protected override float ProcessBinaryOperation(float left, float right)
  358. {
  359. return left / right;
  360. }
  361. sealed protected override int ProcessBinaryOperation(int left, int right)
  362. {
  363. if (right == 0)
  364. return 0;
  365. return left / right;
  366. }
  367. sealed protected override uint ProcessBinaryOperation(uint left, uint right)
  368. {
  369. if (right == 0u)
  370. return 0u;
  371. return left / right;
  372. }
  373. protected override bool ProcessBinaryOperation(bool left, bool right)
  374. {
  375. throw new NotImplementedException();
  376. }
  377. sealed protected override string GetBinaryOperationCode(string left, string right, VFXValueType type)
  378. {
  379. return string.Format("{0} / {1}", left, right);
  380. }
  381. }
  382. class VFXExpressionSubtract : VFXExpressionBinaryNumericOperation
  383. {
  384. public VFXExpressionSubtract() : this(VFXValue<float>.Default, VFXValue<float>.Default)
  385. {
  386. }
  387. public VFXExpressionSubtract(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Subtract)
  388. {
  389. }
  390. protected override VFXExpression Reduce(VFXExpression[] reducedParents)
  391. {
  392. var zero = VFXOperatorUtility.ZeroExpression[reducedParents[0].valueType];
  393. if (zero.Equals(reducedParents[1]))
  394. return reducedParents[0];
  395. return base.Reduce(reducedParents);
  396. }
  397. sealed protected override float ProcessBinaryOperation(float left, float right)
  398. {
  399. return left - right;
  400. }
  401. sealed protected override int ProcessBinaryOperation(int left, int right)
  402. {
  403. return left - right;
  404. }
  405. sealed protected override uint ProcessBinaryOperation(uint left, uint right)
  406. {
  407. return left - right;
  408. }
  409. protected override bool ProcessBinaryOperation(bool left, bool right)
  410. {
  411. throw new NotImplementedException();
  412. }
  413. sealed protected override string GetBinaryOperationCode(string left, string right, VFXValueType type)
  414. {
  415. return string.Format("{0} - {1}", left, right);
  416. }
  417. }
  418. class VFXExpressionMin : VFXExpressionBinaryNumericOperation
  419. {
  420. public VFXExpressionMin() : this(VFXValue<float>.Default, VFXValue<float>.Default)
  421. {
  422. }
  423. public VFXExpressionMin(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Min)
  424. {
  425. }
  426. sealed protected override float ProcessBinaryOperation(float left, float right)
  427. {
  428. return Mathf.Min(left, right);
  429. }
  430. protected override int ProcessBinaryOperation(int left, int right)
  431. {
  432. return Mathf.Min(left, right);
  433. }
  434. protected override uint ProcessBinaryOperation(uint left, uint right)
  435. {
  436. return left < right ? left : right;
  437. }
  438. protected override bool ProcessBinaryOperation(bool left, bool right)
  439. {
  440. return left ? right : left;
  441. }
  442. sealed protected override string GetBinaryOperationCode(string left, string right, VFXValueType type)
  443. {
  444. if (type == VFXValueType.Uint32)
  445. return string.Format("{0} < {1} ? {0} : {1}", left, right);
  446. return string.Format("min({0}, {1})", left, right);
  447. }
  448. protected override VFXExpression Reduce(VFXExpression[] reducedParents)
  449. {
  450. VFXExpression inputSaturateExpression = null;
  451. if (VFXExpressionMax.CanBeReducedToSaturate(this, reducedParents, out inputSaturateExpression))
  452. {
  453. return new VFXExpressionSaturate(inputSaturateExpression);
  454. }
  455. return base.Reduce(reducedParents);
  456. }
  457. }
  458. class VFXExpressionMax : VFXExpressionBinaryNumericOperation
  459. {
  460. public VFXExpressionMax() : this(VFXValue<float>.Default, VFXValue<float>.Default)
  461. {
  462. }
  463. public VFXExpressionMax(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Max)
  464. {
  465. }
  466. sealed protected override float ProcessBinaryOperation(float left, float right)
  467. {
  468. return Mathf.Max(left, right);
  469. }
  470. protected override int ProcessBinaryOperation(int left, int right)
  471. {
  472. return Mathf.Max(left, right);
  473. }
  474. protected override uint ProcessBinaryOperation(uint left, uint right)
  475. {
  476. return left > right ? left : right;
  477. }
  478. protected override bool ProcessBinaryOperation(bool left, bool right)
  479. {
  480. return left ? left : right;
  481. }
  482. protected override string GetBinaryOperationCode(string left, string right, VFXValueType type)
  483. {
  484. if (type == VFXValueType.Uint32)
  485. return string.Format("{0} > {1} ? {0} : {1}", left, right);
  486. return string.Format("max({0}, {1})", left, right);
  487. }
  488. static public bool CanBeReducedToSaturate(VFXExpression current, VFXExpression[] reducedParents, out VFXExpression inputValueRef)
  489. {
  490. inputValueRef = null;
  491. var valueType = current.valueType;
  492. if (reducedParents.Length != 2 || !VFXExpression.IsFloatValueType(valueType))
  493. return false;
  494. var one = VFXOperatorUtility.OneExpression[valueType];
  495. var zero = VFXOperatorUtility.ZeroExpression[valueType];
  496. Type searchInnerFunctionType = null;
  497. VFXExpression searchInnerValueFirstLevel = null;
  498. VFXExpression searchInnerValueSecondLevel = null;
  499. if (current is VFXExpressionMax)
  500. {
  501. searchInnerFunctionType = typeof(VFXExpressionMin);
  502. searchInnerValueFirstLevel = zero;
  503. searchInnerValueSecondLevel = one;
  504. }
  505. else if (current is VFXExpressionMin)
  506. {
  507. searchInnerFunctionType = typeof(VFXExpressionMax);
  508. searchInnerValueFirstLevel = one;
  509. searchInnerValueSecondLevel = zero;
  510. }
  511. else
  512. {
  513. return false;
  514. }
  515. var minReferenceExpected = reducedParents.FirstOrDefault(o => o.GetType() == searchInnerFunctionType);
  516. var firstValueExpected = reducedParents.FirstOrDefault(o => o == searchInnerValueFirstLevel);
  517. if (minReferenceExpected != null && firstValueExpected != null)
  518. {
  519. var indexOf = Array.IndexOf(minReferenceExpected.parents, searchInnerValueSecondLevel);
  520. if (indexOf != -1)
  521. {
  522. var otherIndexOf = (indexOf + 1) % 2;
  523. inputValueRef = minReferenceExpected.parents[otherIndexOf];
  524. return true;
  525. }
  526. }
  527. return false;
  528. }
  529. protected override VFXExpression Reduce(VFXExpression[] reducedParents)
  530. {
  531. VFXExpression inputSaturateExpression = null;
  532. if (CanBeReducedToSaturate(this, reducedParents, out inputSaturateExpression))
  533. {
  534. return new VFXExpressionSaturate(inputSaturateExpression);
  535. }
  536. return base.Reduce(reducedParents);
  537. }
  538. }
  539. class VFXExpressionPow : VFXExpressionBinaryFloatOperation
  540. {
  541. public VFXExpressionPow() : this(VFXValue<float>.Default, VFXValue<float>.Default)
  542. {
  543. }
  544. public VFXExpressionPow(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.Pow)
  545. {
  546. }
  547. sealed protected override float ProcessBinaryOperation(float left, float right)
  548. {
  549. return Mathf.Pow(left, right);
  550. }
  551. sealed protected override string GetBinaryOperationCode(string left, string right)
  552. {
  553. return string.Format("pow({0}, {1})", left, right);
  554. }
  555. }
  556. class VFXExpressionATan2 : VFXExpressionBinaryFloatOperation
  557. {
  558. public VFXExpressionATan2() : this(VFXValue<float>.Default, VFXValue<float>.Default)
  559. {
  560. }
  561. public VFXExpressionATan2(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.ATan2)
  562. {
  563. }
  564. sealed protected override float ProcessBinaryOperation(float left, float right)
  565. {
  566. return Mathf.Atan2(left, right);
  567. }
  568. sealed protected override string GetBinaryOperationCode(string left, string right)
  569. {
  570. return string.Format("atan2({0}, {1})", left, right);
  571. }
  572. }
  573. class VFXExpressionBitwiseLeftShift : VFXExpressionBinaryUIntOperation
  574. {
  575. public VFXExpressionBitwiseLeftShift()
  576. : this(VFXValue<uint>.Default, VFXValue<uint>.Default)
  577. {
  578. }
  579. public VFXExpressionBitwiseLeftShift(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.BitwiseLeftShift)
  580. {
  581. }
  582. sealed protected override uint ProcessBinaryOperation(uint left, uint right)
  583. {
  584. return left << (int)right;
  585. }
  586. sealed protected override string GetBinaryOperationCode(string left, string right)
  587. {
  588. return string.Format("{0} << {1}", left, right);
  589. }
  590. }
  591. class VFXExpressionBitwiseRightShift : VFXExpressionBinaryUIntOperation
  592. {
  593. public VFXExpressionBitwiseRightShift() : this(VFXValue<uint>.Default, VFXValue<uint>.Default)
  594. {
  595. }
  596. public VFXExpressionBitwiseRightShift(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.BitwiseRightShift)
  597. {
  598. }
  599. sealed protected override uint ProcessBinaryOperation(uint left, uint right)
  600. {
  601. return left >> (int)right;
  602. }
  603. sealed protected override string GetBinaryOperationCode(string left, string right)
  604. {
  605. return string.Format("{0} >> {1}", left, right);
  606. }
  607. }
  608. class VFXExpressionBitwiseOr : VFXExpressionBinaryUIntOperation
  609. {
  610. public VFXExpressionBitwiseOr() : this(VFXValue<uint>.Default, VFXValue<uint>.Default)
  611. {
  612. }
  613. public VFXExpressionBitwiseOr(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.BitwiseOr)
  614. {
  615. }
  616. sealed protected override uint ProcessBinaryOperation(uint left, uint right)
  617. {
  618. return left | right;
  619. }
  620. sealed protected override string GetBinaryOperationCode(string left, string right)
  621. {
  622. return string.Format("{0} | {1}", left, right);
  623. }
  624. }
  625. class VFXExpressionBitwiseAnd : VFXExpressionBinaryUIntOperation
  626. {
  627. public VFXExpressionBitwiseAnd() : this(VFXValue<uint>.Default, VFXValue<uint>.Default)
  628. {
  629. }
  630. public VFXExpressionBitwiseAnd(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.BitwiseAnd)
  631. {
  632. }
  633. sealed protected override uint ProcessBinaryOperation(uint left, uint right)
  634. {
  635. return left & right;
  636. }
  637. sealed protected override string GetBinaryOperationCode(string left, string right)
  638. {
  639. return string.Format("{0} & {1}", left, right);
  640. }
  641. }
  642. class VFXExpressionBitwiseXor : VFXExpressionBinaryUIntOperation
  643. {
  644. public VFXExpressionBitwiseXor() : this(VFXValue<uint>.Default, VFXValue<uint>.Default)
  645. {
  646. }
  647. public VFXExpressionBitwiseXor(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.BitwiseXor)
  648. {
  649. }
  650. sealed protected override uint ProcessBinaryOperation(uint left, uint right)
  651. {
  652. return left ^ right;
  653. }
  654. sealed protected override string GetBinaryOperationCode(string left, string right)
  655. {
  656. return string.Format("{0} ^ {1}", left, right);
  657. }
  658. }
  659. class VFXExpressionBitwiseComplement : VFXExpressionUnaryUIntOperation
  660. {
  661. public VFXExpressionBitwiseComplement() : this(VFXValue<uint>.Default)
  662. {
  663. }
  664. public VFXExpressionBitwiseComplement(VFXExpression parent) : base(parent, VFXExpressionOperation.BitwiseComplement)
  665. {
  666. }
  667. sealed protected override uint ProcessUnaryOperation(uint input)
  668. {
  669. return ~input;
  670. }
  671. sealed protected override string GetUnaryOperationCode(string x)
  672. {
  673. return string.Format("~{0}", x);
  674. }
  675. }
  676. class VFXExpressionLogicalAnd : VFXExpressionBinaryBoolOperation
  677. {
  678. public VFXExpressionLogicalAnd() : this(VFXValue<bool>.Default, VFXValue<bool>.Default)
  679. {
  680. }
  681. public VFXExpressionLogicalAnd(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.LogicalAnd)
  682. {
  683. }
  684. sealed protected override bool ProcessBinaryOperation(bool left, bool right)
  685. {
  686. return left && right;
  687. }
  688. sealed protected override string GetBinaryOperationCode(string left, string right)
  689. {
  690. return string.Format("{0} && {1}", left, right);
  691. }
  692. }
  693. class VFXExpressionLogicalOr : VFXExpressionBinaryBoolOperation
  694. {
  695. public VFXExpressionLogicalOr() : this(VFXValue<bool>.Default, VFXValue<bool>.Default)
  696. {
  697. }
  698. public VFXExpressionLogicalOr(VFXExpression parentLeft, VFXExpression parentRight) : base(parentLeft, parentRight, VFXExpressionOperation.LogicalOr)
  699. {
  700. }
  701. sealed protected override bool ProcessBinaryOperation(bool left, bool right)
  702. {
  703. return left || right;
  704. }
  705. sealed protected override string GetBinaryOperationCode(string left, string right)
  706. {
  707. return string.Format("{0} || {1}", left, right);
  708. }
  709. }
  710. class VFXExpressionLogicalNot : VFXExpressionUnaryBoolOperation
  711. {
  712. public VFXExpressionLogicalNot() : this(VFXValue<bool>.Default)
  713. {
  714. }
  715. public VFXExpressionLogicalNot(VFXExpression parent) : base(parent, VFXExpressionOperation.LogicalNot)
  716. {
  717. }
  718. sealed protected override bool ProcessUnaryOperation(bool input)
  719. {
  720. return !input;
  721. }
  722. sealed protected override string GetUnaryOperationCode(string x)
  723. {
  724. return string.Format("!{0}", x);
  725. }
  726. }
  727. }