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:- React
- Vanilla JS
Shader canvas automatically resizes when the container size changes using
ResizeObserver. No manual intervention needed.
Fit Modes
Thefit parameter controls how shader graphics scale within the container:
None
No automatic fitting - renders at natural scale:- Tiling patterns
- Precise pixel control
- Coordinated multi-shader layouts
Contain
Fits entire graphic inside container while maintaining aspect ratio:- Entire graphic visible
- May have empty space on sides
- Maintains aspect ratio
- Default for most object-based shaders
- Logos and graphics that must be fully visible
- Aspect-ratio-sensitive designs
- Card backgrounds
Cover
Fills entire container while maintaining aspect ratio:- Fills entire container
- May crop parts of graphic
- Maintains aspect ratio
- No empty space
- Hero backgrounds
- Full-bleed sections
- When cropping is acceptable
Visual Comparison
Sizing Parameters
Fine-tune shader positioning and scaling:Scale
Zoom the shader graphic:Rotation
Rotate the shader graphic:Origin
Set rotation and scaling pivot point:- 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:- 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
Choose the Right Fit Mode
Choose the Right Fit Mode
- Use
coverfor backgrounds that should fill completely - Use
containfor graphics that must be fully visible - Use
nonefor tiling patterns and precise layouts
Handle Responsive Sizing
Handle Responsive Sizing
- Use percentage-based container widths
- Consider
aspect-ratioCSS property - Adjust
scaleparameter for mobile vs desktop - Test on actual devices, not just browser resize
Performance Considerations
Performance Considerations
- Larger containers = more pixels = slower rendering
- Use
maxPixelCountto limit rendering resolution - Consider static shaders (
speed={0}) for large areas - See Performance Guide for details
Coordinate Multiple Shaders
Coordinate Multiple Shaders
- Use matching
worldWidthandworldHeight - Share
rotationandscalefor synchronized effects - Consider
offsetX/offsetYfor 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 container3
Check scale and offset
Ensure
scale isn’t too large or offset isn’t pushing content outShader looks cropped
- Try
fit="contain"instead ofcover - Reduce
scaleparameter - Adjust
offsetto 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
