Fix for double use of seed in random Particle shader variables. #55607
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #55585
ParticleMaterial generated shaders have one aspect that I observed a couple of times when working with them.
When creating random values using
rand_from_seed(alt_seed)
the same value was returned and used for different calls of the function. That was because the seed is only changed when the particle is restarted.That would result in the behaviour of creating the following random values (exemplary):
but after the restart was done it would result in:
So certain random would appear as being "linked" - in the example above, the random color would be linked to the restart spawn position.
Before this PR:
https://user-images.githubusercontent.com/9423774/144683085-7ac472aa-d61b-479c-b29b-c5189c7ece7c.mp4
After this PR:
https://user-images.githubusercontent.com/9423774/144683228-9715fa93-f550-453d-83cd-0dc41396bcef.mp4
To fix this behavior a second seed value for all restart values was introduce.
Here is a reproduction/test project:
3.4-shader-random-problem.zip