particle_process_material.cpp 114 KB

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