Skip to content

Commit

Permalink
Merge pull request godotengine#50434 from QbieShay/particle-minmax
Browse files Browse the repository at this point in the history
Particle params are expressed as min-max rather than value+range AND separate axes scaling
  • Loading branch information
fire authored Aug 22, 2021
2 parents 2f8a58a + d667209 commit fb176d5
Show file tree
Hide file tree
Showing 13 changed files with 836 additions and 630 deletions.
2 changes: 1 addition & 1 deletion doc/classes/BaseMaterial3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@
</constant>
<constant name="BILLBOARD_PARTICLES" value="3" enum="BillboardMode">
Used for particle systems when assigned to [GPUParticles3D] and [CPUParticles3D] nodes. Enables [code]particles_anim_*[/code] properties.
The [member ParticlesMaterial.anim_speed] or [member CPUParticles3D.anim_speed] should also be set to a positive value for the animation to play.
The [member ParticlesMaterial.anim_speed_min] or [member CPUParticles3D.anim_speed_min] should also be set to a value bigger than zero for the animation to play.
</constant>
<constant name="TEXTURE_CHANNEL_RED" value="0" enum="TextureChannel">
Used to read from the red channel of a texture.
Expand Down
148 changes: 63 additions & 85 deletions doc/classes/CPUParticles2D.xml

Large diffs are not rendered by default.

183 changes: 96 additions & 87 deletions doc/classes/CPUParticles3D.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/classes/CanvasItemMaterial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
[b]Note:[/b] This property is only used and visible in the editor if [member particles_animation] is [code]true[/code].
</member>
<member name="particles_animation" type="bool" setter="set_particles_animation" getter="get_particles_animation" default="false">
If [code]true[/code], enable spritesheet-based animation features when assigned to [GPUParticles2D] and [CPUParticles2D] nodes. The [member ParticlesMaterial.anim_speed] or [member CPUParticles2D.anim_speed] should also be set to a positive value for the animation to play.
If [code]true[/code], enable spritesheet-based animation features when assigned to [GPUParticles2D] and [CPUParticles2D] nodes. The [member ParticlesMaterial.anim_speed_max] or [member CPUParticles2D.anim_speed_max] should also be set to a positive value for the animation to play.
This property (and other [code]particles_anim_*[/code] properties that depend on it) has no effect on other types of nodes.
</member>
</members>
Expand Down
160 changes: 80 additions & 80 deletions doc/classes/ParticlesMaterial.xml

Large diffs are not rendered by default.

254 changes: 166 additions & 88 deletions scene/2d/cpu_particles_2d.cpp

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions scene/2d/cpu_particles_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class CPUParticles2D : public Node2D {
Vector2 direction = Vector2(1, 0);
real_t spread = 45.0;

real_t parameters[PARAM_MAX];
real_t randomness[PARAM_MAX];
real_t parameters_min[PARAM_MAX];
real_t parameters_max[PARAM_MAX];

Ref<Curve> curve_parameters[PARAM_MAX];
Color color;
Expand All @@ -167,6 +167,10 @@ class CPUParticles2D : public Node2D {
Vector<Color> emission_colors;
int emission_point_count = 0;

Ref<Curve> scale_curve_x;
Ref<Curve> scale_curve_y;
bool split_scale = false;

Vector2 gravity = Vector2(0, 980);

void _update_internal();
Expand Down Expand Up @@ -236,11 +240,11 @@ class CPUParticles2D : public Node2D {
void set_spread(real_t p_spread);
real_t get_spread() const;

void set_param(Parameter p_param, real_t p_value);
real_t get_param(Parameter p_param) const;
void set_param_min(Parameter p_param, real_t p_value);
real_t get_param_min(Parameter p_param) const;

void set_param_randomness(Parameter p_param, real_t p_value);
real_t get_param_randomness(Parameter p_param) const;
void set_param_max(Parameter p_param, real_t p_value);
real_t get_param_max(Parameter p_param) const;

void set_param_curve(Parameter p_param, const Ref<Curve> &p_curve);
Ref<Curve> get_param_curve(Parameter p_param) const;
Expand All @@ -261,6 +265,9 @@ class CPUParticles2D : public Node2D {
void set_emission_normals(const Vector<Vector2> &p_normals);
void set_emission_colors(const Vector<Color> &p_colors);
void set_emission_point_count(int p_count);
void set_scale_curve_x(Ref<Curve> p_scale_curve);
void set_scale_curve_y(Ref<Curve> p_scale_curve);
void set_split_scale(bool p_split_scale);

EmissionShape get_emission_shape() const;
real_t get_emission_sphere_radius() const;
Expand All @@ -269,6 +276,9 @@ class CPUParticles2D : public Node2D {
Vector<Vector2> get_emission_normals() const;
Vector<Color> get_emission_colors() const;
int get_emission_point_count() const;
Ref<Curve> get_scale_curve_x() const;
Ref<Curve> get_scale_curve_y() const;
bool get_split_scale();

void set_gravity(const Vector2 &p_gravity);
Vector2 get_gravity() const;
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/gpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ TypedArray<String> GPUParticles2D::get_configuration_warnings() const {
if (get_material().is_null() || (mat && !mat->get_particles_animation())) {
const ParticlesMaterial *process = Object::cast_to<ParticlesMaterial>(process_material.ptr());
if (process &&
(process->get_param(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
(process->get_param_max(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param_max(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) {
warnings.push_back(TTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."));
}
Expand Down
Loading

0 comments on commit fb176d5

Please sign in to comment.