Skip to content

Use accurate meter size in Web Mercator projection - #6117

Merged
Pessimistress merged 8 commits into
masterfrom
x/project-size
Oct 5, 2021
Merged

Pessimistress merged 8 commits into
masterfrom
x/project-size

Conversation

@Pessimistress

@Pessimistress Pessimistress commented Aug 18, 2021 •

Copy link
Copy Markdown
Collaborator

For #6181 & discussion #6101

Before:

deck gl-project_size-old

After:

deck gl-project_size-new

I think the perf impact is acceptable (approximately 1 additional cos instruction per vertex at zoom < 12); the main question is how big of a breaking change this is. Is it major-release-worthy? All existing render tests pass as-is; the applications that will break visually are the ones using meter sizes on a global scale. @heshan0131 what is the default radius units in Kepler.gl?

Change List

  • project shader module project_size returns result based on vertex position
  • WebMercatorViewport.projectPosition returns result based on latitude
  • Separate shader code paths for pixel size and meter size -- we used to differentiate *Units: 'pixels' and *Units: 'meters' by adjusting the *Scale uniform. This no longer works if meter size is non-linear.
  • Render test

TODO

  • Documentation / Upgrade guide

@Pessimistress

Copy link
Copy Markdown
Collaborator Author

Since this is all done in the project module, I think it's possible to make this an opt-in change by introducing a new uniform.

@coveralls

coveralls commented Aug 20, 2021 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.005%) to 81.918% when pulling 32644e9 on x/project-size into 80f4c7c on master.

// If geometry.position (vertex in common space) is populated, use it
// Otherwise use geometry.worldPosition (anchor in world space)

if (geometry.position.w == 0.0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be precalculated so we don't need if statements (they tend to slow things down)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without breaking existing layers.

This test will yield the same result for all vertices in a given layer, so there won't be any sync points.


// used in printing a float into GLSL code, 1 will be 1.0 to avoid GLSL compile errors
const MAX_FRACTION_DIGITS = 5;
function getScalerType(a) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe slightly more descriptive name for this function, or some JSDoc?

@ibgreen

ibgreen commented Aug 29, 2021

Copy link
Copy Markdown
Collaborator

As always it would be awesome to have a perf bench to measure actual performance impact on shaders. It looks fine, but we keep adding features and there is always a nagging concern.

@Pessimistress
Pessimistress marked this pull request as ready for review October 2, 2021 06:05
@Pessimistress
Pessimistress merged commit 9d6d63e into master Oct 5, 2021
@Pessimistress
Pessimistress deleted the x/project-size branch October 5, 2021 01:09
antoinebhs added a commit to gridsuite/gridstudy-app that referenced this pull request Oct 3, 2023
…nd this commit (visgl/deck.gl#6117). In the release notes you can read that the way meters are projected in MapView has changed to take into account the Mercator projection (https://deck.gl/docs/upgrade-guide#meter-size-projection). They advise to

    use common units
    use views: new MapView({legacyMeterSizes: true}) to recover the previous behavior
The legacyMeterSizes boolean does indeed restore the previous behavior, but will be removed for version 9.0.
It would be possible to use common units for distanceBetweenLines, which allows offset between superimposed lines. If you do this, you'll have to modify code elsewhere to ensure that labels are correctly positioned w.r.t arrows/lines (you can't really control projections with deck.gl's TextLayer/IconLayer). Using common units, we could set the distance between lines to a distance independent of latitude. This works well, but this is problematic for the TextLayer and IconLayer, which take latitude into account.
The solution adopted is to use another method than project_size() to switch from meters to common units, taking into account a more precise latitude. The arrow layer requires a high degree of precision when placing icons. The project_size() function in deck.gl does not return a high enough level of precision. I use the latitude of the icon's position to improve accuracy and solve the issue.
I tested at different latitudes and does not seem to impact performance.
antoinebhs added a commit to gridsuite/gridstudy-app that referenced this pull request Oct 3, 2023
…nd this commit (visgl/deck.gl#6117). In the release notes you can read that the way meters are projected in MapView has changed to take into account the Mercator projection (https://deck.gl/docs/upgrade-guide#meter-size-projection). They advise to

    use common units
    use views: new MapView({legacyMeterSizes: true}) to recover the previous behavior
The legacyMeterSizes boolean does indeed restore the previous behavior, but will be removed for version 9.0.
It would be possible to use common units for distanceBetweenLines, which allows offset between superimposed lines. If you do this, you'll have to modify code elsewhere to ensure that labels are correctly positioned w.r.t arrows/lines (you can't really control projections with deck.gl's TextLayer/IconLayer). Using common units, we could set the distance between lines to a distance independent of latitude. This works well, but this is problematic for the TextLayer and IconLayer, which take latitude into account.
The solution adopted is to use another method than project_size() to switch from meters to common units, taking into account a more precise latitude. The arrow layer requires a high degree of precision when placing icons. The project_size() function in deck.gl does not return a high enough level of precision. I use the latitude of the icon's position to improve accuracy and solve the issue.
I tested at different latitudes and does not seem to impact performance.
antoinebhs added a commit to gridsuite/gridstudy-app that referenced this pull request Oct 3, 2023
…nd this commit (visgl/deck.gl#6117). In the release notes you can read that the way meters are projected in MapView has changed to take into account the Mercator projection (https://deck.gl/docs/upgrade-guide#meter-size-projection). They advise to

    use common units
    use views: new MapView({legacyMeterSizes: true}) to recover the previous behavior
The legacyMeterSizes boolean does indeed restore the previous behavior, but will be removed for version 9.0.
It would be possible to use common units for distanceBetweenLines, which allows offset between superimposed lines. If you do this, you'll have to modify code elsewhere to ensure that labels are correctly positioned w.r.t arrows/lines (you can't really control projections with deck.gl's TextLayer/IconLayer). Using common units, we could set the distance between lines to a distance independent of latitude. This works well, but this is problematic for the TextLayer and IconLayer, which take latitude into account.
The solution adopted is to use another method than project_size() to switch from meters to common units, taking into account a more precise latitude. The arrow layer requires a high degree of precision when placing icons. The project_size() function in deck.gl does not return a high enough level of precision. I use the latitude of the icon's position to improve accuracy and solve the issue.
I tested at different latitudes and does not seem to impact performance.
antoinebhs added a commit to gridsuite/gridstudy-app that referenced this pull request Oct 3, 2023
…nd this commit (visgl/deck.gl#6117). In the release notes you can read that the way meters are projected in MapView has changed to take into account the Mercator projection (https://deck.gl/docs/upgrade-guide#meter-size-projection). They advise to

    use common units
    use views: new MapView({legacyMeterSizes: true}) to recover the previous behavior
The legacyMeterSizes boolean does indeed restore the previous behavior, but will be removed for version 9.0.
It would be possible to use common units for distanceBetweenLines, which allows offset between superimposed lines. If you do this, you'll have to modify code elsewhere to ensure that labels are correctly positioned w.r.t arrows/lines (you can't really control projections with deck.gl's TextLayer/IconLayer). Using common units, we could set the distance between lines to a distance independent of latitude. This works well, but this is problematic for the TextLayer and IconLayer, which take latitude into account.
The solution adopted is to use another method than project_size() to switch from meters to common units, taking into account a more precise latitude. The arrow layer requires a high degree of precision when placing icons. The project_size() function in deck.gl does not return a high enough level of precision. I use the latitude of the icon's position to improve accuracy and solve the issue.
I tested at different latitudes and does not seem to impact performance.
antoinebhs added a commit to gridsuite/gridstudy-app that referenced this pull request Oct 3, 2023
…nd this commit (visgl/deck.gl#6117). In the release notes you can read that the way meters are projected in MapView has changed to take into account the Mercator projection (https://deck.gl/docs/upgrade-guide#meter-size-projection). They advise to

    use common units
    use views: new MapView({legacyMeterSizes: true}) to recover the previous behavior
The legacyMeterSizes boolean does indeed restore the previous behavior, but will be removed for version 9.0.
It would be possible to use common units for distanceBetweenLines, which allows offset between superimposed lines. If you do this, you'll have to modify code elsewhere to ensure that labels are correctly positioned w.r.t arrows/lines (you can't really control projections with deck.gl's TextLayer/IconLayer). Using common units, we could set the distance between lines to a distance independent of latitude. This works well, but this is problematic for the TextLayer and IconLayer, which take latitude into account.
The solution adopted is to use another method than project_size() to switch from meters to common units, taking into account a more precise latitude. The arrow layer requires a high degree of precision when placing icons. The project_size() function in deck.gl does not return a high enough level of precision. I use the latitude of the icon's position to improve accuracy and solve the issue.
I tested at different latitudes and does not seem to impact performance.
antoinebhs added a commit to gridsuite/gridstudy-app that referenced this pull request Oct 3, 2023
…nd this commit (visgl/deck.gl#6117). In the release notes you can read that the way meters are projected in MapView has changed to take into account the Mercator projection (https://deck.gl/docs/upgrade-guide#meter-size-projection). They advise to

    use common units
    use views: new MapView({legacyMeterSizes: true}) to recover the previous behavior
The legacyMeterSizes boolean does indeed restore the previous behavior, but will be removed for version 9.0.
It would be possible to use common units for distanceBetweenLines, which allows offset between superimposed lines. If you do this, you'll have to modify code elsewhere to ensure that labels are correctly positioned w.r.t arrows/lines (you can't really control projections with deck.gl's TextLayer/IconLayer). Using common units, we could set the distance between lines to a distance independent of latitude. This works well, but this is problematic for the TextLayer and IconLayer, which take latitude into account.
The solution adopted is to use another method than project_size() to switch from meters to common units, taking into account a more precise latitude. The arrow layer requires a high degree of precision when placing icons. The project_size() function in deck.gl does not return a high enough level of precision. I use the latitude of the icon's position to improve accuracy and solve the issue.
I tested at different latitudes and does not seem to impact performance.
antoinebhs added a commit to gridsuite/gridstudy-app that referenced this pull request Oct 3, 2023
…nd this commit (visgl/deck.gl#6117). In the release notes you can read that the way meters are projected in MapView has changed to take into account the Mercator projection (https://deck.gl/docs/upgrade-guide#meter-size-projection). They advise to

    use common units
    use views: new MapView({legacyMeterSizes: true}) to recover the previous behavior
The legacyMeterSizes boolean does indeed restore the previous behavior, but will be removed for version 9.0.
It would be possible to use common units for distanceBetweenLines, which allows offset between superimposed lines. If you do this, you'll have to modify code elsewhere to ensure that labels are correctly positioned w.r.t arrows/lines (you can't really control projections with deck.gl's TextLayer/IconLayer). Using common units, we could set the distance between lines to a distance independent of latitude. This works well, but this is problematic for the TextLayer and IconLayer, which take latitude into account.
The solution adopted is to use another method than project_size() to switch from meters to common units, taking into account a more precise latitude. The arrow layer requires a high degree of precision when placing icons. The project_size() function in deck.gl does not return a high enough level of precision. I use the latitude of the icon's position to improve accuracy and solve the issue.
I tested at different latitudes and does not seem to impact performance.
antoinebhs added a commit to gridsuite/gridstudy-app that referenced this pull request Oct 3, 2023
…nd this commit (visgl/deck.gl#6117). In the release notes you can read that the way meters are projected in MapView has changed to take into account the Mercator projection (https://deck.gl/docs/upgrade-guide#meter-size-projection). They advise to

    use common units
    use views: new MapView({legacyMeterSizes: true}) to recover the previous behavior
The legacyMeterSizes boolean does indeed restore the previous behavior, but will be removed for version 9.0.
It would be possible to use common units for distanceBetweenLines, which allows offset between superimposed lines. If you do this, you'll have to modify code elsewhere to ensure that labels are correctly positioned w.r.t arrows/lines (you can't really control projections with deck.gl's TextLayer/IconLayer). Using common units, we could set the distance between lines to a distance independent of latitude. This works well, but this is problematic for the TextLayer and IconLayer, which take latitude into account.
The solution adopted is to use another method than project_size() to switch from meters to common units, taking into account a more precise latitude. The arrow layer requires a high degree of precision when placing icons. The project_size() function in deck.gl does not return a high enough level of precision. I use the latitude of the icon's position to improve accuracy and solve the issue.
I tested at different latitudes and does not seem to impact performance.
antoinebhs added a commit to gridsuite/gridstudy-app that referenced this pull request Oct 3, 2023
Regression was introduced with deck.gl 8.6 and in particular alpha4 and this commit (visgl/deck.gl#6117). In the release notes you can read that the way meters are projected in MapView has changed to take into account the Mercator projection (https://deck.gl/docs/upgrade-guide#meter-size-projection). They advise to

    use common units
    use views: new MapView({legacyMeterSizes: true}) to recover the previous behavior

The legacyMeterSizes boolean does indeed restore the previous behavior, but will be removed for version 9.0.
It would be possible to use common units for distanceBetweenLines, which allows offset between superimposed lines. If you do this, you'll have to modify code elsewhere to ensure that labels are correctly positioned w.r.t arrows/lines (you can't really control projections with deck.gl's TextLayer/IconLayer). Using common units, we could set the distance between lines to a distance independent of latitude. This works well, but this is problematic for the TextLayer and IconLayer, which take latitude into account.
The solution adopted is to use another method than project_size() to switch from meters to common units, taking into account the arrow latitude when zoom < 12. I'm not sure why there is a change at zoomLevel = 12, but there seem to be some optimizations on the deck.gl side (see: https://github.com/visgl/deck.gl/blob/401d624c0529faaa62125714c376b3ba3b8f379f/dev-docs/RFCs/v6.1/improved-lnglat-projection-rfc.md?plain=1#L29). When zoom>12, we use the deck.gl project_size() method.
I tested at different latitudes and it does not seem to impact performance.
mfrnd added a commit to mfrnd/deck.gl that referenced this pull request Oct 1, 2026
For visgl#7064. Below zoom 12, getOffsetOrigin sets the geospatial origin to
[0,0,0] for both 'lnglat' and 'cartesian' (since visgl#6117). Lnglat is
corrected per vertex in the shader, but cartesian z (meters) is not, so it
is scaled cos(latitude) too small, while from zoom 12 it uses the viewport
latitude. Tiled TerrainLayer meshes are cartesian, so the terrain is too
flat below zoom 12 (0.69 of its height at Mount St. Helens) and jumps at
12; TerrainExtension layers jump with it.

In WEB_MERCATOR mode, keep the viewport center as geospatial origin for
'cartesian', so z is scaled as in WEB_MERCATOR_AUTO_OFFSET mode.
mfrnd added a commit to mfrnd/deck.gl that referenced this pull request Oct 1, 2026
For visgl#7064. Below zoom 12, getOffsetOrigin sets the geospatial origin to
[0,0,0] for both 'lnglat' and 'cartesian' (since visgl#6117). Lnglat is
corrected per vertex in the shader, but cartesian z (meters) is not, so it
is scaled cos(latitude) too small, while from zoom 12 it uses the viewport
latitude. Tiled TerrainLayer meshes are cartesian, so the terrain is too
flat below zoom 12 (0.69 of its height at Mount St. Helens) and jumps at
12; TerrainExtension layers jump with it.

In WEB_MERCATOR mode, keep the viewport center as geospatial origin for
'cartesian', so z is scaled as in WEB_MERCATOR_AUTO_OFFSET mode.

Update the terrain-layer and terrain-extension-drape golden images: their
terrain is at zoom 11.5 and is now drawn at its true height.
mfrnd added a commit to mfrnd/deck.gl that referenced this pull request Oct 2, 2026
For visgl#7064. Below zoom 12, getOffsetOrigin sets the geospatial origin to
[0,0,0] for both 'lnglat' and 'cartesian' (since visgl#6117). Lnglat is
corrected per vertex in the shader, but cartesian z (meters) is not, so it
is scaled cos(latitude) too small, while from zoom 12 it uses the viewport
latitude. Tiled TerrainLayer meshes are cartesian, so the terrain is too
flat below zoom 12 (0.69 of its height at Mount St. Helens) and jumps at
12; TerrainExtension layers jump with it.

In WEB_MERCATOR mode, keep the viewport center as geospatial origin for
'cartesian', so z is scaled as in WEB_MERCATOR_AUTO_OFFSET mode.

Update the terrain-layer and terrain-extension-drape golden images: their
terrain is at zoom 11.5 and is now drawn at its true height.
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.

3 participants