VFXExpressionNoise.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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 VFXExpressionValueNoise1D : VFXExpression
  9. {
  10. public VFXExpressionValueNoise1D() : this(VFXValue<float>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  11. public VFXExpressionValueNoise1D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  12. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.ValueNoise1D; } }
  13. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  14. {
  15. var coordinate = constParents[0].Get<float>();
  16. var floatParams = constParents[1].Get<Vector3>();
  17. var octaveCount = constParents[2].Get<int>();
  18. return VFXValue.Constant(VFXExpressionNoise.GenerateValueNoise1D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  19. }
  20. public override string GetCodeString(string[] parents)
  21. {
  22. return string.Format("GenerateValueNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  23. }
  24. }
  25. class VFXExpressionValueNoise2D : VFXExpression
  26. {
  27. public VFXExpressionValueNoise2D() : this(VFXValue<Vector2>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  28. public VFXExpressionValueNoise2D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  29. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.ValueNoise2D; } }
  30. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  31. {
  32. var coordinate = constParents[0].Get<Vector2>();
  33. var floatParams = constParents[1].Get<Vector3>();
  34. var octaveCount = constParents[2].Get<int>();
  35. return VFXValue.Constant(VFXExpressionNoise.GenerateValueNoise2D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  36. }
  37. public override string GetCodeString(string[] parents)
  38. {
  39. return string.Format("GenerateValueNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  40. }
  41. }
  42. class VFXExpressionValueNoise3D : VFXExpression
  43. {
  44. public VFXExpressionValueNoise3D() : this(VFXValue<Vector3>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  45. public VFXExpressionValueNoise3D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  46. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.ValueNoise3D; } }
  47. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  48. {
  49. var coordinate = constParents[0].Get<Vector3>();
  50. var floatParams = constParents[1].Get<Vector3>();
  51. var octaveCount = constParents[2].Get<int>();
  52. return VFXValue.Constant(VFXExpressionNoise.GenerateValueNoise3D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  53. }
  54. public override string GetCodeString(string[] parents)
  55. {
  56. return string.Format("GenerateValueNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  57. }
  58. }
  59. class VFXExpressionPerlinNoise1D : VFXExpression
  60. {
  61. public VFXExpressionPerlinNoise1D() : this(VFXValue<float>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  62. public VFXExpressionPerlinNoise1D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  63. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.PerlinNoise1D; } }
  64. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  65. {
  66. var coordinate = constParents[0].Get<float>();
  67. var floatParams = constParents[1].Get<Vector3>();
  68. var octaveCount = constParents[2].Get<int>();
  69. return VFXValue.Constant(VFXExpressionNoise.GeneratePerlinNoise1D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  70. }
  71. public override string GetCodeString(string[] parents)
  72. {
  73. return string.Format("GeneratePerlinNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  74. }
  75. }
  76. class VFXExpressionPerlinNoise2D : VFXExpression
  77. {
  78. public VFXExpressionPerlinNoise2D() : this(VFXValue<Vector2>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  79. public VFXExpressionPerlinNoise2D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  80. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.PerlinNoise2D; } }
  81. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  82. {
  83. var coordinate = constParents[0].Get<Vector2>();
  84. var floatParams = constParents[1].Get<Vector3>();
  85. var octaveCount = constParents[2].Get<int>();
  86. return VFXValue.Constant(VFXExpressionNoise.GeneratePerlinNoise2D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  87. }
  88. public override string GetCodeString(string[] parents)
  89. {
  90. return string.Format("GeneratePerlinNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  91. }
  92. }
  93. class VFXExpressionPerlinNoise3D : VFXExpression
  94. {
  95. public VFXExpressionPerlinNoise3D() : this(VFXValue<Vector3>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  96. public VFXExpressionPerlinNoise3D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  97. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.PerlinNoise3D; } }
  98. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  99. {
  100. var coordinate = constParents[0].Get<Vector3>();
  101. var floatParams = constParents[1].Get<Vector3>();
  102. var octaveCount = constParents[2].Get<int>();
  103. return VFXValue.Constant(VFXExpressionNoise.GeneratePerlinNoise3D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  104. }
  105. public override string GetCodeString(string[] parents)
  106. {
  107. return string.Format("GeneratePerlinNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  108. }
  109. }
  110. class VFXExpressionCellularNoise1D : VFXExpression
  111. {
  112. public VFXExpressionCellularNoise1D() : this(VFXValue<float>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  113. public VFXExpressionCellularNoise1D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  114. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.CellularNoise1D; } }
  115. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  116. {
  117. var coordinate = constParents[0].Get<float>();
  118. var floatParams = constParents[1].Get<Vector3>();
  119. var octaveCount = constParents[2].Get<int>();
  120. return VFXValue.Constant(VFXExpressionNoise.GenerateCellularNoise1D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  121. }
  122. public override string GetCodeString(string[] parents)
  123. {
  124. return string.Format("GenerateCellularNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  125. }
  126. }
  127. class VFXExpressionCellularNoise2D : VFXExpression
  128. {
  129. public VFXExpressionCellularNoise2D() : this(VFXValue<Vector2>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  130. public VFXExpressionCellularNoise2D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  131. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.CellularNoise2D; } }
  132. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  133. {
  134. var coordinate = constParents[0].Get<Vector2>();
  135. var floatParams = constParents[1].Get<Vector3>();
  136. var octaveCount = constParents[2].Get<int>();
  137. return VFXValue.Constant(VFXExpressionNoise.GenerateCellularNoise2D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  138. }
  139. public override string GetCodeString(string[] parents)
  140. {
  141. return string.Format("GenerateCellularNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  142. }
  143. }
  144. class VFXExpressionCellularNoise3D : VFXExpression
  145. {
  146. public VFXExpressionCellularNoise3D() : this(VFXValue<Vector3>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  147. public VFXExpressionCellularNoise3D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  148. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.CellularNoise3D; } }
  149. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  150. {
  151. var coordinate = constParents[0].Get<Vector3>();
  152. var floatParams = constParents[1].Get<Vector3>();
  153. var octaveCount = constParents[2].Get<int>();
  154. return VFXValue.Constant(VFXExpressionNoise.GenerateCellularNoise3D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  155. }
  156. public override string GetCodeString(string[] parents)
  157. {
  158. return string.Format("GenerateCellularNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  159. }
  160. }
  161. class VFXExpressionValueCurlNoise2D : VFXExpression
  162. {
  163. public VFXExpressionValueCurlNoise2D() : this(VFXValue<Vector2>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  164. public VFXExpressionValueCurlNoise2D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  165. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.ValueCurlNoise2D; } }
  166. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  167. {
  168. var coordinate = constParents[0].Get<Vector2>();
  169. var floatParams = constParents[1].Get<Vector3>();
  170. var octaveCount = constParents[2].Get<int>();
  171. return VFXValue.Constant(VFXExpressionNoise.GenerateValueCurlNoise2D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  172. }
  173. public override string GetCodeString(string[] parents)
  174. {
  175. return string.Format("GenerateValueCurlNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  176. }
  177. }
  178. class VFXExpressionValueCurlNoise3D : VFXExpression
  179. {
  180. public VFXExpressionValueCurlNoise3D() : this(VFXValue<Vector3>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  181. public VFXExpressionValueCurlNoise3D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  182. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.ValueCurlNoise3D; } }
  183. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  184. {
  185. var coordinate = constParents[0].Get<Vector3>();
  186. var floatParams = constParents[1].Get<Vector3>();
  187. var octaveCount = constParents[2].Get<int>();
  188. return VFXValue.Constant(VFXExpressionNoise.GenerateValueCurlNoise3D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  189. }
  190. public override string GetCodeString(string[] parents)
  191. {
  192. return string.Format("GenerateValueCurlNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  193. }
  194. }
  195. class VFXExpressionPerlinCurlNoise2D : VFXExpression
  196. {
  197. public VFXExpressionPerlinCurlNoise2D() : this(VFXValue<Vector2>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  198. public VFXExpressionPerlinCurlNoise2D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  199. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.PerlinCurlNoise2D; } }
  200. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  201. {
  202. var coordinate = constParents[0].Get<Vector2>();
  203. var floatParams = constParents[1].Get<Vector3>();
  204. var octaveCount = constParents[2].Get<int>();
  205. return VFXValue.Constant(VFXExpressionNoise.GeneratePerlinCurlNoise2D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  206. }
  207. public override string GetCodeString(string[] parents)
  208. {
  209. return string.Format("GeneratePerlinCurlNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  210. }
  211. }
  212. class VFXExpressionPerlinCurlNoise3D : VFXExpression
  213. {
  214. public VFXExpressionPerlinCurlNoise3D() : this(VFXValue<Vector3>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  215. public VFXExpressionPerlinCurlNoise3D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  216. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.PerlinCurlNoise3D; } }
  217. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  218. {
  219. var coordinate = constParents[0].Get<Vector3>();
  220. var floatParams = constParents[1].Get<Vector3>();
  221. var octaveCount = constParents[2].Get<int>();
  222. return VFXValue.Constant(VFXExpressionNoise.GeneratePerlinCurlNoise3D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  223. }
  224. public override string GetCodeString(string[] parents)
  225. {
  226. return string.Format("GeneratePerlinCurlNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  227. }
  228. }
  229. class VFXExpressionCellularCurlNoise2D : VFXExpression
  230. {
  231. public VFXExpressionCellularCurlNoise2D() : this(VFXValue<Vector2>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  232. public VFXExpressionCellularCurlNoise2D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  233. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.CellularCurlNoise2D; } }
  234. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  235. {
  236. var coordinate = constParents[0].Get<Vector2>();
  237. var floatParams = constParents[1].Get<Vector3>();
  238. var octaveCount = constParents[2].Get<int>();
  239. return VFXValue.Constant(VFXExpressionNoise.GenerateCellularCurlNoise2D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  240. }
  241. public override string GetCodeString(string[] parents)
  242. {
  243. return string.Format("GenerateCellularCurlNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  244. }
  245. }
  246. class VFXExpressionCellularCurlNoise3D : VFXExpression
  247. {
  248. public VFXExpressionCellularCurlNoise3D() : this(VFXValue<Vector3>.Default, VFXValue<Vector3>.Default, VFXValue<int>.Default) { }
  249. public VFXExpressionCellularCurlNoise3D(params VFXExpression[] parents) : base(VFXExpression.Flags.None, parents) { }
  250. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.CellularCurlNoise3D; } }
  251. sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  252. {
  253. var coordinate = constParents[0].Get<Vector3>();
  254. var floatParams = constParents[1].Get<Vector3>();
  255. var octaveCount = constParents[2].Get<int>();
  256. return VFXValue.Constant(VFXExpressionNoise.GenerateCellularCurlNoise3D(coordinate, floatParams.x, octaveCount, floatParams.y, floatParams.z));
  257. }
  258. public override string GetCodeString(string[] parents)
  259. {
  260. return string.Format("GenerateCellularCurlNoise({0}, {1}.x, {2}, {1}.y, {1}.z)", parents[0], parents[1], parents[2]);
  261. }
  262. }
  263. class VFXExpressionVoroNoise2D : VFXExpression
  264. {
  265. public VFXExpressionVoroNoise2D() : this(VFXValue<Vector2>.Default, VFXValue<Vector3>.Default) { }
  266. public VFXExpressionVoroNoise2D(params VFXExpression[] parents) : base(VFXExpression.Flags.InvalidOnCPU, parents) { }
  267. sealed public override VFXValueType valueType { get { return VFXValueType.Float; } }
  268. public override VFXExpressionOperation operation { get { return VFXExpressionOperation.None; } }
  269. /*sealed protected override VFXExpression Evaluate(VFXExpression[] constParents)
  270. {
  271. var coordinate = constParents[0].Get<Vector2>();
  272. var floatParams = constParents[1].Get<Vector3>();
  273. return VFXValue.Constant(VFXExpressionNoise.GenerateVoroNoise2D(coordinate, floatParams.x, floatParams.y, floatParams.z));
  274. }*/
  275. public override string GetCodeString(string[] parents)
  276. {
  277. return string.Format("GenerateVoroNoise({0}, {1}.x, {1}.y, {1}.z)", parents[0], parents[1]);
  278. }
  279. }
  280. }