---
id: "xdog-stylization"
title: "XDoG edge and stylization filter"
aliases: [extended difference of Gaussians, XDoG, eXtended DoG]
domain: "npr"
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"
cost: "cheap"
authority: "Winnemöller et al., 2012"
url: "https://texelatlas.vercel.app/t/xdog-stylization/"
sources_verified_at: "2026-11-29"
---
# XDoG edge and stylization filter (Winnemöller et al., 2012)

> 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.

## Reach for it when

- 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

## 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.

Parameters 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).

It 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 it

Choose it as a one-pass sketch, ink or comic filter on a rendered frame or photo with tunable thickness and softness.

Prefer [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

cheap — Two separable Gaussian blurs and a combine at screen resolution; larger sigmas cost more taps.
Measured GPU Weight: 105.88× baseline (extreme) — 3.4836 ms median / 3.6046 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 83.45× baseline (extreme) — 1.3268 ms median (2.63× faster on L4).
Ampere A100 scaling: 79.97× baseline (extreme) — 2.303 ms median (1.51× faster on A100).

## 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

## Dataflow

- Inputs: ldr-image
- Outputs: ldr-image
- Platforms: webgl2, webgpu, desktop-gpu, unity, unreal, python

## Presets

### XDoG ink look on shaded spheres (glsl-fragment; rendered 2026-11-29)

```json
{
  "sigma": 1.2,
  "k": 1.6,
  "p": 20,
  "eps": 0.3,
  "phi": 3
}
```

```glsl
// XDoG on a procedural luminance image: sharpened difference of Gaussians, then a soft threshold.
const float SIGMA = 1.2;   // pixels
const float K = 1.6;
const float P = 20.0;      // sharpening
const float EPS = 0.3;     // threshold
const float PHI = 3.0;     // threshold softness

float lum(vec2 q) {        // q in pixels; shaded spheres on a gradient
  vec2 uv = q / iResolution.xy;
  float v = 0.55 + 0.25 * uv.y;
  vec2 cs[3] = vec2[3](vec2(0.3, 0.45), vec2(0.62, 0.55), vec2(0.5, 0.2));
  float rs[3] = float[3](0.2, 0.15, 0.1);
  for (int i = 0; i < 3; i++) {
    vec2 d = (uv - cs[i]) / rs[i];
    float r2 = dot(d, d);
    if (r2 < 1.0) {
      vec3 n = vec3(d, sqrt(1.0 - r2));
      v = 0.08 + 0.9 * max(dot(n, normalize(vec3(-0.5, 0.6, 0.6))), 0.0);
    }
  }
  return v;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  float g1 = 0.0, g2 = 0.0, w1 = 0.0, w2 = 0.0;
  float s1 = SIGMA, s2 = SIGMA * K;
  for (int j = -5; j <= 5; j++) for (int i = -5; i <= 5; i++) {
    vec2 o = vec2(float(i), float(j));
    float l = lum(fragCoord + o), d2 = dot(o, o);
    float a = exp(-d2 / (2.0 * s1 * s1)), b = exp(-d2 / (2.0 * s2 * s2));
    g1 += a * l; w1 += a; g2 += b * l; w2 += b;
  }
  float D = (1.0 + P) * (g1 / w1) - P * (g2 / w2);
  float T = D >= EPS ? 1.0 : 1.0 + tanh(PHI * (D - EPS));
  fragColor = vec4(vec3(T), 1.0);
}

```

Attribution: written for this index

## Lineage

- extends [Depth/normal Sobel edge outlines](https://texelatlas.vercel.app/t/screen-space-edge-outline.md)

## Combines with

- [Kuwahara filter](https://texelatlas.vercel.app/t/kuwahara-filter.md): Smooth the image painterly first, then run XDoG on the result to get clean ink lines over flat regions.
- [Posterization](https://texelatlas.vercel.app/t/posterization.md): The soft XDoG threshold can be replaced by tonal quantisation levels for a multi-tone cut-out look.
- [Halftone screens](https://texelatlas.vercel.app/t/halftone-screen.md): XDoG line art multiplied with a halftone dot layer gives a comic-print look.

## Sources

1. [primary] Holger Winnemöller, Jan Eric Kyprianidis, Sven C. Olsen (2012) XDoG: An eXtended difference-of-Gaussians compendium including advanced image stylization. Computers &amp; Graphics. https://doi.org/10.1016/j.cag.2012.03.004 (verified via crossref on 2026-11-29)

## Cite this entry

Texel. "XDoG edge and stylization filter." https://texelatlas.vercel.app/t/xdog-stylization/ (accessed 2026-12-01).
