Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

fix(globe): text labels not occluded for objects on the back side of the globe (#3731)

Igor Dykhtaf6e4f636e2d4
diff --git a/src/layers/src/base-layer.ts b/src/layers/src/base-layer.ts
index 7cc1b5934..3a34879ed 100644
--- a/src/layers/src/base-layer.ts
+++ b/src/layers/src/base-layer.ts
@@ -1664,12 +1664,22 @@ class Layer implements KeplerLayer {
sdf: textLabel[i].outlineWidth > 0
},
parameters: {
- // text will always show on top of all layers
- depthTest: false,
- // Globe mode sets a global `cull: true` to backface-cull the sphere
- // surface. That also culls the glyph quads, hiding every label, so
- // disable culling for the label layer (see mvt-label-layer.ts).
- ...(isGlobeMode ? {cull: false} : null),
+ ...(isGlobeMode
+ ? {
+ // Globe far-side occlusion is the depth disk (see globe-layers.ts),
+ // not GPU face culling. Labels used to force depthTest off so they
+ // always drew on top; with cull also disabled they then showed
+ // through the planet when the parent object was on the back side.
+ // Match the editor overlay: depth-test against the disk, don't write
+ // depth, and keep cull off so billboard glyph quads are not discarded.
+ depthTest: true,
+ depthMask: false,
+ cull: false
+ }
+ : {
+ // text will always show on top of all layers
+ depthTest: false
+ }),
...(mapState?.layerParameters ?? {})
},
@@ -1701,6 +1711,7 @@ class Layer implements KeplerLayer {
...(isGlobeMode ? {type: EnhancedTextBackgroundLayer} : null),
parameters: {
cull: false,
+ ...(isGlobeMode ? {depthTest: true, depthMask: false} : null),
...(mapState?.layerParameters ?? {})
}
}
diff --git a/test/browser/layer-tests/point-layer-specs.js b/test/browser/layer-tests/point-layer-specs.js
index acc572d3f..a87110c4c 100644
--- a/test/browser/layer-tests/point-layer-specs.js
+++ b/test/browser/layer-tests/point-layer-specs.js
@@ -898,6 +898,11 @@ test('#PointLayer -> renderLayer globe mode text labels', t => {
const flatLabel = renderWithMapState(INITIAL_MAP_STATE);
t.ok(flatLabel, 'should create a text label layer in flat mode');
+ t.equal(
+ flatLabel.props.parameters.depthTest,
+ false,
+ 'should not depth-test labels outside globe mode'
+ );
t.notOk('cull' in flatLabel.props.parameters, 'should not touch culling outside globe mode');
t.notOk(
flatLabel.props._subLayerProps.characters,
@@ -907,6 +912,16 @@ test('#PointLayer -> renderLayer globe mode text labels', t => {
// globe mode sets a global `cull: true`, which would otherwise discard the glyph quads
const globeLabel = renderWithMapState({...INITIAL_MAP_STATE, globe: {enabled: true}});
t.equal(globeLabel.props.parameters.cull, false, 'should disable culling in globe mode');
+ t.equal(
+ globeLabel.props.parameters.depthTest,
+ true,
+ 'should depth-test labels against the globe depth disk'
+ );
+ t.equal(
+ globeLabel.props.parameters.depthMask,
+ false,
+ 'should not write depth so labels do not occlude each other'
+ );
t.equal(
globeLabel.props._subLayerProps.characters.type,
EnhancedMultiIconLayer,