Fix z-fighting and performance issues in 2D infinite scroll mode
Description
This pull request addresses both performance issues and zIndex issues in 2D infinite scroll mode.
Currently, the execute2DViewportCommands function clones camera.position so that the camera's x and y positions can be modified to enable infinite scrolling (i.e., rendering another copy of the map to the side). At the end of execute2DViewportCommands, the camera's position is reset to the copy that was created earlier, because the camera modifications made were solely for rendering -- the camera is not actually intended to move. However, it appears that copying the previous camera z position (which is not modified in execute2DViewportCommands for infinite scroll rendering) resets changes made in executeCommands to avoid z-fighting:
https://github.com/CesiumGS/cesium/blob/47b5d295facaca795381bf607b78cc60c643fd85/packages/engine/Source/Scene/Scene.js#L2614-L2617
This pull request fixes this issue by only resetting the x and y values of the camera, rather than the entire position object. This fixes z-fighting reported in https://github.com/CesiumGS/cesium/issues/8302 (zIndex Sandcastle):
| Before | After |
|---|---|
Additionally, this pull request removes an extraneous clone() operation on the frustum. The frustum variable is cloned from the camera on initialization, and thus does not need to be recloned later:
https://github.com/CesiumGS/cesium/blob/31670c1b4a346353f7dffba98d4e8daade04d030/packages/engine/Source/Scene/Scene.js#L3177
These two changes also resolve some performance issues in 2D infinite scroll mode, for reasons that are not entirely clear to me. See the following screen recordings. In the Before recording, the FPS while panning drops from a steady ~100fps to around ~75fps. In the After recording, the FPS starts substantially higher, around ~140fps, and drops to only ~130fps.
Before Change
https://github.com/user-attachments/assets/a8a05ca5-7bbb-497b-b8cf-bbfb6a733a92
After Change
https://github.com/user-attachments/assets/3e658333-d674-4e2d-87d2-72572ff6297b
I am not clear on exactly where this performance hit is coming from, but the improvements appear to be even more noticeable on a lower-spec machine (where panning performance goes from ~30fps before the change to a steady ~90fps after the change).
Issue number and link
zIndex Issue: https://github.com/CesiumGS/cesium/issues/8302
Likely related performance issue: https://github.com/CesiumGS/cesium/issues/5026
Testing plan
I have tested that this fixes both the zIndex and performance issues on a variety of machines using this zIndex Sandcastle.
Author checklist
- [x] I have submitted a Contributor License Agreement
- [x] I have added my name to
CONTRIBUTORS.md - [x] I have updated
CHANGES.mdwith a short summary of my change - [x] I have added or updated unit tests to ensure consistent code coverage
- [x] I have updated the inline documentation, and included code examples where relevant
- [x] I have performed a self-review of my code
Thank you for the pull request, @andrewda!
:white_check_mark: We can confirm we have a CLA on file for you.
This is still a work in progress while I reconcile getting tests to pass.
Hi @andrewda, what is the latest here? Can we help get this over the finish line?