{
 "id": "stroke-based-rendering",
 "title": "Stroke-based rendering",
 "aliases": [],
 "domain": "npr",
 "subdomain": "painterly rendering",
 "stage": "post",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "python",
  "desktop-gpu"
 ],
 "year_introduced": 1990,
 "inputs": [
  "ldr-image",
  "mesh",
  "curves"
 ],
 "outputs": [
  "ldr-image",
  "curves"
 ],
 "style": "stylized",
 "dynamic": "both",
 "summary": "Umbrella family that builds an image by placing discrete marks such as brush strokes, stipples or hatches, selected by a rule, an optimisation, or a learned model.",
 "how_it_works": "Every method in the family defines a stroke model (position, orientation, size, colour, texture), a source of guidance (an image, a 3D scene, a depth map) and a placement strategy. Greedy approaches pick strokes where the canvas differs most from a target; optimisation approaches minimise a loss between the rendered strokes and the source, sometimes with differentiable rasterisation; particle approaches attach strokes to 3D surfaces. Orientation fields, from gradients, a structure tensor or user input, give coherent direction. Ordering and layering (big to small, dark to light) control the final appearance. The survey organises the field by these decisions.",
 "when_to_use": "Choose it as the conceptual map when picking between painterly options. Use `painterly-curved-brush-strokes` for a classic greedy implementation, `painterly-animation-meier` for 3D coherence, `sillage-brush-splatting` for brush marks on a Gaussian splat scene, and `anisotropic-kuwahara` when a filter is enough.",
 "cost": {
  "class": "offline",
  "notes": "Varies; typical algorithms are offline, with GPU variants interactive."
 },
 "failure_modes": [
  "Visual quality depends on stroke placement heuristics, with no single correct answer",
  "Temporal coherence has to be designed in, not assumed",
  "Many strokes (tens of thousands) make rendering and sorting heavy",
  "Optimisation-based methods can converge to blurry local minima"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1109/mcg.2003.1210867",
   "type": "paper",
   "title": "A survey of stroke-based rendering",
   "authors": [
    "A. Hertzmann"
   ],
   "year": 2003,
   "venue": "IEEE Computer Graphics and Applications",
   "url": "https://doi.org/10.1109/mcg.2003.1210867",
   "ids": {
    "doi": "10.1109/mcg.2003.1210867"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.2003.1210867",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.2003.1210867",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.2003.1210867",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.2003.1210867",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1109/mcg.2003.1210867",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "hertzmann2003survey"
  }
 ],
 "presets": [
  {
   "id": "stroke-based-rendering-live",
   "title": "Stroke-Based Rendering — continuous 3D shading (left) vs curvature-aligned pen hatches, cross-hatching & stipples (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_MARK_DENS": 10,
    "P_HATCH_CONTRAST": 0.85,
    "P_STIPPLE_MIX": 0.45,
    "P_SPLIT": 0.42
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_MARK_DENS = 10.00; // P Mark Frequency [5.0, 18.0, 1.0]\nconst float P_HATCH_CONTRAST = 0.85; // P Ink Contrast [0.3, 1.4, 0.05]\nconst float P_STIPPLE_MIX = 0.45; // P Midtone Stippling [0.0, 1.0, 0.05]\nconst float P_SPLIT = 0.42; // P Shaded / Strokes [0.0, 1.0, 0.02]\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(127.1, 311.7));\n  p += dot(p, p + 34.5);\n  return fract(p.x * p.y);\n}\n\nvec2 rot2(vec2 p, float a) {\n  float c = cos(a);\n  float s = sin(a);\n  return vec2(c * p.x - s * p.y, s * p.x + c * p.y);\n}\n\n// Classical plaster-cast sculptural form (sphere + torus ring + plinth) for engraving/SBR mark study\nvec2 mapBust(vec3 p, float t) {\n  float dFloor = p.y + 0.56;\n  vec2 res = vec2(dFloor, 1.0);\n  vec3 rp = p;\n  rp.xz = rot2(rp.xz, 0.35 * sin(t * 0.45));\n\n  float dSph = length(rp - vec3(0.0, 0.02, 0.0)) - 0.40;\n  vec2 tq = vec2(length(rp.xy - vec2(0.0, 0.02)) - 0.36, rp.z);\n  float dRing = length(tq) - 0.11;\n  float dBust = min(dSph, dRing);\n  if (dBust < res.x) res = vec2(dBust, 2.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p, float t) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapBust(p + e.xyy, t).x - mapBust(p - e.xyy, t).x,\n    mapBust(p + e.yxy, t).x - mapBust(p - e.yxy, t).x,\n    mapBust(p + e.yyx, t).x - mapBust(p - e.yyx, t).x\n  ));\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  float mDens = clamp(P_MARK_DENS, 4.0, 20.0);\n  float contrast = clamp(P_HATCH_CONTRAST, 0.25, 1.5);\n  float stipMix = clamp(P_STIPPLE_MIX, 0.0, 1.0);\n\n  // Warm archival cotton drawing paper\n  float grain = (hash21(floor(fragCoord * 0.75)) - 0.5) * 0.05;\n  vec3 paper = vec3(0.95, 0.92, 0.85) + grain;\n  vec3 ink = vec3(0.11, 0.13, 0.18);\n\n  vec3 ro = vec3(0.0, 0.22, 2.15);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.06, -1.50));\n  vec3 lDir = normalize(vec3(0.65 * cos(iTime * 0.35 + 0.5), 0.72, 0.55));\n\n  float dist = 0.05;\n  vec2 hit = vec2(10.0, 0.0);\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapBust(ro + rd * dist, iTime);\n    if (h.x < 0.002) { hit = vec2(dist, h.y); break; }\n    dist += h.x;\n    if (dist > 7.5) break;\n  }\n\n  vec3 col = paper * mix(0.90, 1.0, smoothstep(-0.5, 0.5, uv.y));\n  if (hit.y > 0.5) {\n    vec3 p = ro + rd * hit.x;\n    vec3 n = calcNormal(p, iTime);\n    float ndl = max(dot(n, lDir), 0.0);\n    float ndv = max(dot(n, -rd), 0.0);\n    float spec = pow(max(dot(reflect(-lDir, n), -rd), 0.0), 28.0);\n    // Floor contact shadow\n    float sh = (hit.y < 1.5) ? smoothstep(0.24, 0.66, length(p.xz - vec2(-0.12, -0.05))) : 1.0;\n    float tone = clamp((0.14 + 0.82 * ndl) * sh + spec * 0.28, 0.0, 1.0);\n\n    if (screenX < split) {\n      // Left: Continuous grayscale sculptural lighting reference\n      col = mix(vec3(0.14, 0.16, 0.20), vec3(0.93, 0.91, 0.87), tone);\n      if (hit.y < 1.5) col = mix(paper * 0.92, col, exp(-hit.x * 0.16));\n    } else {\n      // Right: Discrete Stroke-Based Rendering (curvature-oriented hatches + cross-hatch + stipples + contour!)\n      // Surface-aligned stroke coordinates following principal surface curvature\n      vec2 sc = (hit.y < 1.5) ? (p.xz * 1.4) : vec2(atan(n.z, n.x) * 0.55, asin(clamp(n.y, -1.0, 1.0)) * 0.95);\n      float freq = mDens * 2.8;\n\n      // Layer 1: Primary pen hatching strokes (engaged below tone < 0.78)\n      float h1Wave = abs(sin(sc.x * freq + sc.y * freq * 0.35 + 0.6 * sin(sc.y * 5.0)));\n      float h1Thick = clamp((0.78 - tone) * 1.35 * contrast, 0.0, 0.92);\n      float hatch1 = smoothstep(h1Thick + 0.08, h1Thick - 0.06, h1Wave) * step(tone, 0.80);\n\n      // Layer 2: Cross-hatching strokes at 60 deg (engaged in mid-deep shadows tone < 0.48)\n      float h2Wave = abs(sin(sc.y * freq * 1.15 - sc.x * freq * 0.55));\n      float h2Thick = clamp((0.50 - tone) * 1.65 * contrast, 0.0, 0.92);\n      float hatch2 = smoothstep(h2Thick + 0.08, h2Thick - 0.06, h2Wave) * step(tone, 0.52);\n\n      // Layer 3: Stipple dot marks in highlight-to-midtone transition (0.42 < tone < 0.88)\n      vec2 stGrid = fragCoord * (0.14 * mDens * 0.12 + 0.12);\n      vec2 stCell = floor(stGrid);\n      vec2 stF = fract(stGrid) - 0.5;\n      vec2 stJit = (vec2(hash21(stCell + 3.1), hash21(stCell + 19.7)) - 0.5) * 0.55;\n      float stR = clamp((0.86 - tone) * 0.48, 0.0, 0.36);\n      float stipple = smoothstep(stR + 0.06, stR - 0.04, length(stF - stJit)) * stipMix * step(tone, 0.88);\n\n      // Silhouette ink contour stroke around grazing edges\n      float contour = (hit.y > 1.5) ? smoothstep(0.32, 0.14, ndv) : 0.0;\n\n      float inkCoverage = clamp(max(max(hatch1, hatch2), max(stipple, contour)), 0.0, 1.0);\n      // Warm sepia/cobalt wash tint under strokes\n      vec3 wash = mix(vec3(0.84, 0.80, 0.74), paper, smoothstep(0.15, 0.75, tone));\n      col = mix(wash, ink, inkCoverage * 0.92);\n      if (hit.y < 1.5) col = mix(paper * 0.94, col, exp(-hit.x * 0.16));\n    }\n  } else if (screenX >= split) {\n    // Light atmospheric sky hatch lines on paper background\n    float skyH = smoothstep(0.08, 0.02, abs(sin(uv.y * mDens * 5.0 + 0.25 * sin(uv.x * 6.0)))) * smoothstep(0.05, 0.55, uv.y) * 0.16;\n    col = mix(col, vec3(0.24, 0.34, 0.48), skyH);\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.12, 0.14, 0.18), sep);\n  fragColor = vec4(clamp(col, 0.0, 1.0), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "stroke-based-rendering",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:26.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.772,
      "std": 0.2213,
      "min": 0.1398,
      "max": 0.9467
     },
     "image": "/specimens/stroke-based-rendering-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "painterly-curved-brush-strokes",
  "painterly-animation-meier",
  "sillage-brush-splatting"
 ],
 "extends": [],
 "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/stroke-based-rendering.json"
 },
 "solves": [
  "unsure which painterly approach to pick",
  "want images made of strokes, stipples or hatches",
  "turn a photo into discrete brush marks",
  "compare ways to build an image from marks",
  "non-photorealistic rendering from placed primitives"
 ],
 "authority": "Hertzmann, 2003",
 "url": "https://texelatlas.vercel.app/t/stroke-based-rendering/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 11.53,
  "tier": "moderate",
  "p50_ms": 0.3795,
  "p95_ms": 0.3961,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "stroke-based-rendering-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 10.03,
   "tier": "moderate",
   "p50_ms": 0.1595,
   "p95_ms": 0.1619,
   "speedup_x": 2.38,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 7.15,
   "tier": "moderate",
   "p50_ms": 0.206,
   "p95_ms": 0.2068,
   "speedup_x": 1.84,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}