Skip to content
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 scene.pickPosition when depthTestAgainstTerrain is false #11983

Merged
merged 2 commits into from
May 14, 2024

Conversation

ggetz
Copy link
Contributor

@ggetz ggetz commented May 14, 2024

Description

Fixes inaccurate results for scene.pickPosition when depthTestAgainstTerrain is false.

Although we were copying the initial globe depth before clearing the globe for subsequent passes, the globe depth was not getting copied into the pickDepth buffer.

This updates pickDepth to resolve depth from both the original and updated globe depth values.

Issue number and link

Fixes #4368

Testing plan

  1. Here's a testing Sandcastle that clearly illustrated the initiation problem. It outputs the results of pickPosition vs globe.pick. The values are wildly different before the fix, and should be similar after.
  2. Copy/paste the picking code into various examples to confirm:
  • Scene with globe and model
  • Scene with globe and tileset
  • Scene with translucent globe
  • 2D scene
  • Scene with classification

// Mouse over the globe to see the cartographic height
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function (movement) {
  const scene = viewer.scene;
  if (scene.mode !== Cesium.SceneMode.MORPHING) {
      let cartesian = scene.pickPosition(
        movement.endPosition
      );
    
    

      let heightString = "";
      if (Cesium.defined(cartesian)) {
        const cartographic = Cesium.Cartographic.fromCartesian(
          cartesian
        );
        const longitudeString = Cesium.Math.toDegrees(
          cartographic.longitude
        ).toFixed(2);
        const latitudeString = Cesium.Math.toDegrees(
          cartographic.latitude
        ).toFixed(2);
       heightString += cartographic.height.toFixed(2);
      }
    
    heightString += " | ";
    
    
    cartesian = scene.globe.pick(scene.camera.getPickRay(movement.endPosition), scene);
    
    if (Cesium.defined(cartesian)) {
        const cartographic = Cesium.Cartographic.fromCartesian(
          cartesian
        );
        const longitudeString = Cesium.Math.toDegrees(
          cartographic.longitude
        ).toFixed(2);
        const latitudeString = Cesium.Math.toDegrees(
          cartographic.latitude
        ).toFixed(2);
       heightString += cartographic.height.toFixed(2);
      }
    
    console.log(heightString);
    }
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have update the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

@ggetz
Copy link
Contributor Author

ggetz commented May 14, 2024

@lilleyse Can you take a look please?

Copy link

Thank you for the pull request, @ggetz!

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

@lilleyse
Copy link
Contributor

I'm always a little concerned about changes like this, but I couldn't think of any cases where it would break. Hopefully two weeks in main is enough time to catch any issues.

The code looks good though. I like that it's a simple shader change.

@lilleyse lilleyse merged commit db62d07 into main May 14, 2024
10 checks passed
@lilleyse lilleyse deleted the pick-position branch May 14, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scene.pickPosition returns incorrect position
2 participants