Debian Codegraph @

scene/resources/particle_process_material.cpp

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