Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ratio to cpu particles to dynamically change amount emitted #70145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chrisb123
Copy link

@chrisb123 chrisb123 commented Dec 16, 2022

This commit adds a ratio slider expressed in percentage to the cpu particles so that users can dynamically adjusts the amount of emitted particles without clearing or resetting the existing particles.

A new property ratio is added
Two extra bool properties are added to the particle array to control processing of the particles

Setting the ratio clears the stopped flag and evenly distributes which particles should be stopped by setting a stopping flag or clearing it for other particles that should keep running
Each particle continues its life until it restarts
When the particle is restarted the stopping flag is checked, if true the stopped flag is set

It will always submit at least 1 particle.

Another option maybe to:

  1. Clear emitting when ratio is set 0% and when raised above 0% set emitting
  2. Use integer math instead of float
  3. Increase ratio precision

image

This is my first commit and pull request

@chrisb123 chrisb123 requested review from a team as code owners December 16, 2022 11:43
@KoBeWi KoBeWi added this to the 4.x milestone Dec 16, 2022
@chrisb123 chrisb123 force-pushed the particles-dynamic-amount branch 3 times, most recently from dfe1b01 to 5aa8d3c Compare December 16, 2022 13:08
@Zireael07
Copy link
Contributor

This needs some docs. Percentage of what???

@chrisb123
Copy link
Author

chrisb123 commented Dec 16, 2022

ratio is percent of amount with a minimum of 1 particle

@KoBeWi
Copy link
Member

KoBeWi commented Dec 16, 2022

You need to run doctool and fill the descriptions (start your compiled executable with --doctool argument).

@chrisb123 chrisb123 requested a review from a team as a code owner December 16, 2022 14:52
@Calinou
Copy link
Member

Calinou commented Dec 16, 2022

Should ratio be renamed to amount_ratio to make it clearer that it affects how the Amount will appear in practice?

@chrisb123
Copy link
Author

chrisb123 commented Dec 17, 2022

It will make it clearer as to what ratio refers too, all reference to ratio are now amount_ratio

@chrisb123 chrisb123 force-pushed the particles-dynamic-amount branch 4 times, most recently from ba3642d to 0f0b70d Compare December 18, 2022 05:10
@KoBeWi
Copy link
Member

KoBeWi commented Dec 20, 2022

The feature looks ok, but I think it shouldn't affect emitting.

Also it would be nice to see it in GPUParticles, but could be done in another PR.

@chrisb123
Copy link
Author

The purpose of that code is to evenly distribute which individual particles do not get restarted.

@Calinou
Copy link
Member

Calinou commented Aug 3, 2023

Also it would be nice to see it in GPUParticles, but could be done in another PR.

This is now done in #79527 (comment) 🙂

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally (rebased on top of master eb4301b), it works as expected in both 2D and 3D.

Testing project: test_pr_70145.zip

One issue I notice however is that Emitting is dynamically set based on Amount Ratio. Considering the controversy around Oneshot toggling Emitting on its own, I would prefer not having this kind of automatic behavior which can work against the user.

A GPUParticles implementation would also not toggle Emitting on its own for Amount Ratio, so I'd prefer it to work consistently too.

Comment on lines +93 to +94
Amount Ratio multiplied by [member amount] is how many particles will be emmitted each cycle. This value is to be adjusted while emitting particles as it will not clear the existing particles.
When not used leave this ratio at 1 and adjust amount accordingly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve documentation to match my GPUParticles branch:

Suggested change
Amount Ratio multiplied by [member amount] is how many particles will be emmitted each cycle. This value is to be adjusted while emitting particles as it will not clear the existing particles.
When not used leave this ratio at 1 and adjust amount accordingly.
The ratio of particles that should actually be emitted. If set to a value lower than [code]1.0[/code], this will set the amount of emitted particles throughout the lifetime to [code]amount * amount_ratio[/code]. Unlike changing [member amount], changing [member amount_ratio] while emitting does not affect already-emitted particles and doesn't cause the particle system to restart. [member amount_ratio] can be used to create effects that make the number of emitted particles vary over time.
[b]Note:[/b] If you don't need to change the number of particles emitted while particles are emitting, keep [member amount_ratio] at [code]1.0[/code] and change [member amount] instead. This will result in better performance, as inactive particles still need to be partially evaluated in the shader otherwise.

Comment on lines +92 to +93
Amount Ratio multiplied by [member amount] is how many particles will be emmitted each cycle. This value is to be adjusted while emitting particles as it will not clear the existing particles.
When not used leave this ratio at 1 and adjust amount accordingly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Amount Ratio multiplied by [member amount] is how many particles will be emmitted each cycle. This value is to be adjusted while emitting particles as it will not clear the existing particles.
When not used leave this ratio at 1 and adjust amount accordingly.
The ratio of particles that should actually be emitted. If set to a value lower than [code]1.0[/code], this will set the amount of emitted particles throughout the lifetime to [code]amount * amount_ratio[/code]. Unlike changing [member amount], changing [member amount_ratio] while emitting does not affect already-emitted particles and doesn't cause the particle system to restart. [member amount_ratio] can be used to create effects that make the number of emitted particles vary over time.
[b]Note:[/b] If you don't need to change the number of particles emitted while particles are emitting, keep [member amount_ratio] at [code]1.0[/code] and change [member amount] instead. This will result in better performance, as inactive particles still need to be partially evaluated in the shader otherwise.

@QbieShay
Copy link
Contributor

To merge after #79527 and once Calinou's feedback on documentation and functionality is addressed 👍 good job!

@clayjohn
Copy link
Member

@QbieShay This is superseded by #79527 now right?

@QbieShay
Copy link
Contributor

No this is CPUParticles!

@damian1ilin
Copy link

Hi! Any chance to get a similar function but in 2d particles? I'm using 2d cpu particles in my game and I'm facing the issue of them disappearing as trying to dinamically change the amount.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Dynamically adjust the amount of particles emitted without clearing all the particles
7 participants