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 CPUParticles3D using angle incorrectly when ROTATE_Y is set. #89595

Merged

Conversation

apples
Copy link
Contributor

@apples apples commented Mar 17, 2024

Resolves #89559.

@apples apples requested a review from a team as a code owner March 17, 2024 06:09
@AThousandShips AThousandShips changed the title Fixed CPUParticles3D using angle incorrectly when ROTATE_Y is set. Fix CPUParticles3D using angle incorrectly when ROTATE_Y is set. Mar 17, 2024
@AThousandShips AThousandShips added this to the 4.3 milestone Mar 17, 2024
@akien-mga akien-mga changed the title Fix CPUParticles3D using angle incorrectly when ROTATE_Y is set. Fix CPUParticles3D using angle incorrectly when ROTATE_Y is set. Mar 18, 2024
@aXu-AP
Copy link
Contributor

aXu-AP commented May 4, 2024

Seems to be working as intended 👍
rotation
Pictured: CpuParticles3D and GpuParticles3D with same settings.

@@ -1124,7 +1124,7 @@ void CPUParticles3D::_particles_process(double p_delta) {
//turn particle by rotation in Y
if (particle_flags[PARTICLE_FLAG_ROTATE_Y]) {
Basis rot_y(Vector3(0, 1, 0), p.custom[0]);
p.transform.basis = p.transform.basis * rot_y;
p.transform.basis = rot_y;
Copy link
Member

Choose a reason for hiding this comment

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

The equivalent GPU particles code is this:

                // turn particle by rotation in Y
                if (particle_flags[PARTICLE_FLAG_ROTATE_Y]) {
                        code += "       vec4 origin = TRANSFORM[3];\n";
                        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";
                        code += "       TRANSFORM[3] = origin;\n";
                }

I'm not too familiar with the math here, but aren't we losing at least the origin potentially?

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, we're only changing basis, so origin is untouched.

Copy link
Member

Choose a reason for hiding this comment

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

The equivalent GPU particles code is this:

These look the same indeed. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

We are losing align with velocity though. But GpuParticles behavior seems to be similiar, it's one or another.

Copy link
Member

@akien-mga akien-mga 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, and I confirmed this fixes the MRP.

@@ -1124,7 +1124,7 @@ void CPUParticles3D::_particles_process(double p_delta) {
//turn particle by rotation in Y
if (particle_flags[PARTICLE_FLAG_ROTATE_Y]) {
Basis rot_y(Vector3(0, 1, 0), p.custom[0]);
p.transform.basis = p.transform.basis * rot_y;
p.transform.basis = rot_y;
Copy link
Member

Choose a reason for hiding this comment

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

The equivalent GPU particles code is this:

These look the same indeed. 👍

@akien-mga akien-mga merged commit 16eb8db into godotengine:master May 6, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first (!?) merged Godot contribution 🎉

I guess this will help with getting CI running out of the box to finalize #80710 once the rendering team is ready for it :D

@apples apples deleted the 89559-cpuparticles3d-angle-rotate_y-fix branch May 6, 2024 22:56
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.

CPUParticles3D incorrectly applies the angle parameters when particle_flag_rotate_y is used.
5 participants