cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Fix z-fighting and performance issues in 2D infinite scroll mode

Open andrewda opened this issue 1 year ago • 3 comments

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
CleanShot 2025-02-19 at 12 32 09 CleanShot 2025-02-19 at 12 32 25

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.md with 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

andrewda avatar Feb 19 '25 21:02 andrewda

Thank you for the pull request, @andrewda!

:white_check_mark: We can confirm we have a CLA on file for you.

github-actions[bot] avatar Feb 19 '25 21:02 github-actions[bot]

This is still a work in progress while I reconcile getting tests to pass.

andrewda avatar Feb 26 '25 17:02 andrewda

Hi @andrewda, what is the latest here? Can we help get this over the finish line?

ggetz avatar Apr 17 '25 13:04 ggetz