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