Skip to content

fix(EffectComposer): resize the composer when the pixel ratio changes - #381

Open
tonyblu331 wants to merge 1 commit into
pmndrs:masterfrom
tonyblu331:fix/280-composer-pixel-ratio
Open

tonyblu331 wants to merge 1 commit into
pmndrs:masterfrom
tonyblu331:fix/280-composer-pixel-ratio

Conversation

@tonyblu331

Copy link
Copy Markdown

Fixes #280.

<EffectComposer> compares gl.getSize() every frame to decide when to call composer.setSize(). That's the CSS size, which doesn't change when only the pixel ratio does: setDpr, <AdaptiveDpr>, a dpr prop change, or moving to a display with another ratio. The composer's buffers and passes kept the old drawing-buffer size.

postprocessing's setSize() sizes the buffers and every pass from renderer.getDrawingBufferSize(), so this adds gl.getPixelRatio() to the same check. setSize() still only runs on frames where something changed. There's no new listener and no API change.

Chromium, 480×320 canvas with N8AO, setDpr(2) → setDpr(1):

canvas composer + N8AO pass composer GPU time (timer query, median)
before 480×320 960×640 3.03 ms
after 480×320 480×320 0.83 ms

Tests: a sizing block in EffectComposer.test.tsx advances frames by hand. Two tests are red without the fix (pixel ratio up, pixel ratio down), plus a guard that nothing resizes when nothing changed. pnpm test (183), eslint:ci, typecheck and build pass.

🤖 Generated with Claude Code

The per-frame size check compared gl.getSize(), the CSS size, which doesn't
change when only the pixel ratio does (setDpr, AdaptiveDpr, a dpr prop
change, another display). composer.setSize() never ran, so the buffers and
every pass kept the old drawing-buffer size.

postprocessing sizes them from renderer.getDrawingBufferSize(), so include
gl.getPixelRatio() in the check. setSize() still only runs on frames where
something changed.

Fixes pmndrs#280

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

[Bug] - N8AO works incorrectly with adaptiveDpr

1 participant