mapbox / mapbox/mapbox-gl-js

Improve terrain symbol occlusion opacity calculation

Open
#11,501 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Motivation

In the symbol shaders (symbol_icon & symbol_sdf), we determine opacity of the symbol based on occlusion from the terrain using the function occlusionFade. Here we use the NDC coordinates of the symbol center to determine if the opacity should be lowered or make it completely invisible.

The issue caused by the non-linear nature of the depth texture. Depth is stored in a logarithmic manner: 1 / depth. This means that there is more precision close to the camera; half of all possible values are used in the depth range from near plane to twice the near plane distance.

We are currently using constants for calculating the occlusion for the whole depth range. This means that the constants have different effect at different distances from the camera. Far from the camera, symbols show up through terrain at varying opacities.

Screenshot 2022-02-11 at 15 15 07

Design Alternatives

We could take the depth non-linearity into account and change the constants used for occlusion calculation based on the symbol depth. This needs some experimentation and could make the opacity less stable when the camera is moving due to smaller depth differences causing larger changes in opacity.

We can improve depth precision by moving the near plane farther out. We'd need to make sure there are no situation where the rendered geometry could clip through the near plane.

We could change the depth texture to be stored as linear depth. It would let us have more depth precision far away from the camera, and it would allow us to use the same constants throughout the depth range. This would, of course require more changes than the other options so it might not be feasible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with occlusionFade in src/shaders/_prelude_terrain.vertex.glsl and the symbol_icon and symbol_sdf shaders. Compare how depth and NDC coordinates drive opacity, then evaluate the proposed depth-handling alternatives; done means terrain occlusion opacity behaves consistently across the depth range without unstable camera-motion changes.

Written by the indexing model from the issue text.

Assessment

Domain
computer-graphics
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.