Skip to content

Conversation

artokun
Copy link

@artokun artokun commented Sep 20, 2025

Summary

Adds pixelPerfect prop to both ScrollControls and Html components to prevent subpixel rendering blur caused by CSS transform3d values with decimal pixels.

Problem

HTML elements rendered with CSS transforms in 3D scenes often appear blurry due to subpixel positioning, especially during animations. This affects text readability and overall visual quality, as discussed in issues #859 and #2380.

Solution

Implements a pixelPerfect prop that rounds transform values to whole pixels using devicePixelRatio-based calculation for accurate rendering across all display types.

Key Features

  • ScrollControls: pixelPerfect prop for <Scroll html> components
  • Html: pixelPerfect prop for transform mode rendering
  • DevicePixelRatio Support: Proper high-DPI display handling via window.devicePixelRatio
  • Performance Optimized: Velocity-based conditional application (only when motion < 0.001)
  • Backward Compatible: Default behavior unchanged, opt-in via prop

Usage

// ScrollControls
<ScrollControls pages={3}>
  <Scroll html pixelPerfect>
    <div>Crisp text during scroll animations</div>
  </Scroll>
</ScrollControls>

// Html component
<Html transform pixelPerfect>
  <div>Crisp text during 3D transforms</div>
</Html>

Implementation Details

  • Helper Function: roundToPixelRatio() uses window.devicePixelRatio for accurate rounding
  • Velocity Detection: Only applies rounding when velocity < 0.001 to maintain smooth animation
  • Cross-Component: Consistent implementation across ScrollControls and Html components

Documentation & Examples

  • ✅ Updated component documentation with usage examples
  • ✅ Comprehensive Storybook stories with before/after comparisons
  • ✅ Interactive demos showing the difference in text crispness

Credit

Special thanks to @chris-xinhai-li for suggesting the devicePixelRatio approach in issue #2380.

Fixes

Testing

The feature has been thoroughly tested with:

  • Various device pixel ratios (1x, 1.5x, 2x, etc.)
  • Different animation scenarios (scroll, transform, etc.)
  • Performance impact validation
  • Cross-browser compatibility

Copy link

vercel bot commented Sep 20, 2025

@artokun is attempting to deploy a commit to the Poimandres Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codesandbox-ci bot commented Sep 20, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Adds pixelPerfect prop to prevent subpixel rendering blur caused by CSS
transform3d values with decimal pixels. Uses devicePixelRatio-based
rounding for accurate rendering across all display types.

Features:
- ScrollControls: pixelPerfect prop for Scroll html components
- Html: pixelPerfect prop for transform mode
- Velocity-based optimization (only applies when motion < 0.001)
- devicePixelRatio support for high-DPI displays
- Comprehensive Storybook examples and documentation
- Performance optimized with conditional application

Credit: chris-xinhai-li for devicePixelRatio suggestion (pmndrs#2380)

Fixes: pmndrs#859, pmndrs#2380

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@artokun artokun force-pushed the feat/scroll-pixel-perfect branch from a7135bc to 9f0fc53 Compare September 20, 2025 01:56
@artokun artokun changed the title feat: add pixelPerfect prop to ScrollControls to prevent subpixel blur feat(ScrollControls): add pixelPerfect prop to ScrollControls to prevent subpixel blur Sep 29, 2025
@artokun artokun changed the title feat(ScrollControls): add pixelPerfect prop to ScrollControls to prevent subpixel blur feat(ScrollControls&Html): add pixelPerfect prop to ScrollControls to prevent subpixel blur Sep 29, 2025
@artokun artokun changed the title feat(ScrollControls&Html): add pixelPerfect prop to ScrollControls to prevent subpixel blur feat(ScrollControls&Html): add pixelPerfect prop to prevent subpixel blur Sep 29, 2025
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.

Html: Blurry text caused by subpixel translate3d() positioning Html component render blurry when using transform attribute on firefox

1 participant