Skip to content

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])?;

Radial lens distortion around UV center (0.5, 0.5).

fn barrel(uv: vec2<f32>, k: f32) -> vec2<f32>

map/barrel preview

Inverse of polar: (angle/TAU, radius) → UV around center.

fn cartesian(pr: vec2<f32>, center: vec2<f32>) -> vec2<f32>

map/cartesian preview

Spherical fisheye mapping.

fn fisheye(uv: vec2<f32>, strength: f32) -> vec2<f32>

map/fisheye preview

n-fold rotational symmetry fold around the UV center.

fn kaleidoscope(uv: vec2<f32>, n: u32) -> vec2<f32>

map/kaleidoscope preview

Fold UV across x = 0.5. Useful for horizontal symmetry.

fn mirror_x(uv: vec2<f32>) -> vec2<f32>

map/mirror_x preview

Fold UV across y = 0.5. Useful for vertical symmetry.

fn mirror_y(uv: vec2<f32>) -> vec2<f32>

map/mirror_y preview

Inverse of barrel distortion (k always positive for pincushion).

fn pincushion(uv: vec2<f32>, k: f32) -> vec2<f32>

map/pincushion preview

(uv - center)(angle/TAU, radius). Handy for radial patterns.

fn polar(uv: vec2<f32>, center: vec2<f32>) -> vec2<f32>

map/polar preview

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>

map/ripple preview

Rotate a 2D point by a radians around the origin.

fn rotate2(p: vec2<f32>, a: f32) -> vec2<f32>

map/rotate2 preview

Non-uniform 2D scale about a pivot.

fn scale2(p: vec2<f32>, pivot: vec2<f32>, s: vec2<f32>) -> vec2<f32>

map/scale2 preview

Tile UVs by cells per unit side. Returns UVs in [0, 1) per cell.

fn tile(uv: vec2<f32>, cells: vec2<f32>) -> vec2<f32>

map/tile preview

Translate a 2D point.

fn translate2(p: vec2<f32>, t: vec2<f32>) -> vec2<f32>

map/translate2 preview

UV twirl around center. Falls off smoothly with distance.

fn twirl(uv: vec2<f32>, center: vec2<f32>, strength: f32) -> vec2<f32>

map/twirl preview

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>

map/wave preview