{
 "id": "xdog-stylization",
 "title": "XDoG edge and stylization filter",
 "aliases": [
  "extended difference of Gaussians",
  "XDoG",
  "eXtended DoG"
 ],
 "domain": "npr",
 "subdomain": "image-space filters",
 "stage": "post",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "unity",
  "unreal",
  "python"
 ],
 "year_introduced": 2012,
 "inputs": [
  "ldr-image"
 ],
 "outputs": [
  "ldr-image"
 ],
 "style": "stylized",
 "dynamic": "both",
 "summary": "A tunable difference-of-Gaussians filter with sharpening and a soft threshold. Depending on its parameters it gives pencil lines, ink drawings, tone-separated posterised shapes or hatched looks from any image.",
 "how_it_works": "A difference of Gaussians subtracts two blurs of the image at different scales, which acts as an edge and band-pass detector. XDoG makes it expressive by adding two controls. A sharpening weight `p` amplifies the narrower blur, `D = (1 + p) * G(sigma) - p * G(k * sigma)`, so the response is stronger and more contrasty. A thresholding function then maps D to output: values above an epsilon go to white, values below fall off smoothly with `1 + tanh(phi * (D - eps))`, with `phi` controlling how hard the transition is.\n\nParameters change the character. A large `p` with a low `phi` makes bold pen lines; a large `eps` removes thin detail leaving blobs; a higher sigma gives thick brush-like lines; setting `eps` near zero gives a flat-colour stylisation with outlines. Thresholding can be replaced by a ramp for multi-tone results, as in [posterization](posterization).\n\nIt runs as two or three separable blur passes plus a pointwise combine. Applying it to luminance, depth or normals gives different line sets.",
 "when_to_use": "Choose it as a one-pass sketch, ink or comic filter on a rendered frame or photo with tunable thickness and softness.\n\nPrefer [screen-space-edge-outline](screen-space-edge-outline) or [jump-flood-outline](jump-flood-outline) for clean silhouette lines driven by depth, normals or object IDs. Prefer [kuwahara-filter](kuwahara-filter) or [anisotropic-kuwahara](anisotropic-kuwahara) for painterly smoothing instead of line art. Prefer [halftone-screen](halftone-screen) or [procedural-cross-hatching](procedural-cross-hatching) for shading-based tonal patterns. Prefer [toon-shading](toon-shading) when stylisation should come from the lighting rather than a post filter.",
 "cost": {
  "class": "cheap",
  "notes": "Two separable Gaussian blurs and a combine at screen resolution; larger sigmas cost more taps."
 },
 "failure_modes": [
  "Noise and texture in the source become speckled lines; the image must be smoothed or run on a low-detail channel",
  "Temporal flicker on moving content because thresholds flip pixels between frames",
  "Line width changes with image resolution and scale unless sigma is expressed in resolution-independent units",
  "Thin features vanish when `eps` is high, and flat areas turn pure white or black with extreme `p`",
  "Lines on shading gradients follow lighting rather than geometry, producing contours across smooth surfaces",
  "Colour images need a luminance conversion first; applying it per channel gives rainbow fringes"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1016/j.cag.2012.03.004",
   "type": "paper",
   "title": "XDoG: An eXtended difference-of-Gaussians compendium including advanced image stylization",
   "authors": [
    "Holger Winnemöller",
    "Jan Eric Kyprianidis",
    "Sven C. Olsen"
   ],
   "year": 2012,
   "venue": "Computers &amp; Graphics",
   "url": "https://doi.org/10.1016/j.cag.2012.03.004",
   "ids": {
    "doi": "10.1016/j.cag.2012.03.004"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1016/j.cag.2012.03.004",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1016/j.cag.2012.03.004",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1016/j.cag.2012.03.004",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1016/j.cag.2012.03.004",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1016/j.cag.2012.03.004",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "winnemller2012xdog"
  }
 ],
 "presets": [
  {
   "id": "xdog-ink-spheres",
   "title": "XDoG ink look on shaded spheres",
   "runtime": "glsl-fragment",
   "params": {
    "sigma": 1.2,
    "k": 1.6,
    "p": 20,
    "eps": 0.3,
    "phi": 3
   },
   "code": "// XDoG on a procedural luminance image: sharpened difference of Gaussians, then a soft threshold.\nconst float SIGMA = 1.2;   // pixels\nconst float K = 1.6;\nconst float P = 20.0;      // sharpening\nconst float EPS = 0.3;     // threshold\nconst float PHI = 3.0;     // threshold softness\n\nfloat lum(vec2 q) {        // q in pixels; shaded spheres on a gradient\n  vec2 uv = q / iResolution.xy;\n  float v = 0.55 + 0.25 * uv.y;\n  vec2 cs[3] = vec2[3](vec2(0.3, 0.45), vec2(0.62, 0.55), vec2(0.5, 0.2));\n  float rs[3] = float[3](0.2, 0.15, 0.1);\n  for (int i = 0; i < 3; i++) {\n    vec2 d = (uv - cs[i]) / rs[i];\n    float r2 = dot(d, d);\n    if (r2 < 1.0) {\n      vec3 n = vec3(d, sqrt(1.0 - r2));\n      v = 0.08 + 0.9 * max(dot(n, normalize(vec3(-0.5, 0.6, 0.6))), 0.0);\n    }\n  }\n  return v;\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  float g1 = 0.0, g2 = 0.0, w1 = 0.0, w2 = 0.0;\n  float s1 = SIGMA, s2 = SIGMA * K;\n  for (int j = -5; j <= 5; j++) for (int i = -5; i <= 5; i++) {\n    vec2 o = vec2(float(i), float(j));\n    float l = lum(fragCoord + o), d2 = dot(o, o);\n    float a = exp(-d2 / (2.0 * s1 * s1)), b = exp(-d2 / (2.0 * s2 * s2));\n    g1 += a * l; w1 += a; g2 += b * l; w2 += b;\n  }\n  float D = (1.0 + P) * (g1 / w1) - P * (g2 / w2);\n  float T = D >= EPS ? 1.0 : 1.0 + tanh(PHI * (D - EPS));\n  fragColor = vec4(vec3(T), 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": "xdog-stylization",
     "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.9582,
      "std": 0.1616,
      "unique_colors": 32
     },
     "image": "/specimens/xdog-ink-spheres.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "screen-space-edge-outline",
  "jump-flood-outline",
  "kuwahara-filter",
  "halftone-screen",
  "posterization",
  "toon-shading"
 ],
 "extends": [
  "screen-space-edge-outline"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "kuwahara-filter",
   "why": "Smooth the image painterly first, then run XDoG on the result to get clean ink lines over flat regions."
  },
  {
   "id": "posterization",
   "why": "The soft XDoG threshold can be replaced by tonal quantisation levels for a multi-tone cut-out look."
  },
  {
   "id": "halftone-screen",
   "why": "XDoG line art multiplied with a halftone dot layer gives a comic-print look."
  }
 ],
 "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/xdog-stylization.json"
 },
 "solves": [
  "want pencil sketch or ink lines from a rendered frame",
  "comic book line art filter that is tunable",
  "need soft thresholded edges from an image",
  "turn a photo into a stylized drawing in one pass"
 ],
 "authority": "Winnemöller et al., 2012",
 "url": "https://texelatlas.vercel.app/t/xdog-stylization/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 105.88,
  "tier": "extreme",
  "p50_ms": 3.4836,
  "p95_ms": 3.6046,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "xdog-ink-spheres",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 83.45,
   "tier": "extreme",
   "p50_ms": 1.3268,
   "p95_ms": 1.3338,
   "speedup_x": 2.63,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 79.97,
   "tier": "extreme",
   "p50_ms": 2.303,
   "p95_ms": 2.3034,
   "speedup_x": 1.51,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}