particle_process_material.cpp 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430
  1. /**************************************************************************/
  2. /* particle_process_material.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "particle_process_material.h"
  31. #include "core/version.h"
  32. Mutex ParticleProcessMaterial::material_mutex;
  33. SelfList<ParticleProcessMaterial>::List ParticleProcessMaterial::dirty_materials;
  34. HashMap<ParticleProcessMaterial::MaterialKey, ParticleProcessMaterial::ShaderData, ParticleProcessMaterial::MaterialKey> ParticleProcessMaterial::shader_map;
  35. RBSet<String> ParticleProcessMaterial::min_max_properties;
  36. ParticleProcessMaterial::ShaderNames *ParticleProcessMaterial::shader_names = nullptr;
  37. void ParticleProcessMaterial::init_shaders() {
  38. shader_names = memnew(ShaderNames);
  39. shader_names->direction = "direction";
  40. shader_names->spread = "spread";
  41. shader_names->flatness = "flatness";
  42. shader_names->initial_linear_velocity_min = "initial_linear_velocity_min";
  43. shader_names->initial_angle_min = "initial_angle_min";
  44. shader_names->angular_velocity_min = "angular_velocity_min";
  45. shader_names->orbit_velocity_min = "orbit_velocity_min";
  46. shader_names->radial_velocity_min = "radial_velocity_min";
  47. shader_names->linear_accel_min = "linear_accel_min";
  48. shader_names->radial_accel_min = "radial_accel_min";
  49. shader_names->tangent_accel_min = "tangent_accel_min";
  50. shader_names->damping_min = "damping_min";
  51. shader_names->scale_min = "scale_min";
  52. shader_names->hue_variation_min = "hue_variation_min";
  53. shader_names->anim_speed_min = "anim_speed_min";
  54. shader_names->anim_offset_min = "anim_offset_min";
  55. shader_names->directional_velocity_min = "directional_velocity_min";
  56. shader_names->scale_over_velocity_min = "scale_over_velocity_min";
  57. shader_names->initial_linear_velocity_max = "initial_linear_velocity_max";
  58. shader_names->initial_angle_max = "initial_angle_max";
  59. shader_names->angular_velocity_max = "angular_velocity_max";
  60. shader_names->orbit_velocity_max = "orbit_velocity_max";
  61. shader_names->radial_velocity_max = "radial_velocity_max";
  62. shader_names->linear_accel_max = "linear_accel_max";
  63. shader_names->radial_accel_max = "radial_accel_max";
  64. shader_names->tangent_accel_max = "tangent_accel_max";
  65. shader_names->damping_max = "damping_max";
  66. shader_names->scale_max = "scale_max";
  67. shader_names->hue_variation_max = "hue_variation_max";
  68. shader_names->anim_speed_max = "anim_speed_max";
  69. shader_names->anim_offset_max = "anim_offset_max";
  70. shader_names->directional_velocity_max = "directional_velocity_max";
  71. shader_names->scale_over_velocity_max = "scale_over_velocity_max";
  72. shader_names->angle_texture = "angle_texture";
  73. shader_names->angular_velocity_texture = "angular_velocity_texture";
  74. shader_names->orbit_velocity_texture = "orbit_velocity_curve";
  75. shader_names->radial_velocity_texture = "radial_velocity_curve";
  76. shader_names->linear_accel_texture = "linear_accel_texture";
  77. shader_names->radial_accel_texture = "radial_accel_texture";
  78. shader_names->tangent_accel_texture = "tangent_accel_texture";
  79. shader_names->damping_texture = "damping_texture";
  80. shader_names->scale_texture = "scale_curve";
  81. shader_names->hue_variation_texture = "hue_rot_curve";
  82. shader_names->anim_speed_texture = "animation_speed_curve";
  83. shader_names->anim_offset_texture = "animation_offset_curve";
  84. shader_names->directional_velocity_texture = "directional_velocity_curve";
  85. shader_names->scale_over_velocity_texture = "scale_over_velocity_curve";
  86. shader_names->color = "color_value";
  87. shader_names->color_ramp = "color_ramp";
  88. shader_names->alpha_ramp = "alpha_curve";
  89. shader_names->emission_ramp = "emission_curve";
  90. shader_names->color_initial_ramp = "color_initial_ramp";
  91. shader_names->velocity_limit_curve = "velocity_limit_curve";
  92. shader_names->inherit_emitter_velocity_ratio = "inherit_emitter_velocity_ratio";
  93. shader_names->velocity_pivot = "velocity_pivot";
  94. shader_names->emission_sphere_radius = "emission_sphere_radius";
  95. shader_names->emission_box_extents = "emission_box_extents";
  96. shader_names->emission_texture_point_count = "emission_texture_point_count";
  97. shader_names->emission_texture_points = "emission_texture_points";
  98. shader_names->emission_texture_normal = "emission_texture_normal";
  99. shader_names->emission_texture_color = "emission_texture_color";
  100. shader_names->emission_ring_axis = "emission_ring_axis";
  101. shader_names->emission_ring_height = "emission_ring_height";
  102. shader_names->emission_ring_radius = "emission_ring_radius";
  103. shader_names->emission_ring_inner_radius = "emission_ring_inner_radius";
  104. shader_names->emission_ring_cone_angle = "emission_ring_cone_angle";
  105. shader_names->emission_shape_offset = "emission_shape_offset";
  106. shader_names->emission_shape_scale = "emission_shape_scale";
  107. shader_names->turbulence_enabled = "turbulence_enabled";
  108. shader_names->turbulence_noise_strength = "turbulence_noise_strength";
  109. shader_names->turbulence_noise_scale = "turbulence_noise_scale";
  110. shader_names->turbulence_noise_speed = "turbulence_noise_speed";
  111. shader_names->turbulence_noise_speed_random = "turbulence_noise_speed_random";
  112. shader_names->turbulence_influence_over_life = "turbulence_influence_over_life";
  113. shader_names->turbulence_influence_min = "turbulence_influence_min";
  114. shader_names->turbulence_influence_max = "turbulence_influence_max";
  115. shader_names->turbulence_initial_displacement_min = "turbulence_initial_displacement_min";
  116. shader_names->turbulence_initial_displacement_max = "turbulence_initial_displacement_max";
  117. shader_names->gravity = "gravity";
  118. shader_names->lifetime_randomness = "lifetime_randomness";
  119. shader_names->sub_emitter_frequency = "sub_emitter_frequency";
  120. shader_names->sub_emitter_amount_at_end = "sub_emitter_amount_at_end";
  121. shader_names->sub_emitter_amount_at_collision = "sub_emitter_amount_at_collision";
  122. shader_names->sub_emitter_amount_at_start = "sub_emitter_amount_at_start";
  123. shader_names->sub_emitter_keep_velocity = "sub_emitter_keep_velocity";
  124. shader_names->collision_friction = "collision_friction";
  125. shader_names->collision_bounce = "collision_bounce";
  126. }
  127. void ParticleProcessMaterial::finish_shaders() {
  128. dirty_materials.clear();
  129. memdelete(shader_names);
  130. shader_names = nullptr;
  131. }
  132. void ParticleProcessMaterial::_update_shader() {
  133. MaterialKey mk = _compute_key();
  134. if (mk == current_key) {
  135. return; // No update required in the end.
  136. }
  137. if (shader_map.has(current_key)) {
  138. shader_map[current_key].users--;
  139. if (shader_map[current_key].users == 0) {
  140. // Deallocate shader, as it's no longer in use.
  141. RS::get_singleton()->free(shader_map[current_key].shader);
  142. shader_map.erase(current_key);
  143. }
  144. }
  145. current_key = mk;
  146. if (shader_map.has(mk)) {
  147. RS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader);
  148. shader_map[mk].users++;
  149. return;
  150. }
  151. // No pre-existing shader, create one.
  152. // Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
  153. String code = "// NOTE: Shader automatically converted from " VERSION_NAME " " VERSION_FULL_CONFIG "'s ParticleProcessMaterial.\n\n";
  154. code += "shader_type particles;\n";
  155. code += "render_mode disable_velocity;\n";
  156. if (collision_scale) {
  157. code += "render_mode collision_use_scale;\n";
  158. }
  159. code += "\n";
  160. // Define uniforms.
  161. code += "uniform vec3 direction;\n";
  162. code += "uniform float spread;\n";
  163. code += "uniform float flatness;\n";
  164. code += "uniform float inherit_emitter_velocity_ratio = 0.0;\n";
  165. code += "uniform float initial_linear_velocity_min;\n";
  166. code += "uniform float initial_linear_velocity_max;\n";
  167. code += "uniform float directional_velocity_min;\n";
  168. code += "uniform float directional_velocity_max;\n";
  169. code += "uniform float angular_velocity_min;\n";
  170. code += "uniform float angular_velocity_max;\n";
  171. code += "uniform float orbit_velocity_min;\n";
  172. code += "uniform float orbit_velocity_max;\n";
  173. code += "uniform float radial_velocity_min;\n";
  174. code += "uniform float radial_velocity_max;\n";
  175. code += "uniform float linear_accel_min;\n";
  176. code += "uniform float linear_accel_max;\n";
  177. code += "uniform float radial_accel_min;\n";
  178. code += "uniform float radial_accel_max;\n";
  179. code += "uniform float tangent_accel_min;\n";
  180. code += "uniform float tangent_accel_max;\n";
  181. code += "uniform float damping_min;\n";
  182. code += "uniform float damping_max;\n";
  183. code += "uniform float initial_angle_min;\n";
  184. code += "uniform float initial_angle_max;\n";
  185. code += "uniform float scale_min;\n";
  186. code += "uniform float scale_max;\n";
  187. code += "uniform float hue_variation_min;\n";
  188. code += "uniform float hue_variation_max;\n";
  189. code += "uniform float anim_speed_min;\n";
  190. code += "uniform float anim_speed_max;\n";
  191. code += "uniform float anim_offset_min;\n";
  192. code += "uniform float anim_offset_max;\n";
  193. code += "uniform float lifetime_randomness;\n";
  194. code += "uniform vec3 emission_shape_offset = vec3(0.0);\n";
  195. code += "uniform vec3 emission_shape_scale = vec3(1.0);\n";
  196. code += "uniform vec3 velocity_pivot = vec3(0.0);\n";
  197. if (tex_parameters[PARAM_SCALE_OVER_VELOCITY].is_valid()) {
  198. code += "uniform float scale_over_velocity_min = 0.0;\n";
  199. code += "uniform float scale_over_velocity_max = 5.0;\n";
  200. }
  201. switch (emission_shape) {
  202. case EMISSION_SHAPE_POINT: {
  203. //do none
  204. } break;
  205. case EMISSION_SHAPE_SPHERE: {
  206. code += "uniform float emission_sphere_radius;\n";
  207. } break;
  208. case EMISSION_SHAPE_SPHERE_SURFACE: {
  209. code += "uniform float emission_sphere_radius;\n";
  210. } break;
  211. case EMISSION_SHAPE_BOX: {
  212. code += "uniform vec3 emission_box_extents;\n";
  213. } break;
  214. case EMISSION_SHAPE_DIRECTED_POINTS: {
  215. code += "uniform sampler2D emission_texture_normal : hint_default_black;\n";
  216. [[fallthrough]];
  217. }
  218. case EMISSION_SHAPE_POINTS: {
  219. code += "uniform sampler2D emission_texture_points : hint_default_black;\n";
  220. code += "uniform int emission_texture_point_count;\n";
  221. if (emission_color_texture.is_valid()) {
  222. code += "uniform sampler2D emission_texture_color : hint_default_white;\n";
  223. }
  224. } break;
  225. case EMISSION_SHAPE_RING: {
  226. code += "uniform vec3 " + shader_names->emission_ring_axis + ";\n";
  227. code += "uniform float " + shader_names->emission_ring_height + ";\n";
  228. code += "uniform float " + shader_names->emission_ring_radius + ";\n";
  229. code += "uniform float " + shader_names->emission_ring_inner_radius + ";\n";
  230. code += "uniform float " + shader_names->emission_ring_cone_angle + ";\n";
  231. } break;
  232. case EMISSION_SHAPE_MAX: { // Max value for validity check.
  233. break;
  234. }
  235. }
  236. if (sub_emitter_mode != SUB_EMITTER_DISABLED && !RenderingServer::get_singleton()->is_low_end()) {
  237. if (sub_emitter_mode == SUB_EMITTER_CONSTANT) {
  238. code += "uniform float sub_emitter_frequency;\n";
  239. }
  240. if (sub_emitter_mode == SUB_EMITTER_AT_END) {
  241. code += "uniform int sub_emitter_amount_at_end;\n";
  242. }
  243. if (sub_emitter_mode == SUB_EMITTER_AT_COLLISION) {
  244. code += "uniform int sub_emitter_amount_at_collision;\n";
  245. }
  246. if (sub_emitter_mode == SUB_EMITTER_AT_START) {
  247. code += "uniform int sub_emitter_amount_at_start;\n";
  248. }
  249. code += "uniform bool sub_emitter_keep_velocity;\n";
  250. }
  251. code += "uniform vec4 color_value : source_color;\n";
  252. code += "uniform vec3 gravity;\n";
  253. if (color_ramp.is_valid()) {
  254. code += "uniform sampler2D color_ramp : repeat_disable;\n";
  255. }
  256. if (color_initial_ramp.is_valid()) {
  257. code += "uniform sampler2D color_initial_ramp : repeat_disable;\n";
  258. }
  259. if (alpha_curve.is_valid()) {
  260. code += "uniform sampler2D alpha_curve : repeat_disable;\n";
  261. }
  262. if (emission_curve.is_valid()) {
  263. code += "uniform sampler2D emission_curve : repeat_disable;\n";
  264. }
  265. if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
  266. code += "uniform sampler2D linear_velocity_texture : repeat_disable;\n";
  267. }
  268. if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) {
  269. code += "uniform sampler2D orbit_velocity_curve : repeat_disable;\n";
  270. }
  271. if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) {
  272. code += "uniform sampler2D angular_velocity_texture : repeat_disable;\n";
  273. }
  274. if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid()) {
  275. code += "uniform sampler2D linear_accel_texture : repeat_disable;\n";
  276. }
  277. if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid()) {
  278. code += "uniform sampler2D radial_accel_texture : repeat_disable;\n";
  279. }
  280. if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) {
  281. code += "uniform sampler2D tangent_accel_texture : repeat_disable;\n";
  282. }
  283. if (tex_parameters[PARAM_DAMPING].is_valid()) {
  284. code += "uniform sampler2D damping_texture : repeat_disable;\n";
  285. }
  286. if (tex_parameters[PARAM_ANGLE].is_valid()) {
  287. code += "uniform sampler2D angle_texture : repeat_disable;\n";
  288. }
  289. if (tex_parameters[PARAM_SCALE].is_valid()) {
  290. code += "uniform sampler2D scale_curve : repeat_disable;\n";
  291. }
  292. if (tex_parameters[PARAM_HUE_VARIATION].is_valid()) {
  293. code += "uniform sampler2D hue_rot_curve : repeat_disable;\n";
  294. }
  295. if (tex_parameters[PARAM_ANIM_SPEED].is_valid()) {
  296. code += "uniform sampler2D animation_speed_curve : repeat_disable;\n";
  297. }
  298. if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) {
  299. code += "uniform sampler2D animation_offset_curve : repeat_disable;\n";
  300. }
  301. if (tex_parameters[PARAM_RADIAL_VELOCITY].is_valid()) {
  302. code += "uniform sampler2D radial_velocity_curve : repeat_disable;\n";
  303. }
  304. if (tex_parameters[PARAM_SCALE_OVER_VELOCITY].is_valid()) {
  305. code += "uniform sampler2D scale_over_velocity_curve : repeat_disable;\n";
  306. }
  307. if (tex_parameters[PARAM_DIRECTIONAL_VELOCITY].is_valid()) {
  308. code += "uniform sampler2D directional_velocity_curve : repeat_disable;\n";
  309. }
  310. if (velocity_limit_curve.is_valid()) {
  311. code += "uniform sampler2D velocity_limit_curve : repeat_disable;\n";
  312. }
  313. if (collision_mode == COLLISION_RIGID) {
  314. code += "uniform float collision_friction;\n";
  315. code += "uniform float collision_bounce;\n";
  316. }
  317. if (turbulence_enabled) {
  318. code += "uniform float turbulence_noise_strength;\n";
  319. code += "uniform float turbulence_noise_scale;\n";
  320. code += "uniform float turbulence_influence_min;\n";
  321. code += "uniform float turbulence_influence_max;\n";
  322. code += "uniform float turbulence_initial_displacement_min;\n";
  323. code += "uniform float turbulence_initial_displacement_max;\n";
  324. code += "uniform float turbulence_noise_speed_random;\n";
  325. code += "uniform vec3 turbulence_noise_speed = vec3(1.0, 1.0, 1.0);\n";
  326. if (tex_parameters[PARAM_TURB_INFLUENCE_OVER_LIFE].is_valid()) {
  327. code += "uniform sampler2D turbulence_influence_over_life;\n";
  328. }
  329. if (turbulence_color_ramp.is_valid()) {
  330. code += "uniform sampler2D turbulence_color_ramp;\n";
  331. }
  332. }
  333. code += "\n";
  334. // Define helper functions.
  335. if (turbulence_enabled) {
  336. // Functions for 3D noise / turbulence.
  337. code += "// Functions for 3D noise / turbulence.\n";
  338. code += "vec4 grad(vec4 p) {\n";
  339. code += " p = fract(vec4(\n";
  340. code += " dot(p, vec4(0.143081, 0.001724, 0.280166, 0.262771)),\n";
  341. code += " dot(p, vec4(0.645401, -0.047791, -0.146698, 0.595016)),\n";
  342. code += " dot(p, vec4(-0.499665, -0.095734, 0.425674, -0.207367)),\n";
  343. code += " dot(p, vec4(-0.013596, -0.848588, 0.423736, 0.17044))));\n";
  344. code += " return fract((p.xyzw * p.yzwx) * 2365.952041) * 2.0 - 1.0;\n";
  345. code += "}\n\n";
  346. code += "float noise(vec4 coord) {\n";
  347. code += " // Domain rotation to improve the look of XYZ slices + animation patterns.\n";
  348. code += " coord = vec4(\n";
  349. code += " coord.xyz + dot(coord, vec4(vec3(-0.1666667), -0.5)),\n";
  350. code += " dot(coord, vec4(0.5)));\n\n";
  351. code += " vec4 base = floor(coord), delta = coord - base;\n\n";
  352. code += " vec4 grad_0000 = grad(base + vec4(0.0, 0.0, 0.0, 0.0)), grad_1000 = grad(base + vec4(1.0, 0.0, 0.0, 0.0));\n";
  353. code += " vec4 grad_0100 = grad(base + vec4(0.0, 1.0, 0.0, 0.0)), grad_1100 = grad(base + vec4(1.0, 1.0, 0.0, 0.0));\n";
  354. code += " vec4 grad_0010 = grad(base + vec4(0.0, 0.0, 1.0, 0.0)), grad_1010 = grad(base + vec4(1.0, 0.0, 1.0, 0.0));\n";
  355. code += " vec4 grad_0110 = grad(base + vec4(0.0, 1.0, 1.0, 0.0)), grad_1110 = grad(base + vec4(1.0, 1.0, 1.0, 0.0));\n";
  356. code += " vec4 grad_0001 = grad(base + vec4(0.0, 0.0, 0.0, 1.0)), grad_1001 = grad(base + vec4(1.0, 0.0, 0.0, 1.0));\n";
  357. code += " vec4 grad_0101 = grad(base + vec4(0.0, 1.0, 0.0, 1.0)), grad_1101 = grad(base + vec4(1.0, 1.0, 0.0, 1.0));\n";
  358. code += " vec4 grad_0011 = grad(base + vec4(0.0, 0.0, 1.0, 1.0)), grad_1011 = grad(base + vec4(1.0, 0.0, 1.0, 1.0));\n";
  359. code += " vec4 grad_0111 = grad(base + vec4(0.0, 1.0, 1.0, 1.0)), grad_1111 = grad(base + vec4(1.0, 1.0, 1.0, 1.0));\n\n";
  360. code += " vec4 result_0123 = vec4(\n";
  361. code += " dot(delta - vec4(0.0, 0.0, 0.0, 0.0), grad_0000), dot(delta - vec4(1.0, 0.0, 0.0, 0.0), grad_1000),\n";
  362. code += " dot(delta - vec4(0.0, 1.0, 0.0, 0.0), grad_0100), dot(delta - vec4(1.0, 1.0, 0.0, 0.0), grad_1100));\n";
  363. code += " vec4 result_4567 = vec4(\n";
  364. code += " dot(delta - vec4(0.0, 0.0, 1.0, 0.0), grad_0010), dot(delta - vec4(1.0, 0.0, 1.0, 0.0), grad_1010),\n";
  365. code += " dot(delta - vec4(0.0, 1.0, 1.0, 0.0), grad_0110), dot(delta - vec4(1.0, 1.0, 1.0, 0.0), grad_1110));\n";
  366. code += " vec4 result_89AB = vec4(\n";
  367. code += " dot(delta - vec4(0.0, 0.0, 0.0, 1.0), grad_0001), dot(delta - vec4(1.0, 0.0, 0.0, 1.0), grad_1001),\n";
  368. code += " dot(delta - vec4(0.0, 1.0, 0.0, 1.0), grad_0101), dot(delta - vec4(1.0, 1.0, 0.0, 1.0), grad_1101));\n";
  369. code += " vec4 result_CDEF = vec4(\n";
  370. code += " dot(delta - vec4(0.0, 0.0, 1.0, 1.0), grad_0011), dot(delta - vec4(1.0, 0.0, 1.0, 1.0), grad_1011),\n";
  371. code += " dot(delta - vec4(0.0, 1.0, 1.0, 1.0), grad_0111), dot(delta - vec4(1.0, 1.0, 1.0, 1.0), grad_1111));\n\n";
  372. code += " vec4 fade = delta * delta * delta * (10.0 + delta * (-15.0 + delta * 6.0));\n";
  373. code += " vec4 result_W0 = mix(result_0123, result_89AB, fade.w), result_W1 = mix(result_4567, result_CDEF, fade.w);\n";
  374. code += " vec4 result_WZ = mix(result_W0, result_W1, fade.z);\n";
  375. code += " vec2 result_WZY = mix(result_WZ.xy, result_WZ.zw, fade.y);\n";
  376. code += " return mix(result_WZY.x, result_WZY.y, fade.x);\n";
  377. code += "}\n\n";
  378. code += "// Curl 3D and three-noise function with friendly permission by Isaac Cohen.\n";
  379. code += "// Modified to accept 4D noise.\n";
  380. code += "vec3 noise_3x(vec4 p) {\n";
  381. code += " float s = noise(p);\n";
  382. code += " float s1 = noise(p + vec4(vec3(0.0), 1.7320508 * 2048.333333));\n";
  383. code += " float s2 = noise(p - vec4(vec3(0.0), 1.7320508 * 2048.333333));\n";
  384. code += " vec3 c = vec3(s, s1, s2);\n";
  385. code += " return c;\n";
  386. code += "}\n\n";
  387. code += "vec3 curl_3d(vec4 p, float c) {\n";
  388. code += " float epsilon = 0.001 + c;\n";
  389. code += " vec4 dx = vec4(epsilon, 0.0, 0.0, 0.0);\n";
  390. code += " vec4 dy = vec4(0.0, epsilon, 0.0, 0.0);\n";
  391. code += " vec4 dz = vec4(0.0, 0.0, epsilon, 0.0);\n";
  392. code += " vec3 x0 = noise_3x(p - dx).xyz;\n";
  393. code += " vec3 x1 = noise_3x(p + dx).xyz;\n";
  394. code += " vec3 y0 = noise_3x(p - dy).xyz;\n";
  395. code += " vec3 y1 = noise_3x(p + dy).xyz;\n";
  396. code += " vec3 z0 = noise_3x(p - dz).xyz;\n";
  397. code += " vec3 z1 = noise_3x(p + dz).xyz;\n";
  398. code += " float x = (y1.z - y0.z) - (z1.y - z0.y);\n";
  399. code += " float y = (z1.x - z0.x) - (x1.z - x0.z);\n";
  400. code += " float z = (x1.y - x0.y) - (y1.x - y0.x);\n";
  401. code += " return normalize(vec3(x, y, z));\n";
  402. code += "}\n\n";
  403. code += "vec3 get_noise_direction(vec3 pos) {\n";
  404. code += " float adj_contrast = max((turbulence_noise_strength - 1.0), 0.0) * 70.0;\n";
  405. code += " vec4 noise_time = TIME * vec4(turbulence_noise_speed, turbulence_noise_speed_random);\n";
  406. code += " vec4 noise_pos = vec4(pos * turbulence_noise_scale, 0.0);\n";
  407. code += " vec3 noise_direction = curl_3d(noise_pos + noise_time, adj_contrast);\n";
  408. code += " noise_direction = mix(0.9 * noise_direction, noise_direction, turbulence_noise_strength - 9.0);\n";
  409. code += " return noise_direction;\n";
  410. code += "}\n\n";
  411. }
  412. code += "vec4 rotate_hue(vec4 current_color, float hue_rot_angle) {\n";
  413. code += " float hue_rot_c = cos(hue_rot_angle);\n";
  414. code += " float hue_rot_s = sin(hue_rot_angle);\n";
  415. code += " mat4 hue_rot_mat =\n";
  416. code += " mat4(vec4(0.299, 0.587, 0.114, 0.0),\n";
  417. code += " vec4(0.299, 0.587, 0.114, 0.0),\n";
  418. code += " vec4(0.299, 0.587, 0.114, 0.0),\n";
  419. code += " vec4(0.000, 0.000, 0.000, 1.0)) +\n";
  420. code += " mat4(vec4(0.701, -0.587, -0.114, 0.0),\n";
  421. code += " vec4(-0.299, 0.413, -0.114, 0.0),\n";
  422. code += " vec4(-0.300, -0.588, 0.886, 0.0),\n";
  423. code += " vec4(0.000, 0.000, 0.000, 0.0)) *\n";
  424. code += " hue_rot_c +\n";
  425. code += " mat4(vec4(0.168, 0.330, -0.497, 0.0),\n";
  426. code += " vec4(-0.328, 0.035, 0.292, 0.0),\n";
  427. code += " vec4(1.250, -1.050, -0.203, 0.0),\n";
  428. code += " vec4(0.000, 0.000, 0.000, 0.0)) *\n";
  429. code += " hue_rot_s;\n";
  430. code += " return hue_rot_mat * current_color;\n";
  431. code += "}\n\n";
  432. // Random functions.
  433. code += "float rand_from_seed(inout uint seed) {\n";
  434. code += " int k;\n";
  435. code += " int s = int(seed);\n";
  436. code += " if (s == 0) {\n";
  437. code += " s = 305420679;\n";
  438. code += " }\n";
  439. code += " k = s / 127773;\n";
  440. code += " s = 16807 * (s - k * 127773) - 2836 * k;\n";
  441. code += " if (s < 0) {\n";
  442. code += " s += 2147483647;\n";
  443. code += " }\n";
  444. code += " seed = uint(s);\n";
  445. code += " return float(seed % uint(65536)) / 65535.0;\n";
  446. code += "}\n\n";
  447. code += "float rand_from_seed_m1_p1(inout uint seed) {\n";
  448. code += " return rand_from_seed(seed) * 2.0 - 1.0;\n";
  449. code += "}\n\n";
  450. // Improve seed quality.
  451. code += "uint hash(uint x) {\n";
  452. code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n";
  453. code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n";
  454. code += " x = (x >> uint(16)) ^ x;\n";
  455. code += " return x;\n";
  456. code += "}\n\n";
  457. // Define structs.
  458. code += "struct DisplayParameters {\n";
  459. code += " vec3 scale;\n";
  460. code += " float hue_rotation;\n";
  461. code += " float animation_speed;\n";
  462. code += " float animation_offset;\n";
  463. code += " float lifetime;\n";
  464. code += " vec4 color;\n";
  465. code += " float emission_texture_position;\n";
  466. code += "};\n\n";
  467. code += "struct DynamicsParameters {\n";
  468. code += " float angle;\n";
  469. code += " float angular_velocity;\n";
  470. code += " float initial_velocity_multiplier;\n";
  471. code += " float directional_velocity;\n";
  472. code += " float radial_velocity;\n";
  473. code += " float orbit_velocity;\n";
  474. if (turbulence_enabled) {
  475. code += " float turb_influence;\n";
  476. }
  477. code += "};\n\n";
  478. code += "struct PhysicalParameters {\n";
  479. code += " float linear_accel;\n";
  480. code += " float radial_accel;\n";
  481. code += " float tangent_accel;\n";
  482. code += " float damping;\n";
  483. code += "};\n\n";
  484. code += "void calculate_initial_physical_params(inout PhysicalParameters params, inout uint alt_seed) {\n";
  485. code += " params.linear_accel = mix(linear_accel_min, linear_accel_max, rand_from_seed(alt_seed));\n";
  486. code += " params.radial_accel = mix(radial_accel_min, radial_accel_max, rand_from_seed(alt_seed));\n";
  487. code += " params.tangent_accel = mix(tangent_accel_min, tangent_accel_max, rand_from_seed(alt_seed));\n";
  488. code += " params.damping = mix(damping_min, damping_max, rand_from_seed(alt_seed));\n";
  489. code += "}\n\n";
  490. code += "void calculate_initial_dynamics_params(inout DynamicsParameters params, inout uint alt_seed) {\n";
  491. code += " // -------------------- DO NOT REORDER OPERATIONS, IT BREAKS VISUAL COMPATIBILITY\n";
  492. code += " // -------------------- ADD NEW OPERATIONS AT THE BOTTOM\n";
  493. code += " params.angle = mix(initial_angle_min, initial_angle_max, rand_from_seed(alt_seed));\n";
  494. code += " params.angular_velocity = mix(angular_velocity_min, angular_velocity_max, rand_from_seed(alt_seed));\n";
  495. code += " params.initial_velocity_multiplier = mix(initial_linear_velocity_min, initial_linear_velocity_max, rand_from_seed(alt_seed));\n";
  496. code += " params.directional_velocity = mix(directional_velocity_min, directional_velocity_max, rand_from_seed(alt_seed));\n";
  497. code += " params.radial_velocity = mix(radial_velocity_min, radial_velocity_max, rand_from_seed(alt_seed));\n";
  498. code += " params.orbit_velocity = mix(orbit_velocity_min, orbit_velocity_max, rand_from_seed(alt_seed));\n";
  499. if (turbulence_enabled) {
  500. code += " params.turb_influence = mix(turbulence_influence_min, turbulence_influence_max, rand_from_seed(alt_seed));\n";
  501. }
  502. code += "}\n\n";
  503. code += "void calculate_initial_display_params(inout DisplayParameters params, inout uint alt_seed) {\n";
  504. code += " // -------------------- DO NOT REORDER OPERATIONS, IT BREAKS VISUAL COMPATIBILITY\n";
  505. code += " // -------------------- ADD NEW OPERATIONS AT THE BOTTOM\n";
  506. code += " float pi = 3.14159;\n";
  507. code += " params.scale = vec3(mix(scale_min, scale_max, rand_from_seed(alt_seed)));\n";
  508. code += " params.scale = sign(params.scale) * max(abs(params.scale), 0.001);\n";
  509. code += " params.hue_rotation = pi * 2.0 * mix(hue_variation_min, hue_variation_max, rand_from_seed(alt_seed));\n";
  510. code += " params.animation_speed = mix(anim_speed_min, anim_speed_max, rand_from_seed(alt_seed));\n";
  511. code += " params.animation_offset = mix(anim_offset_min, anim_offset_max, rand_from_seed(alt_seed));\n";
  512. code += " params.lifetime = (1.0 - lifetime_randomness * rand_from_seed(alt_seed));\n";
  513. code += " params.color = color_value;\n";
  514. if (color_initial_ramp.is_valid()) {
  515. code += " params.color *= texture(color_initial_ramp, vec2(rand_from_seed(alt_seed)));\n";
  516. }
  517. if (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
  518. code += " params.emission_texture_position = rand_from_seed(alt_seed);\n";
  519. if (emission_color_texture.is_valid()) {
  520. code += " int point = min(emission_texture_point_count - 1, int(params.emission_texture_position * float(emission_texture_point_count)));\n";
  521. code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n";
  522. code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n";
  523. code += " params.color *= texelFetch(emission_texture_color, emission_tex_ofs, 0);\n";
  524. }
  525. }
  526. code += "}\n\n";
  527. // Process display parameters that are bound solely by lifetime.
  528. code += "void process_display_param(inout DisplayParameters parameters, float lifetime) {\n";
  529. code += " // Compile-time add textures.\n";
  530. if (tex_parameters[PARAM_SCALE].is_valid()) {
  531. code += " parameters.scale *= texture(scale_curve, vec2(lifetime)).rgb;\n";
  532. }
  533. if (tex_parameters[PARAM_HUE_VARIATION].is_valid()) {
  534. code += " parameters.hue_rotation *= texture(hue_rot_curve, vec2(lifetime)).r;\n";
  535. }
  536. if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) {
  537. code += " parameters.animation_offset += texture(animation_offset_curve, vec2(lifetime)).r;\n";
  538. }
  539. if (tex_parameters[PARAM_ANIM_SPEED].is_valid()) {
  540. code += " parameters.animation_speed *= texture(animation_speed_curve, vec2(lifetime)).r;\n";
  541. }
  542. if (color_ramp.is_valid()) {
  543. code += " parameters.color *= texture(color_ramp, vec2(lifetime));\n";
  544. }
  545. if (alpha_curve.is_valid()) {
  546. code += " parameters.color.a *= texture(alpha_curve, vec2(lifetime)).r;\n";
  547. }
  548. code += " parameters.color = rotate_hue(parameters.color, parameters.hue_rotation);\n";
  549. if (emission_curve.is_valid()) {
  550. code += " parameters.color.rgb *= 1.0 + texture(emission_curve, vec2(lifetime)).r;\n";
  551. }
  552. code += "}\n\n";
  553. code += "vec3 calculate_initial_position(inout DisplayParameters params, inout uint alt_seed) {\n";
  554. code += " float pi = 3.14159;\n";
  555. code += " vec3 pos = vec3(0.0);\n";
  556. code += " { // Emission shape.\n";
  557. if (emission_shape == EMISSION_SHAPE_POINT) {
  558. code += " pos = vec3(0.0);\n";
  559. }
  560. if (emission_shape == EMISSION_SHAPE_SPHERE) {
  561. code += " float s = rand_from_seed(alt_seed) * 2.0 - 1.0;\n";
  562. code += " float t = rand_from_seed(alt_seed) * 2.0 * pi;\n";
  563. code += " float p = rand_from_seed(alt_seed);\n";
  564. code += " float radius = emission_sphere_radius * sqrt(1.0 - s * s);\n";
  565. code += " pos = mix(vec3(0.0, 0.0, 0.0), vec3(radius * cos(t), radius * sin(t), emission_sphere_radius * s), p);\n";
  566. }
  567. if (emission_shape == EMISSION_SHAPE_SPHERE_SURFACE) {
  568. code += " float s = rand_from_seed(alt_seed) * 2.0 - 1.0;\n";
  569. code += " float t = rand_from_seed(alt_seed) * 2.0 * pi;\n";
  570. code += " float radius = emission_sphere_radius * sqrt(1.0 - s * s);\n";
  571. code += " pos = vec3(radius * cos(t), radius * sin(t), emission_sphere_radius * s);\n";
  572. }
  573. if (emission_shape == EMISSION_SHAPE_BOX) {
  574. code += " pos = vec3(rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0 - 1.0) * emission_box_extents;\n";
  575. }
  576. if (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
  577. code += " int point = min(emission_texture_point_count - 1, int(params.emission_texture_position * float(emission_texture_point_count)));\n";
  578. code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n";
  579. code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n";
  580. code += " pos = texelFetch(emission_texture_points, emission_tex_ofs, 0).xyz;\n";
  581. }
  582. if (emission_shape == EMISSION_SHAPE_RING) {
  583. code += " float radius_clamped = max(0.001, emission_ring_radius);\n";
  584. code += " float top_radius = max(radius_clamped - tan(radians(90.0 - emission_ring_cone_angle)) * emission_ring_height, 0.0);\n";
  585. code += " float y_pos = rand_from_seed(alt_seed);\n";
  586. code += " float skew = max(min(radius_clamped, top_radius) / max(radius_clamped, top_radius), 0.5);\n";
  587. code += " y_pos = radius_clamped < top_radius ? pow(y_pos, skew) : 1.0 - pow(y_pos, skew);\n";
  588. code += " float ring_spawn_angle = rand_from_seed(alt_seed) * 2.0 * pi;\n";
  589. code += " float ring_random_radius = sqrt(rand_from_seed(alt_seed) * (radius_clamped * radius_clamped - emission_ring_inner_radius * emission_ring_inner_radius) + emission_ring_inner_radius * emission_ring_inner_radius);\n";
  590. code += " ring_random_radius = mix(ring_random_radius, ring_random_radius * (top_radius / radius_clamped), y_pos);\n";
  591. code += " vec3 axis = emission_ring_axis == vec3(0.0) ? vec3(0.0, 0.0, 1.0) : normalize(emission_ring_axis);\n";
  592. code += " vec3 ortho_axis = vec3(0.0);\n";
  593. code += " if (abs(axis) == vec3(1.0, 0.0, 0.0)) {\n";
  594. code += " ortho_axis = cross(axis, vec3(0.0, 1.0, 0.0));\n";
  595. code += " } else {\n";
  596. code += " ortho_axis = cross(axis, vec3(1.0, 0.0, 0.0));\n";
  597. code += " }\n";
  598. code += " ortho_axis = normalize(ortho_axis);\n";
  599. code += " float s = sin(ring_spawn_angle);\n";
  600. code += " float c = cos(ring_spawn_angle);\n";
  601. code += " float oc = 1.0 - c;\n";
  602. code += " ortho_axis = mat3(\n";
  603. code += " vec3(c + axis.x * axis.x * oc, axis.x * axis.y * oc - axis.z * s, axis.x * axis.z *oc + axis.y * s),\n";
  604. code += " vec3(axis.x * axis.y * oc + s * axis.z, c + axis.y * axis.y * oc, axis.y * axis.z * oc - axis.x * s),\n";
  605. code += " vec3(axis.z * axis.x * oc - axis.y * s, axis.z * axis.y * oc + axis.x * s, c + axis.z * axis.z * oc)\n";
  606. code += " ) * ortho_axis;\n";
  607. code += " ortho_axis = normalize(ortho_axis);\n";
  608. code += " pos = ortho_axis * ring_random_radius + (y_pos * emission_ring_height - emission_ring_height / 2.0) * axis;\n";
  609. }
  610. code += " }\n";
  611. code += " return pos * emission_shape_scale + emission_shape_offset;\n";
  612. code += "}\n\n";
  613. if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid() || particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  614. code += "vec3 process_orbit_displacement(DynamicsParameters param, float lifetime, inout uint alt_seed, mat4 transform, mat4 emission_transform, float delta, float total_lifetime) {\n";
  615. // No reason to run all these expensive calculation below if we have no orbit velocity
  616. // HOWEVER
  617. // May be a bad idea for fps consistency?
  618. code += " if (abs(param.orbit_velocity) < 0.01 || delta < 0.001) {\n";
  619. code += " return vec3(0.0);\n";
  620. code += " }\n";
  621. code += " vec3 displacement = vec3(0.0);\n";
  622. code += " float pi = 3.14159;\n";
  623. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  624. code += " float orbit_amount = param.orbit_velocity;\n";
  625. if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) {
  626. CurveTexture *texture = Object::cast_to<CurveTexture>(tex_parameters[PARAM_ORBIT_VELOCITY].ptr());
  627. if (texture) {
  628. code += " orbit_amount *= texture(orbit_velocity_curve, vec2(lifetime)).r;\n";
  629. } else {
  630. code += " orbit_amount *= texture(orbit_velocity_curve, vec2(lifetime)).b;\n";
  631. }
  632. }
  633. code += " if (orbit_amount != 0.0) {\n";
  634. code += " vec3 pos = transform[3].xyz;\n";
  635. code += " vec3 org = emission_transform[3].xyz;\n";
  636. code += " vec3 diff = pos - org;\n";
  637. code += " float ang = orbit_amount * pi * 2.0 * delta;\n";
  638. code += " mat2 rot = mat2(vec2(cos(ang), -sin(ang)), vec2(sin(ang), cos(ang)));\n";
  639. code += " displacement.xy -= diff.xy;\n";
  640. code += " displacement.xy += rot * diff.xy;\n";
  641. code += " }\n";
  642. } else {
  643. code += " vec3 orbit_velocities = vec3(param.orbit_velocity);\n";
  644. code += " orbit_velocities *= texture(orbit_velocity_curve, vec2(lifetime)).rgb;\n";
  645. code += " orbit_velocities *= pi * 2.0;\n";
  646. code += " orbit_velocities *= delta; // We wanna process those by the delta angle.\n\n";
  647. code += " // X axis.\n";
  648. code += " vec3 local_pos = (inverse(emission_transform) * transform[3]).xyz;\n";
  649. code += " local_pos -= velocity_pivot;\n";
  650. code += " local_pos.x = 0.0;\n";
  651. code += " mat3 x_rotation_mat = mat3(\n";
  652. code += " vec3(1.0, 0.0, 0.0),\n";
  653. code += " vec3(0.0, cos(orbit_velocities.x), sin(orbit_velocities.x)),\n";
  654. code += " vec3(0.0, -sin(orbit_velocities.x), cos(orbit_velocities.x))\n";
  655. code += " );\n";
  656. code += " vec3 new_pos = x_rotation_mat * local_pos;\n";
  657. code += " displacement = new_pos - local_pos;\n\n";
  658. code += " // Y axis.\n";
  659. code += " local_pos = (inverse(emission_transform) * transform[3]).xyz;\n";
  660. code += " local_pos -= velocity_pivot;\n";
  661. code += " local_pos.y = 0.0;\n";
  662. code += " mat3 y_rotation_mat = mat3(\n";
  663. code += " vec3(cos(orbit_velocities.y), 0.0, -sin(orbit_velocities.y)),\n";
  664. code += " vec3(0.0, 1.0, 0.0),\n";
  665. code += " vec3(sin(orbit_velocities.y), 0.0, cos(orbit_velocities.y))\n";
  666. code += " );\n";
  667. code += " new_pos = y_rotation_mat * local_pos;\n";
  668. code += " displacement += new_pos - local_pos;\n\n";
  669. code += " // Z axis.\n";
  670. code += " local_pos = (inverse(emission_transform) * transform[3]).xyz;\n";
  671. code += " local_pos -= velocity_pivot;\n";
  672. code += " local_pos.z = 0.0;\n";
  673. code += " mat3 z_rotation_mat = mat3(\n";
  674. code += " vec3(cos(orbit_velocities.z), sin(orbit_velocities.z), 0.0),\n";
  675. code += " vec3(-sin(orbit_velocities.z), cos(orbit_velocities.z), 0.0),\n";
  676. code += " vec3(0.0, 0.0, 1.0)\n";
  677. code += " );\n";
  678. code += " new_pos = z_rotation_mat * local_pos;\n";
  679. code += " displacement += new_pos - local_pos;\n\n";
  680. }
  681. code += " return (emission_transform * vec4(displacement / delta, 0.0)).xyz;\n";
  682. code += "}\n\n";
  683. }
  684. code += "vec3 get_random_direction_from_spread(inout uint alt_seed, float spread_angle) {\n";
  685. code += " float pi = 3.14159;\n";
  686. code += " float degree_to_rad = pi / 180.0;\n";
  687. code += " float spread_rad = spread_angle * degree_to_rad;\n";
  688. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  689. // Spread calculation for 2D.
  690. code += " float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;\n";
  691. code += " angle1_rad += direction.x != 0.0 ? atan(direction.y, direction.x) : sign(direction.y) * (pi / 2.0);\n";
  692. code += " vec3 spread_direction = vec3(cos(angle1_rad), sin(angle1_rad), 0.0);\n";
  693. code += " return spread_direction;\n";
  694. } else {
  695. // Spread calculation for 3D.
  696. code += " float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;\n";
  697. code += " float angle2_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad * (1.0 - flatness);\n";
  698. code += " vec3 direction_xz = vec3(sin(angle1_rad), 0.0, cos(angle1_rad));\n";
  699. code += " vec3 direction_yz = vec3(0.0, sin(angle2_rad), cos(angle2_rad));\n";
  700. code += " direction_yz.z = direction_yz.z / max(0.0001, sqrt(abs(direction_yz.z))); // Better uniform distribution.\n";
  701. code += " vec3 spread_direction = vec3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);\n";
  702. code += " vec3 direction_nrm = length(direction) > 0.0 ? normalize(direction) : vec3(0.0, 0.0, 1.0);\n";
  703. code += " // Rotate spread to direction.\n";
  704. code += " vec3 binormal = cross(vec3(0.0, 1.0, 0.0), direction_nrm);\n";
  705. code += " if (length(binormal) < 0.0001) {\n";
  706. code += " // Direction is parallel to Y. Choose Z as the binormal.\n";
  707. code += " binormal = vec3(0.0, 0.0, 1.0);\n";
  708. code += " }\n";
  709. code += " binormal = normalize(binormal);\n";
  710. code += " vec3 normal = cross(binormal, direction_nrm);\n";
  711. code += " spread_direction = binormal * spread_direction.x + normal * spread_direction.y + direction_nrm * spread_direction.z;\n";
  712. code += " return normalize(spread_direction);\n";
  713. }
  714. code += "}\n\n";
  715. code += "vec3 process_radial_displacement(DynamicsParameters param, float lifetime, inout uint alt_seed, mat4 transform, mat4 emission_transform, float delta) {\n";
  716. code += " vec3 radial_displacement = vec3(0.0);\n";
  717. code += " if (delta < 0.001) {\n";
  718. code += " return radial_displacement;\n";
  719. code += " }\n";
  720. code += " float radial_displacement_multiplier = 1.0;\n";
  721. if (tex_parameters[PARAM_RADIAL_VELOCITY].is_valid()) {
  722. code += " radial_displacement_multiplier = texture(radial_velocity_curve, vec2(lifetime)).r;\n";
  723. }
  724. code += " vec3 global_pivot = (emission_transform * vec4(velocity_pivot, 1.0)).xyz;\n";
  725. code += " if (length(transform[3].xyz - global_pivot) > 0.01) {\n";
  726. code += " radial_displacement = normalize(transform[3].xyz - global_pivot) * radial_displacement_multiplier * param.radial_velocity;\n";
  727. code += " } else {\n";
  728. code += " radial_displacement = get_random_direction_from_spread(alt_seed, 360.0) * param.radial_velocity;\n";
  729. code += " }\n";
  730. code += " if (radial_displacement_multiplier * param.radial_velocity < 0.0) {\n";
  731. code += " // Prevent inwards velocity to flicker once the point is reached.\n";
  732. code += " radial_displacement = normalize(radial_displacement) * min(abs(radial_displacement_multiplier * param.radial_velocity), length(transform[3].xyz - global_pivot) / delta);\n";
  733. code += " }\n";
  734. code += " return radial_displacement;\n";
  735. code += "}\n\n";
  736. if (tex_parameters[PARAM_DIRECTIONAL_VELOCITY].is_valid()) {
  737. code += "vec3 process_directional_displacement(DynamicsParameters param, float lifetime_percent, mat4 transform, mat4 emission_transform) {\n";
  738. code += " vec3 displacement = texture(directional_velocity_curve, vec2(lifetime_percent)).xyz * param.directional_velocity;\n";
  739. if (directional_velocity_global) {
  740. code += " displacement = (emission_transform * vec4(displacement, 0.0)).xyz;\n";
  741. }
  742. code += " return displacement;\n";
  743. code += "}\n\n";
  744. }
  745. code += "void process_physical_parameters(inout PhysicalParameters params, float lifetime_percent) {\n";
  746. if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid()) {
  747. code += " params.linear_accel *= texture(linear_accel_texture, vec2(lifetime_percent)).r;\n";
  748. }
  749. if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid()) {
  750. code += " params.radial_accel *= texture(radial_accel_texture, vec2(lifetime_percent)).r;\n";
  751. }
  752. if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) {
  753. code += " params.tangent_accel *= texture(tangent_accel_texture, vec2(lifetime_percent)).r;\n";
  754. }
  755. if (tex_parameters[PARAM_DAMPING].is_valid()) {
  756. code += " params.damping *= texture(damping_texture, vec2(lifetime_percent)).r;\n";
  757. }
  758. code += "}\n\n";
  759. code += "void start() {\n";
  760. code += " uint base_number = NUMBER;\n";
  761. code += " uint alt_seed = hash(base_number + uint(1) + RANDOM_SEED);\n";
  762. code += " DisplayParameters params;\n";
  763. code += " calculate_initial_display_params(params, alt_seed);\n";
  764. code += " // Reset alt seed?\n";
  765. code += " //alt_seed = hash(base_number + uint(1) + RANDOM_SEED);\n";
  766. code += " DynamicsParameters dynamic_params;\n";
  767. code += " calculate_initial_dynamics_params(dynamic_params, alt_seed);\n";
  768. code += " PhysicalParameters physics_params;\n";
  769. code += " calculate_initial_physical_params(physics_params, alt_seed);\n";
  770. code += " process_display_param(params, 0.0);\n";
  771. code += " if (rand_from_seed(alt_seed) > AMOUNT_RATIO) {\n";
  772. code += " ACTIVE = false;\n";
  773. code += " }\n\n";
  774. code += " if (RESTART_CUSTOM) {\n";
  775. code += " CUSTOM = vec4(0.0);\n";
  776. code += " CUSTOM.w = params.lifetime;\n";
  777. code += " CUSTOM.x = dynamic_params.angle;\n";
  778. code += " }\n";
  779. code += " if (RESTART_COLOR) {\n";
  780. code += " COLOR = params.color;\n";
  781. code += " }\n";
  782. code += " if (RESTART_ROT_SCALE) {\n";
  783. code += " TRANSFORM[0].xyz = vec3(1.0, 0.0, 0.0);\n";
  784. code += " TRANSFORM[1].xyz = vec3(0.0, 1.0, 0.0);\n";
  785. code += " TRANSFORM[2].xyz = vec3(0.0, 0.0, 1.0);\n";
  786. code += " }\n";
  787. code += " if (RESTART_POSITION) {\n";
  788. code += " TRANSFORM[3].xyz = calculate_initial_position(params, alt_seed);\n";
  789. if (turbulence_enabled) {
  790. code += " float initial_turbulence_displacement = mix(turbulence_initial_displacement_min, turbulence_initial_displacement_max, rand_from_seed(alt_seed));\n";
  791. code += " vec3 noise_direction = get_noise_direction(TRANSFORM[3].xyz);\n";
  792. code += " TRANSFORM[3].xyz += noise_direction * initial_turbulence_displacement;\n";
  793. }
  794. code += " TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;\n";
  795. code += " }\n";
  796. code += " if (RESTART_VELOCITY) {\n";
  797. code += " VELOCITY = get_random_direction_from_spread(alt_seed, spread) * dynamic_params.initial_velocity_multiplier;\n";
  798. if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
  799. code += " int point = min(emission_texture_point_count - 1, int(params.emission_texture_position * float(emission_texture_point_count)));\n";
  800. code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n";
  801. code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n";
  802. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  803. code += " {\n";
  804. code += " mat2 rotm;\n";
  805. code += " rotm[0] = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xy;\n";
  806. code += " rotm[1] = rotm[0].yx * vec2(1.0, -1.0);\n";
  807. code += " VELOCITY.xy = rotm * VELOCITY.xy;\n";
  808. code += " }\n";
  809. } else {
  810. code += " {\n";
  811. code += " vec3 normal = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xyz;\n";
  812. code += " vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);\n";
  813. code += " vec3 tangent = normalize(cross(v0, normal));\n";
  814. code += " vec3 bitangent = normalize(cross(tangent, normal));\n";
  815. code += " VELOCITY = mat3(tangent, bitangent, normal) * VELOCITY;\n";
  816. code += " }\n";
  817. }
  818. }
  819. code += " }\n\n";
  820. code += " process_display_param(params, 0.0);\n\n";
  821. code += " VELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY, 0.0)).xyz;\n";
  822. code += " VELOCITY += EMITTER_VELOCITY * inherit_emitter_velocity_ratio;\n";
  823. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  824. code += " VELOCITY.z = 0.0;\n";
  825. code += " TRANSFORM[3].z = 0.0;\n";
  826. }
  827. code += "}\n\n";
  828. code += "void process() {\n";
  829. code += " uint base_number = NUMBER;\n";
  830. // TODO: Add optional determinism here.
  831. code += " //if (repeatable) {\n";
  832. code += " // base_number = INDEX;\n";
  833. code += " //}\n";
  834. code += " uint alt_seed = hash(base_number + uint(1) + RANDOM_SEED);\n";
  835. code += " DisplayParameters params;\n";
  836. code += " calculate_initial_display_params(params, alt_seed);\n";
  837. code += " DynamicsParameters dynamic_params;\n";
  838. code += " calculate_initial_dynamics_params(dynamic_params, alt_seed);\n";
  839. code += " PhysicalParameters physics_params;\n";
  840. code += " calculate_initial_physical_params(physics_params, alt_seed);\n\n";
  841. code += " float pi = 3.14159;\n";
  842. code += " float degree_to_rad = pi / 180.0;\n\n";
  843. if (sub_emitter_mode == SUB_EMITTER_AT_START && !RenderingServer::get_singleton()->is_low_end()) {
  844. code += " bool just_spawned = CUSTOM.y == 0.0;\n";
  845. }
  846. code += " CUSTOM.y += DELTA / LIFETIME;\n";
  847. code += " CUSTOM.y = mix(CUSTOM.y, 1.0, INTERPOLATE_TO_END);\n";
  848. code += " float lifetime_percent = CUSTOM.y / params.lifetime;\n";
  849. code += " if (CUSTOM.y > CUSTOM.w) {\n";
  850. code += " ACTIVE = false;\n";
  851. code += " }\n\n";
  852. code += " // Calculate all velocity.\n";
  853. code += " vec3 controlled_displacement = vec3(0.0);\n";
  854. if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid() || particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  855. code += " controlled_displacement += process_orbit_displacement(dynamic_params, lifetime_percent, alt_seed, TRANSFORM, EMISSION_TRANSFORM, DELTA, params.lifetime * LIFETIME);\n";
  856. }
  857. code += " controlled_displacement += process_radial_displacement(dynamic_params, lifetime_percent, alt_seed, TRANSFORM, EMISSION_TRANSFORM, DELTA);\n";
  858. if (tex_parameters[PARAM_DIRECTIONAL_VELOCITY].is_valid()) {
  859. code += " controlled_displacement += process_directional_displacement(dynamic_params, lifetime_percent, TRANSFORM, EMISSION_TRANSFORM);\n";
  860. }
  861. code += "\n";
  862. code += " process_physical_parameters(physics_params, lifetime_percent);\n";
  863. code += " vec3 force;\n";
  864. code += " {\n";
  865. code += " // Copied from previous version.\n";
  866. code += " vec3 pos = TRANSFORM[3].xyz;\n";
  867. code += " force = gravity;\n";
  868. code += " // Apply linear acceleration.\n";
  869. code += " force += length(VELOCITY) > 0.0 ? normalize(VELOCITY) * physics_params.linear_accel : vec3(0.0);\n";
  870. code += " // Apply radial acceleration.\n";
  871. code += " vec3 org = EMISSION_TRANSFORM[3].xyz;\n";
  872. code += " vec3 diff = pos - org;\n";
  873. code += " force += length(diff) > 0.0 ? normalize(diff) * physics_params.radial_accel : vec3(0.0);\n";
  874. code += " // Apply tangential acceleration.\n";
  875. code += " float tangent_accel_val = physics_params.tangent_accel;\n";
  876. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  877. code += " force += length(diff.yx) > 0.0 ? vec3(normalize(diff.yx * vec2(-1.0, 1.0)), 0.0) * tangent_accel_val : vec3(0.0);\n";
  878. } else {
  879. code += " vec3 crossDiff = cross(normalize(diff), normalize(gravity));\n";
  880. code += " force += length(crossDiff) > 0.0 ? normalize(crossDiff) * tangent_accel_val : vec3(0.0);\n";
  881. }
  882. if (attractor_interaction_enabled) {
  883. code += " force += ATTRACTOR_FORCE;\n";
  884. }
  885. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  886. code += " force.z = 0.0;\n";
  887. }
  888. code += " // Apply attractor forces.\n";
  889. code += " VELOCITY += force * DELTA;\n";
  890. code += " }\n";
  891. code += " {\n";
  892. code += " // Copied from previous version.\n";
  893. code += " if (physics_params.damping > 0.0) {\n";
  894. code += " float v = length(VELOCITY);\n";
  895. if (!particle_flags[PARTICLE_FLAG_DAMPING_AS_FRICTION]) {
  896. code += " v -= physics_params.damping * DELTA;\n";
  897. } else {
  898. code += " if (v > 0.001) {\n";
  899. code += " // Realistic friction formula. We assume the mass of a particle to be 0.05 kg.\n";
  900. code += " float damp = v * v * physics_params.damping * 0.05 * DELTA;\n";
  901. code += " v -= damp;\n";
  902. code += " }\n";
  903. }
  904. code += " if (v < 0.0) {\n";
  905. code += " VELOCITY = vec3(0.0);\n";
  906. code += " } else {\n";
  907. code += " VELOCITY = normalize(VELOCITY) * v;\n";
  908. code += " }\n";
  909. code += " }\n";
  910. code += " }\n\n";
  911. if (collision_mode == COLLISION_RIGID) {
  912. code += " if (COLLIDED) {\n";
  913. code += " float collision_response = dot(COLLISION_NORMAL, VELOCITY);\n";
  914. code += " float slide_to_bounce_trigger = step(2.0 / clamp(collision_bounce + 1.0, 1.0, 2.0), abs(collision_response));\n";
  915. code += " TRANSFORM[3].xyz += COLLISION_NORMAL * COLLISION_DEPTH;\n";
  916. code += " // Remove all components of VELOCITY that are not tangential to COLLISION_NORMAL.\n";
  917. code += " VELOCITY -= COLLISION_NORMAL * collision_response;\n";
  918. code += " // Apply friction only to VELOCITY across the surface (effectively decouples friction and bounce behavior).\n";
  919. code += " VELOCITY = mix(VELOCITY, vec3(0.0), clamp(collision_friction, 0.0, 1.0));\n";
  920. code += " // Add bounce velocity to VELOCITY.\n";
  921. code += " VELOCITY -= COLLISION_NORMAL * collision_response * (collision_bounce * slide_to_bounce_trigger);\n";
  922. code += " }\n\n";
  923. } else if (collision_mode == COLLISION_HIDE_ON_CONTACT) {
  924. code += " if (COLLIDED) {\n";
  925. code += " ACTIVE = false;\n";
  926. code += " }\n\n";
  927. }
  928. code += " // Turbulence before limiting.\n";
  929. if (turbulence_enabled) {
  930. if (tex_parameters[PARAM_TURB_INFLUENCE_OVER_LIFE].is_valid()) {
  931. code += " float turbulence_influence = textureLod(turbulence_influence_over_life, vec2(lifetime_percent, 0.0), 0.0).r;\n";
  932. } else {
  933. code += " float turbulence_influence = 1.0;\n";
  934. }
  935. code += "\n";
  936. code += " vec3 noise_direction = get_noise_direction(TRANSFORM[3].xyz);\n";
  937. // Godot detects when the COLLIDED keyword is used. If it's used anywhere in the shader then Godot will generate the screen space SDF for collisions.
  938. // We don't need it as long as collision is disabled. Refer to GH-83744 for more info.
  939. if (collision_mode == COLLISION_RIGID) {
  940. code += " if (!COLLIDED) {\n";
  941. } else {
  942. code += " {\n";
  943. }
  944. code += " float vel_mag = length(VELOCITY);\n";
  945. code += " float vel_infl = clamp(dynamic_params.turb_influence * turbulence_influence, 0.0, 1.0);\n";
  946. code += " VELOCITY = mix(VELOCITY, normalize(noise_direction) * vel_mag * (1.0 + (1.0 - vel_infl) * 0.2), vel_infl);\n";
  947. code += " vel_mag = length(controlled_displacement);\n";
  948. code += " controlled_displacement = mix(controlled_displacement, normalize(noise_direction) * vel_mag * (1.0 + (1.0 - vel_infl) * 0.2), vel_infl);\n";
  949. code += " }\n";
  950. }
  951. code += " vec3 final_velocity = controlled_displacement + VELOCITY;\n\n";
  952. if (velocity_limit_curve.is_valid()) {
  953. code += " // Limit velocity.\n";
  954. code += " if (length(final_velocity) > 0.001) {\n";
  955. code += " final_velocity = normalize(final_velocity) * min(abs(length(final_velocity)), abs(texture(velocity_limit_curve, vec2(lifetime_percent)).r));\n";
  956. code += " }\n\n";
  957. }
  958. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  959. code += " final_velocity.z = 0.0;\n\n";
  960. }
  961. code += " TRANSFORM[3].xyz += final_velocity * DELTA;\n\n";
  962. code += " process_display_param(params, lifetime_percent);\n\n";
  963. code += " float base_angle = dynamic_params.angle;\n";
  964. if (tex_parameters[PARAM_ANGLE].is_valid()) {
  965. code += " base_angle *= texture(angle_texture, vec2(lifetime_percent)).r;\n";
  966. }
  967. if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) {
  968. code += " base_angle += CUSTOM.y * LIFETIME * dynamic_params.angular_velocity * texture(angular_velocity_texture, vec2(lifetime_percent)).r;\n";
  969. } else {
  970. code += " base_angle += CUSTOM.y * LIFETIME * dynamic_params.angular_velocity;\n";
  971. }
  972. code += " CUSTOM.x = base_angle * degree_to_rad;\n";
  973. code += " COLOR = params.color;\n\n";
  974. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  975. if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
  976. code += " if (length(final_velocity) > 0.0) {\n";
  977. code += " TRANSFORM[1].xyz = normalize(final_velocity);\n";
  978. code += " } else {\n";
  979. code += " TRANSFORM[1].xyz = normalize(TRANSFORM[1].xyz);\n";
  980. code += " }\n";
  981. code += " TRANSFORM[0].xyz = normalize(cross(TRANSFORM[1].xyz, TRANSFORM[2].xyz));\n";
  982. code += " TRANSFORM[2] = vec4(0.0, 0.0, 1.0, 0.0);\n";
  983. } else {
  984. code += " TRANSFORM[0] = vec4(cos(CUSTOM.x), -sin(CUSTOM.x), 0.0, 0.0);\n";
  985. code += " TRANSFORM[1] = vec4(sin(CUSTOM.x), cos(CUSTOM.x), 0.0, 0.0);\n";
  986. code += " TRANSFORM[2] = vec4(0.0, 0.0, 1.0, 0.0);\n";
  987. }
  988. } else {
  989. // Orient particle Y towards velocity.
  990. if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
  991. code += " if (length(final_velocity) > 0.0) {\n";
  992. code += " TRANSFORM[1].xyz = normalize(final_velocity);\n";
  993. code += " } else {\n";
  994. code += " TRANSFORM[1].xyz = normalize(TRANSFORM[1].xyz);\n";
  995. code += " }\n";
  996. code += " if (TRANSFORM[1].xyz == normalize(TRANSFORM[0].xyz)) {\n";
  997. code += " TRANSFORM[0].xyz = normalize(cross(normalize(TRANSFORM[1].xyz), normalize(TRANSFORM[2].xyz)));\n";
  998. code += " TRANSFORM[2].xyz = normalize(cross(normalize(TRANSFORM[0].xyz), normalize(TRANSFORM[1].xyz)));\n";
  999. code += " } else {\n";
  1000. code += " TRANSFORM[2].xyz = normalize(cross(normalize(TRANSFORM[0].xyz), normalize(TRANSFORM[1].xyz)));\n";
  1001. code += " TRANSFORM[0].xyz = normalize(cross(normalize(TRANSFORM[1].xyz), normalize(TRANSFORM[2].xyz)));\n";
  1002. code += " }\n";
  1003. } else {
  1004. code += " TRANSFORM[0].xyz = normalize(TRANSFORM[0].xyz);\n";
  1005. code += " TRANSFORM[1].xyz = normalize(TRANSFORM[1].xyz);\n";
  1006. code += " TRANSFORM[2].xyz = normalize(TRANSFORM[2].xyz);\n";
  1007. }
  1008. // Turn particle by rotation in Y.
  1009. if (particle_flags[PARTICLE_FLAG_ROTATE_Y]) {
  1010. code += " vec4 origin = TRANSFORM[3];\n";
  1011. code += " TRANSFORM = mat4(vec4(cos(CUSTOM.x), 0.0, -sin(CUSTOM.x), 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(sin(CUSTOM.x), 0.0, cos(CUSTOM.x), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n";
  1012. code += " TRANSFORM[3] = origin;\n";
  1013. }
  1014. }
  1015. if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
  1016. code += " TRANSFORM[3].z = 0.0;\n\n";
  1017. }
  1018. if (tex_parameters[PARAM_SCALE_OVER_VELOCITY].is_valid()) {
  1019. code += " if (length(final_velocity) > 0.001) {\n";
  1020. code += " params.scale *= texture(scale_over_velocity_curve, vec2(clamp(length(final_velocity) / (scale_over_velocity_max - scale_over_velocity_min), 0.0, 1.0), 0.0)).rgb;\n";
  1021. code += " } else {\n";
  1022. code += " params.scale *= texture(scale_over_velocity_curve, vec2(0.0)).rgb;\n";
  1023. code += " }\n";
  1024. }
  1025. code += " TRANSFORM[0].xyz *= sign(params.scale.x) * max(abs(params.scale.x), 0.001);\n";
  1026. code += " TRANSFORM[1].xyz *= sign(params.scale.y) * max(abs(params.scale.y), 0.001);\n";
  1027. code += " TRANSFORM[2].xyz *= sign(params.scale.z) * max(abs(params.scale.z), 0.001);\n";
  1028. code += "\n";
  1029. code += " CUSTOM.z = params.animation_offset + lifetime_percent * params.animation_speed;\n\n";
  1030. if (sub_emitter_mode != SUB_EMITTER_DISABLED && !RenderingServer::get_singleton()->is_low_end()) {
  1031. code += " int emit_count = 0;\n";
  1032. switch (sub_emitter_mode) {
  1033. case SUB_EMITTER_CONSTANT: {
  1034. code += " float interval_from = CUSTOM.y * LIFETIME - DELTA;\n";
  1035. code += " float interval_rem = sub_emitter_frequency - mod(interval_from, sub_emitter_frequency);\n";
  1036. code += " if (DELTA >= interval_rem) {\n";
  1037. code += " emit_count = 1;\n";
  1038. code += " }\n";
  1039. } break;
  1040. case SUB_EMITTER_AT_COLLISION: {
  1041. code += " if (COLLIDED) {\n";
  1042. code += " emit_count = sub_emitter_amount_at_collision;\n";
  1043. code += " }\n";
  1044. } break;
  1045. case SUB_EMITTER_AT_END: {
  1046. code += " if ((CUSTOM.y / CUSTOM.w * LIFETIME) > (LIFETIME - DELTA)) {\n";
  1047. code += " emit_count = sub_emitter_amount_at_end;\n";
  1048. code += " }\n";
  1049. } break;
  1050. case SUB_EMITTER_AT_START: {
  1051. code += " if (just_spawned) {\n";
  1052. code += " emit_count = sub_emitter_amount_at_start;\n";
  1053. code += " }\n";
  1054. } break;
  1055. default: {
  1056. }
  1057. }
  1058. code += " for (int i = 0; i < emit_count; i++) {\n";
  1059. code += " uint flags = FLAG_EMIT_POSITION | FLAG_EMIT_ROT_SCALE;\n";
  1060. code += " if (sub_emitter_keep_velocity) {\n";
  1061. code += " flags |= FLAG_EMIT_VELOCITY;\n";
  1062. code += " }\n";
  1063. code += " emit_subparticle(TRANSFORM, VELOCITY, vec4(0.0), vec4(0.0), flags);\n";
  1064. code += " }\n\n";
  1065. }
  1066. code += " if (CUSTOM.y > CUSTOM.w) {\n";
  1067. code += " ACTIVE = false;\n";
  1068. code += " }\n";
  1069. code += "}\n";
  1070. ShaderData shader_data;
  1071. shader_data.shader = RS::get_singleton()->shader_create();
  1072. shader_data.users = 1;
  1073. RS::get_singleton()->shader_set_code(shader_data.shader, code);
  1074. shader_map[mk] = shader_data;
  1075. RS::get_singleton()->material_set_shader(_get_material(), shader_data.shader);
  1076. }
  1077. void ParticleProcessMaterial::flush_changes() {
  1078. MutexLock lock(material_mutex);
  1079. while (dirty_materials.first()) {
  1080. dirty_materials.first()->self()->_update_shader();
  1081. dirty_materials.first()->remove_from_list();
  1082. }
  1083. }
  1084. void ParticleProcessMaterial::_queue_shader_change() {
  1085. if (!_is_initialized()) {
  1086. return;
  1087. }
  1088. MutexLock lock(material_mutex);
  1089. if (!element.in_list()) {
  1090. dirty_materials.add(&element);
  1091. }
  1092. }
  1093. bool ParticleProcessMaterial::has_min_max_property(const String &p_name) {
  1094. return min_max_properties.has(p_name);
  1095. }
  1096. void ParticleProcessMaterial::set_direction(Vector3 p_direction) {
  1097. direction = p_direction;
  1098. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->direction, direction);
  1099. }
  1100. Vector3 ParticleProcessMaterial::get_direction() const {
  1101. return direction;
  1102. }
  1103. void ParticleProcessMaterial::set_spread(float p_spread) {
  1104. spread = p_spread;
  1105. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->spread, p_spread);
  1106. }
  1107. float ParticleProcessMaterial::get_spread() const {
  1108. return spread;
  1109. }
  1110. void ParticleProcessMaterial::set_flatness(float p_flatness) {
  1111. flatness = p_flatness;
  1112. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->flatness, p_flatness);
  1113. }
  1114. float ParticleProcessMaterial::get_flatness() const {
  1115. return flatness;
  1116. }
  1117. void ParticleProcessMaterial::set_velocity_pivot(const Vector3 &p_pivot) {
  1118. velocity_pivot = p_pivot;
  1119. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->velocity_pivot, p_pivot);
  1120. }
  1121. Vector3 ParticleProcessMaterial::get_velocity_pivot() {
  1122. return velocity_pivot;
  1123. }
  1124. void ParticleProcessMaterial::set_param(Parameter p_param, const Vector2 &p_value) {
  1125. set_param_min(p_param, p_value.x);
  1126. set_param_max(p_param, p_value.y);
  1127. }
  1128. Vector2 ParticleProcessMaterial::get_param(Parameter p_param) const {
  1129. return Vector2(get_param_min(p_param), get_param_max(p_param));
  1130. }
  1131. void ParticleProcessMaterial::set_param_min(Parameter p_param, float p_value) {
  1132. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  1133. params_min[p_param] = p_value;
  1134. if (params_min[p_param] > params_max[p_param]) {
  1135. set_param_max(p_param, p_value);
  1136. }
  1137. switch (p_param) {
  1138. case PARAM_INITIAL_LINEAR_VELOCITY: {
  1139. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_linear_velocity_min, p_value);
  1140. } break;
  1141. case PARAM_ANGULAR_VELOCITY: {
  1142. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_min, p_value);
  1143. } break;
  1144. case PARAM_ORBIT_VELOCITY: {
  1145. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_min, p_value);
  1146. } break;
  1147. case PARAM_LINEAR_ACCEL: {
  1148. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_min, p_value);
  1149. } break;
  1150. case PARAM_RADIAL_ACCEL: {
  1151. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_min, p_value);
  1152. } break;
  1153. case PARAM_TANGENTIAL_ACCEL: {
  1154. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_min, p_value);
  1155. } break;
  1156. case PARAM_DAMPING: {
  1157. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_min, p_value);
  1158. } break;
  1159. case PARAM_ANGLE: {
  1160. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_angle_min, p_value);
  1161. } break;
  1162. case PARAM_SCALE: {
  1163. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_min, p_value);
  1164. } break;
  1165. case PARAM_HUE_VARIATION: {
  1166. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_min, p_value);
  1167. } break;
  1168. case PARAM_ANIM_SPEED: {
  1169. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_min, p_value);
  1170. } break;
  1171. case PARAM_ANIM_OFFSET: {
  1172. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_min, p_value);
  1173. } break;
  1174. case PARAM_TURB_VEL_INFLUENCE: {
  1175. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_influence_min, p_value);
  1176. } break;
  1177. case PARAM_TURB_INIT_DISPLACEMENT: {
  1178. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_initial_displacement_min, p_value);
  1179. } break;
  1180. case PARAM_TURB_INFLUENCE_OVER_LIFE: {
  1181. // Can't happen, but silences warning
  1182. } break;
  1183. case PARAM_RADIAL_VELOCITY: {
  1184. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_velocity_min, p_value);
  1185. } break;
  1186. case PARAM_SCALE_OVER_VELOCITY: {
  1187. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_over_velocity_min, p_value);
  1188. } break;
  1189. case PARAM_DIRECTIONAL_VELOCITY: {
  1190. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->directional_velocity_min, p_value);
  1191. } break;
  1192. case PARAM_MAX:
  1193. break; // Can't happen, but silences warning
  1194. }
  1195. }
  1196. float ParticleProcessMaterial::get_param_min(Parameter p_param) const {
  1197. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  1198. return params_min[p_param];
  1199. }
  1200. void ParticleProcessMaterial::set_param_max(Parameter p_param, float p_value) {
  1201. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  1202. params_max[p_param] = p_value;
  1203. if (params_min[p_param] > params_max[p_param]) {
  1204. set_param_min(p_param, p_value);
  1205. }
  1206. switch (p_param) {
  1207. case PARAM_INITIAL_LINEAR_VELOCITY: {
  1208. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_linear_velocity_max, p_value);
  1209. } break;
  1210. case PARAM_ANGULAR_VELOCITY: {
  1211. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_max, p_value);
  1212. } break;
  1213. case PARAM_ORBIT_VELOCITY: {
  1214. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_max, p_value);
  1215. } break;
  1216. case PARAM_LINEAR_ACCEL: {
  1217. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_max, p_value);
  1218. } break;
  1219. case PARAM_RADIAL_ACCEL: {
  1220. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_max, p_value);
  1221. } break;
  1222. case PARAM_TANGENTIAL_ACCEL: {
  1223. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_max, p_value);
  1224. } break;
  1225. case PARAM_DAMPING: {
  1226. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_max, p_value);
  1227. } break;
  1228. case PARAM_ANGLE: {
  1229. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_angle_max, p_value);
  1230. } break;
  1231. case PARAM_SCALE: {
  1232. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_max, p_value);
  1233. } break;
  1234. case PARAM_HUE_VARIATION: {
  1235. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_max, p_value);
  1236. } break;
  1237. case PARAM_ANIM_SPEED: {
  1238. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_max, p_value);
  1239. } break;
  1240. case PARAM_ANIM_OFFSET: {
  1241. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_max, p_value);
  1242. } break;
  1243. case PARAM_TURB_VEL_INFLUENCE: {
  1244. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_influence_max, p_value);
  1245. } break;
  1246. case PARAM_TURB_INIT_DISPLACEMENT: {
  1247. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_initial_displacement_max, p_value);
  1248. } break;
  1249. case PARAM_TURB_INFLUENCE_OVER_LIFE: {
  1250. // Can't happen, but silences warning
  1251. } break;
  1252. case PARAM_RADIAL_VELOCITY: {
  1253. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_velocity_max, p_value);
  1254. } break;
  1255. case PARAM_SCALE_OVER_VELOCITY: {
  1256. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_over_velocity_max, p_value);
  1257. } break;
  1258. case PARAM_DIRECTIONAL_VELOCITY: {
  1259. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->directional_velocity_max, p_value);
  1260. } break;
  1261. case PARAM_MAX:
  1262. break; // Can't happen, but silences warning
  1263. }
  1264. }
  1265. float ParticleProcessMaterial::get_param_max(Parameter p_param) const {
  1266. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
  1267. return params_max[p_param];
  1268. }
  1269. static void _adjust_curve_range(const Ref<Texture2D> &p_texture, float p_min, float p_max) {
  1270. Ref<CurveTexture> curve_tex = p_texture;
  1271. if (curve_tex.is_valid()) {
  1272. curve_tex->ensure_default_setup(p_min, p_max);
  1273. return;
  1274. }
  1275. Ref<CurveXYZTexture> curve_xyz_tex = p_texture;
  1276. if (curve_xyz_tex.is_valid()) {
  1277. curve_xyz_tex->ensure_default_setup(p_min, p_max);
  1278. return;
  1279. }
  1280. }
  1281. void ParticleProcessMaterial::set_param_texture(Parameter p_param, const Ref<Texture2D> &p_texture) {
  1282. ERR_FAIL_INDEX(p_param, PARAM_MAX);
  1283. tex_parameters[p_param] = p_texture;
  1284. Variant tex_rid = p_texture.is_valid() ? Variant(p_texture->get_rid()) : Variant();
  1285. switch (p_param) {
  1286. case PARAM_INITIAL_LINEAR_VELOCITY: {
  1287. //do none for this one
  1288. } break;
  1289. case PARAM_ANGULAR_VELOCITY: {
  1290. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_texture, tex_rid);
  1291. _adjust_curve_range(p_texture, -360, 360);
  1292. } break;
  1293. case PARAM_ORBIT_VELOCITY: {
  1294. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_texture, tex_rid);
  1295. _adjust_curve_range(p_texture, -2, 2);
  1296. notify_property_list_changed();
  1297. } break;
  1298. case PARAM_LINEAR_ACCEL: {
  1299. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_texture, tex_rid);
  1300. _adjust_curve_range(p_texture, -200, 200);
  1301. } break;
  1302. case PARAM_RADIAL_ACCEL: {
  1303. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_texture, tex_rid);
  1304. _adjust_curve_range(p_texture, -200, 200);
  1305. } break;
  1306. case PARAM_TANGENTIAL_ACCEL: {
  1307. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_texture, tex_rid);
  1308. _adjust_curve_range(p_texture, -200, 200);
  1309. } break;
  1310. case PARAM_DAMPING: {
  1311. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_texture, tex_rid);
  1312. _adjust_curve_range(p_texture, 0, 100);
  1313. } break;
  1314. case PARAM_ANGLE: {
  1315. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angle_texture, tex_rid);
  1316. _adjust_curve_range(p_texture, -360, 360);
  1317. } break;
  1318. case PARAM_SCALE: {
  1319. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_texture, tex_rid);
  1320. _adjust_curve_range(p_texture, 0, 1);
  1321. } break;
  1322. case PARAM_HUE_VARIATION: {
  1323. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_texture, tex_rid);
  1324. _adjust_curve_range(p_texture, -1, 1);
  1325. } break;
  1326. case PARAM_ANIM_SPEED: {
  1327. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_texture, tex_rid);
  1328. _adjust_curve_range(p_texture, 0, 200);
  1329. } break;
  1330. case PARAM_ANIM_OFFSET: {
  1331. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_texture, tex_rid);
  1332. } break;
  1333. case PARAM_TURB_INFLUENCE_OVER_LIFE: {
  1334. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_influence_over_life, tex_rid);
  1335. _adjust_curve_range(p_texture, 0, 1);
  1336. } break;
  1337. case PARAM_TURB_VEL_INFLUENCE: {
  1338. // Can't happen, but silences warning
  1339. } break;
  1340. case PARAM_TURB_INIT_DISPLACEMENT: {
  1341. // Can't happen, but silences warning
  1342. } break;
  1343. case PARAM_RADIAL_VELOCITY: {
  1344. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_velocity_texture, tex_rid);
  1345. } break;
  1346. case PARAM_SCALE_OVER_VELOCITY: {
  1347. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_over_velocity_texture, tex_rid);
  1348. _adjust_curve_range(p_texture, 0, 3);
  1349. notify_property_list_changed();
  1350. } break;
  1351. case PARAM_DIRECTIONAL_VELOCITY: {
  1352. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->directional_velocity_texture, tex_rid);
  1353. notify_property_list_changed();
  1354. } break;
  1355. case PARAM_MAX:
  1356. break; // Can't happen, but silences warning
  1357. }
  1358. _queue_shader_change();
  1359. }
  1360. Ref<Texture2D> ParticleProcessMaterial::get_param_texture(Parameter p_param) const {
  1361. ERR_FAIL_INDEX_V(p_param, PARAM_MAX, Ref<Texture2D>());
  1362. return tex_parameters[p_param];
  1363. }
  1364. void ParticleProcessMaterial::set_color(const Color &p_color) {
  1365. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color, p_color);
  1366. color = p_color;
  1367. }
  1368. Color ParticleProcessMaterial::get_color() const {
  1369. return color;
  1370. }
  1371. void ParticleProcessMaterial::set_color_ramp(const Ref<Texture2D> &p_texture) {
  1372. color_ramp = p_texture;
  1373. Variant tex_rid = p_texture.is_valid() ? Variant(p_texture->get_rid()) : Variant();
  1374. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color_ramp, tex_rid);
  1375. _queue_shader_change();
  1376. notify_property_list_changed();
  1377. }
  1378. Ref<Texture2D> ParticleProcessMaterial::get_color_ramp() const {
  1379. return color_ramp;
  1380. }
  1381. void ParticleProcessMaterial::set_color_initial_ramp(const Ref<Texture2D> &p_texture) {
  1382. color_initial_ramp = p_texture;
  1383. Variant tex_rid = p_texture.is_valid() ? Variant(p_texture->get_rid()) : Variant();
  1384. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color_initial_ramp, tex_rid);
  1385. _queue_shader_change();
  1386. notify_property_list_changed();
  1387. }
  1388. Ref<Texture2D> ParticleProcessMaterial::get_color_initial_ramp() const {
  1389. return color_initial_ramp;
  1390. }
  1391. void ParticleProcessMaterial::set_particle_flag(ParticleFlags p_particle_flag, bool p_enable) {
  1392. ERR_FAIL_INDEX(p_particle_flag, PARTICLE_FLAG_MAX);
  1393. particle_flags[p_particle_flag] = p_enable;
  1394. _queue_shader_change();
  1395. if (p_particle_flag == PARTICLE_FLAG_DISABLE_Z) {
  1396. notify_property_list_changed();
  1397. }
  1398. }
  1399. void ParticleProcessMaterial::set_alpha_curve(const Ref<Texture2D> &p_texture) {
  1400. alpha_curve = p_texture;
  1401. Variant tex_rid = p_texture.is_valid() ? Variant(p_texture->get_rid()) : Variant();
  1402. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->alpha_ramp, tex_rid);
  1403. _queue_shader_change();
  1404. notify_property_list_changed();
  1405. }
  1406. Ref<Texture2D> ParticleProcessMaterial::get_alpha_curve() const {
  1407. return alpha_curve;
  1408. }
  1409. void ParticleProcessMaterial::set_emission_curve(const Ref<Texture2D> &p_texture) {
  1410. emission_curve = p_texture;
  1411. Variant tex_rid = p_texture.is_valid() ? Variant(p_texture->get_rid()) : Variant();
  1412. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ramp, tex_rid);
  1413. _queue_shader_change();
  1414. notify_property_list_changed();
  1415. }
  1416. Ref<Texture2D> ParticleProcessMaterial::get_emission_curve() const {
  1417. return emission_curve;
  1418. }
  1419. void ParticleProcessMaterial::set_velocity_limit_curve(const Ref<Texture2D> &p_texture) {
  1420. velocity_limit_curve = p_texture;
  1421. Variant tex_rid = p_texture.is_valid() ? Variant(p_texture->get_rid()) : Variant();
  1422. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->velocity_limit_curve, tex_rid);
  1423. _queue_shader_change();
  1424. notify_property_list_changed();
  1425. }
  1426. Ref<Texture2D> ParticleProcessMaterial::get_velocity_limit_curve() const {
  1427. return velocity_limit_curve;
  1428. }
  1429. bool ParticleProcessMaterial::get_particle_flag(ParticleFlags p_particle_flag) const {
  1430. ERR_FAIL_INDEX_V(p_particle_flag, PARTICLE_FLAG_MAX, false);
  1431. return particle_flags[p_particle_flag];
  1432. }
  1433. void ParticleProcessMaterial::set_emission_shape(EmissionShape p_shape) {
  1434. ERR_FAIL_INDEX(p_shape, EMISSION_SHAPE_MAX);
  1435. emission_shape = p_shape;
  1436. notify_property_list_changed();
  1437. _queue_shader_change();
  1438. #ifdef TOOLS_ENABLED
  1439. emit_signal("emission_shape_changed");
  1440. #endif
  1441. }
  1442. void ParticleProcessMaterial::set_emission_sphere_radius(real_t p_radius) {
  1443. emission_sphere_radius = p_radius;
  1444. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_sphere_radius, p_radius);
  1445. #ifdef TOOLS_ENABLED
  1446. emit_signal("emission_shape_changed");
  1447. #endif
  1448. }
  1449. void ParticleProcessMaterial::set_emission_box_extents(Vector3 p_extents) {
  1450. emission_box_extents = p_extents;
  1451. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_box_extents, p_extents);
  1452. #ifdef TOOLS_ENABLED
  1453. emit_signal("emission_shape_changed");
  1454. #endif
  1455. }
  1456. void ParticleProcessMaterial::set_emission_point_texture(const Ref<Texture2D> &p_points) {
  1457. emission_point_texture = p_points;
  1458. Variant tex_rid = p_points.is_valid() ? Variant(p_points->get_rid()) : Variant();
  1459. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_points, tex_rid);
  1460. }
  1461. void ParticleProcessMaterial::set_emission_normal_texture(const Ref<Texture2D> &p_normals) {
  1462. emission_normal_texture = p_normals;
  1463. Variant tex_rid = p_normals.is_valid() ? Variant(p_normals->get_rid()) : Variant();
  1464. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_normal, tex_rid);
  1465. }
  1466. void ParticleProcessMaterial::set_emission_color_texture(const Ref<Texture2D> &p_colors) {
  1467. emission_color_texture = p_colors;
  1468. Variant tex_rid = p_colors.is_valid() ? Variant(p_colors->get_rid()) : Variant();
  1469. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_color, tex_rid);
  1470. _queue_shader_change();
  1471. }
  1472. void ParticleProcessMaterial::set_emission_point_count(int p_count) {
  1473. emission_point_count = p_count;
  1474. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_point_count, p_count);
  1475. }
  1476. void ParticleProcessMaterial::set_emission_ring_axis(Vector3 p_axis) {
  1477. emission_ring_axis = p_axis;
  1478. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_axis, p_axis);
  1479. #ifdef TOOLS_ENABLED
  1480. emit_signal("emission_shape_changed");
  1481. #endif
  1482. }
  1483. void ParticleProcessMaterial::set_emission_ring_height(real_t p_height) {
  1484. emission_ring_height = p_height;
  1485. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_height, p_height);
  1486. #ifdef TOOLS_ENABLED
  1487. emit_signal("emission_shape_changed");
  1488. #endif
  1489. }
  1490. void ParticleProcessMaterial::set_emission_ring_radius(real_t p_radius) {
  1491. emission_ring_radius = p_radius;
  1492. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_radius, p_radius);
  1493. #ifdef TOOLS_ENABLED
  1494. emit_signal("emission_shape_changed");
  1495. #endif
  1496. }
  1497. void ParticleProcessMaterial::set_emission_ring_inner_radius(real_t p_radius) {
  1498. emission_ring_inner_radius = p_radius;
  1499. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_inner_radius, p_radius);
  1500. #ifdef TOOLS_ENABLED
  1501. emit_signal("emission_shape_changed");
  1502. #endif
  1503. }
  1504. void ParticleProcessMaterial::set_emission_ring_cone_angle(real_t p_angle) {
  1505. emission_ring_cone_angle = p_angle;
  1506. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_ring_cone_angle, p_angle);
  1507. #ifdef TOOLS_ENABLED
  1508. emit_signal("emission_shape_changed");
  1509. #endif
  1510. }
  1511. void ParticleProcessMaterial::set_inherit_velocity_ratio(double p_ratio) {
  1512. inherit_emitter_velocity_ratio = p_ratio;
  1513. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->inherit_emitter_velocity_ratio, p_ratio);
  1514. }
  1515. ParticleProcessMaterial::EmissionShape ParticleProcessMaterial::get_emission_shape() const {
  1516. return emission_shape;
  1517. }
  1518. real_t ParticleProcessMaterial::get_emission_sphere_radius() const {
  1519. return emission_sphere_radius;
  1520. }
  1521. Vector3 ParticleProcessMaterial::get_emission_box_extents() const {
  1522. return emission_box_extents;
  1523. }
  1524. Ref<Texture2D> ParticleProcessMaterial::get_emission_point_texture() const {
  1525. return emission_point_texture;
  1526. }
  1527. Ref<Texture2D> ParticleProcessMaterial::get_emission_normal_texture() const {
  1528. return emission_normal_texture;
  1529. }
  1530. Ref<Texture2D> ParticleProcessMaterial::get_emission_color_texture() const {
  1531. return emission_color_texture;
  1532. }
  1533. int ParticleProcessMaterial::get_emission_point_count() const {
  1534. return emission_point_count;
  1535. }
  1536. Vector3 ParticleProcessMaterial::get_emission_ring_axis() const {
  1537. return emission_ring_axis;
  1538. }
  1539. real_t ParticleProcessMaterial::get_emission_ring_height() const {
  1540. return emission_ring_height;
  1541. }
  1542. real_t ParticleProcessMaterial::get_emission_ring_radius() const {
  1543. return emission_ring_radius;
  1544. }
  1545. real_t ParticleProcessMaterial::get_emission_ring_inner_radius() const {
  1546. return emission_ring_inner_radius;
  1547. }
  1548. real_t ParticleProcessMaterial::get_emission_ring_cone_angle() const {
  1549. return emission_ring_cone_angle;
  1550. }
  1551. void ParticleProcessMaterial::set_emission_shape_offset(const Vector3 &p_emission_shape_offset) {
  1552. emission_shape_offset = p_emission_shape_offset;
  1553. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_shape_offset, p_emission_shape_offset);
  1554. #ifdef TOOLS_ENABLED
  1555. emit_signal("emission_shape_changed");
  1556. #endif
  1557. }
  1558. Vector3 ParticleProcessMaterial::get_emission_shape_offset() const {
  1559. return emission_shape_offset;
  1560. }
  1561. void ParticleProcessMaterial::set_emission_shape_scale(const Vector3 &p_emission_shape_scale) {
  1562. emission_shape_scale = p_emission_shape_scale;
  1563. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_shape_scale, p_emission_shape_scale);
  1564. #ifdef TOOLS_ENABLED
  1565. emit_signal("emission_shape_changed");
  1566. #endif
  1567. }
  1568. Vector3 ParticleProcessMaterial::get_emission_shape_scale() const {
  1569. return emission_shape_scale;
  1570. }
  1571. double ParticleProcessMaterial::get_inherit_velocity_ratio() {
  1572. return inherit_emitter_velocity_ratio;
  1573. }
  1574. void ParticleProcessMaterial::set_turbulence_enabled(const bool p_turbulence_enabled) {
  1575. turbulence_enabled = p_turbulence_enabled;
  1576. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_enabled, turbulence_enabled);
  1577. _queue_shader_change();
  1578. notify_property_list_changed();
  1579. }
  1580. bool ParticleProcessMaterial::get_turbulence_enabled() const {
  1581. return turbulence_enabled;
  1582. }
  1583. void ParticleProcessMaterial::set_turbulence_noise_strength(float p_turbulence_noise_strength) {
  1584. turbulence_noise_strength = p_turbulence_noise_strength;
  1585. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_noise_strength, p_turbulence_noise_strength);
  1586. }
  1587. float ParticleProcessMaterial::get_turbulence_noise_strength() const {
  1588. return turbulence_noise_strength;
  1589. }
  1590. void ParticleProcessMaterial::set_turbulence_noise_scale(float p_turbulence_noise_scale) {
  1591. turbulence_noise_scale = p_turbulence_noise_scale;
  1592. const float noise_frequency_when_slider_is_zero = 4.0;
  1593. const float max_slider_value = 10.0;
  1594. const float curve_exponent = 0.25;
  1595. const float curve_rescale = noise_frequency_when_slider_is_zero / pow(max_slider_value, curve_exponent);
  1596. float shader_turbulence_noise_scale = pow(p_turbulence_noise_scale, curve_exponent) * curve_rescale - noise_frequency_when_slider_is_zero;
  1597. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_noise_scale, shader_turbulence_noise_scale);
  1598. }
  1599. float ParticleProcessMaterial::get_turbulence_noise_scale() const {
  1600. return turbulence_noise_scale;
  1601. }
  1602. void ParticleProcessMaterial::set_turbulence_noise_speed_random(float p_turbulence_noise_speed_random) {
  1603. turbulence_noise_speed_random = p_turbulence_noise_speed_random;
  1604. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_noise_speed_random, p_turbulence_noise_speed_random);
  1605. }
  1606. float ParticleProcessMaterial::get_turbulence_noise_speed_random() const {
  1607. return turbulence_noise_speed_random;
  1608. }
  1609. void ParticleProcessMaterial::set_turbulence_noise_speed(const Vector3 &p_turbulence_noise_speed) {
  1610. turbulence_noise_speed = p_turbulence_noise_speed;
  1611. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_noise_speed, turbulence_noise_speed);
  1612. }
  1613. Vector3 ParticleProcessMaterial::get_turbulence_noise_speed() const {
  1614. return turbulence_noise_speed;
  1615. }
  1616. void ParticleProcessMaterial::set_gravity(const Vector3 &p_gravity) {
  1617. gravity = p_gravity;
  1618. Vector3 gset = gravity;
  1619. if (gset == Vector3()) {
  1620. gset = Vector3(0, -0.000001, 0); //as gravity is used as upvector in some calculations
  1621. }
  1622. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->gravity, gset);
  1623. }
  1624. Vector3 ParticleProcessMaterial::get_gravity() const {
  1625. return gravity;
  1626. }
  1627. void ParticleProcessMaterial::set_lifetime_randomness(double p_lifetime) {
  1628. lifetime_randomness = p_lifetime;
  1629. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->lifetime_randomness, lifetime_randomness);
  1630. }
  1631. double ParticleProcessMaterial::get_lifetime_randomness() const {
  1632. return lifetime_randomness;
  1633. }
  1634. RID ParticleProcessMaterial::get_shader_rid() const {
  1635. ERR_FAIL_COND_V(!shader_map.has(current_key), RID());
  1636. return shader_map[current_key].shader;
  1637. }
  1638. void ParticleProcessMaterial::_validate_property(PropertyInfo &p_property) const {
  1639. if (p_property.name == "emission_sphere_radius" && (emission_shape != EMISSION_SHAPE_SPHERE && emission_shape != EMISSION_SHAPE_SPHERE_SURFACE)) {
  1640. p_property.usage = PROPERTY_USAGE_NONE;
  1641. }
  1642. if (p_property.name == "emission_box_extents" && emission_shape != EMISSION_SHAPE_BOX) {
  1643. p_property.usage = PROPERTY_USAGE_NONE;
  1644. }
  1645. if ((p_property.name == "emission_point_texture" || p_property.name == "emission_color_texture") && (emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS)) {
  1646. p_property.usage = PROPERTY_USAGE_NONE;
  1647. }
  1648. if (p_property.name == "emission_normal_texture" && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS) {
  1649. p_property.usage = PROPERTY_USAGE_NONE;
  1650. }
  1651. if (p_property.name == "emission_point_count" && (emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS)) {
  1652. p_property.usage = PROPERTY_USAGE_NONE;
  1653. }
  1654. if (p_property.name.begins_with("emission_ring_") && emission_shape != EMISSION_SHAPE_RING) {
  1655. p_property.usage = PROPERTY_USAGE_NONE;
  1656. }
  1657. if (p_property.name == "sub_emitter_frequency" && sub_emitter_mode != SUB_EMITTER_CONSTANT) {
  1658. p_property.usage = PROPERTY_USAGE_NONE;
  1659. }
  1660. if (p_property.name == "sub_emitter_amount_at_end" && sub_emitter_mode != SUB_EMITTER_AT_END) {
  1661. p_property.usage = PROPERTY_USAGE_NONE;
  1662. }
  1663. if (p_property.name == "sub_emitter_amount_at_collision" && sub_emitter_mode != SUB_EMITTER_AT_COLLISION) {
  1664. p_property.usage = PROPERTY_USAGE_NONE;
  1665. }
  1666. if (p_property.name == "sub_emitter_amount_at_start" && sub_emitter_mode != SUB_EMITTER_AT_START) {
  1667. p_property.usage = PROPERTY_USAGE_NONE;
  1668. }
  1669. if (!turbulence_enabled) {
  1670. if (p_property.name == "turbulence_noise_strength" ||
  1671. p_property.name == "turbulence_noise_scale" ||
  1672. p_property.name == "turbulence_noise_speed" ||
  1673. p_property.name == "turbulence_noise_speed_random" ||
  1674. p_property.name == "turbulence_influence_over_life" ||
  1675. p_property.name == "turbulence_influence" ||
  1676. p_property.name == "turbulence_initial_displacement") {
  1677. p_property.usage &= ~PROPERTY_USAGE_EDITOR;
  1678. }
  1679. }
  1680. if (p_property.name == "collision_friction" && collision_mode != COLLISION_RIGID) {
  1681. p_property.usage = PROPERTY_USAGE_NONE;
  1682. }
  1683. if (p_property.name == "collision_bounce" && collision_mode != COLLISION_RIGID) {
  1684. p_property.usage = PROPERTY_USAGE_NONE;
  1685. }
  1686. if ((p_property.name == "directional_velocity_min" || p_property.name == "directional_velocity_max") && !tex_parameters[PARAM_DIRECTIONAL_VELOCITY].is_valid()) {
  1687. p_property.usage = PROPERTY_USAGE_NONE;
  1688. }
  1689. if ((p_property.name == "scale_over_velocity_min" || p_property.name == "scale_over_velocity_max") && !tex_parameters[PARAM_SCALE_OVER_VELOCITY].is_valid()) {
  1690. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  1691. }
  1692. if ((p_property.name == "orbit_velocity_min" || p_property.name == "orbit_velocity_max") && (!tex_parameters[PARAM_ORBIT_VELOCITY].is_valid() && !particle_flags[PARTICLE_FLAG_DISABLE_Z])) {
  1693. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  1694. }
  1695. if (p_property.usage & PROPERTY_USAGE_EDITOR && (p_property.name.ends_with("_min") || p_property.name.ends_with("_max"))) {
  1696. p_property.usage &= ~PROPERTY_USAGE_EDITOR;
  1697. }
  1698. }
  1699. void ParticleProcessMaterial::set_sub_emitter_mode(SubEmitterMode p_sub_emitter_mode) {
  1700. sub_emitter_mode = p_sub_emitter_mode;
  1701. _queue_shader_change();
  1702. notify_property_list_changed();
  1703. if (sub_emitter_mode != SUB_EMITTER_DISABLED && RenderingServer::get_singleton()->is_low_end()) {
  1704. WARN_PRINT_ONCE_ED("Sub-emitter modes other than SUB_EMITTER_DISABLED are not supported in the Compatibility renderer.");
  1705. }
  1706. }
  1707. ParticleProcessMaterial::SubEmitterMode ParticleProcessMaterial::get_sub_emitter_mode() const {
  1708. return sub_emitter_mode;
  1709. }
  1710. void ParticleProcessMaterial::set_sub_emitter_frequency(double p_frequency) {
  1711. sub_emitter_frequency = p_frequency;
  1712. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->sub_emitter_frequency, 1.0 / p_frequency); //pass delta instead of frequency, since its easier to compute
  1713. }
  1714. double ParticleProcessMaterial::get_sub_emitter_frequency() const {
  1715. return sub_emitter_frequency;
  1716. }
  1717. void ParticleProcessMaterial::set_sub_emitter_amount_at_end(int p_amount) {
  1718. sub_emitter_amount_at_end = p_amount;
  1719. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->sub_emitter_amount_at_end, p_amount);
  1720. }
  1721. int ParticleProcessMaterial::get_sub_emitter_amount_at_end() const {
  1722. return sub_emitter_amount_at_end;
  1723. }
  1724. void ParticleProcessMaterial::set_sub_emitter_amount_at_collision(int p_amount) {
  1725. sub_emitter_amount_at_collision = p_amount;
  1726. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->sub_emitter_amount_at_collision, p_amount);
  1727. }
  1728. int ParticleProcessMaterial::get_sub_emitter_amount_at_collision() const {
  1729. return sub_emitter_amount_at_collision;
  1730. }
  1731. void ParticleProcessMaterial::set_sub_emitter_amount_at_start(int p_amount) {
  1732. sub_emitter_amount_at_start = p_amount;
  1733. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->sub_emitter_amount_at_start, p_amount);
  1734. }
  1735. int ParticleProcessMaterial::get_sub_emitter_amount_at_start() const {
  1736. return sub_emitter_amount_at_start;
  1737. }
  1738. void ParticleProcessMaterial::set_sub_emitter_keep_velocity(bool p_enable) {
  1739. sub_emitter_keep_velocity = p_enable;
  1740. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->sub_emitter_keep_velocity, p_enable);
  1741. }
  1742. bool ParticleProcessMaterial::get_sub_emitter_keep_velocity() const {
  1743. return sub_emitter_keep_velocity;
  1744. }
  1745. void ParticleProcessMaterial::set_attractor_interaction_enabled(bool p_enable) {
  1746. attractor_interaction_enabled = p_enable;
  1747. _queue_shader_change();
  1748. }
  1749. bool ParticleProcessMaterial::is_attractor_interaction_enabled() const {
  1750. return attractor_interaction_enabled;
  1751. }
  1752. void ParticleProcessMaterial::set_collision_mode(CollisionMode p_collision_mode) {
  1753. collision_mode = p_collision_mode;
  1754. _queue_shader_change();
  1755. notify_property_list_changed();
  1756. }
  1757. ParticleProcessMaterial::CollisionMode ParticleProcessMaterial::get_collision_mode() const {
  1758. return collision_mode;
  1759. }
  1760. void ParticleProcessMaterial::set_collision_use_scale(bool p_scale) {
  1761. collision_scale = p_scale;
  1762. _queue_shader_change();
  1763. }
  1764. bool ParticleProcessMaterial::is_collision_using_scale() const {
  1765. return collision_scale;
  1766. }
  1767. void ParticleProcessMaterial::set_collision_friction(float p_friction) {
  1768. collision_friction = p_friction;
  1769. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->collision_friction, p_friction);
  1770. }
  1771. float ParticleProcessMaterial::get_collision_friction() const {
  1772. return collision_friction;
  1773. }
  1774. void ParticleProcessMaterial::set_collision_bounce(float p_bounce) {
  1775. collision_bounce = p_bounce;
  1776. RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->collision_bounce, p_bounce);
  1777. }
  1778. float ParticleProcessMaterial::get_collision_bounce() const {
  1779. return collision_bounce;
  1780. }
  1781. Shader::Mode ParticleProcessMaterial::get_shader_mode() const {
  1782. return Shader::MODE_PARTICLES;
  1783. }
  1784. void ParticleProcessMaterial::_bind_methods() {
  1785. ClassDB::bind_method(D_METHOD("set_direction", "degrees"), &ParticleProcessMaterial::set_direction);
  1786. ClassDB::bind_method(D_METHOD("get_direction"), &ParticleProcessMaterial::get_direction);
  1787. ClassDB::bind_method(D_METHOD("set_inherit_velocity_ratio", "ratio"), &ParticleProcessMaterial::set_inherit_velocity_ratio);
  1788. ClassDB::bind_method(D_METHOD("get_inherit_velocity_ratio"), &ParticleProcessMaterial::get_inherit_velocity_ratio);
  1789. ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &ParticleProcessMaterial::set_spread);
  1790. ClassDB::bind_method(D_METHOD("get_spread"), &ParticleProcessMaterial::get_spread);
  1791. ClassDB::bind_method(D_METHOD("set_flatness", "amount"), &ParticleProcessMaterial::set_flatness);
  1792. ClassDB::bind_method(D_METHOD("get_flatness"), &ParticleProcessMaterial::get_flatness);
  1793. ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &ParticleProcessMaterial::set_param);
  1794. ClassDB::bind_method(D_METHOD("get_param", "param"), &ParticleProcessMaterial::get_param);
  1795. ClassDB::bind_method(D_METHOD("set_param_min", "param", "value"), &ParticleProcessMaterial::set_param_min);
  1796. ClassDB::bind_method(D_METHOD("get_param_min", "param"), &ParticleProcessMaterial::get_param_min);
  1797. ClassDB::bind_method(D_METHOD("set_param_max", "param", "value"), &ParticleProcessMaterial::set_param_max);
  1798. ClassDB::bind_method(D_METHOD("get_param_max", "param"), &ParticleProcessMaterial::get_param_max);
  1799. ClassDB::bind_method(D_METHOD("set_param_texture", "param", "texture"), &ParticleProcessMaterial::set_param_texture);
  1800. ClassDB::bind_method(D_METHOD("get_param_texture", "param"), &ParticleProcessMaterial::get_param_texture);
  1801. ClassDB::bind_method(D_METHOD("set_color", "color"), &ParticleProcessMaterial::set_color);
  1802. ClassDB::bind_method(D_METHOD("get_color"), &ParticleProcessMaterial::get_color);
  1803. ClassDB::bind_method(D_METHOD("set_color_ramp", "ramp"), &ParticleProcessMaterial::set_color_ramp);
  1804. ClassDB::bind_method(D_METHOD("get_color_ramp"), &ParticleProcessMaterial::get_color_ramp);
  1805. ClassDB::bind_method(D_METHOD("set_alpha_curve", "curve"), &ParticleProcessMaterial::set_alpha_curve);
  1806. ClassDB::bind_method(D_METHOD("get_alpha_curve"), &ParticleProcessMaterial::get_alpha_curve);
  1807. ClassDB::bind_method(D_METHOD("set_emission_curve", "curve"), &ParticleProcessMaterial::set_emission_curve);
  1808. ClassDB::bind_method(D_METHOD("get_emission_curve"), &ParticleProcessMaterial::get_emission_curve);
  1809. ClassDB::bind_method(D_METHOD("set_color_initial_ramp", "ramp"), &ParticleProcessMaterial::set_color_initial_ramp);
  1810. ClassDB::bind_method(D_METHOD("get_color_initial_ramp"), &ParticleProcessMaterial::get_color_initial_ramp);
  1811. ClassDB::bind_method(D_METHOD("set_velocity_limit_curve", "curve"), &ParticleProcessMaterial::set_velocity_limit_curve);
  1812. ClassDB::bind_method(D_METHOD("get_velocity_limit_curve"), &ParticleProcessMaterial::get_velocity_limit_curve);
  1813. ClassDB::bind_method(D_METHOD("set_particle_flag", "particle_flag", "enable"), &ParticleProcessMaterial::set_particle_flag);
  1814. ClassDB::bind_method(D_METHOD("get_particle_flag", "particle_flag"), &ParticleProcessMaterial::get_particle_flag);
  1815. ClassDB::bind_method(D_METHOD("set_velocity_pivot", "pivot"), &ParticleProcessMaterial::set_velocity_pivot);
  1816. ClassDB::bind_method(D_METHOD("get_velocity_pivot"), &ParticleProcessMaterial::get_velocity_pivot);
  1817. ClassDB::bind_method(D_METHOD("set_emission_shape", "shape"), &ParticleProcessMaterial::set_emission_shape);
  1818. ClassDB::bind_method(D_METHOD("get_emission_shape"), &ParticleProcessMaterial::get_emission_shape);
  1819. ClassDB::bind_method(D_METHOD("set_emission_sphere_radius", "radius"), &ParticleProcessMaterial::set_emission_sphere_radius);
  1820. ClassDB::bind_method(D_METHOD("get_emission_sphere_radius"), &ParticleProcessMaterial::get_emission_sphere_radius);
  1821. ClassDB::bind_method(D_METHOD("set_emission_box_extents", "extents"), &ParticleProcessMaterial::set_emission_box_extents);
  1822. ClassDB::bind_method(D_METHOD("get_emission_box_extents"), &ParticleProcessMaterial::get_emission_box_extents);
  1823. ClassDB::bind_method(D_METHOD("set_emission_point_texture", "texture"), &ParticleProcessMaterial::set_emission_point_texture);
  1824. ClassDB::bind_method(D_METHOD("get_emission_point_texture"), &ParticleProcessMaterial::get_emission_point_texture);
  1825. ClassDB::bind_method(D_METHOD("set_emission_normal_texture", "texture"), &ParticleProcessMaterial::set_emission_normal_texture);
  1826. ClassDB::bind_method(D_METHOD("get_emission_normal_texture"), &ParticleProcessMaterial::get_emission_normal_texture);
  1827. ClassDB::bind_method(D_METHOD("set_emission_color_texture", "texture"), &ParticleProcessMaterial::set_emission_color_texture);
  1828. ClassDB::bind_method(D_METHOD("get_emission_color_texture"), &ParticleProcessMaterial::get_emission_color_texture);
  1829. ClassDB::bind_method(D_METHOD("set_emission_point_count", "point_count"), &ParticleProcessMaterial::set_emission_point_count);
  1830. ClassDB::bind_method(D_METHOD("get_emission_point_count"), &ParticleProcessMaterial::get_emission_point_count);
  1831. ClassDB::bind_method(D_METHOD("set_emission_ring_axis", "axis"), &ParticleProcessMaterial::set_emission_ring_axis);
  1832. ClassDB::bind_method(D_METHOD("get_emission_ring_axis"), &ParticleProcessMaterial::get_emission_ring_axis);
  1833. ClassDB::bind_method(D_METHOD("set_emission_ring_height", "height"), &ParticleProcessMaterial::set_emission_ring_height);
  1834. ClassDB::bind_method(D_METHOD("get_emission_ring_height"), &ParticleProcessMaterial::get_emission_ring_height);
  1835. ClassDB::bind_method(D_METHOD("set_emission_ring_radius", "radius"), &ParticleProcessMaterial::set_emission_ring_radius);
  1836. ClassDB::bind_method(D_METHOD("get_emission_ring_radius"), &ParticleProcessMaterial::get_emission_ring_radius);
  1837. ClassDB::bind_method(D_METHOD("set_emission_ring_inner_radius", "inner_radius"), &ParticleProcessMaterial::set_emission_ring_inner_radius);
  1838. ClassDB::bind_method(D_METHOD("get_emission_ring_inner_radius"), &ParticleProcessMaterial::get_emission_ring_inner_radius);
  1839. ClassDB::bind_method(D_METHOD("set_emission_ring_cone_angle", "cone_angle"), &ParticleProcessMaterial::set_emission_ring_cone_angle);
  1840. ClassDB::bind_method(D_METHOD("get_emission_ring_cone_angle"), &ParticleProcessMaterial::get_emission_ring_cone_angle);
  1841. ClassDB::bind_method(D_METHOD("set_emission_shape_offset", "emission_shape_offset"), &ParticleProcessMaterial::set_emission_shape_offset);
  1842. ClassDB::bind_method(D_METHOD("get_emission_shape_offset"), &ParticleProcessMaterial::get_emission_shape_offset);
  1843. ClassDB::bind_method(D_METHOD("set_emission_shape_scale", "emission_shape_scale"), &ParticleProcessMaterial::set_emission_shape_scale);
  1844. ClassDB::bind_method(D_METHOD("get_emission_shape_scale"), &ParticleProcessMaterial::get_emission_shape_scale);
  1845. ClassDB::bind_method(D_METHOD("get_turbulence_enabled"), &ParticleProcessMaterial::get_turbulence_enabled);
  1846. ClassDB::bind_method(D_METHOD("set_turbulence_enabled", "turbulence_enabled"), &ParticleProcessMaterial::set_turbulence_enabled);
  1847. ClassDB::bind_method(D_METHOD("get_turbulence_noise_strength"), &ParticleProcessMaterial::get_turbulence_noise_strength);
  1848. ClassDB::bind_method(D_METHOD("set_turbulence_noise_strength", "turbulence_noise_strength"), &ParticleProcessMaterial::set_turbulence_noise_strength);
  1849. ClassDB::bind_method(D_METHOD("get_turbulence_noise_scale"), &ParticleProcessMaterial::get_turbulence_noise_scale);
  1850. ClassDB::bind_method(D_METHOD("set_turbulence_noise_scale", "turbulence_noise_scale"), &ParticleProcessMaterial::set_turbulence_noise_scale);
  1851. ClassDB::bind_method(D_METHOD("get_turbulence_noise_speed_random"), &ParticleProcessMaterial::get_turbulence_noise_speed_random);
  1852. ClassDB::bind_method(D_METHOD("set_turbulence_noise_speed_random", "turbulence_noise_speed_random"), &ParticleProcessMaterial::set_turbulence_noise_speed_random);
  1853. ClassDB::bind_method(D_METHOD("get_turbulence_noise_speed"), &ParticleProcessMaterial::get_turbulence_noise_speed);
  1854. ClassDB::bind_method(D_METHOD("set_turbulence_noise_speed", "turbulence_noise_speed"), &ParticleProcessMaterial::set_turbulence_noise_speed);
  1855. ClassDB::bind_method(D_METHOD("get_gravity"), &ParticleProcessMaterial::get_gravity);
  1856. ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &ParticleProcessMaterial::set_gravity);
  1857. ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "randomness"), &ParticleProcessMaterial::set_lifetime_randomness);
  1858. ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &ParticleProcessMaterial::get_lifetime_randomness);
  1859. ClassDB::bind_method(D_METHOD("get_sub_emitter_mode"), &ParticleProcessMaterial::get_sub_emitter_mode);
  1860. ClassDB::bind_method(D_METHOD("set_sub_emitter_mode", "mode"), &ParticleProcessMaterial::set_sub_emitter_mode);
  1861. ClassDB::bind_method(D_METHOD("get_sub_emitter_frequency"), &ParticleProcessMaterial::get_sub_emitter_frequency);
  1862. ClassDB::bind_method(D_METHOD("set_sub_emitter_frequency", "hz"), &ParticleProcessMaterial::set_sub_emitter_frequency);
  1863. ClassDB::bind_method(D_METHOD("get_sub_emitter_amount_at_end"), &ParticleProcessMaterial::get_sub_emitter_amount_at_end);
  1864. ClassDB::bind_method(D_METHOD("set_sub_emitter_amount_at_end", "amount"), &ParticleProcessMaterial::set_sub_emitter_amount_at_end);
  1865. ClassDB::bind_method(D_METHOD("get_sub_emitter_amount_at_collision"), &ParticleProcessMaterial::get_sub_emitter_amount_at_collision);
  1866. ClassDB::bind_method(D_METHOD("set_sub_emitter_amount_at_collision", "amount"), &ParticleProcessMaterial::set_sub_emitter_amount_at_collision);
  1867. ClassDB::bind_method(D_METHOD("get_sub_emitter_amount_at_start"), &ParticleProcessMaterial::get_sub_emitter_amount_at_start);
  1868. ClassDB::bind_method(D_METHOD("set_sub_emitter_amount_at_start", "amount"), &ParticleProcessMaterial::set_sub_emitter_amount_at_start);
  1869. ClassDB::bind_method(D_METHOD("get_sub_emitter_keep_velocity"), &ParticleProcessMaterial::get_sub_emitter_keep_velocity);
  1870. ClassDB::bind_method(D_METHOD("set_sub_emitter_keep_velocity", "enable"), &ParticleProcessMaterial::set_sub_emitter_keep_velocity);
  1871. ClassDB::bind_method(D_METHOD("set_attractor_interaction_enabled", "enabled"), &ParticleProcessMaterial::set_attractor_interaction_enabled);
  1872. ClassDB::bind_method(D_METHOD("is_attractor_interaction_enabled"), &ParticleProcessMaterial::is_attractor_interaction_enabled);
  1873. ClassDB::bind_method(D_METHOD("set_collision_mode", "mode"), &ParticleProcessMaterial::set_collision_mode);
  1874. ClassDB::bind_method(D_METHOD("get_collision_mode"), &ParticleProcessMaterial::get_collision_mode);
  1875. ClassDB::bind_method(D_METHOD("set_collision_use_scale", "radius"), &ParticleProcessMaterial::set_collision_use_scale);
  1876. ClassDB::bind_method(D_METHOD("is_collision_using_scale"), &ParticleProcessMaterial::is_collision_using_scale);
  1877. ClassDB::bind_method(D_METHOD("set_collision_friction", "friction"), &ParticleProcessMaterial::set_collision_friction);
  1878. ClassDB::bind_method(D_METHOD("get_collision_friction"), &ParticleProcessMaterial::get_collision_friction);
  1879. ClassDB::bind_method(D_METHOD("set_collision_bounce", "bounce"), &ParticleProcessMaterial::set_collision_bounce);
  1880. ClassDB::bind_method(D_METHOD("get_collision_bounce"), &ParticleProcessMaterial::get_collision_bounce);
  1881. #define ADD_MIN_MAX_PROPERTY(m_property, m_range, m_parameter_name) \
  1882. ADD_PROPERTYI(PropertyInfo(Variant::VECTOR2, m_property, PROPERTY_HINT_RANGE, m_range, PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "set_param", "get_param", m_parameter_name); \
  1883. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, m_property "_min", PROPERTY_HINT_RANGE, m_range), "set_param_min", "get_param_min", m_parameter_name); \
  1884. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, m_property "_max", PROPERTY_HINT_RANGE, m_range), "set_param_max", "get_param_max", m_parameter_name); \
  1885. min_max_properties.insert(m_property);
  1886. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime_randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_lifetime_randomness", "get_lifetime_randomness");
  1887. ADD_GROUP("Particle Flags", "particle_flag_");
  1888. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_align_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
  1889. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_rotate_y"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_ROTATE_Y);
  1890. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_disable_z"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_DISABLE_Z);
  1891. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "particle_flag_damping_as_friction"), "set_particle_flag", "get_particle_flag", PARTICLE_FLAG_DAMPING_AS_FRICTION);
  1892. ADD_GROUP("Spawn", "");
  1893. ADD_SUBGROUP("Position", "");
  1894. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_shape_offset"), "set_emission_shape_offset", "get_emission_shape_offset");
  1895. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_shape_scale"), "set_emission_shape_scale", "get_emission_shape_scale");
  1896. ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Sphere Surface,Box,Points,Directed Points,Ring"), "set_emission_shape", "get_emission_shape");
  1897. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_sphere_radius", PROPERTY_HINT_RANGE, "0.01,128,0.01,or_greater"), "set_emission_sphere_radius", "get_emission_sphere_radius");
  1898. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_box_extents"), "set_emission_box_extents", "get_emission_box_extents");
  1899. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "emission_point_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_emission_point_texture", "get_emission_point_texture");
  1900. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "emission_normal_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_emission_normal_texture", "get_emission_normal_texture");
  1901. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "emission_color_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_emission_color_texture", "get_emission_color_texture");
  1902. ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_point_count", PROPERTY_HINT_RANGE, "0,1000000,1"), "set_emission_point_count", "get_emission_point_count");
  1903. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "emission_ring_axis"), "set_emission_ring_axis", "get_emission_ring_axis");
  1904. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_height", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_emission_ring_height", "get_emission_ring_height");
  1905. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_radius", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_emission_ring_radius", "get_emission_ring_radius");
  1906. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_inner_radius", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_emission_ring_inner_radius", "get_emission_ring_inner_radius");
  1907. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_ring_cone_angle", PROPERTY_HINT_RANGE, "0,90,0.01,degrees"), "set_emission_ring_cone_angle", "get_emission_ring_cone_angle");
  1908. ADD_SUBGROUP("Angle", "");
  1909. ADD_MIN_MAX_PROPERTY("angle", "-720,720,0.1,or_less,or_greater,degrees", PARAM_ANGLE);
  1910. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angle_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANGLE);
  1911. ADD_SUBGROUP("Velocity", "");
  1912. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inherit_velocity_ratio", PROPERTY_HINT_RANGE, "0.0,1.0,0.001,or_less,or_greater"), "set_inherit_velocity_ratio", "get_inherit_velocity_ratio");
  1913. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "velocity_pivot"), "set_velocity_pivot", "get_velocity_pivot");
  1914. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "direction"), "set_direction", "get_direction");
  1915. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spread", PROPERTY_HINT_RANGE, "0,180,0.001"), "set_spread", "get_spread");
  1916. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "flatness", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_flatness", "get_flatness");
  1917. ADD_MIN_MAX_PROPERTY("initial_velocity", "0,1000,0.01,or_less,or_greater", PARAM_INITIAL_LINEAR_VELOCITY);
  1918. ADD_GROUP("Animated Velocity", "");
  1919. ADD_SUBGROUP("Velocity Limit", "");
  1920. ADD_SUBGROUP("Angular Velocity", "angular_");
  1921. ADD_MIN_MAX_PROPERTY("angular_velocity", "-720,720,0.01,or_less,or_greater", PARAM_ANGULAR_VELOCITY);
  1922. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angular_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANGULAR_VELOCITY);
  1923. ADD_SUBGROUP("Directional Velocity", "directional_");
  1924. ADD_MIN_MAX_PROPERTY("directional_velocity", "-720,720,0.01,or_less,or_greater", PARAM_DIRECTIONAL_VELOCITY);
  1925. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "directional_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveXYZTexture"), "set_param_texture", "get_param_texture", PARAM_DIRECTIONAL_VELOCITY);
  1926. ADD_SUBGROUP("Orbit Velocity", "orbit_");
  1927. ADD_MIN_MAX_PROPERTY("orbit_velocity", "-2,2,0.001,or_less,or_greater", PARAM_ORBIT_VELOCITY);
  1928. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "orbit_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture,CurveXYZTexture"), "set_param_texture", "get_param_texture", PARAM_ORBIT_VELOCITY);
  1929. ADD_SUBGROUP("Radial Velocity", "radial_");
  1930. ADD_MIN_MAX_PROPERTY("radial_velocity", "-1000,1000,0.01,or_less,or_greater", PARAM_RADIAL_VELOCITY);
  1931. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "radial_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_RADIAL_VELOCITY);
  1932. ADD_SUBGROUP("Velocity Limit", "");
  1933. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "velocity_limit_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_velocity_limit_curve", "get_velocity_limit_curve");
  1934. ADD_GROUP("Accelerations", "");
  1935. ADD_SUBGROUP("Gravity", "");
  1936. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity"), "set_gravity", "get_gravity");
  1937. ADD_SUBGROUP("Linear Accel", "linear_");
  1938. ADD_MIN_MAX_PROPERTY("linear_accel", "-100,100,0.01,or_less,or_greater", PARAM_LINEAR_ACCEL);
  1939. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "linear_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_LINEAR_ACCEL);
  1940. ADD_SUBGROUP("Radial Accel", "radial_");
  1941. ADD_MIN_MAX_PROPERTY("radial_accel", "-100,100,0.01,or_less,or_greater", PARAM_RADIAL_ACCEL);
  1942. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "radial_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_RADIAL_ACCEL);
  1943. ADD_SUBGROUP("Tangential Accel", "tangential_");
  1944. ADD_MIN_MAX_PROPERTY("tangential_accel", "-100,100,0.01,or_less,or_greater", PARAM_TANGENTIAL_ACCEL);
  1945. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "tangential_accel_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_TANGENTIAL_ACCEL);
  1946. ADD_SUBGROUP("Damping", "");
  1947. ADD_MIN_MAX_PROPERTY("damping", "0,100,0.001,or_greater", PARAM_DAMPING);
  1948. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "damping_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_DAMPING);
  1949. ADD_SUBGROUP("Attractor Interaction", "attractor_interaction_");
  1950. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "attractor_interaction_enabled"), "set_attractor_interaction_enabled", "is_attractor_interaction_enabled");
  1951. ADD_GROUP("Display", "");
  1952. ADD_SUBGROUP("Scale", "");
  1953. ADD_MIN_MAX_PROPERTY("scale", "0,1000,0.01,or_greater", PARAM_SCALE);
  1954. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "scale_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture,CurveXYZTexture"), "set_param_texture", "get_param_texture", PARAM_SCALE);
  1955. ADD_SUBGROUP("Scale Over Velocity", "");
  1956. ADD_MIN_MAX_PROPERTY("scale_over_velocity", "0,1000,0.01,or_greater", PARAM_SCALE_OVER_VELOCITY);
  1957. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "scale_over_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture,CurveXYZTexture"), "set_param_texture", "get_param_texture", PARAM_SCALE_OVER_VELOCITY);
  1958. ADD_SUBGROUP("Color Curves", "");
  1959. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
  1960. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_ramp", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture1D"), "set_color_ramp", "get_color_ramp");
  1961. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_initial_ramp", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture1D"), "set_color_initial_ramp", "get_color_initial_ramp");
  1962. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "alpha_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_alpha_curve", "get_alpha_curve");
  1963. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "emission_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_emission_curve", "get_emission_curve");
  1964. ADD_SUBGROUP("Hue Variation", "hue_");
  1965. ADD_MIN_MAX_PROPERTY("hue_variation", "-1,1,0.01", PARAM_HUE_VARIATION);
  1966. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "hue_variation_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_HUE_VARIATION);
  1967. ADD_SUBGROUP("Animation", "anim_");
  1968. ADD_MIN_MAX_PROPERTY("anim_speed", "0,16,0.01,or_less,or_greater", PARAM_ANIM_SPEED);
  1969. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_speed_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANIM_SPEED);
  1970. ADD_MIN_MAX_PROPERTY("anim_offset", "0,1,0.0001", PARAM_ANIM_OFFSET);
  1971. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_offset_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANIM_OFFSET);
  1972. ADD_GROUP("Turbulence", "turbulence_");
  1973. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "turbulence_enabled"), "set_turbulence_enabled", "get_turbulence_enabled");
  1974. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "turbulence_noise_strength", PROPERTY_HINT_RANGE, "0,20,0.01"), "set_turbulence_noise_strength", "get_turbulence_noise_strength");
  1975. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "turbulence_noise_scale", PROPERTY_HINT_RANGE, "0,10,0.001,or_greater"), "set_turbulence_noise_scale", "get_turbulence_noise_scale");
  1976. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "turbulence_noise_speed"), "set_turbulence_noise_speed", "get_turbulence_noise_speed");
  1977. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "turbulence_noise_speed_random", PROPERTY_HINT_RANGE, "0,4,0.01"), "set_turbulence_noise_speed_random", "get_turbulence_noise_speed_random");
  1978. ADD_MIN_MAX_PROPERTY("turbulence_influence", "0,1,0.001", PARAM_TURB_VEL_INFLUENCE);
  1979. ADD_MIN_MAX_PROPERTY("turbulence_initial_displacement", "-100,100,0.1", PARAM_TURB_INIT_DISPLACEMENT);
  1980. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "turbulence_influence_over_life", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_TURB_INFLUENCE_OVER_LIFE);
  1981. ADD_GROUP("Collision", "collision_");
  1982. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mode", PROPERTY_HINT_ENUM, "Disabled,Rigid,Hide On Contact"), "set_collision_mode", "get_collision_mode");
  1983. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_friction", "get_collision_friction");
  1984. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_bounce", "get_collision_bounce");
  1985. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_use_scale"), "set_collision_use_scale", "is_collision_using_scale");
  1986. ADD_GROUP("Sub Emitter", "sub_emitter_");
  1987. ADD_PROPERTY(PropertyInfo(Variant::INT, "sub_emitter_mode", PROPERTY_HINT_ENUM, "Disabled:0,Constant:1,At Start:4,At End:2,At Collision:3"), "set_sub_emitter_mode", "get_sub_emitter_mode");
  1988. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sub_emitter_frequency", PROPERTY_HINT_RANGE, "0.01,100,0.01,suffix:Hz"), "set_sub_emitter_frequency", "get_sub_emitter_frequency");
  1989. ADD_PROPERTY(PropertyInfo(Variant::INT, "sub_emitter_amount_at_end", PROPERTY_HINT_RANGE, "1,32,1"), "set_sub_emitter_amount_at_end", "get_sub_emitter_amount_at_end");
  1990. ADD_PROPERTY(PropertyInfo(Variant::INT, "sub_emitter_amount_at_collision", PROPERTY_HINT_RANGE, "1,32,1"), "set_sub_emitter_amount_at_collision", "get_sub_emitter_amount_at_collision");
  1991. ADD_PROPERTY(PropertyInfo(Variant::INT, "sub_emitter_amount_at_start", PROPERTY_HINT_RANGE, "1,32,1"), "set_sub_emitter_amount_at_start", "get_sub_emitter_amount_at_start");
  1992. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sub_emitter_keep_velocity"), "set_sub_emitter_keep_velocity", "get_sub_emitter_keep_velocity");
  1993. ADD_SIGNAL(MethodInfo("emission_shape_changed"));
  1994. BIND_ENUM_CONSTANT(PARAM_INITIAL_LINEAR_VELOCITY);
  1995. BIND_ENUM_CONSTANT(PARAM_ANGULAR_VELOCITY);
  1996. BIND_ENUM_CONSTANT(PARAM_ORBIT_VELOCITY);
  1997. BIND_ENUM_CONSTANT(PARAM_LINEAR_ACCEL);
  1998. BIND_ENUM_CONSTANT(PARAM_RADIAL_ACCEL);
  1999. BIND_ENUM_CONSTANT(PARAM_TANGENTIAL_ACCEL);
  2000. BIND_ENUM_CONSTANT(PARAM_DAMPING);
  2001. BIND_ENUM_CONSTANT(PARAM_ANGLE);
  2002. BIND_ENUM_CONSTANT(PARAM_SCALE);
  2003. BIND_ENUM_CONSTANT(PARAM_HUE_VARIATION);
  2004. BIND_ENUM_CONSTANT(PARAM_ANIM_SPEED);
  2005. BIND_ENUM_CONSTANT(PARAM_ANIM_OFFSET);
  2006. BIND_ENUM_CONSTANT(PARAM_RADIAL_VELOCITY);
  2007. BIND_ENUM_CONSTANT(PARAM_DIRECTIONAL_VELOCITY);
  2008. BIND_ENUM_CONSTANT(PARAM_SCALE_OVER_VELOCITY);
  2009. BIND_ENUM_CONSTANT(PARAM_MAX);
  2010. BIND_ENUM_CONSTANT(PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY);
  2011. BIND_ENUM_CONSTANT(PARTICLE_FLAG_ROTATE_Y);
  2012. BIND_ENUM_CONSTANT(PARTICLE_FLAG_DISABLE_Z);
  2013. BIND_ENUM_CONSTANT(PARTICLE_FLAG_DAMPING_AS_FRICTION);
  2014. BIND_ENUM_CONSTANT(PARTICLE_FLAG_MAX);
  2015. BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINT);
  2016. BIND_ENUM_CONSTANT(EMISSION_SHAPE_SPHERE);
  2017. BIND_ENUM_CONSTANT(EMISSION_SHAPE_SPHERE_SURFACE);
  2018. BIND_ENUM_CONSTANT(EMISSION_SHAPE_BOX);
  2019. BIND_ENUM_CONSTANT(EMISSION_SHAPE_POINTS);
  2020. BIND_ENUM_CONSTANT(EMISSION_SHAPE_DIRECTED_POINTS);
  2021. BIND_ENUM_CONSTANT(EMISSION_SHAPE_RING);
  2022. BIND_ENUM_CONSTANT(EMISSION_SHAPE_MAX);
  2023. BIND_ENUM_CONSTANT(PARAM_TURB_VEL_INFLUENCE);
  2024. BIND_ENUM_CONSTANT(PARAM_TURB_INIT_DISPLACEMENT);
  2025. BIND_ENUM_CONSTANT(PARAM_TURB_INFLUENCE_OVER_LIFE);
  2026. BIND_ENUM_CONSTANT(SUB_EMITTER_DISABLED);
  2027. BIND_ENUM_CONSTANT(SUB_EMITTER_CONSTANT);
  2028. BIND_ENUM_CONSTANT(SUB_EMITTER_AT_END);
  2029. BIND_ENUM_CONSTANT(SUB_EMITTER_AT_COLLISION);
  2030. BIND_ENUM_CONSTANT(SUB_EMITTER_AT_START);
  2031. BIND_ENUM_CONSTANT(SUB_EMITTER_MAX);
  2032. BIND_ENUM_CONSTANT(COLLISION_DISABLED);
  2033. BIND_ENUM_CONSTANT(COLLISION_RIGID);
  2034. BIND_ENUM_CONSTANT(COLLISION_HIDE_ON_CONTACT);
  2035. BIND_ENUM_CONSTANT(COLLISION_MAX);
  2036. #undef ADD_MIN_MAX_PROPERTY
  2037. }
  2038. ParticleProcessMaterial::ParticleProcessMaterial() :
  2039. element(this) {
  2040. _set_material(RS::get_singleton()->material_create());
  2041. set_direction(Vector3(1, 0, 0));
  2042. set_spread(45);
  2043. set_flatness(0);
  2044. set_param_min(PARAM_INITIAL_LINEAR_VELOCITY, 0);
  2045. set_param_min(PARAM_ANGULAR_VELOCITY, 0);
  2046. set_param_min(PARAM_ORBIT_VELOCITY, 0);
  2047. set_param_min(PARAM_LINEAR_ACCEL, 0);
  2048. set_param_min(PARAM_RADIAL_ACCEL, 0);
  2049. set_param_min(PARAM_TANGENTIAL_ACCEL, 0);
  2050. set_param_min(PARAM_DAMPING, 0);
  2051. set_param_min(PARAM_ANGLE, 0);
  2052. set_param_min(PARAM_SCALE, 1);
  2053. set_param_min(PARAM_HUE_VARIATION, 0);
  2054. set_param_min(PARAM_ANIM_SPEED, 0);
  2055. set_param_min(PARAM_ANIM_OFFSET, 0);
  2056. set_param_max(PARAM_INITIAL_LINEAR_VELOCITY, 0);
  2057. set_param_max(PARAM_ANGULAR_VELOCITY, 0);
  2058. set_param_max(PARAM_ORBIT_VELOCITY, 0);
  2059. set_param_max(PARAM_LINEAR_ACCEL, 0);
  2060. set_param_max(PARAM_RADIAL_ACCEL, 0);
  2061. set_param_max(PARAM_TANGENTIAL_ACCEL, 0);
  2062. set_param_max(PARAM_DAMPING, 0);
  2063. set_param_max(PARAM_ANGLE, 0);
  2064. set_param_max(PARAM_SCALE, 1);
  2065. set_param_max(PARAM_HUE_VARIATION, 0);
  2066. set_param_max(PARAM_ANIM_SPEED, 0);
  2067. set_param_max(PARAM_ANIM_OFFSET, 0);
  2068. set_param_min(PARAM_DIRECTIONAL_VELOCITY, 1.0);
  2069. set_param_max(PARAM_DIRECTIONAL_VELOCITY, 1.0);
  2070. set_emission_shape(EMISSION_SHAPE_POINT);
  2071. set_emission_sphere_radius(1);
  2072. set_emission_box_extents(Vector3(1, 1, 1));
  2073. set_emission_ring_axis(Vector3(0, 0, 1.0));
  2074. set_emission_ring_height(1);
  2075. set_emission_ring_radius(1);
  2076. set_emission_ring_inner_radius(0);
  2077. set_emission_ring_cone_angle(90);
  2078. set_emission_shape_offset(Vector3(0.0, 0.0, 0.0));
  2079. set_emission_shape_scale(Vector3(1.0, 1.0, 1.0));
  2080. set_turbulence_enabled(false);
  2081. set_turbulence_noise_speed(Vector3(0.0, 0.0, 0.0));
  2082. set_turbulence_noise_strength(1);
  2083. set_turbulence_noise_scale(9);
  2084. set_turbulence_noise_speed_random(0.2);
  2085. set_param_min(PARAM_TURB_VEL_INFLUENCE, 0.1);
  2086. set_param_max(PARAM_TURB_VEL_INFLUENCE, 0.1);
  2087. set_param_min(PARAM_TURB_INIT_DISPLACEMENT, 0.0);
  2088. set_param_max(PARAM_TURB_INIT_DISPLACEMENT, 0.0);
  2089. set_gravity(Vector3(0, -9.8, 0));
  2090. set_lifetime_randomness(0);
  2091. set_sub_emitter_mode(SUB_EMITTER_DISABLED);
  2092. set_sub_emitter_frequency(4);
  2093. set_sub_emitter_amount_at_end(1);
  2094. set_sub_emitter_amount_at_collision(1);
  2095. set_sub_emitter_amount_at_start(1);
  2096. set_sub_emitter_keep_velocity(false);
  2097. set_attractor_interaction_enabled(true);
  2098. set_collision_mode(COLLISION_DISABLED);
  2099. set_collision_bounce(0.0);
  2100. set_collision_friction(0.0);
  2101. set_collision_use_scale(false);
  2102. for (int i = 0; i < PARTICLE_FLAG_MAX; i++) {
  2103. particle_flags[i] = false;
  2104. }
  2105. set_color(Color(1, 1, 1, 1));
  2106. current_key.invalid_key = 1;
  2107. _mark_initialized(callable_mp(this, &ParticleProcessMaterial::_queue_shader_change), callable_mp(this, &ParticleProcessMaterial::_update_shader));
  2108. }
  2109. ParticleProcessMaterial::~ParticleProcessMaterial() {
  2110. ERR_FAIL_NULL(RenderingServer::get_singleton());
  2111. MutexLock lock(material_mutex);
  2112. if (shader_map.has(current_key)) {
  2113. shader_map[current_key].users--;
  2114. if (shader_map[current_key].users == 0) {
  2115. //deallocate shader, as it's no longer in use
  2116. RS::get_singleton()->free(shader_map[current_key].shader);
  2117. shader_map.erase(current_key);
  2118. }
  2119. RS::get_singleton()->material_set_shader(_get_material(), RID());
  2120. }
  2121. }