Fine tone control in hardware hatching
Extends tonal art map hatching by packing several tone levels into multitexture channels and combining them per fragment so tone can be reproduced in many more steps than the number of textures.
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 hardware hatching shader or tone-control pass. |
| Unity | None found | |
| Unreal 5.7 | None found | No built-in hardware hatching shader or tone-control pass. |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Classic tonal art maps blend only two textures at a time, which limits tonal precision and needs many levels for smooth gradients. The multitexture approach stores several hatch levels in the channels of a few textures and computes per-fragment blend weights that sum to the target tone. The shader chooses weights so that the integrated darkness of the combined strokes matches the desired lighting value, with sharper transitions between layers than a plain cross-fade. This yields finer tone control and reduced blurring of strokes between neighbouring tone levels while still using standard texturing hardware.
When to choose it
Reach for it when
- real-time pen and ink hatching look
- hatching strokes pop or swim when the camera moves
- smooth tone gradients in sketch style rendering
- non-photorealistic engraving style on the gpu
Choose it when plain Real-time hatching with tonal art maps shows visible tone steps or greyish blending and you want more controlled hatching on the GPU. Prefer Procedural cross-hatching shader for screen-space shader hatching without precomputed textures.
Field marks
- Needs the same careful UV and direction parameterisation as tonal art maps
- Channel packing limits you to a fixed number of stroke layers
- Weights tuned for one texture set do not transfer to another without recalibration
- Mip transitions still change stroke thickness at distance
Presets
Hardware hatching tone control — continuous multi-stroke copperplate TAM engraving
{
"P_HATCH_DENSITY": 26,
"P_STROKE_CONTRAST": 3.4,
"P_LIGHT_ANGLE": 0.85,
"P_CROSS_WEIGHT": 0.9
}Show GLSL (155 lines)
const float P_HATCH_DENSITY = 26.0; // P Hatch Density [10.0, 52.0, 1.0]
const float P_STROKE_CONTRAST = 3.4; // P Stroke Crispness [1.0, 6.0, 0.1]
const float P_LIGHT_ANGLE = 0.85; // P Light Azimuth [0.0, 6.28, 0.05]
const float P_CROSS_WEIGHT = 0.9; // P Cross-Hatch [0.0, 1.5, 0.05]
mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
float sdTorus(vec3 p, vec2 t) {
vec2 q = vec2(length(p.xz) - t.x, p.y);
return length(q) - t.y;
}
float sdCylinder(vec3 p, float r, float h) {
vec2 d = abs(vec2(length(p.xz), p.y)) - vec2(r, h);
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0));
}
// Sculpted classical geometry: fluted pedestal, tilted torus, sphere
vec2 mapScene(vec3 p) {
vec2 res = vec2(p.y + 0.95, 1.0);
// Central classical sphere
float dS = length(p - vec3(-0.32, -0.22, 0.15)) - 0.56;
if (dS < res.x) res = vec2(dS, 2.0);
// Tilted sculptural ring
vec3 q = p - vec3(0.42, 0.08, -0.15);
q.xy = rot2(0.65 + 0.25 * sin(iTime * 0.45)) * q.xy;
q.xz = rot2(iTime * 0.35) * q.xz;
float dT = sdTorus(q, vec2(0.52, 0.17));
if (dT < res.x) res = vec2(dT, 3.0);
// Background fluted column
vec3 cp = p - vec3(-0.95, 0.1, -1.1);
float fluting = 0.025 * cos(atan(cp.z, cp.x) * 14.0);
float dC = sdCylinder(cp, 0.38 + fluting, 1.35);
if (dC < res.x) res = vec2(dC, 4.0);
return res;
}
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.002, 0.0);
return normalize(vec3(
mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,
mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,
mapScene(p + e.yyx).x - mapScene(p - e.yyx).x
));
}
// Continuous hardware hatching stroke signal with fine tone-controlled thresholding
float hatchWave(vec2 uv, float ang, float freq, float wobble) {
vec2 r = rot2(ang) * uv;
float w = sin(r.x * freq + sin(r.y * freq * 0.18) * wobble);
return 0.5 + 0.5 * w;
}
// Evaluate 5 nested tonal art map (TAM) engraving bands with fine tone control
float evalHatchTone(vec2 uv, float tone, float freq, float contrast, float crossW) {
// Paper grain subtly modulates threshold so transitions feel hand-engraved
float grain = 0.04 * sin(uv.x * 110.0) * cos(uv.y * 97.0);
float t = clamp(tone + grain, 0.0, 1.0);
// Band 1: primary parallel diagonal strokes (light midtones)
float s1 = hatchWave(uv, 0.68, freq, 0.45);
float ink1 = smoothstep(0.0, 1.0, (0.82 - t) * contrast - s1 * 0.95 + 0.48);
// Band 2: tighter interstitial parallel strokes (midtones)
float s2 = hatchWave(uv + vec2(0.017, -0.011), 0.68, freq * 1.45, 0.35);
float ink2 = smoothstep(0.0, 1.0, (0.62 - t) * contrast - s2 * 0.95 + 0.44);
// Band 3: opposing cross-hatch strokes (core shadow)
float s3 = hatchWave(uv, -0.62, freq * 1.05, 0.42);
float ink3 = smoothstep(0.0, 1.0, (0.46 - t) * contrast - s3 * 0.95 + 0.42) * clamp(crossW, 0.0, 1.5);
// Band 4: near-horizontal engraving lines (deep shadow)
float s4 = hatchWave(uv, 0.08, freq * 1.25, 0.3);
float ink4 = smoothstep(0.0, 1.0, (0.28 - t) * contrast - s4 * 0.92 + 0.38) * clamp(crossW, 0.0, 1.5);
// Band 5: solid ink velvet shadow
float ink5 = smoothstep(0.14, 0.03, t);
return clamp(max(max(ink1, ink2), max(max(ink3, ink4), ink5)), 0.0, 1.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.32, 2.85);
vec3 rd = normalize(vec3(uv, -1.6));
float t = 0.0;
float matId = 0.0;
bool hit = false;
for (int i = 0; i < 64; i++) {
vec2 h = mapScene(ro + rd * t);
if (h.x < 0.002) { matId = h.y; hit = true; break; }
t += h.x;
if (t > 12.0) break;
}
float freq = clamp(P_HATCH_DENSITY, 8.0, 64.0) * 6.28318 * 0.5;
float contrast = clamp(P_STROKE_CONTRAST, 0.8, 7.0);
float crossW = clamp(P_CROSS_WEIGHT, 0.0, 1.6);
// Warm archival cotton rag paper base
float paperTex = 0.97 + 0.03 * sin(uv.x * 190.0 + sin(uv.y * 130.0)) * cos(uv.y * 165.0);
vec3 paper = vec3(0.95, 0.91, 0.83) * paperTex;
vec3 ink = vec3(0.09, 0.08, 0.11);
float tone = clamp(0.62 + 0.34 * uv.y - 0.12 * abs(uv.x), 0.18, 0.98);
vec2 hatchUV = uv;
float silhouette = 0.0;
if (hit) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p);
float lAng = P_LIGHT_ANGLE + 0.35 * sin(iTime * 0.5);
vec3 lDir = normalize(vec3(cos(lAng) * 0.9, 0.78, sin(lAng) * 0.7 + 0.45));
// Soft cast shadow check
float sh = 1.0;
float ts = 0.03;
for (int s = 0; s < 18; s++) {
float ds = mapScene(p + n * 0.015 + lDir * ts).x;
sh = min(sh, clamp(6.0 * ds / ts, 0.0, 1.0));
ts += max(ds, 0.04);
if (ts > 3.0) break;
}
float diff = max(dot(n, lDir), 0.0) * (0.35 + 0.65 * sh);
float hemi = 0.5 + 0.5 * n.y;
vec3 hVec = normalize(lDir - rd);
float spec = pow(max(dot(n, hVec), 0.0), 28.0) * 0.42 * sh;
float baseAl = (matId < 1.5) ? 0.84 : (matId < 2.5 ? 0.94 : 0.88);
tone = clamp((0.12 * hemi + 0.82 * diff + spec) * baseAl, 0.0, 1.0);
// Object-space curved UV projection so strokes wrap gracefully over 3D curvature
if (matId < 1.5) {
hatchUV = p.xz * 0.48;
} else {
hatchUV = vec2(atan(n.x, n.z) * 0.28 + p.x * 0.18, p.y * 0.72 + n.y * 0.15);
}
// Crisp grazing-angle contour ink line
float ndv = max(dot(n, -rd), 0.0);
silhouette = smoothstep(0.26, 0.08, ndv) * step(1.5, matId);
}
float inkMask = evalHatchTone(hatchUV, tone, freq, contrast, crossW);
inkMask = max(inkMask, silhouette * 0.92);
// Subtle architectural copperplate border frame
vec2 b = abs(fragCoord / iResolution.xy - 0.5);
float border = smoothstep(0.468, 0.472, max(b.x, b.y)) * (1.0 - smoothstep(0.478, 0.482, max(b.x, b.y)));
vec3 col = mix(paper, ink, clamp(inkMask + border * 0.6, 0.0, 1.0));
fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| hardware-hatching-tone-control-live | Tesla T4 1920x1080 | 42.9× baseline (heavy) · 1.41 ms / 1.46 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| hardware-hatching-tone-control-live | NVIDIA L4 1920x1080 | 39.5× baseline (heavy) · 0.628 ms / 0.646 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| hardware-hatching-tone-control-live | NVIDIA A100-SXM4-40GB 1920x1080 | 26.6× baseline (heavy) · 0.767 ms / 0.773 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Deferred shading (G-buffer).
Sources
- primaryMatthew Webb, Emil Praun, Adam Finkelstein, Hugues Hoppe (2002). Fine tone control in hardware hatching. Proceedings of the 2nd international symposium on Non-photorealistic animation and rendering.Verified via crossref · 2026-11-29doi:10.1145/508530.508540