Skip to content

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

fix: labels background depth test fix (#3761)

Igor Dykhtaf6d2c3ab80d9
diff --git a/src/layers/src/base-layer.ts b/src/layers/src/base-layer.ts
index ce36fa92b..62769641c 100644
--- a/src/layers/src/base-layer.ts
+++ b/src/layers/src/base-layer.ts
@@ -1712,6 +1712,27 @@ class Layer implements KeplerLayer {
const labelId = `${this.id}-label-${textLabel[i].field?.name}${
collisionEnabled ? '-collision' : ''
}`;
+ // Glyphs inherit these from the TextLayer. The background sublayer's
+ // `_subLayerProps.background.parameters` replaces that object, so the
+ // same depth settings have to be repeated there. Otherwise the box
+ // keeps deck.gl's default depth test and is discarded against extruded
+ // geometry while the text (depthTest off) still draws on top.
+ const labelDepthParameters = 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
+ };
accu.push(
// @ts-expect-error
@@ -1742,22 +1763,7 @@ class Layer implements KeplerLayer {
sdf: textLabel[i].outlineWidth > 0
},
parameters: {
- ...(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
- }),
+ ...labelDepthParameters,
...(mapState?.layerParameters ?? {})
},
...(collisionEnabled
@@ -1789,17 +1795,20 @@ class Layer implements KeplerLayer {
collisionEnabled
},
_subLayerProps: {
- // Labels anchored on the far hemisphere would otherwise be drawn
- // through the planet, since depthTest is off. Both the glyphs and the
- // label background need it, or a far-side label leaves an empty box.
+ // Far-side labels would otherwise draw through the planet. Both the
+ // glyphs and the label background need the back-face cull shader, or
+ // a far-side label leaves an empty box.
...(isGlobeMode ? {characters: {type: EnhancedMultiIconLayer}} : null),
...(background
? {
background: {
...(isGlobeMode ? {type: EnhancedTextBackgroundLayer} : null),
parameters: {
- cull: false,
- ...(isGlobeMode ? {depthTest: true, depthMask: false} : null),
+ ...labelDepthParameters,
+ // Flat mode leaves parent culling alone; the background quad
+ // is camera-facing and must not be discarded if a parent
+ // parameter enables cull.
+ ...(isGlobeMode ? null : {cull: false}),
...(mapState?.layerParameters ?? {})
}
}
diff --git a/test/browser/layer-tests/point-layer-specs.js b/test/browser/layer-tests/point-layer-specs.js
index 4427fa60b..de9c84875 100644
--- a/test/browser/layer-tests/point-layer-specs.js
+++ b/test/browser/layer-tests/point-layer-specs.js
@@ -1017,6 +1017,11 @@ test('#PointLayer -> renderLayer globe mode text labels', t => {
flatLabel.props._subLayerProps.characters,
'should not override the glyph sublayer outside globe mode'
);
+ t.equal(
+ flatLabel.props._subLayerProps.background.parameters.depthTest,
+ false,
+ 'should not depth-test the label background outside globe mode'
+ );
// globe mode sets a global `cull: true`, which would otherwise discard the glyph quads
const globeLabel = renderWithMapState({...INITIAL_MAP_STATE, globe: {enabled: true}});
@@ -1041,6 +1046,16 @@ test('#PointLayer -> renderLayer globe mode text labels', t => {
EnhancedTextBackgroundLayer,
'should render the label background with the globe back-face culling sublayer'
);
+ t.equal(
+ globeLabel.props._subLayerProps.background.parameters.depthTest,
+ true,
+ 'should depth-test the label background against the globe depth disk'
+ );
+ t.equal(
+ globeLabel.props._subLayerProps.background.parameters.depthMask,
+ false,
+ 'should not write depth from the label background'
+ );
t.end();
});