Skip to main content

Overview

Paper Shaders provide powerful sizing controls to manage how shader graphics scale and fit within their containers. This guide covers the sizing system, fit modes, and responsive strategies.

Container Sizing

Shaders automatically fill their container element:
Shader canvas automatically resizes when the container size changes using ResizeObserver. No manual intervention needed.

Fit Modes

The fit parameter controls how shader graphics scale within the container:

None

No automatic fitting - renders at natural scale:
Use cases:
  • Tiling patterns
  • Precise pixel control
  • Coordinated multi-shader layouts

Contain

Fits entire graphic inside container while maintaining aspect ratio:
Behavior:
  • Entire graphic visible
  • May have empty space on sides
  • Maintains aspect ratio
  • Default for most object-based shaders
Use cases:
  • Logos and graphics that must be fully visible
  • Aspect-ratio-sensitive designs
  • Card backgrounds

Cover

Fills entire container while maintaining aspect ratio:
Behavior:
  • Fills entire container
  • May crop parts of graphic
  • Maintains aspect ratio
  • No empty space
Use cases:
  • Hero backgrounds
  • Full-bleed sections
  • When cropping is acceptable

Visual Comparison

Sizing Parameters

Fine-tune shader positioning and scaling:

Scale

Zoom the shader graphic:
scale applies after fit calculations, so fit="contain" + scale={2} will contain the graphic then zoom it 2x (likely cropping).

Rotation

Rotate the shader graphic:

Origin

Set rotation and scaling pivot point:
Common origin points:
  • Top-left: originX={0}, originY={0}
  • Top-center: originX={0.5}, originY={0}
  • Center: originX={0.5}, originY={0.5} (default)
  • Bottom-right: originX={1}, originY={1}

Offset

Shift the graphic position:

World Dimensions

Define virtual canvas size for precise control:
Use cases:
  • Matching shader scale across different containers
  • Consistent sizing in responsive layouts
  • Precise alignment with other elements

Complete Sizing Example

Combine all sizing parameters:

Sizing in Vanilla JS

Set sizing parameters as uniforms:

Responsive Strategies

Fluid Container

Let shader scale naturally with container:

Aspect Ratio Container

Maintain aspect ratio on resize:

Breakpoint-Based Sizing

Adjust sizing parameters by screen size:

Container Queries

Use container queries for component-level responsive sizing:

Pattern vs Object Sizing

Different shader types have different default sizing:

Pattern Shaders

Default: fit="none" for tiling:

Object Shaders

Default: fit="contain" for full visibility:

Advanced: Coordinated Sizing

Sync sizing across multiple shaders:

Sizing Best Practices

  • Use cover for backgrounds that should fill completely
  • Use contain for graphics that must be fully visible
  • Use none for tiling patterns and precise layouts
  • Use percentage-based container widths
  • Consider aspect-ratio CSS property
  • Adjust scale parameter for mobile vs desktop
  • Test on actual devices, not just browser resize
  • Larger containers = more pixels = slower rendering
  • Use maxPixelCount to limit rendering resolution
  • Consider static shaders (speed={0}) for large areas
  • See Performance Guide for details
  • Use matching worldWidth and worldHeight
  • Share rotation and scale for synchronized effects
  • Consider offsetX/offsetY for layered compositions

Common Sizing Patterns

Full-Screen Background

Hero Section

Card Background

Tiling Pattern

Troubleshooting

Shader not visible

1

Check container has dimensions

Ensure container has explicit width and height (CSS or inline)
2

Verify fit mode

Try fit="cover" to ensure shader fills container
3

Check scale and offset

Ensure scale isn’t too large or offset isn’t pushing content out

Shader looks cropped

  • Try fit="contain" instead of cover
  • Reduce scale parameter
  • Adjust offset to recenter

Shader doesn’t resize

  • Verify container size actually changes (check DevTools)
  • ResizeObserver works automatically - no manual action needed
  • Check for fixed dimensions preventing resize

Next Steps

Performance

Optimize shader resolution and rendering

Customization

Customize shader visual parameters

React Usage

React-specific sizing patterns

Vanilla Usage

Vanilla JS sizing control