Skip to content

[3.x] CPUParticles2D - fix interpolated transforms and culling#80887

Merged
akien-mga merged 1 commit intogodotengine:3.xfrom
lawnjelly:cpuparticles2d_fix_double_xform
Sep 18, 2023
Merged

[3.x] CPUParticles2D - fix interpolated transforms and culling#80887
akien-mga merged 1 commit intogodotengine:3.xfrom
lawnjelly:cpuparticles2d_fix_double_xform

Conversation

@lawnjelly
Copy link
Copy Markdown
Member

@lawnjelly lawnjelly commented Aug 22, 2023

  1. Physics interpolated particles in global mode are specified in global space. In VisualServer they should therefore ignore local transform.
  2. Additionally, the expected final_transform should be passed on to children, rather than the identity transform used on the local item.
  3. Local bounds in hierarchical culling are fixed for items using identity transform, by calculating their local bound in local space from the global space particles.

Fixes #80880

broken.mp4
fixed.mp4

Explanation

The first bug fix is that as CPUParticles2D are specified with vertices in global space, then the local transform of the item should not be applied during rendering. If it changes, this should reflect in the vertex positions, not be applied during rendering. For this reason the flag is renamed from ignore_parent_xform to use_identity_xform, as that is what it now does.

An additional bug was I noticed that during rendering the global transform passed to any children from such an item would be incorrect. It now calculates the final_xform as normal (and passes to children), but substitutes in the identity transform only for rendering (which is done by substituting the camera transform only, as the camera transform is always combined in the final transform).

Next, I realised that the local bound for hierarchical culling was incorrect, as it was specified in global space, whereas hierarchical culling expects bounds in local space. This was fixed by back-calculating a local bound during the local bound update pass. This isn't particularly efficient, but it should work and is not overly complex. I couldn't immediately think of a better way of doing this but perhaps it can be improved / optimized in a later PR.

Notes

  • Normally I would split these up into 2 or 3 PRs but the rename makes this more tricky.
  • These bugs currently only affect particles when physics interpolation is switched on.

Testing

Run the MRP from #80880

I also have an MRP for displaying the local bounds to verify these are correct, run with 3.6 beta 3 (to see problems), and with this PR to see fixed:
CPUPartlcles2D_LocalBounds.zip

1) Physics interpolated particles in global mode are specified in global space. In VisualServer they should therefore ignore local transform.

2) Additionally, the expected final_transform should be passed on to children, rather than the identity transform used on the local item.

3) Local bounds in hierarchical culling are fixed for items using identity transform, by calculating their local bound in local space from the global space particles.
@lawnjelly lawnjelly added this to the 3.6 milestone Aug 22, 2023
@lawnjelly lawnjelly marked this pull request as ready for review August 22, 2023 13:01
@lawnjelly lawnjelly requested review from a team as code owners August 22, 2023 13:01
@lawnjelly lawnjelly changed the title CPUParticles2D - fix interpolated transforms and culling [3.x] CPUParticles2D - fix interpolated transforms and culling Aug 22, 2023
@akien-mga akien-mga merged commit cc48c18 into godotengine:3.x Sep 18, 2023
@akien-mga
Copy link
Copy Markdown
Member

Thanks!

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.

2 participants