---
id: "procedural-cross-hatching"
title: "Procedural cross-hatching shader"
aliases: [hatching shader]
domain: "npr"
stage: "material"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot]
year_introduced: 2001
inputs: [normals, depth]
outputs: [ldr-image]
style: "stylized"
dynamic: "dynamic"
cost: "cheap"
authority: "Praun et al., 2001"
url: "https://texelatlas.vercel.app/t/procedural-cross-hatching/"
sources_verified_at: "2026-11-29"
---
# Procedural cross-hatching shader (Praun et al., 2001)

> Generates hatch lines in the fragment shader from line functions at several angles, enabling more layers as lighting gets darker, without any pre-authored textures.

## Reach for it when

- want pen-and-ink shading without authored textures
- hatch lines should get denser in darker areas
- need engraving look on generated geometry
- texture-free sketch style as a post process

## How it works

The shader computes a tone value, from N·L or a luminance buffer, and defines a set of line masks: periodic functions of a rotated coordinate (such as `abs(fract(x)-0.5)`) thresholded to a line width. Darker tones enable more layers: first one diagonal, then the crossing diagonal, then horizontal, then vertical, each gated by a threshold on tone. Coordinates come from screen space (simple, gives the 'shower door' effect), object space or triplanar projection (sticks to surfaces), or a UV-based direction field. Smoothstep with `fwidth` anti-aliases lines. A paper texture and slight wobble from noise sell the hand-drawn effect, and wobble that is stable across frames avoids shimmering.

## When to use it

Choose it for fast, texture-free pen-and-ink shading, especially as a post-process or on procedurally generated geometry. Prefer [Real-time hatching with tonal art maps](https://texelatlas.vercel.app/t/tonal-art-maps.md) when strokes should be hand-drawn, follow the surface direction and be stable across mip levels. Prefer [Halftone screens](https://texelatlas.vercel.app/t/halftone-screen.md) when the dot-based print look is wanted rather than lines.

## Cost

cheap — One pass with a few trig and fract ops per layer; negligible.
Measured GPU Weight: 2.55× baseline (light) — 0.0839 ms median / 0.0884 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 1.79× baseline (feather) — 0.0285 ms median (2.94× faster on L4).
Ampere A100 scaling: 1.52× baseline (feather) — 0.0439 ms median (1.91× faster on A100).

## Failure modes

- Screen-space coordinates make lines slide over moving objects (shower-door effect)
- Lines of fixed pixel width alias when sampled coarsely or moire when layers align
- Hard thresholds between layers cause visible popping across smooth lighting
- No sense of surface direction unless a direction field is supplied

## Dataflow

- Inputs: normals, depth
- Outputs: ldr-image
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot

## Presets

### Four-layer procedural hatching on a lit sphere (glsl-fragment; rendered 2026-11-29)

```json
{
  "freq": 70,
  "width": 0.16
}
```

```glsl
// GLSL ES 3.0, Shadertoy-style: screen-space cross-hatching driven by a lit sphere
const vec3  PAPER = vec3(0.96, 0.93, 0.84);
const vec3  INK   = vec3(0.10, 0.12, 0.25);
const float FREQ  = 70.0;    // hatch lines per unit height
const float WIDTH = 0.16;    // line half-width (fraction of spacing)

float hatch(vec2 p, float ang){
  float v = (p.x*cos(ang) - p.y*sin(ang)) * FREQ;
  float d = abs(fract(v) - 0.5);                 // 0.5 between lines, 0 on the line centre
  float aa = fwidth(v);
  return 1.0 - smoothstep(0.5 - WIDTH*2.0 - aa, 0.5 - WIDTH*2.0 + aa, d);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord){
  vec2 uv = (fragCoord - 0.5*iResolution.xy) / iResolution.y;
  float tone = 0.92;
  vec2 c = uv - vec2(0.0, 0.03);
  float r = length(c);
  if(r < 0.33){
    vec3 n = vec3(c, sqrt(0.33*0.33 - r*r)) / 0.33;
    vec3 l = normalize(vec3(-0.55 + 0.15*sin(iTime), 0.65, 0.55));
    tone = clamp(dot(n, l)*0.9 + 0.1, 0.0, 1.0);
  } else {
    float shadow = smoothstep(0.38, 0.1, length((uv - vec2(0.18, -0.34))*vec2(0.6, 1.8)));
    tone = 0.92 - 0.6*shadow;
  }
  float dark = 1.0 - tone;
  float ink = 0.0;
  ink = max(ink, step(0.12, dark) * hatch(uv, 0.785));
  ink = max(ink, step(0.35, dark) * hatch(uv, -0.785));
  ink = max(ink, step(0.55, dark) * hatch(uv, 0.0));
  ink = max(ink, step(0.75, dark) * hatch(uv, 1.571));
  fragColor = vec4(mix(PAPER, INK, ink), 1.0);
}

```

Attribution: written for this index

## Combines with

- [Depth/normal Sobel edge outlines](https://texelatlas.vercel.app/t/screen-space-edge-outline.md): Outline pass adds contour lines over the hatched tone.

## Sources

1. [primary] Emil Praun, Hugues Hoppe, Matthew Webb, Adam Finkelstein (2001) Real-time hatching. Proceedings of the 28th annual conference on Computer graphics and interactive techniques. https://doi.org/10.1145/383259.383328 (verified via crossref on 2026-11-29)
2. [tutorial] Wikipedia Hatching. en.wikipedia.org. https://en.wikipedia.org/wiki/Hatching (verified via http on 2026-11-29)

## Cite this entry

Texel. "Procedural cross-hatching shader." https://texelatlas.vercel.app/t/procedural-cross-hatching/ (accessed 2026-12-01).
