Sizing modes
Two defaults are exported from@paper-design/shaders. Each built-in shader uses whichever makes sense for its type.
defaultObjectSizing
Used by object-like shaders — gradients, effects, and anything that has a natural center and should scale to fit its container.
defaultPatternSizing
Used by repeating pattern shaders — anything that tiles or fills the canvas without needing to maintain a specific aspect ratio.
fit value.
ShaderFit options
The fit prop controls how the shader’s world coordinate space is mapped onto the canvas.
| Value | Behaviour |
|---|---|
'none' | No fitting applied. The shader fills the canvas at 1:1 scale. Pixels outside the world dimensions tile or clip depending on the shader. |
'contain' | Scale to fit entirely inside the canvas, maintaining the world aspect ratio. Equivalent to CSS object-fit: contain. |
'cover' | Scale to fill the canvas entirely, cropping as needed. Equivalent to CSS object-fit: cover. |
ShaderSizingParams reference
All sizing params are optional. They are passed as props on React components or as uniforms when using the vanilla ShaderMount.
How to fit the shader’s world space into the canvas. See the table above.
Uniform zoom level applied on top of the fit transform.
2 zooms in by 2×, 0.5 zooms out.Rotation of the graphic in degrees. Applied around the origin point.
The horizontal anchor point for rotation and scaling, as a fraction of the canvas width.
0 is the left edge, 1 is the right edge, 0.5 is centre.The vertical anchor point for rotation and scaling, as a fraction of the canvas height.
0 is the top edge, 1 is the bottom edge, 0.5 is centre.Horizontal pan of the graphic, in normalised units (−1 to 1 spans the canvas width).
Vertical pan of the graphic, in normalised units (−1 to 1 spans the canvas height).
The virtual width of the shader’s coordinate space in pixels before fitting is applied. Used with tiling pattern shaders to keep a consistent tile size regardless of canvas dimensions.
0 means the world width matches the canvas width.The virtual height of the shader’s coordinate space in pixels before fitting is applied.
0 means the world height matches the canvas height.worldWidth and worldHeight for tiling patterns
Pattern shaders (those using defaultPatternSizing) tile based on their world coordinate space. By fixing worldWidth and worldHeight you pin the physical size of each tile regardless of how large or small the canvas is.
worldWidth and worldHeight are 0 (the default), the pattern adapts to fill the canvas exactly once.
Code examples
- React
- Vanilla JS