{
 "id": "procedural-cross-hatching",
 "title": "Procedural cross-hatching shader",
 "aliases": [
  "hatching shader"
 ],
 "domain": "npr",
 "subdomain": "hatching",
 "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",
 "summary": "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.",
 "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": "Choose it for fast, texture-free pen-and-ink shading, especially as a post-process or on procedurally generated geometry. Prefer `tonal-art-maps` when strokes should be hand-drawn, follow the surface direction and be stable across mip levels. Prefer `halftone-screen` when the dot-based print look is wanted rather than lines.",
 "cost": {
  "class": "cheap",
  "notes": "One pass with a few trig and fract ops per layer; negligible."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/383259.383328",
   "type": "paper",
   "title": "Real-time hatching",
   "authors": [
    "Emil Praun",
    "Hugues Hoppe",
    "Matthew Webb",
    "Adam Finkelstein"
   ],
   "year": 2001,
   "venue": "Proceedings of the 28th annual conference on Computer graphics and interactive techniques",
   "url": "https://doi.org/10.1145/383259.383328",
   "ids": {
    "doi": "10.1145/383259.383328"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/383259.383328",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/383259.383328",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/383259.383328",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/383259.383328",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/383259.383328",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "praun2001hatching"
  },
  {
   "role": "tutorial",
   "key": "url:https://en.wikipedia.org/wiki/Hatching",
   "type": "tutorial",
   "title": "Hatching",
   "authors": [
    "Wikipedia"
   ],
   "year": null,
   "venue": "en.wikipedia.org",
   "url": "https://en.wikipedia.org/wiki/Hatching",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261114160639/https://en.wikipedia.org/wiki/Hatching",
     "timestamp": "20261114160639"
    },
    "page_title": "Hatching - Wikipedia",
    "host": "en.wikipedia.org",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://en.wikipedia.org/wiki/Hatching → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://en.wikipedia.org/wiki/Hatching → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://en.wikipedia.org/wiki/Hatching → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.9,
   "__bib": "wikipediahatching"
  }
 ],
 "presets": [
  {
   "id": "hatch-four-layer-sphere",
   "title": "Four-layer procedural hatching on a lit sphere",
   "runtime": "glsl-fragment",
   "params": {
    "freq": 70,
    "width": 0.16
   },
   "code": "// GLSL ES 3.0, Shadertoy-style: screen-space cross-hatching driven by a lit sphere\nconst vec3  PAPER = vec3(0.96, 0.93, 0.84);\nconst vec3  INK   = vec3(0.10, 0.12, 0.25);\nconst float FREQ  = 70.0;    // hatch lines per unit height\nconst float WIDTH = 0.16;    // line half-width (fraction of spacing)\n\nfloat hatch(vec2 p, float ang){\n  float v = (p.x*cos(ang) - p.y*sin(ang)) * FREQ;\n  float d = abs(fract(v) - 0.5);                 // 0.5 between lines, 0 on the line centre\n  float aa = fwidth(v);\n  return 1.0 - smoothstep(0.5 - WIDTH*2.0 - aa, 0.5 - WIDTH*2.0 + aa, d);\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord){\n  vec2 uv = (fragCoord - 0.5*iResolution.xy) / iResolution.y;\n  float tone = 0.92;\n  vec2 c = uv - vec2(0.0, 0.03);\n  float r = length(c);\n  if(r < 0.33){\n    vec3 n = vec3(c, sqrt(0.33*0.33 - r*r)) / 0.33;\n    vec3 l = normalize(vec3(-0.55 + 0.15*sin(iTime), 0.65, 0.55));\n    tone = clamp(dot(n, l)*0.9 + 0.1, 0.0, 1.0);\n  } else {\n    float shadow = smoothstep(0.38, 0.1, length((uv - vec2(0.18, -0.34))*vec2(0.6, 1.8)));\n    tone = 0.92 - 0.6*shadow;\n  }\n  float dark = 1.0 - tone;\n  float ink = 0.0;\n  ink = max(ink, step(0.12, dark) * hatch(uv, 0.785));\n  ink = max(ink, step(0.35, dark) * hatch(uv, -0.785));\n  ink = max(ink, step(0.55, dark) * hatch(uv, 0.0));\n  ink = max(ink, step(0.75, dark) * hatch(uv, 1.571));\n  fragColor = vec4(mix(PAPER, INK, ink), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "procedural-cross-hatching",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6909,
      "std": 0.3143,
      "unique_colors": 72
     },
     "image": "/specimens/hatch-four-layer-sphere.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "tonal-art-maps",
  "halftone-screen",
  "obra-dinn-1bit-dithered-3d"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "screen-space-edge-outline",
   "why": "Outline pass adds contour lines over the hatched tone."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/npr/procedural-cross-hatching.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Praun et al., 2001",
 "url": "https://texelatlas.vercel.app/t/procedural-cross-hatching/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 2.55,
  "tier": "light",
  "p50_ms": 0.0839,
  "p95_ms": 0.0884,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "hatch-four-layer-sphere",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 1.79,
   "tier": "feather",
   "p50_ms": 0.0285,
   "p95_ms": 0.0285,
   "speedup_x": 2.94,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1.52,
   "tier": "feather",
   "p50_ms": 0.0439,
   "p95_ms": 0.0443,
   "speedup_x": 1.91,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}