XDoG edge and stylization filter
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.
Also known as extended difference of Gaussians, XDoG, eXtended DoG
In the family Stylized & non-photorealistic rendering, image-space filters
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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.
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 choose it
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
Choose it as a one-pass sketch, ink or comic filter on a rendered frame or photo with tunable thickness and softness.
Prefer Depth/normal Sobel edge outlines or Jump-flood wide outlines for clean silhouette lines driven by depth, normals or object IDs. Prefer Kuwahara filter or Anisotropic Kuwahara filter for painterly smoothing instead of line art. Prefer Halftone screens or Procedural cross-hatching shader for shading-based tonal patterns. Prefer Toon / cel shading with lighting ramps when stylisation should come from the lighting rather than a post filter.
Field marks
- 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
Presets
XDoG ink look on shaded spheres
{
"sigma": 1.2,
"k": 1.6,
"p": 20,
"eps": 0.3,
"phi": 3
}Show GLSL (36 lines)
// 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
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| xdog-ink-spheres | Tesla T4 1920x1080 | 106× baseline (extreme) · 3.48 ms / 3.60 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| xdog-ink-spheres | NVIDIA L4 1920x1080 | 83.5× baseline (extreme) · 1.33 ms / 1.33 ms · 2.6× faster on L4 | opengl-timer-query · Cross-architecture validation |
| xdog-ink-spheres | NVIDIA A100-SXM4-40GB 1920x1080 | 80.0× baseline (extreme) · 2.30 ms / 2.30 ms · 1.5× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Real-time hatching with tonal art maps, Wang Tiles (Aperiodic Tile Synthesis).
Crosses
- Kuwahara filter: Smooth the image painterly first, then run XDoG on the result to get clean ink lines over flat regions.
- Posterization: The soft XDoG threshold can be replaced by tonal quantisation levels for a multi-tone cut-out look.
- Halftone screens: XDoG line art multiplied with a halftone dot layer gives a comic-print look.
Sources
- primaryHolger Winnemöller, Jan Eric Kyprianidis, Sven C. Olsen (2012). XDoG: An eXtended difference-of-Gaussians compendium including advanced image stylization. Computers & Graphics.Verified via crossref · 2026-11-29doi:10.1016/j.cag.2012.03.004