-
Notifications
You must be signed in to change notification settings - Fork 447
fix: buffered linear interpolator jitter and exposing more properties #3355
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: buffered linear interpolator jitter and exposing more properties #3355
Conversation
- Removed the lerp smoothing parameter and made it an internal bool (don't need to add to API and it should be set through the NetworkTransform anyway). - Added additional BufferedLinearInterpolator debug code. - Added additional PreUpdate pass for NetworkTransforms using Rigidbody motion in order to reset a fixed time delta. - Added incemental fixed time delta when the FixedUpdate is invoked multiple times within a single frame. - Added internal time sync counter. - Added a "1/3rd" rule to smooth dampening and LerpExtrapolateBlend when smooth lerp is enabled in order to still be able to balance between smoothing the final lerped value and reaching the target (or getting much closer).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand all of it, but here is an initial pass review :)
com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs
Outdated
Show resolved
Hide resolved
com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs
Outdated
Show resolved
Hide resolved
Exposing internal access to position and rotation interpolators for future tests and tools. Noticed the slerp for full precision rotation was only being applied when using Lerp, now it is for all interpolation types. Making the time to approximately reach adjustment be the default when there is no pending item to be consumed and slightly sooner when there is. Removing the adjustment to the slerp smoothing as this should be a consistantly applied value for all interpolation types.
Renaming NetworkTransformMultipleChangesOverTime to just MultipleChangesOverTime (no need for the NetworkTransform part as it is already part of the NetworkTransformTests). Turning off Lerp smoothing for MultipleChangesOverTime and added lengthy comment as to why. Fixed the initial check for the first state update in MultipleChangesOverTime due to a change in the Interpolation value. It was not properly checking both pushed and updated values and should only be checked when interpolation is turned off as the default is enabled and when running MultipleChangesOverTime for 3 axis it remains enabled (i.e. there will be no state update for that as nothing changed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok! I get it! There's one Update()
for Lerp, and a separate one for Smooth Dampening and LerpExtrapolateBlend! Ok, this looks good!
Renamed LerpExtrapolateBlend to LerpAhead. Found some issues with the original lerp's buffer consumption where it was always calculating 2x the time to target. Assuring that the original lerp logic isn't executed upon arriving to the final destination. Increasing the k_AproximatePrecision...preceision value to be one one hundred thousandth. Removed some debug code from NetworkTransformBase.
…b.com/Unity-Technologies/com.unity.netcode.gameobjects into fix/bufferedlinearinterpolator-jitter
Is it something that should be also ported to 1.X or not really @NoelStephensUnity? |
Still had one more line of code needed to go back to original lerp buffer consumption where the time to target is always 2x the actual time to target (it ends up consuming 2 state updates for each non-authority update). Making sure some of the debugging BLI accessor methods in NetworkTransform are still accessible for internal testing purposes.
After testing for quite some time I came to the conclusion that we needed a "new" lerp and should mark the original lerp as the "legacy" lerp while keeping the added option to have the smooth dampening. Removed the additional phases from the "new" lerp and smooth dampening while also providing users with a more direct and constant maximum interpolation setting that is not directly tied to the frame time delta. This yields a wider range of fine tuning and will be easier to handle adjusting during runtime. The LinearBufferInterpolator RNSM component hooks are in place so we can provide users with a tool to be able to determine what is happening with the LinearBufferInterpolator... it will be released in the examples section once ready to be released. Adjusted API XML documentation and all places that referenced the other enum names changed.
After doing some testing I noticed a few anomalies with the updated
BufferedLinearInterpolator<T>
. As it turns out, there are more than one approaches a user might need depending upon what they are trying to accomplish and each option really performs best when tweaking some properties within theBufferedLinearInterpolator<T>
that were not completely exposed.Various options:
NetworkTransform.InterpolationBufferTickOffset
) used depending upon context.This PR renames
Lerp
toLegacyLerp
and adds a 3rd newLerp
interpolator type:Lerp (new)
Uses a 1 to 2 phase approach that lerps towards the target, lerps towards the next target (if one exists) ahead by 1 frame delta, blends the two results, and (optionally) smooth the final value.
Changelog
Lerp
interpolation type that still uses a lerp approach but uses the new buffer consumption logic.NetworkTransform.InterpolationBufferTickOffset
static property to provide users with a way to increase or decrease the time marker where interpolators will pull state update from the queue.Lerp
to be renamed toLegacyLerp
.Testing and Documentation
NetworkTransform
. (Will be adding to PR-1443)