Procedural cross-hatching shader
Generates hatch lines in the fragment shader from line functions at several angles, enabling more layers as lighting gets darker, without any pre-authored textures.
Also known as hatching shader
In the family Stylized & non-photorealistic rendering, hatching
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 | No built-in procedural cross-hatching material or post-process. |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
The shader computes a tone value, from N·L or a luminance buffer, and defines a set of line masks: periodic functions of a rotated coordinate (such as abs(fract(x)-0.5)) thresholded to a line width. Darker tones enable more layers: first one diagonal, then the crossing diagonal, then horizontal, then vertical, each gated by a threshold on tone. Coordinates come from screen space (simple, gives the 'shower door' effect), object space or triplanar projection (sticks to surfaces), or a UV-based direction field. Smoothstep with fwidth anti-aliases lines. A paper texture and slight wobble from noise sell the hand-drawn effect, and wobble that is stable across frames avoids shimmering.
When to choose it
Reach for it when
- want pen-and-ink shading without authored textures
- hatch lines should get denser in darker areas
- need engraving look on generated geometry
- texture-free sketch style as a post process
Choose it for fast, texture-free pen-and-ink shading, especially as a post-process or on procedurally generated geometry. Prefer Real-time hatching with tonal art maps when strokes should be hand-drawn, follow the surface direction and be stable across mip levels. Prefer Halftone screens when the dot-based print look is wanted rather than lines.
Field marks
- Screen-space coordinates make lines slide over moving objects (shower-door effect)
- Lines of fixed pixel width alias when sampled coarsely or moire when layers align
- Hard thresholds between layers cause visible popping across smooth lighting
- No sense of surface direction unless a direction field is supplied
Presets
Four-layer procedural hatching on a lit sphere
{
"freq": 70,
"width": 0.16
}Show GLSL (34 lines)
// GLSL ES 3.0, Shadertoy-style: screen-space cross-hatching driven by a lit sphere
const vec3 PAPER = vec3(0.96, 0.93, 0.84);
const vec3 INK = vec3(0.10, 0.12, 0.25);
const float FREQ = 70.0; // hatch lines per unit height
const float WIDTH = 0.16; // line half-width (fraction of spacing)
float hatch(vec2 p, float ang){
float v = (p.x*cos(ang) - p.y*sin(ang)) * FREQ;
float d = abs(fract(v) - 0.5); // 0.5 between lines, 0 on the line centre
float aa = fwidth(v);
return 1.0 - smoothstep(0.5 - WIDTH*2.0 - aa, 0.5 - WIDTH*2.0 + aa, d);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord){
vec2 uv = (fragCoord - 0.5*iResolution.xy) / iResolution.y;
float tone = 0.92;
vec2 c = uv - vec2(0.0, 0.03);
float r = length(c);
if(r < 0.33){
vec3 n = vec3(c, sqrt(0.33*0.33 - r*r)) / 0.33;
vec3 l = normalize(vec3(-0.55 + 0.15*sin(iTime), 0.65, 0.55));
tone = clamp(dot(n, l)*0.9 + 0.1, 0.0, 1.0);
} else {
float shadow = smoothstep(0.38, 0.1, length((uv - vec2(0.18, -0.34))*vec2(0.6, 1.8)));
tone = 0.92 - 0.6*shadow;
}
float dark = 1.0 - tone;
float ink = 0.0;
ink = max(ink, step(0.12, dark) * hatch(uv, 0.785));
ink = max(ink, step(0.35, dark) * hatch(uv, -0.785));
ink = max(ink, step(0.55, dark) * hatch(uv, 0.0));
ink = max(ink, step(0.75, dark) * hatch(uv, 1.571));
fragColor = vec4(mix(PAPER, INK, ink), 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| hatch-four-layer-sphere | Tesla T4 1920x1080 | 2.55× baseline (light) · 0.084 ms / 0.088 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| hatch-four-layer-sphere | NVIDIA L4 1920x1080 | 1.79× baseline (feather) · 0.029 ms / 0.029 ms · 2.9× faster on L4 | opengl-timer-query · Cross-architecture validation |
| hatch-four-layer-sphere | NVIDIA A100-SXM4-40GB 1920x1080 | 1.52× baseline (feather) · 0.044 ms / 0.044 ms · 1.9× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Painterly rendering for animation (Meier), Inverted-hull outlines, Deferred shading (G-buffer).
Crosses
- Depth/normal Sobel edge outlines: Outline pass adds contour lines over the hatched tone.
Sources
- primaryEmil Praun, Hugues Hoppe, Matthew Webb, Adam Finkelstein (2001). Real-time hatching. Proceedings of the 28th annual conference on Computer graphics and interactive techniques.Verified via crossref · 2026-11-29doi:10.1145/383259.383328