Skip to content

webgl_postprocessing_pixel: Snap Objects to Pixel Grid - #33908

Merged
Mugen87 merged 17 commits into
mrdoob:devfrom
zalo:feat-pixel-snap-objects
Jun 30, 2026
Merged

Mugen87 merged 17 commits into
mrdoob:devfrom
zalo:feat-pixel-snap-objects

Conversation

@zalo

@zalo zalo commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

The pixelated rendering demo already snaps the camera frustum translation to the pixel grid to achieve pixel stability under camera panning.

This PR adds a checkbox to snap scene object translations and rotations to the pixel grid so they maintain pixel stability under translation (and look more like sprites). Also adds snapping to the camera rotation and scale as well.

Example: https://rawcdn.githack.com/zalo/three.js/90e77c4be36f33fa35de39923736a2b89b34b5fe/examples/webgl_postprocessing_pixel.html

zalo and others added 3 commits June 28, 2026 15:11
…ation demo

Adds a pixelAlignedObjects checkbox to webgl_postprocessing_pixel that snaps
moving objects to the screen-space pixel grid, complementing the existing
pixel-aligned camera panning. The crystal's true (unsnapped) position is
restored after rendering so its bulk motion is unaffected. Defaults the demo
to pixelSize 4 with both alignment options enabled.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zalo zalo changed the title Feat pixel snap objects webgl_postprocessing_pixel: Snap Objects to Pixel Grid Jun 29, 2026
@Mugen87

Mugen87 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

webgl_postprocessing_pixel.jpg.zip

Can you please replace the E2E screenshot with this version? It should solve the CI issues.

@Mugen87 Mugen87 added this to the r186 milestone Jun 29, 2026
Adds a rotationSnap slider (degrees, 0 = off) that snaps moving objects'
rotations to the nearest camera-relative euler increment for a stepped,
retro look. Like the position snapping, the object's true rotation is
restored after rendering so its bulk motion is unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Mugen87

Mugen87 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

The sphere transformation looks somewhat broken when rotationSnap is active:

Bildschirmaufnahme.2026-06-29.um.19.47.44.mov

zalo and others added 3 commits June 29, 2026 12:38
Restoring the unsnapped rotation via the quaternion let three.js re-derive a
gimbal-equivalent euler (e.g. a 180-deg Y rotation became x=PI, z=PI), which
the next frame's rotation.y assignment left baked in, permanently corrupting
the spin. Snapshot and restore the euler rotation directly instead, since that
is what drives the motion.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Regenerated to reflect the new default pixelSize, object pixel snapping and
camera-relative rotation snapping. Verified with `npm run test-e2e` (0.0% diff).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zalo

zalo commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Apologies! The rotation snapping was a last minute bit of inspiration before I took a nap; it’s all fixed now 😄

I think with these two new elements, the whole effect is much more convincing, and should stay perfectly convincing so long as the camera is not rotating…

I could also snap the camera rotation and scale too, I suppose… that would make the effect much more solid on mobile too (where the two fingered touch is used…)

zalo and others added 4 commits June 29, 2026 13:40
Adds cameraRotationSnap (deg) and cameraZoomSnap sliders that snap the camera's
orientation and zoom to fixed increments, keeping the pixelated effect solid
while orbiting or pinch-zooming. The camera snap runs before the frustum
(translation) snap so the latter derives its pixel grid and screen-space basis
from the already-snapped orientation and zoom. The camera's true transform is
restored after rendering so OrbitControls interaction is unaffected. Both
sliders default to 0 (off). Regenerated the e2e screenshot (0.0% diff).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
When snapping the camera's orientation while orbiting, re-place the camera
along the snapped view axis at the same distance from the orbit target, so the
orbit translation snaps together with the rotation and the target stays
centered instead of sliding smoothly off-screen. The camera position is
snapshotted and restored after rendering alongside its rotation and zoom so
OrbitControls interaction is unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Snapping the camera's euler angles independently could combine into a rolled
orientation. Snap the orbit's azimuth/polar angle around the target in
spherical coordinates instead, then re-aim with lookAt and world up, which is
roll-free by construction (and keeps the target centered). Default
cameraRotationSnap to 10 deg and cameraZoomSnap to 0.1; the default view sits
on these grids so the screenshot is unchanged (verified e2e, 0.0% diff).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Regenerated the e2e screenshot for the slightly steeper default framing (the
60-degree polar angle snaps to 63). Verified e2e (0.0% diff).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zalo

zalo commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Snapping the camera rotation and scale got rid of the last “immersion breaker” (even on mobile). Now it’s “authentic” by default 😄

https://rawcdn.githack.com/zalo/three.js/90e77c4be36f33fa35de39923736a2b89b34b5fe/examples/webgl_postprocessing_pixel.html

zalo and others added 6 commits June 29, 2026 14:01
Move the five snapping controls into a 'Snapping' folder and add a top-level
'snapping (all)' checkbox that enables/disables every snapping effect at once
(and greys out the folder when off).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Snap the pulsing emissiveIntensity to 32 discrete levels to match the
pixelated, retro aesthetic. Regenerated the e2e screenshot (0.0% diff).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Coarser stepping reads better with the pixelated look than 32 levels.
Regenerated the e2e screenshot (0.0% diff).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Also make the comment value-agnostic so it stays accurate. Regenerated the
e2e screenshot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Mugen87
Mugen87 merged commit a441be8 into mrdoob:dev Jun 30, 2026
8 checks passed
@mrdoob

mrdoob commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Have you encountered this issue when panning?

Screen.Recording.2026-06-30.at.23.51.55.mov

@Mugen87

Mugen87 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Strange, that did appear on my setup (Chrome + macMini and 5K screen).

@zalo

zalo commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

It’s probably one of those things that only started showing up when snapping all the camera parameters and scale to be perfectly axis aligned…
I wonder if it could be fixed by adding subpixel offsets to either the translation or scale…

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.

3 participants