{
 "id": "painterly-curved-brush-strokes",
 "title": "Painterly rendering with curved brush strokes",
 "aliases": [],
 "domain": "npr",
 "subdomain": "painterly rendering",
 "stage": "post",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "python"
 ],
 "year_introduced": 1998,
 "inputs": [
  "ldr-image"
 ],
 "outputs": [
  "ldr-image"
 ],
 "style": "stylized",
 "dynamic": "static",
 "summary": "Paints an image by laying down curved strokes in layers, from large brushes to small, with strokes placed where the canvas differs from a blurred reference and following image gradients.",
 "how_it_works": "Start from a source photograph. For each brush radius (largest to smallest), blur the reference by that radius and compare it to the current canvas. In grid cells where the difference is large, place a stroke starting at the worst-error point and trace a curve perpendicular to the gradient of the blurred reference, stopping when colour deviates, when the stroke reaches maximum length or when it hits low curvature. Strokes are drawn as thick splines with the colour sampled at their seed. Painting from coarse to fine means broad areas get big brush strokes and only high-detail regions get small ones. Parameters (threshold, curvature filter, jitter) define styles such as impressionist or pointillist.",
 "when_to_use": "Choose it when you want an individual stroke-by-stroke painted look from a rendered still with a clear stroke structure. Prefer `anisotropic-kuwahara` for an automatic real-time filter, and `painterly-animation-meier` when frame coherence for animation matters.",
 "cost": {
  "class": "offline",
  "notes": "Many layered passes on CPU; seconds per image in the original implementation."
 },
 "failure_modes": [
  "No temporal coherence: strokes re-seed each frame, so animation flickers",
  "Stroke placement depends on the arbitrary grid and error threshold",
  "Gradient directions are noisy on textured regions",
  "Long strokes can wander across edges when the gradient is weak"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/280814.280951",
   "type": "paper",
   "title": "Painterly rendering with curved brush strokes of multiple sizes",
   "authors": [
    "Aaron Hertzmann"
   ],
   "year": 1998,
   "venue": "Proceedings of the 25th annual conference on Computer graphics and interactive techniques  - SIGGRAPH '98",
   "url": "https://doi.org/10.1145/280814.280951",
   "ids": {
    "doi": "10.1145/280814.280951"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280951",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280951",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280951",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280951",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/280814.280951",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "hertzmann1998painterly"
  },
  {
   "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": "painterly-curved-brush-strokes-live",
   "title": "Painterly Curved Brush Strokes (Hertzmann 1998) — smooth reference render (left) vs coarse-to-fine gradient-curved impasto strokes (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_BRUSH_SCALE": 1,
    "P_CURVATURE": 0.75,
    "P_IMPASTO": 0.65,
    "P_SPLIT": 0.42
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_BRUSH_SCALE = 1.00; // P Brush Size [0.5, 1.8, 0.05]\nconst float P_CURVATURE = 0.75; // P Flow Curvature [0.1, 1.2, 0.05]\nconst float P_IMPASTO = 0.65; // P Bristle Impasto [0.0, 1.2, 0.05]\nconst float P_SPLIT = 0.42; // P Reference / Painted [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\n// Vibrant sunlit coastal landscape & glowing moon/sun sphere (ideal source photo for Hertzmann curved strokes)\nvec3 evalReference(vec2 uv, float t) {\n  // Swirled sunset sky gradient\n  vec3 skyTop = vec3(0.10, 0.22, 0.48);\n  vec3 skyMid = vec3(0.86, 0.44, 0.24);\n  vec3 skyLow = vec3(0.98, 0.80, 0.36);\n  vec3 col = mix(skyLow, skyMid, smoothstep(-0.08, 0.24, uv.y));\n  col = mix(col, skyTop, smoothstep(0.18, 0.55, uv.y));\n\n  // Glowing sun orb\n  vec2 sunPos = vec2(0.18 + 0.08 * sin(t * 0.4), 0.22);\n  float dSun = length(uv - sunPos);\n  col = mix(col, vec3(1.15, 0.96, 0.62), smoothstep(0.14, 0.09, dSun));\n  col += vec3(0.95, 0.65, 0.25) * exp(-dSun * 6.5) * 0.45;\n\n  // Rolling cypress hills\n  float hill1 = -0.02 + 0.10 * sin(uv.x * 3.8 + 0.6) + 0.04 * cos(uv.x * 8.5);\n  if (uv.y < hill1) {\n    col = mix(vec3(0.14, 0.34, 0.28), vec3(0.28, 0.56, 0.34), smoothstep(-0.22, hill1, uv.y));\n  }\n  // Shimmering cobalt water foreground\n  float waterLine = -0.14 + 0.02 * sin(uv.x * 6.0);\n  if (uv.y < waterLine) {\n    float wave = 0.5 + 0.5 * sin(uv.y * 55.0 + uv.x * 8.0 + t * 1.4);\n    float sunRefl = exp(-abs(uv.x - sunPos.x) * 7.5) * (0.4 + 0.6 * wave);\n    col = mix(vec3(0.08, 0.20, 0.42), vec3(0.18, 0.44, 0.66), wave * 0.6) + vec3(0.98, 0.76, 0.32) * sunRefl * 0.78;\n  }\n  // Foreground sunlit terracotta archway / sphere silhouette on left-center\n  vec2 sp = uv - vec2(-0.14, -0.06);\n  float r = length(sp);\n  if (r < 0.20) {\n    float nz = sqrt(max(0.20 * 0.20 - r * r, 0.0));\n    vec3 n = normalize(vec3(sp, nz));\n    vec3 l = normalize(vec3(0.65, 0.55, 0.52));\n    col = vec3(0.88, 0.34, 0.22) * (0.28 + 0.92 * max(dot(n, l), 0.0)) + vec3(0.25, 0.42, 0.64) * max(-n.x, 0.0) * 0.35;\n  }\n  return col;\n}\n\nfloat luma(vec3 c) {\n  return dot(c, vec3(0.299, 0.587, 0.114));\n}\n\n// Compute unit tangent perpendicular to luminance gradient (Hertzmann stroke spline direction!)\nvec2 gradTangent(vec2 p, float eps, float t) {\n  float gx = luma(evalReference(p + vec2(eps, 0.0), t)) - luma(evalReference(p - vec2(eps, 0.0), t));\n  float gy = luma(evalReference(p + vec2(0.0, eps), t)) - luma(evalReference(p - vec2(0.0, eps), t));\n  vec2 g = vec2(gx, gy);\n  float len = length(g);\n  if (len < 1e-4) return normalize(vec2(1.0, 0.25 * sin(p.x * 5.0)));\n  return vec2(-g.y, g.x) / len;\n}\n\n// Paint one coarse-to-fine layer of curved spline strokes that follow iso-luminance flow lines\nvec4 paintLayer(vec2 uv, float gridN, float bRadius, float curv, float impasto, float t, float layerSeed) {\n  vec2 g = uv * gridN;\n  vec2 cell = floor(g);\n  vec4 outPaint = vec4(0.0);\n\n  for (int j = -1; j <= 1; j++) {\n    for (int i = -1; i <= 1; i++) {\n      vec2 nb = cell + vec2(float(i), float(j));\n      vec2 p0 = (nb + 0.15 + 0.70 * vec2(hash21(nb + layerSeed), hash21(nb + layerSeed + 23.7))) / gridN;\n      vec3 strokeCol = evalReference(p0, t);\n\n      // Trace 3-segment curved brush spine along perpendicular luminance gradient!\n      vec2 tang0 = gradTangent(p0, bRadius * 0.65, t);\n      float stepL = bRadius * 1.45 * curv;\n      vec2 p1 = p0 + tang0 * stepL;\n      vec2 tang1 = gradTangent(p1, bRadius * 0.65, t);\n      vec2 p2 = p1 + tang1 * stepL;\n      vec2 pm = p0 - tang0 * stepL;\n\n      // Minimum distance from uv to the 3 curved polyline segments\n      float minD = 9.0;\n      float alongT = 0.0;\n      float crossS = 0.0;\n      vec2 segA[3];\n      vec2 segB[3];\n      segA[0] = pm; segB[0] = p0;\n      segA[1] = p0; segB[1] = p1;\n      segA[2] = p1; segB[2] = p2;\n      for (int s = 0; s < 3; s++) {\n        vec2 ab = segB[s] - segA[s];\n        float ab2 = max(dot(ab, ab), 1e-6);\n        float proj = clamp(dot(uv - segA[s], ab) / ab2, 0.0, 1.0);\n        vec2 closest = segA[s] + ab * proj;\n        float dd = length(uv - closest);\n        if (dd < minD) {\n          minD = dd;\n          vec2 dir = ab / sqrt(ab2);\n          crossS = dot(uv - closest, vec2(-dir.y, dir.x)) / max(bRadius, 1e-4);\n          alongT = (float(s) + proj) / 3.0;\n        }\n      }\n\n      // Tapered brush stroke width + bristle texture + impasto rim lighting\n      float width = bRadius * (0.72 + 0.35 * sin(alongT * 3.14159));\n      float mask = smoothstep(width, width * 0.58, minD);\n      if (mask > outPaint.a) {\n        float bristle = 0.90 + 0.16 * sin(crossS * 18.0 + hash21(nb + 7.1) * 6.28);\n        float relief = 1.0 + impasto * (crossS * 0.22 - abs(crossS) * 0.12);\n        vec3 colJit = strokeCol * bristle * relief;\n        outPaint = vec4(colJit, mask);\n      }\n    }\n  }\n  return outPaint;\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\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 bScale = clamp(P_BRUSH_SCALE, 0.45, 2.0);\n  float curv = clamp(P_CURVATURE, 0.1, 1.4);\n  float impasto = clamp(P_IMPASTO, 0.0, 1.3);\n\n  vec3 refCol = evalReference(uv, iTime);\n  vec3 col = refCol;\n\n  if (screenX >= split) {\n    // Right: Hertzmann 3-layer coarse-to-fine curved brush strokes (large -> medium -> fine error-refinement)\n    vec3 canvas = vec3(0.92, 0.89, 0.82) * 0.45 + refCol * 0.55;\n    vec4 L1 = paintLayer(uv, 9.0 / bScale, 0.048 * bScale, curv, impasto, iTime, 11.3);\n    canvas = mix(canvas, L1.rgb, L1.a);\n\n    // Medium layer paints over regions where canvas differs from reference\n    vec4 L2 = paintLayer(uv, 16.0 / bScale, 0.026 * bScale, curv, impasto, iTime, 37.9);\n    float err2 = smoothstep(0.04, 0.22, length(canvas - refCol));\n    canvas = mix(canvas, L2.rgb, L2.a * (0.45 + 0.55 * err2));\n\n    // Fine detail brush layer only along high-error silhouettes & highlights\n    vec4 L3 = paintLayer(uv, 27.0 / bScale, 0.015 * bScale, curv, impasto, iTime, 71.1);\n    float err3 = smoothstep(0.06, 0.25, length(canvas - refCol));\n    canvas = mix(canvas, L3.rgb, L3.a * (0.35 + 0.65 * err3));\n    col = canvas;\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.96, 0.95, 0.90), sep);\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "painterly-curved-brush-strokes",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:22.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7324,
      "std": 0.0947,
      "min": 0.3357,
      "max": 0.9324
     },
     "image": "/specimens/painterly-curved-brush-strokes-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "stroke-based-rendering",
  "painterly-animation-meier",
  "anisotropic-kuwahara"
 ],
 "extends": [
  "stroke-based-rendering"
 ],
 "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/painterly-curved-brush-strokes.json"
 },
 "solves": [
  "turn a photo into a brush stroke painting",
  "stylized image with visible curved paint strokes",
  "want a hand painted look with detail where needed",
  "automatic impressionist rendering of pictures"
 ],
 "authority": "Hertzmann, 1998",
 "url": "https://texelatlas.vercel.app/t/painterly-curved-brush-strokes/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 253.67,
  "tier": "extreme",
  "p50_ms": 8.3459,
  "p95_ms": 8.4575,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "painterly-curved-brush-strokes-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 204.6,
   "tier": "extreme",
   "p50_ms": 3.2532,
   "p95_ms": 3.3113,
   "speedup_x": 2.57,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 176.19,
   "tier": "extreme",
   "p50_ms": 5.0744,
   "p95_ms": 5.159,
   "speedup_x": 1.64,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}