Alpha Carving on GPU

A small demo for computing the alpha-carved space of 2D segments in realtime on the GPU.

Alpha carving removes all points that can be swept out by a disk of radius alpha. A point is carved if some such disk covers it and the disk center can be moved in from the boundary without the disk colliding with the segment mesh.

The 3D analogue is like carving with an ice cream scoop: a radius-alpha ball can remove whatever volume it can reach from outside without intersecting the input. For a production 3D version, see CGAL’s 3D Alpha Wrapping, which shrink-wraps triangle soups or meshes into watertight surface meshes using alpha and offset parameters.

Animated preview of alpha carving on scattered line segments
Alpha decreases from 0.3 to 0 on the scattered segment field. Blue is the alpha-carved reachable region; red marks pockets that the disk cannot reach.

Compute Shader Structure

For each alpha value, the carving pipeline runs the following 5 compute passes:

  1. Compute clearance: how far each grid cell is from the nearest segment.
  2. Threshold by alpha: valid center = clearance >= alpha.
  3. Union-find: atomically unions neighboring valid centers; boundary-connected sets are marked reachable.
  4. Jump flood: starts with reachable centers as seeds and propagates the nearest reachable seed across the texture.
  5. Compose: a pixel is blue if its nearest reachable center is within alpha; otherwise it is red.

Interactive Demo

Click pairs of points on the canvas to add segments, then use the alpha slider to change the carving radius.

Drawing
Resolution
Compute update--
Segments--