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

Fix ParticlesMaterial spread. #47228

Merged

Conversation

mortarroad
Copy link
Contributor

@mortarroad mortarroad commented Mar 21, 2021

Fixes #47145
For 3.x: #47310

Instead of doing some butchery with atan and then manipulating angles, we simply rotate the vector.

@mortarroad mortarroad changed the title Fix ParticlesMaterial spread add add up property Fix ParticlesMaterial spread and add up property Mar 21, 2021
@Calinou Calinou added this to the 4.0 milestone Mar 21, 2021
@clayjohn clayjohn requested review from QbieShay and clayjohn March 21, 2021 16:00
@QbieShay
Copy link
Contributor

I don't think "up" is a good name: people will most likely will assign the y vector and expect it to work.

I'm trying to think of something different, but I'd also like to do some research in math first to determine if there is a mathematical way to pick a random vec2 in a plane that doesn't have defined axes, so that we don't need to expose this variable at all.

@mortarroad
Copy link
Contributor Author

Well, setting up to be the y axis will always work, in the sense that it will still be emitting in the chosen direction.

Also, we need an up axis, because we have the flatness property, and the up axis determines along which axis it should get flatter.

But I agree, the distribution could be better, currently it is quite rectangular.

@QbieShay
Copy link
Contributor

@mortarroad after some brainstorming with a friend we came up with picking the vector like this:

(x, y, z) -> (-y, z, x)

Can you try if this looks better?

@mortarroad
Copy link
Contributor Author

@QbieShay Is that a formula for deriving the up vector from the direction?
If so, it won't work either:
Let direction = (1, 1, -1).
Then up = (-1, -1, 1), which is parallel to direction.

@QbieShay
Copy link
Contributor

aw :( I'm still not sure about this. I suppose in this case we can restore the singularity, but instead place it on the X axis?

Alternatively I think we can call this property "basis vector" and give it a meaningful description such as "used to calculate the angles for particles. please don't make it the same direction as the direction vector. Orthogonal to the direction vector would be best."

@mortarroad
Copy link
Contributor Author

Emitting either happens in the XZ plane, in which Y is a good choice for up, or mostly along Y, in which X or Z is a good choice for up.
There's no good solution here.
Maybe we can automatically set up to be Z, if the user chooses Y as the direction in the editor.

I still think "up" is the right name. Everything else would be confusing.

A fitting description could be:
"A vector perpendicular to direction, along which spread is applied. The second implicit vector for applying the spread is orthogonal to both up and direction."

@QbieShay
Copy link
Contributor

I disagree with "up" being a good choice. It's confusing: it's not necessarily pointing up. What about spread normal?

@mortarroad mortarroad force-pushed the master-fix-particles-material-spread branch from 03f6aac to e66efba Compare March 23, 2021 10:56
@mortarroad mortarroad requested a review from a team as a code owner March 23, 2021 10:56
@mortarroad
Copy link
Contributor Author

Renamed up to spread_normal.
Added docs for spread_normal.

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks good to me! Let's just get @QbieShay's approval before merging. This will be a nice addition to 3.4 as well

@clayjohn clayjohn added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Mar 23, 2021
@Calinou Calinou removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Mar 23, 2021
@QbieShay QbieShay changed the title Fix ParticlesMaterial spread and add up property Fix ParticlesMaterial spread and add "spread_normal" property Mar 24, 2021
@QbieShay
Copy link
Contributor

Hey @mortarroad. First of all, thanks for all the time you spent on this. I'm super sorry, but upon reviewing this code, and the addition to a user facing variable, I'm under the impression that your original implementation was the best one. I have given it more thought, and I don't believe that there are many cases for people smoothly rotating the direction of the particle shader to justify adding a user facing parameters.

Sorry again for changing my mind, and thanks for your time!

@mortarroad
Copy link
Contributor Author

Are you sure?
I mean, the user can just leave the variable at its default value without having to care about it.

But if you're sure, I'll just remove it and have it pick either Y or X at the up vector automatically as in the original patch.

@QbieShay
Copy link
Contributor

Yes I think that would be best. Thanks for your patience 🙏

@mortarroad mortarroad changed the title Fix ParticlesMaterial spread and add "spread_normal" property Fix ParticlesMaterial spread. Mar 25, 2021
@mortarroad mortarroad force-pushed the master-fix-particles-material-spread branch from e66efba to 0fc8318 Compare March 25, 2021 16:40
@akien-mga akien-mga merged commit b3a409f into godotengine:master Mar 25, 2021
@akien-mga
Copy link
Member

akien-mga commented Mar 25, 2021

Thanks! And congrats for your first merged Godot contribution 🎉

@mortarroad mortarroad deleted the master-fix-particles-material-spread branch April 13, 2021 09:13
mortarroad added a commit to mortarroad/godot that referenced this pull request Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ParticlesMaterial's emission direction is wrong if direction.z != 0 and direction.y != 0
5 participants