Skip to content

Effects: measure in pixels of the texture drawn, no textureSize needed - #1769

Merged
obiot merged 1 commit into
masterfrom
fix/effect-texture-size
Oct 26, 2026
Merged

obiot merged 1 commit into
masterfrom
fix/effect-texture-size

Conversation

@obiot

@obiot obiot commented Oct 26, 2026

Copy link
Copy Markdown
Member

Summary

Glow, outline, blur, drop shadow, chromatic aberration, pixelate and bloom measure their widths, offsets and sizes in texels. Without a textureSize they assumed a 256×256 texture (the screen for an outline or a bloom), so on any other texture they came out thinner or thicker than their docs say ("in pixels" / "in texels"). Games worked around it by passing the texture size by hand.

They now take the size of the texture they actually draw:

  • a sprite: its whole texture (the atlas image, not the frame)
  • a camera's (or any full-screen) pass: the render target it reads
  • a mesh hosting the effect: the mesh's texture

No new API. It's internal to ShaderEffect and the batchers:

  • An explicit textureSize, setTextureSize() or setUniform("uTextureSize") still wins.
  • A clone keeps its original's behaviour.
  • A custom ShaderEffect that declares its own uTextureSize is never touched.
  • The size is only rewritten when it changes, so sprites from one texture keep sharing a draw.

What games see: widths now match the docs. A game that tuned its values around the old 256×256 guess will see them change; the changelog entry says so.

Example

The Shader Effects example:

  • Drops its hand-passed sizes. It renders identically without them: 0 differing pixels on WebGL and on WebGPU, on a frozen frame.
  • Adds Shine, Squish, Color Matrix and Bloom. Five full rows of four.
  • Gallery text: no longer claims "all 16 … (WebGL)".

Testing

  • New spec: tests/effect-texture-size.spec.js (27 tests). It covers:

    • all seven effects picking up each texture's size on WebGL; on WebGPU the same is checked through the mocked renderer, which records what the engine uploads
    • an outline as many pixels wide as asked, including two textures in one frame
    • sprites from one texture still sharing one draw
    • each kind of explicit size kept
    • custom effects left alone
    • clones
    • meshes on both renderers
    • a camera pixelate making blocks of screen pixels

    15 deliberately broken versions of the code were all caught.

  • Mock fix: webgpu_warm_keys had a fake mesh texture lacking the getTexture() every real mesh texture has.

  • Full suite and lint: the full suite passes and pnpm lint passes.

  • No regression in the demo: the Shader Effects demo was A/B'd against master's engine on a real GPU (WebGL and WebGPU), with 0 differing pixels.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx

Glow, outline, blur, drop shadow, chromatic aberration, pixelate and bloom
measure their widths, offsets and sizes in texels, and assumed a 256x256
texture (the screen for an outline or a bloom) unless given `textureSize`.
On any other texture they came out thinner or thicker than their docs say.

They now take the size of the texture they draw: the sprite's texture, the
render target of a camera's pass, a mesh's texture. The size is only
rewritten when it changes, so sprites from one texture still share a draw.
An explicit `textureSize`, `setTextureSize()` or `setUniform("uTextureSize")`
still wins, a clone keeps its original's behaviour, and a custom effect
declaring its own `uTextureSize` is never touched. No new API.

The Shader Effects example drops its hand-passed sizes (identical frames
on WebGL and WebGPU) and adds Shine, Squish, Color Matrix and Bloom.

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 02:41

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 3076f99 into master Oct 26, 2026
6 checks passed
@obiot
obiot deleted the fix/effect-texture-size branch October 26, 2026 03:10
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