Ink vortex
glint · Examples · Tutorials · Gallery
Falling for ever into a spiral funnel of blocks, picture frames and circuit boards, drawn in engraved ink on paper. Not 3D: the log-polar map behind Escher's Print Gallery turns a flat wall of blocks into a funnel where every ring is a smaller copy of the last, so falling in never ends.

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.
The code
One pass, in GLSL.
fragment shader
#version 300 es
precision highp float;
uniform float time;
uniform vec2 resolution;
uniform float speed;
uniform float twist;
in vec2 v_texcoord;
out vec4 fragColor;
const vec3 PAPER = vec3(0.93, 0.89, 0.8);
const vec3 INK = vec3(0.1, 0.09, 0.08);
float hash21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float lineSet(vec2 q, float ang, float w) {
float l = abs(fract(dot(q, vec2(cos(ang), sin(ang)))) - 0.5) * 2.0;
float aa = 0.18;
return 1.0 - smoothstep(w - aa, w + aa, l);
}
// 0 = ink, 1 = paper. lum 0..1; ang the main stroke direction.
float engrave(float lum, float ang) {
vec2 q = gl_FragCoord.xy / (resolution.y / 240.0) / 3.2;
lum = clamp(lum, 0.0, 1.0);
float ink = lineSet(q, ang, clamp(0.95 - lum * 1.15, 0.0, 1.0));
ink = max(ink, lineSet(q, ang + 1.4, clamp(0.55 - lum * 1.3, 0.0, 1.0)));
ink = max(ink, lineSet(q * 1.3, ang - 0.7, clamp(0.3 - lum * 1.2, 0.0, 1.0)));
return 1.0 - ink;
}
// Paper with a little grain and a darker edge.
vec3 paper(vec2 st) {
float g = hash21(floor(gl_FragCoord.xy)) * 0.04;
float edge = smoothstep(0.75, 1.2, length((st - 0.5) * vec2(1.6, 1.2)));
return PAPER * (0.98 - g) * (1.0 - edge * 0.25);
}
vec3 ink(float paperAmount, vec2 st) { return mix(INK, paper(st), paperAmount); }
mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, s, -s, c); }
// Falling into a funnel of blocks, drawn as an engraving. No 3D at all: each pixel's angle round the hole and the
// logarithm of its distance from it are the coordinates of a flat wall of blocks (equal scales, so squares stay
// square: the log-polar map behind Escher's Print Gallery). Every ring is then a smaller copy of the one outside it,
// falling in is just sliding the wall outwards, and a twist makes it a spiral. Each block is its front face (picture
// frames, circuit mazes, ones and noughts) and its side, swept towards the hole as perspective would; the block
// nearer you is drawn over the one behind.
const float N = 13.0; // blocks round each ring
// The block in a cell: front (centre, half size), how far its side reaches towards the hole, and its kind
// (0: a picture frame, 1: a circuit board, 2: a deep open frame, 3: no block, just the wall behind).
struct Block { vec2 c; vec2 h; float depth; float kind; vec2 id; };
Block blockIn(vec2 cell) {
vec2 id = vec2(mod(cell.x, N), cell.y);
float h1 = hash21(id), h2 = hash21(id + 7.1), h3 = hash21(id + 13.7), h4 = hash21(id + 21.3);
vec2 h = vec2(mix(0.3, 0.45, h1), mix(0.28, 0.44, h2));
vec2 c = cell + vec2(cell.y * 0.5, 0.0) + 0.5 + (vec2(hash21(id + 3.3), hash21(id + 5.9)) - 0.5) * (1.0 - 2.0 * h) * 0.9;
float kind = h4 < 0.45 ? 0.0 : h4 < 0.7 ? 1.0 : h4 < 0.92 ? 2.0 : 3.0;
return Block(c, h, mix(0.2, 0.75, h3 * h3), kind, id);
}
// Which cell a point of the wall is in (each ring is staggered by half a block).
vec2 cellOf(vec2 w) { float y = floor(w.y); return vec2(floor(w.x - y * 0.5), y); }
// Engraved lines along the coordinate c, w wide (0..1 of their spacing), at any distance about five pixels apart,
// as an engraver would cut them: the spacing doubles or halves with distance, blending between the two nearest.
float lines(float c, float fw, float w) {
float l = abs(fract(c) - 0.5) * 2.0;
return (1.0 - smoothstep(w - fw, w + fw, l)) * smoothstep(0.0, 0.08, w); // no hairline at w = 0
}
float hatch(float c, float w) {
float fw = max(fwidth(c), 1e-6);
float lev = log2(1.0 / (5.0 * fw));
float l0 = floor(lev);
float s0 = exp2(l0), s1 = s0 * 2.0;
return mix(lines(c * s0, fw * s0, w), lines(c * s1, fw * s1, w), lev - l0);
}
// A circuit maze on a face (uv -1..1): traces from each cell's middle to some of its sides, and pads.
float maze(vec2 uv, vec2 id, float px) {
const float G = 6.0;
vec2 g = (uv * 0.5 + 0.5) * G;
vec2 cell = floor(g), f = fract(g) - 0.5;
float h = hash21(cell + id * 17.0);
float d = 1e9;
if (h < 0.55) d = min(d, max(abs(f.y), f.x < 0.0 ? 0.0 : f.x));
if (fract(h * 7.0) < 0.5) d = min(d, max(abs(f.x), f.y > 0.0 ? 0.0 : -f.y));
if (fract(h * 13.0) < 0.3) d = min(d, max(abs(f.y), f.x > 0.0 ? 0.0 : -f.x));
if (fract(h * 29.0) < 0.22) d = min(d, max(abs(f.x), abs(f.y)) - 0.12);
float w = 0.07, aa = px * G * 0.5;
return (1.0 - smoothstep(w - aa, w + aa, d)) * step(max(abs(uv.x), abs(uv.y)), 0.95);
}
// Rows of ones and noughts.
float binary(vec2 uv, vec2 id, float px) {
vec2 g = (uv * 0.5 + 0.5) * vec2(7.0, 4.0);
vec2 cell = floor(g), f = fract(g) - 0.5;
float d = hash21(cell + id * 31.0) > 0.5 ? max(abs(f.x) - 0.05, abs(f.y) - 0.3) : abs(length(f * vec2(1.7, 1.0)) - 0.25);
float aa = px * 7.0 * 0.5;
return (1.0 - smoothstep(0.06 - aa, 0.06 + aa, d)) * step(max(abs(uv.x), abs(uv.y)), 0.9);
}
// A square outline (half size h) at distance about a pixel and a half wide.
float outline(vec2 q, vec2 h, float px) {
vec2 d = abs(q) - h;
float e = abs(max(d.x, d.y));
return 1.0 - smoothstep(px * 0.7, px * 1.6, e);
}
void main() {
vec2 st = gl_FragCoord.xy / resolution;
vec2 p = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y - vec2(0.03, -0.1); // the hole, a little low
float r = length(p);
// The wall's coordinates: round the hole, and out from it (log), on the same scale; sliding outwards with time.
vec2 w = vec2(atan(p.y, p.x) / 6.2832 * N, log(r) / 6.2832 * N - time * speed);
w.x += w.y * twist + time * 0.05;
float px = fwidth(w.y); // one pixel, in wall units
// The nearest thing at this point: a block's front, a block's side (from this cell or the rings outside it,
// whose sides reach in over this one), or the wall behind.
float what = 0.0; // 0 wall, 1 front, 2 side
Block b;
vec2 q;
for (int k = 2; k >= 0; k--) {
vec2 probe = w + vec2(0.0, float(k));
vec2 cell = cellOf(probe);
for (int j = -1; j <= 1; j++) {
Block c = blockIn(cell + vec2(float(j), 0.0));
if (c.kind > 2.5) continue;
vec2 d = w - c.c;
d.x -= floor((d.x + N * 0.5) / N) * N; // round the ring
if (abs(d.x) < c.h.x && d.y < c.h.y && d.y > -c.h.y - c.depth) {
// Nearer blocks (further out) win: rings outside first, so the first found stays.
if (what == 0.0) { what = d.y > -c.h.y ? 1.0 : 2.0; b = c; q = d; }
}
}
}
float ink = 0.0;
if (what == 1.0) {
// The front: paper, outlined; a frame (border, a recessed panel with hatching, a smaller raised square),
// a circuit board, or a deep frame you look into.
vec2 inner = b.h * (b.kind == 2.0 ? 0.62 : 0.72);
ink = outline(q, b.h, px);
if (b.kind == 1.0) ink = max(ink, maze(q / (b.h * 0.9), b.id, px / b.h.x));
else {
ink = max(ink, outline(q, inner, px));
bool inPanel = abs(q.x) < inner.x && abs(q.y) < inner.y;
if (inPanel) {
// The recess's walls: the top and right in shadow, hatched; the floor lighter.
vec2 t = (abs(q) - inner * 0.82) / (inner * 0.18);
bool wall = max(t.x, t.y) > 0.0;
float shade = b.kind == 2.0 ? 0.25 : wall ? (q.y > 0.0 || q.x > 0.0 ? 0.35 : 0.8) : 0.85;
ink = max(ink, hatch(wall ? q.y * 3.0 + q.x : w.y * 4.0, clamp((0.88 - shade) * 1.1, 0.0, 0.9)));
ink = max(ink, outline(q, inner * 0.82, px));
if (b.kind == 0.0) {
float sel = hash21(b.id + 41.0);
vec2 pu = q / (inner * 0.82);
if (sel < 0.35) ink = max(ink, outline(q, inner * 0.4, px));
else if (sel < 0.6) ink = max(ink, maze(pu, b.id, px / inner.x));
else if (sel < 0.75) ink = max(ink, binary(pu, b.id, px / inner.x));
} else {
// Deep frames: nested squares going down into the dark.
for (int i = 1; i <= 3; i++) ink = max(ink, outline(q, inner * (0.82 - 0.2 * float(i)), px));
}
}
}
} else if (what == 2.0) {
// The side, swept towards the hole: dark, engraved along its length, darker deeper in.
float along = (-q.y - b.h.y) / b.depth; // 0 at the front's edge, 1 at the far end
float shade = mix(0.42, 0.18, along);
ink = hatch(q.x * 2.0 + q.y * 0.15, clamp((0.88 - shade) * 1.1, 0.0, 0.9));
ink = max(ink, hatch(q.y * 3.0, clamp((0.45 - shade) * 1.3, 0.0, 0.9)));
ink = max(ink, 1.0 - smoothstep(px * 0.7, px * 1.6, abs(abs(q.x) - b.h.x))); // its edges
} else {
// The wall behind the blocks: deep, dark rings.
ink = max(hatch(w.y * 3.0, 0.75), 0.55);
}
vec3 col = mix(paper(st), INK, ink);
// Down the hole: into the dark (where the rings are smaller than the pen).
col = mix(col, INK, 1.0 - smoothstep(0.015, 0.11, r));
fragColor = vec4(col, 1.0);
}More Art & illusions examples
Metamorphosis (after Escher) · Möbius ants (after Escher) · Mirror sphere (after Escher) · Relativity (after Escher)