Skip to content

fix: turn off all lighting for raster layers - #670

Merged
kylebarron merged 1 commit into
mainfrom
fix/raster-ignore-lighting
Sep 23, 2026
Merged

kylebarron merged 1 commit into
mainfrom
fix/raster-ignore-lighting

Conversation

@kylebarron

@kylebarron kylebarron commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

This turns off all lighting support for the raster layer.


Note

This PR was written by Claude (Claude Code) on behalf of @kylebarron.

Closes #612. Alternative to and closes #613.

Problem

MeshTextureLayer's fragment shader is vendored from SimpleMeshLayer, which runs every fragment through Phong lighting (lighting_getLightColor). #423 set a default material (ambient: 1, diffuse: 0) that cancels lighting out, but only against deck.gl's default lights (a white ambient light at intensity 1.0). With a user-supplied LightingEffect, raster colors change:

  • An ambient light at intensity 0.4 renders the raster at ~40% brightness.
  • Directional lights with no ambient light render the raster black.

BitmapLayer doesn't have this problem because its shader never applies lighting.

Change

The raster mesh is flat, so lighting can only multiply the whole raster by a constant. It never tells you anything about the data. This PR removes the lighting call from the fragment shader and writes the sampled color directly, like BitmapLayer:

fragColor = vec4(color.rgb, color.a * layer.opacity);

material no longer has any effect, so its default is removed and it's excluded from MeshTextureLayerProps. MeshTextureLayer isn't exported from the package, so the public API doesn't change.

Unlike #613, this doesn't add a material prop to RasterLayer / RasterTileLayer or override shader module props in draw(). The fact that material: false doesn't disable lighting in deck.gl v9 is an upstream bug: visgl/deck.gl#9696.

If lighting becomes useful later (e.g. for extruded terrain), it can come back as an opt-in along with real mesh normals.

Testing

Checked examples/cog-basic in Chrome with a temporary LightingEffect passed to the overlay, e.g.:

effects={[
  new LightingEffect({
    ambient: new AmbientLight({ color: [255, 255, 255], intensity: 0.4 }),
  }),
]}
Scene lighting main this PR
None (deck.gl default lights) true colors true colors
AmbientLight, intensity 0.4 ~40% brightness true colors
DirectionalLight only black true colors

No new console errors or warnings. tsc --noEmit and vitest pass. There's no new automated test, because a unit test could only check the shader source text.

🤖 Written by Claude Code

MeshTextureLayer's fragment shader was vendored from SimpleMeshLayer, which
runs every fragment through Phong lighting. The default material from #423
(ambient 1, diffuse 0) only cancels that out against deck.gl's default lights
(white ambient at intensity 1). Any user-supplied LightingEffect changes the
raster: an ambient intensity of 0.4 renders it at ~40% brightness, and a
LightingEffect with only directional lights renders it black.

The mesh is flat, so lighting can only ever scale the whole raster by a
constant. Drop the lighting call and write the sampled color directly, like
BitmapLayer. `material` no longer has any effect, so remove its default and
exclude it from MeshTextureLayerProps.

Closes #612

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the fix label Sep 23, 2026
@kylebarron kylebarron changed the title fix: Render rasters unlit, ignoring scene lighting fix: turn off all lighting for raster layers Sep 23, 2026
@kylebarron
kylebarron enabled auto-merge (squash) September 23, 2026 22:40
@kylebarron
kylebarron merged commit ce20b05 into main Sep 23, 2026
6 checks passed
@kylebarron
kylebarron deleted the fix/raster-ignore-lighting branch September 23, 2026 22:40
kylebarron added a commit that referenced this pull request Nov 10, 2026
…#874)

> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Follows up #670.

### Problem

#670 removed the lighting call from `MeshTextureLayer`'s fragment
shader, but the layer still inherits `SimpleMeshLayer`'s `phongMaterial`
shader module, which pulls in `lighting`. Nothing in the shaders reads
them, yet deck.gl still computes and uploads both modules' uniforms on
every draw. Every raster tile pays for lighting it never applies.

### Change

`MeshTextureLayer.getShaders()` drops `phongMaterial` from the inherited
modules. `lighting` was only there as its dependency, so it goes too.
The vertex and fragment shaders don't reference either module.

deck.gl's `LightingEffect` still sends `lighting` and `phongMaterial`
props to every layer. luma.gl's `ShaderInputs` would warn `Module
lighting not found` for them, but deck.gl's `Layer.getShaders()` sets
`disableWarnings: true` on every model. That's the same path that
already silences the `shadow` and `gouraudMaterial` props
`LightingEffect` sends to every `SimpleMeshLayer`. I checked this with
luma.gl's real `ShaderInputs`, the layer's shaders, and the props
`LightingEffect` and the picking pass send: nothing is logged.

### Measurement

This was measured in an app with about 300 COG tile meshes in view, in a
production build:

- **View:** 288 tile meshes at zoom 12.
- **Browser:** headless Chrome at 2× DPR.
- **Metric:** deck's draw time (`renderLayers`) per frame, averaged over
120 frames. The zoom was nudged every frame so the view uniforms change.
Two runs each.

It was measured by patching `MeshTextureLayer.prototype.getShaders` at
runtime in the built app to filter out the same two modules, then
rebuilding the tiles. It was not measured with this exact diff.

| | draw time per frame | per tile mesh |
|---|---|---|
| with `phongMaterial` + `lighting` | 4.5 ms | 15.6 µs |
| without them | **3.2 ms** | **11.1 µs** |

That's about 29% less draw time.

### Tests

- New test: the resolved shader modules of a `MeshTextureLayer` contain
neither `phongMaterial` nor `lighting`. It fails without the change.
- `pnpm -r --filter="!docs" typecheck`, `biome ci .` and the
`deck.gl-raster` tests pass locally.

No visible change: the shader already ignored lighting, so there are no
screenshots.

🤖 Written by [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raster imagery darkened by scene LightingEffect; no consumer control over mesh material/lighting

1 participant