-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
Account for physics interpolation and transform snapping when Y-sorting #93025
Account for physics interpolation and transform snapping when Y-sorting #93025
Conversation
I'll take a look. I vaguely remember doing something to fix y-sorting at some point but maybe it's not working in 3.x too, I'll check the issue and see if I can reproduce in 3.x. EDIT: @rburing welcome to look as he is maintaining 4.x (I can't guarantee I can spend much time on this). Key things is probably making sure it isn't doing more work than necessary, ideally shouldn't be interpolating transforms twice. |
IIRC in 3.x the canvas item with
Yes, currently it indeed does interpolate twice per y-sorted item, I'm well aware of that and I do dislike it. Was focusing on conceptually fixing the transform calculations here (in fact I haven't tested it much in action, only in the MRP from #92982; was fixing purely from the code standpoint; so testing further welcomed). |
5206a36
to
bcdc456
Compare
Added second commit (see updated description) and rebased against BTW @markdibarry have you tested how/if y-sorting works with parallax? 🤔 I haven't and am just curious. 🙃 In any case in this PR I just tried to ensure the parallax calculations remain the same as before. |
@kleonc Oof! I never even imagined anyone would use a parallax effect with y-sorting... and I still can't think of a use case, but I'm sure someone can and will be very upset! I tried it on the master branch and it seems to remove all repeats due to
|
@markdibarry Firstly let's clarify of what behavior of y-sorting + repeating we're talking.
Knowing a little how these work I intuitively was thinking about (2) but I guess someone could expect (1). (1) seems not feasible performance-wise to me, as it would require each repeat to basically become its own item to be ordered separately (thus in case of items' different materials more batching breaking etc.; way costlier/slower). (2) should be easy to achieve. Actually it already works in some cases. 🙃 Also given it's questionable whether it has a use case I'd
I've looked into the repeating code and main issue is that for all y-sorted items Meaning it already works e.g. if Parallax2D is the first y-sorted node (the root of the y-sorted subtree) and there are no nested Parallax2Ds involved etc. In v4.3.beta1.official [a4f2ea9]:
Fixing it would be pretty much the same as what's done in this PR, aka it's a matter of propagating proper There are some other little issues with the repeating I can see in code, but it's offtopic here. In general I dislike how now things need to be duplicated codewise to be done before y-sorting, so I'm thinking |
bcdc456
to
c1133a1
Compare
Rebased (#93182 was merged). |
Needs a rebase, and then an approval would be great :) |
c1133a1
to
c170f1a
Compare
Rebased (pretty much no changes compared to the pre-rebase version). |
|
Am happy that @rburing has checked properly, I've had a little look through and it looked fine but I didn't follow it completely. 😁 |
Thanks! |
Hmm, this change replaces the |
Absolutely not. It was like that originally and I must have overlooked this while rebasing, my bad. Thanks for spotting it out! |
Note: if/when cherry-picking, should be done together with #98195. |
Makes the transforms used for Y-sorting canvas items match the transforms used for such items in
RendererCanvasCull::_cull_canvas_item
, aka it accounts for physics interpolation and transform snapping.Fixes #92982.
This is done in the first commit as a simple change which results in calculating physics interpolation and transform snapping twice for each y-sorted item: when determining transforms used for y-sorting while gathering to-be-y-sorted items, and when actually handling them after they're y-sorted (also note that calculating transforms twice introduces a chance of using different transforms for sorting/rendering in case there's some mismatch in calculations).
The second commit makes the transform calculations (physics interpolation, transform snapping) happen once for each y-sorted item, before y-sorting (so it's sorted according to the position used later for rendering).
For reviewing the second commit I recommend looking at combined first+second commits diff, should be simpler.
In more detail:
RendererCanvasCull::Item::ysort_xform
was previously storing a transform from the parent of the given item to the y-sorted subtree's root, now it's changed to store a transform from the given item to the y-sorted subtree's root instead.Meaning previously y-sorted
item
's final transform wasysorted_subtree_root.final_xform * item.ysort_xform * item.self_xform
, now it'sysorted_subtree_root.final_xform * item.ysort_xform
asitem.self_xform
is calculated before y-sorting and it's included intoitem.ysort_xform
to not need to recalculate it later.As a result
RendererCanvasCull::Item::ysort_pos
was removed as no longer needed, nowitem.ysort_xform.origin
is the exact same position (the item's position in y-sorted subtree's root coordinate space) which can be used for sorting instead.Renamed
RendererCanvasCull::_cull_canvas_item
'sp_allow_y_sort
parameter top_is_already_y_sorted
as it seemed more intuitive to me, given it's usage (and negated the passed value everywhere).So now when
p_is_already_y_sorted == true
the item's final transform was already calculated during y-sorting, and it's passed asp_parent_xform
toRendererCanvasCull::_cull_canvas_item
(kinda disliking this naming/behavior discrepancy but oh well). Thus in such case self/local transform is not being recalculated, and thus it's not available (only the final transform is passed).Also extracted the count-only part of
RendererCanvasCull::_collect_ysort_children
into separateRendererCanvasCull::_count_ysort_children
as with the transform calculations added it seemed too "ify".And moved
_mark_ysort_dirty
intoRendererCanvasCull
as well.I guess that's it, feel free to ask for any further explanation/clarification in case something is unclear.
Oh, and I'd understand if the second commit is considered too risky for cherry-picking into 4.3.stable etc. so of course I could split it into 2 PRs or whatever else is desired.