{
 "id": "hardware-hatching-tone-control",
 "title": "Fine tone control in hardware hatching",
 "aliases": [],
 "domain": "npr",
 "subdomain": "hatching",
 "stage": "material",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu"
 ],
 "year_introduced": 2002,
 "inputs": [
  "mesh",
  "uv-atlas",
  "normals",
  "texture"
 ],
 "outputs": [
  "ldr-image"
 ],
 "style": "stylized",
 "dynamic": "dynamic",
 "summary": "Extends tonal art map hatching by packing several tone levels into multitexture channels and combining them per fragment so tone can be reproduced in many more steps than the number of textures.",
 "how_it_works": "Classic tonal art maps blend only two textures at a time, which limits tonal precision and needs many levels for smooth gradients. The multitexture approach stores several hatch levels in the channels of a few textures and computes per-fragment blend weights that sum to the target tone. The shader chooses weights so that the integrated darkness of the combined strokes matches the desired lighting value, with sharper transitions between layers than a plain cross-fade. This yields finer tone control and reduced blurring of strokes between neighbouring tone levels while still using standard texturing hardware.",
 "when_to_use": "Choose it when plain `tonal-art-maps` shows visible tone steps or greyish blending and you want more controlled hatching on the GPU. Prefer `procedural-cross-hatching` for screen-space shader hatching without precomputed textures.",
 "cost": {
  "class": "cheap",
  "notes": "Cheap: a few texture fetches and a per-fragment weight computation."
 },
 "failure_modes": [
  "Needs the same careful UV and direction parameterisation as tonal art maps",
  "Channel packing limits you to a fixed number of stroke layers",
  "Weights tuned for one texture set do not transfer to another without recalibration",
  "Mip transitions still change stroke thickness at distance"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/508530.508540",
   "type": "paper",
   "title": "Fine tone control in hardware hatching",
   "authors": [
    "Matthew Webb",
    "Emil Praun",
    "Adam Finkelstein",
    "Hugues Hoppe"
   ],
   "year": 2002,
   "venue": "Proceedings of the 2nd international symposium on Non-photorealistic animation and rendering",
   "url": "https://doi.org/10.1145/508530.508540",
   "ids": {
    "doi": "10.1145/508530.508540"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/508530.508540",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/508530.508540",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/508530.508540",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/508530.508540",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/508530.508540",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "webb2002fine"
  }
 ],
 "presets": [
  {
   "id": "hardware-hatching-tone-control-live",
   "title": "Hardware hatching tone control — continuous multi-stroke copperplate TAM engraving",
   "runtime": "glsl-fragment",
   "params": {
    "P_HATCH_DENSITY": 26,
    "P_STROKE_CONTRAST": 3.4,
    "P_LIGHT_ANGLE": 0.85,
    "P_CROSS_WEIGHT": 0.9
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_HATCH_DENSITY = 26.0; // P Hatch Density [10.0, 52.0, 1.0]\nconst float P_STROKE_CONTRAST = 3.4; // P Stroke Crispness [1.0, 6.0, 0.1]\nconst float P_LIGHT_ANGLE = 0.85; // P Light Azimuth [0.0, 6.28, 0.05]\nconst float P_CROSS_WEIGHT = 0.9; // P Cross-Hatch [0.0, 1.5, 0.05]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\n\nfloat sdTorus(vec3 p, vec2 t) {\n  vec2 q = vec2(length(p.xz) - t.x, p.y);\n  return length(q) - t.y;\n}\n\nfloat sdCylinder(vec3 p, float r, float h) {\n  vec2 d = abs(vec2(length(p.xz), p.y)) - vec2(r, h);\n  return min(max(d.x, d.y), 0.0) + length(max(d, 0.0));\n}\n\n// Sculpted classical geometry: fluted pedestal, tilted torus, sphere\nvec2 mapScene(vec3 p) {\n  vec2 res = vec2(p.y + 0.95, 1.0);\n  // Central classical sphere\n  float dS = length(p - vec3(-0.32, -0.22, 0.15)) - 0.56;\n  if (dS < res.x) res = vec2(dS, 2.0);\n  // Tilted sculptural ring\n  vec3 q = p - vec3(0.42, 0.08, -0.15);\n  q.xy = rot2(0.65 + 0.25 * sin(iTime * 0.45)) * q.xy;\n  q.xz = rot2(iTime * 0.35) * q.xz;\n  float dT = sdTorus(q, vec2(0.52, 0.17));\n  if (dT < res.x) res = vec2(dT, 3.0);\n  // Background fluted column\n  vec3 cp = p - vec3(-0.95, 0.1, -1.1);\n  float fluting = 0.025 * cos(atan(cp.z, cp.x) * 14.0);\n  float dC = sdCylinder(cp, 0.38 + fluting, 1.35);\n  if (dC < res.x) res = vec2(dC, 4.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.002, 0.0);\n  return normalize(vec3(\n    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,\n    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,\n    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x\n  ));\n}\n\n// Continuous hardware hatching stroke signal with fine tone-controlled thresholding\nfloat hatchWave(vec2 uv, float ang, float freq, float wobble) {\n  vec2 r = rot2(ang) * uv;\n  float w = sin(r.x * freq + sin(r.y * freq * 0.18) * wobble);\n  return 0.5 + 0.5 * w;\n}\n\n// Evaluate 5 nested tonal art map (TAM) engraving bands with fine tone control\nfloat evalHatchTone(vec2 uv, float tone, float freq, float contrast, float crossW) {\n  // Paper grain subtly modulates threshold so transitions feel hand-engraved\n  float grain = 0.04 * sin(uv.x * 110.0) * cos(uv.y * 97.0);\n  float t = clamp(tone + grain, 0.0, 1.0);\n\n  // Band 1: primary parallel diagonal strokes (light midtones)\n  float s1 = hatchWave(uv, 0.68, freq, 0.45);\n  float ink1 = smoothstep(0.0, 1.0, (0.82 - t) * contrast - s1 * 0.95 + 0.48);\n\n  // Band 2: tighter interstitial parallel strokes (midtones)\n  float s2 = hatchWave(uv + vec2(0.017, -0.011), 0.68, freq * 1.45, 0.35);\n  float ink2 = smoothstep(0.0, 1.0, (0.62 - t) * contrast - s2 * 0.95 + 0.44);\n\n  // Band 3: opposing cross-hatch strokes (core shadow)\n  float s3 = hatchWave(uv, -0.62, freq * 1.05, 0.42);\n  float ink3 = smoothstep(0.0, 1.0, (0.46 - t) * contrast - s3 * 0.95 + 0.42) * clamp(crossW, 0.0, 1.5);\n\n  // Band 4: near-horizontal engraving lines (deep shadow)\n  float s4 = hatchWave(uv, 0.08, freq * 1.25, 0.3);\n  float ink4 = smoothstep(0.0, 1.0, (0.28 - t) * contrast - s4 * 0.92 + 0.38) * clamp(crossW, 0.0, 1.5);\n\n  // Band 5: solid ink velvet shadow\n  float ink5 = smoothstep(0.14, 0.03, t);\n\n  return clamp(max(max(ink1, ink2), max(max(ink3, ink4), ink5)), 0.0, 1.0);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n\n  vec3 ro = vec3(0.0, 0.32, 2.85);\n  vec3 rd = normalize(vec3(uv, -1.6));\n\n  float t = 0.0;\n  float matId = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapScene(ro + rd * t);\n    if (h.x < 0.002) { matId = h.y; hit = true; break; }\n    t += h.x;\n    if (t > 12.0) break;\n  }\n\n  float freq = clamp(P_HATCH_DENSITY, 8.0, 64.0) * 6.28318 * 0.5;\n  float contrast = clamp(P_STROKE_CONTRAST, 0.8, 7.0);\n  float crossW = clamp(P_CROSS_WEIGHT, 0.0, 1.6);\n\n  // Warm archival cotton rag paper base\n  float paperTex = 0.97 + 0.03 * sin(uv.x * 190.0 + sin(uv.y * 130.0)) * cos(uv.y * 165.0);\n  vec3 paper = vec3(0.95, 0.91, 0.83) * paperTex;\n  vec3 ink = vec3(0.09, 0.08, 0.11);\n\n  float tone = clamp(0.62 + 0.34 * uv.y - 0.12 * abs(uv.x), 0.18, 0.98);\n  vec2 hatchUV = uv;\n  float silhouette = 0.0;\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p);\n    float lAng = P_LIGHT_ANGLE + 0.35 * sin(iTime * 0.5);\n    vec3 lDir = normalize(vec3(cos(lAng) * 0.9, 0.78, sin(lAng) * 0.7 + 0.45));\n\n    // Soft cast shadow check\n    float sh = 1.0;\n    float ts = 0.03;\n    for (int s = 0; s < 18; s++) {\n      float ds = mapScene(p + n * 0.015 + lDir * ts).x;\n      sh = min(sh, clamp(6.0 * ds / ts, 0.0, 1.0));\n      ts += max(ds, 0.04);\n      if (ts > 3.0) break;\n    }\n\n    float diff = max(dot(n, lDir), 0.0) * (0.35 + 0.65 * sh);\n    float hemi = 0.5 + 0.5 * n.y;\n    vec3 hVec = normalize(lDir - rd);\n    float spec = pow(max(dot(n, hVec), 0.0), 28.0) * 0.42 * sh;\n    float baseAl = (matId < 1.5) ? 0.84 : (matId < 2.5 ? 0.94 : 0.88);\n    tone = clamp((0.12 * hemi + 0.82 * diff + spec) * baseAl, 0.0, 1.0);\n\n    // Object-space curved UV projection so strokes wrap gracefully over 3D curvature\n    if (matId < 1.5) {\n      hatchUV = p.xz * 0.48;\n    } else {\n      hatchUV = vec2(atan(n.x, n.z) * 0.28 + p.x * 0.18, p.y * 0.72 + n.y * 0.15);\n    }\n\n    // Crisp grazing-angle contour ink line\n    float ndv = max(dot(n, -rd), 0.0);\n    silhouette = smoothstep(0.26, 0.08, ndv) * step(1.5, matId);\n  }\n\n  float inkMask = evalHatchTone(hatchUV, tone, freq, contrast, crossW);\n  inkMask = max(inkMask, silhouette * 0.92);\n\n  // Subtle architectural copperplate border frame\n  vec2 b = abs(fragCoord / iResolution.xy - 0.5);\n  float border = smoothstep(0.468, 0.472, max(b.x, b.y)) * (1.0 - smoothstep(0.478, 0.482, max(b.x, b.y)));\n  vec3 col = mix(paper, ink, clamp(inkMask + border * 0.6, 0.0, 1.0));\n\n  fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "hardware-hatching-tone-control",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T16:50:13.852Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6135,
      "std": 0.2566,
      "unique_colors": 60
     },
     "image": "/specimens/hardware-hatching-tone-control-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "tonal-art-maps",
  "procedural-cross-hatching"
 ],
 "extends": [
  "tonal-art-maps"
 ],
 "supersedes": [],
 "combines_with": [],
 "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/hardware-hatching-tone-control.json"
 },
 "solves": [
  "real-time pen and ink hatching look",
  "hatching strokes pop or swim when the camera moves",
  "smooth tone gradients in sketch style rendering",
  "non-photorealistic engraving style on the gpu"
 ],
 "authority": "Webb et al., 2002",
 "url": "https://texelatlas.vercel.app/t/hardware-hatching-tone-control/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 42.88,
  "tier": "heavy",
  "p50_ms": 1.4107,
  "p95_ms": 1.4563,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "hardware-hatching-tone-control-live",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 39.51,
   "tier": "heavy",
   "p50_ms": 0.6282,
   "p95_ms": 0.6457,
   "speedup_x": 2.25,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 26.63,
   "tier": "heavy",
   "p50_ms": 0.767,
   "p95_ms": 0.7734,
   "speedup_x": 1.84,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}