Skip to content

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

fix: shadows effect issues with highlighted objects (#3683)

Igor Dykhtaadab6c25d769
diff --git a/src/effects/src/custom-deck-lighting-effect.spec.ts b/src/effects/src/custom-deck-lighting-effect.spec.ts
index 20ec1329a..ede7fb2b9 100644
--- a/src/effects/src/custom-deck-lighting-effect.spec.ts
+++ b/src/effects/src/custom-deck-lighting-effect.spec.ts
@@ -1,7 +1,27 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
-import {alignExportShadowPass, patchShadowPassDepth} from './custom-deck-lighting-effect';
+import {
+ alignExportShadowPass,
+ patchShadowPassDepth,
+ shadowMapHoverFixModule
+} from './custom-deck-lighting-effect';
+
+describe('shadowMapHoverFixModule', () => {
+ test('re-encodes shadow map depth after picking highlight', () => {
+ const inject = (
+ shadowMapHoverFixModule as {
+ inject: Record<string, {order: number; injection: string}>;
+ }
+ ).inject['fs:DECKGL_FILTER_COLOR'];
+
+ // deck.gl picking blends highlightColor at order 99, which would overwrite
+ // encoded shadow depth for the hovered object.
+ expect(inject.order).toBeGreaterThan(99);
+ expect(inject.injection).toContain('shadow.drawShadowMap');
+ expect(inject.injection).toContain('shadow_filterShadowColor');
+ });
+});
describe('patchShadowPassDepth', () => {
test('forces WebGL depth writes and disables polygon offset', () => {
diff --git a/src/effects/src/custom-deck-lighting-effect.ts b/src/effects/src/custom-deck-lighting-effect.ts
index bc38dd854..81fb6e19f 100644
--- a/src/effects/src/custom-deck-lighting-effect.ts
+++ b/src/effects/src/custom-deck-lighting-effect.ts
@@ -196,6 +196,26 @@ function createCustomShadowModule(): ShaderModule | null {
const CustomShadowModule = createCustomShadowModule();
+// deck.gl picking injects at order 99 and blends highlightColor over the
+// fragment. In the shadow pass that overwrites encoded depth, so a hovered
+// extruded feature stops casting a shadow. Re-encode after picking.
+// Color-pass highlight compositing is unchanged (shadow still runs first).
+const PICKING_FILTER_COLOR_ORDER = 99;
+
+export const shadowMapHoverFixModule = {
+ name: 'shadow-map-hover-fix',
+ inject: {
+ 'fs:DECKGL_FILTER_COLOR': {
+ order: PICKING_FILTER_COLOR_ORDER + 1,
+ injection: `
+ if (shadow.drawShadowMap) {
+ color = shadow_filterShadowColor(color);
+ }
+ `
+ }
+ }
+} as unknown as ShaderModule;
+
/**
* Detect layers that use the PBR shader module (3D tile sublayers:
* ScenegraphLayer sets `_lighting: 'pbr'`, SimpleMeshLayer sets `pbrMaterial`).
@@ -211,6 +231,8 @@ function isPbrLayer(layer: any): boolean {
* - A patched shadow module with `outputUniformShadow` for uniform shadow
* during nighttime (avoids partial shadows from below).
* - Simple phong replacement for PBR layers (avoids microfacet specular).
+ * - Shadow-map depth re-encoded after picking highlight so hovered extruded
+ * features still cast shadows.
* - getShaderModuleProps override that always provides dummyShadowMap
* to prevent "Bad texture binding" errors when shadows are disabled.
*/
@@ -238,6 +260,7 @@ class CustomDeckLightingEffect extends LightingEffect {
alignExportShadowPass(shadowPass, () => this.isExportMode);
}
deck._addDefaultShaderModule(CustomShadowModule || shadow);
+ deck._addDefaultShaderModule(shadowMapHoverFixModule);
this._private.dummyShadowMap = device.createTexture({width: 1, height: 1});
}
}
@@ -270,6 +293,7 @@ class CustomDeckLightingEffect extends LightingEffect {
this._private.dummyShadowMap.destroy();
this._private.dummyShadowMap = null;
context.deck._removeDefaultShaderModule(CustomShadowModule || shadow);
+ context.deck._removeDefaultShaderModule(shadowMapHoverFixModule);
}
}
diff --git a/src/effects/tsconfig.production.json b/src/effects/tsconfig.production.json
index 1d2a7a9b1..ae2345bd8 100644
--- a/src/effects/tsconfig.production.json
+++ b/src/effects/tsconfig.production.json
@@ -24,5 +24,6 @@
"isolatedModules": true,
"baseUrl": "./src"
},
- "include": ["src", "../deckgl-types.d.ts"]
+ "include": ["src", "../deckgl-types.d.ts"],
+ "exclude": ["**/*.spec.*"]
}