Ground primitive not showing up in 2D
- Dominant language
- JavaScript
- Stars
- 15.7k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
In [this sandcastle](https://sandcastle.cesium.com/#c=bVNdb9sgFP0rKE+JFBETx/laGm1Kq6lSu03LtCdLFbFvXDYMFmBX6ZT/PsBfSVs/YLj3nHsPB6ioQhWDF1DoBgl4QTvQrMzxbx8bxoPEr3dSGMoEqHgw+hSLyrJ0AgIsqWZjv7SpOvkC2tjcNMJkOiWLOVnMCIns15JlaZ4tIJrj1XxJwuWMLKKQhKTJA73ghysSBv6bNmkh1QU9XK6iYLmYR/No1ilQkBgqMu4kem24UCxnhlWgMU3TYSzQ5Ya/KlmK9EeLGf5zeYQykDkYdboX2pazZqyvSG+yLavnXcF/tppaXo9HveD1Ozg+KpnfQqYA9LBnIG/zuDZz7D0b19b0mNG4nZ/baTehRQFUOd1XKh+pAcUo/9Kle5lHTs0aGVVCV8z93Tjy1ne7wH11nDcVr69Y26eufqQHxZI1alqZU2FVxYP7nGYQD5pupWBHqXLdwRBiDuCQGE/8XE/q+k8PMpNPO8mlwn+KrKtx9n83nkfdbSmktscuhVXYqNtRZeyMivDK/SvHSRD413DxAnBCc1AUH/npl6x3lloKE9SVX3eNvIi0VE04wIHXg7ygy3q5TKFXtXexRxvC+93dt7vprW0/GA822pw4bFtPPrO8sNcAlYoPrS0G8sKem3XmUCZ/weBEa6fbQTeTS+omZRVi6c0Hzx4lnGptM8eS8z17tYey3Uws/h2VS5oykX2vQHF6crBnsn2ogxjjzcQuP2YaKfmBqjeV/wM) the ground primitive is missing in 2D but visible in 3D.
2D | 3D
--|--
|
The problem is that `GroundPrimitive` uses `ApproximateTerrainHeights` to determine the min/max height for the shadow volume even when terrain is off. The approximate min/max height for this location is
```
-0.000018664832009763883
275.13
```
In 2D the globe tiles themselves are exactly `0.0` which means the shadow volume should just barely covers the surface, but there's likely precision issues at play that cause the shadow volume to be slightly above the surface so that nothing gets rendered.
To confirm this suspicion I lowered the min height by `-10.0` and the shadow volume shows up again. This is definitely not a recommended solution.
```
function setMinMaxTerrainHeights(primitive, rectangle, ellipsoid) {
var result = ApproximateTerrainHeights.getMinimumMaximumHeights(
rectangle,
ellipsoid
);
primitive._minTerrainHeight = result.minimumTerrainHeight - 10.0;
primitive._maxTerrainHeight = result.maximumTerrainHeight;
}
```
The only reason it works in 3D is because the globe triangles are not consistently at 0.0 height. If I raise the min height by `0.5` the shadow volume disappears.
The key point is that `ApproximateTerrainHeights` should not be used for ground primitives in 2D, or used at all (CC https://github.com/CesiumGS/cesium/issues/8480)
Contributor guide
Research direction
Reproduce the issue from the linked Sandcastle, comparing GroundPrimitive behavior in 2D and 3D. Start by tracing how GroundPrimitive uses ApproximateTerrainHeights to set the shadow-volume bounds, then verify the fix with a 2D case where the globe tiles are at exactly 0.0 height. Done means the ground primitive renders in 2D without the manual height offset and remains visible in 3D.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100