Coordinate Maps
A UV map is a small function that takes a UV and returns another UV. Compose it with a sampler — procedural or texture-backed — and you can distort, tile, mirror, warp, or wrap the underlying image without touching its pixels.
Pull one in by slug and apply it inline before sampling:
let main = r#"fn checker(uv: vec2<f32>) -> vec3<f32> { let c = step(vec2<f32>(0.5), fract(uv * 8.0)); return mix(vec3<f32>(0.18), vec3<f32>(0.95), c.x * c.y + (1.0 - c.x) * (1.0 - c.y));}
@fragment fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { let warped = barrel(in.uv, 0.4); return vec4<f32>(checker(warped), 1.0);}"#;let shader = Shader::new(&["map/barrel", main])?;barrel
Section titled “barrel”Radial lens distortion around UV center (0.5, 0.5).
fn barrel(uv: vec2<f32>, k: f32) -> vec2<f32>
cartesian
Section titled “cartesian”Inverse of polar: (angle/TAU, radius) → UV around center.
fn cartesian(pr: vec2<f32>, center: vec2<f32>) -> vec2<f32>
fisheye
Section titled “fisheye”Spherical fisheye mapping.
fn fisheye(uv: vec2<f32>, strength: f32) -> vec2<f32>
kaleidoscope
Section titled “kaleidoscope”n-fold rotational symmetry fold around the UV center.
fn kaleidoscope(uv: vec2<f32>, n: u32) -> vec2<f32>
mirror_x
Section titled “mirror_x”Fold UV across x = 0.5. Useful for horizontal symmetry.
fn mirror_x(uv: vec2<f32>) -> vec2<f32>
mirror_y
Section titled “mirror_y”Fold UV across y = 0.5. Useful for vertical symmetry.
fn mirror_y(uv: vec2<f32>) -> vec2<f32>
pincushion
Section titled “pincushion”Inverse of barrel distortion (k always positive for pincushion).
fn pincushion(uv: vec2<f32>, k: f32) -> vec2<f32>
(uv - center) → (angle/TAU, radius). Handy for radial patterns.
fn polar(uv: vec2<f32>, center: vec2<f32>) -> vec2<f32>
ripple
Section titled “ripple”Radial ripple emanating from center. amp scales UV displacement.
fn ripple(uv: vec2<f32>, center: vec2<f32>, freq: f32, phase: f32, amp: f32) -> vec2<f32>
rotate2
Section titled “rotate2”Rotate a 2D point by a radians around the origin.
fn rotate2(p: vec2<f32>, a: f32) -> vec2<f32>
scale2
Section titled “scale2”Non-uniform 2D scale about a pivot.
fn scale2(p: vec2<f32>, pivot: vec2<f32>, s: vec2<f32>) -> vec2<f32>
Tile UVs by cells per unit side. Returns UVs in [0, 1) per cell.
fn tile(uv: vec2<f32>, cells: vec2<f32>) -> vec2<f32>
translate2
Section titled “translate2”Translate a 2D point.
fn translate2(p: vec2<f32>, t: vec2<f32>) -> vec2<f32>
UV twirl around center. Falls off smoothly with distance.
fn twirl(uv: vec2<f32>, center: vec2<f32>, strength: f32) -> vec2<f32>
Horizontal sine displacement of UVs. amp is in UV units, freq in
cycles per unit.
fn wave(uv: vec2<f32>, freq: f32, phase: f32, amp: f32) -> vec2<f32>