Skip to content

Lighting: warn on Canvas only when a normal-mapped sprite goes unlit - #1771

Merged
obiot merged 1 commit into
masterfrom
fix/canvas-light-warning
Oct 26, 2026
Merged

obiot merged 1 commit into
masterfrom
fix/canvas-light-warning

Conversation

@obiot

@obiot obiot commented Oct 26, 2026

Copy link
Copy Markdown
Member

Summary

On the Canvas renderer, "Light2d normal-map lighting requires a GPU backend…" fired as soon as any Light2d existed (since 20.3.0). That was a false alarm for most games.

A light only reaches a sprite with a normal map: WebGL and WebGPU switch to the lit pipeline only when there are active lights and the sprite being drawn has a normalMap. A sprite without one is drawn unlit on every renderer. So a lit game without normal maps loses nothing on Canvas, yet it was warned.

The fix

  • The base setLightUniforms (which only Canvas uses) now just counts the lights it's given, as activeLightCount, like the GPU renderers do.
  • CanvasRenderer.drawImage warns once when it draws a sprite with a normal map while lights are active.
  • The message is unchanged.

Also: setLightUniforms' doc comment had been orphaned, sitting above setFog's doc since setFog was inserted. It's back on its method, and updated (it still said "WebGPU once it lands").

Testing

  • Unit tests (tests/lights.spec.js), which replace the old pair that pinned the false alarm:
    • lights alone stay quiet;
    • a normal-mapped sprite under lights warns exactly once;
    • a normal-mapped sprite with no light stays quiet;
    • lights are counted from an array or any iterable.
  • Whole-frame tests: a lit world without normal maps stays quiet, with a check that the sprite was really drawn; a normal-mapped sprite under a Light2d warns.
  • Mutation testing: 6 deliberately broken versions were caught. A seventh survived because the Set.size shortcut it removed was redundant, so the shortcut was dropped.
  • In the browser on Canvas: the Isometric Dungeon and Lights examples (no normal maps) are now quiet; Normal Map and Sprite Illuminator still warn once.
  • Full suite and lint: the full suite passes, apart from one real-time timer test that flaked under load; it passes 3 out of 3 on its own and is unrelated. pnpm lint passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx

The Canvas renderer warned that normal-map lighting needs a GPU backend as
soon as any Light2d existed. A light only reaches a sprite with a normal
map, on WebGL and WebGPU alike, so a lit game without normal maps loses
nothing on Canvas and was warned for nothing. Canvas now counts the lights
it is given and warns once, when it draws a sprite with a normal map under
them.

Also puts setLightUniforms' doc comment back on it: inserting setFog had
left it orphaned above setFog's own doc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx
Copilot AI balanced review requested due to automatic review settings October 26, 2026 03:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@obiot
obiot merged commit f480594 into master Oct 26, 2026
6 checks passed
@obiot
obiot deleted the fix/canvas-light-warning branch October 26, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants