Tesseract
glint · Examples · Tutorials · Gallery
A four-dimensional cube: its 16 corners rotated in the xw and zw planes, projected to 3D with perspective in w, then to the screen. Its 32 edges are the corner pairs that differ in one coordinate.

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;
in vec2 v_texcoord;
out vec4 fragColor;
float hash(float n) { return fract(sin(n * 127.1) * 43758.5453); }
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
vec2 hash2(float n) { return fract(sin(vec2(n * 127.1, n * 269.5)) * 43758.5453); }
mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, s, -s, c); }
vec3 pal(float t) { return 0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.33, 0.67))); }
float segment(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a, ba = b - a;
return length(pa - ba * clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0));
}
vec4 corner(int i) { return vec4(float(i & 1), float((i >> 1) & 1), float((i >> 2) & 1), float((i >> 3) & 1)) * 2.0 - 1.0; }
vec3 project4(vec4 v) {
float a = time * 0.5, b = time * 0.3;
v.xw = mat2(cos(a), sin(a), -sin(a), cos(a)) * v.xw;
v.zw = mat2(cos(b), sin(b), -sin(b), cos(b)) * v.zw;
vec3 p = v.xyz / (3.0 - v.w); // 4D -> 3D
p.xz = mat2(cos(time * 0.2), sin(time * 0.2), -sin(time * 0.2), cos(time * 0.2)) * p.xz;
p.yz = mat2(cos(0.4), sin(0.4), -sin(0.4), cos(0.4)) * p.yz;
return vec3(p.xy / (2.5 - p.z) * 1.4, p.z); // 3D -> 2D
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
vec3 col = vec3(0.02, 0.02, 0.04);
float px = 1.5 / resolution.y;
for (int i = 0; i < 16; i++) {
vec3 a = project4(corner(i));
for (int bit = 0; bit < 4; bit++) {
int j = i ^ (1 << bit);
if (j < i) continue;
vec3 b = project4(corner(j));
float d = segment(uv, a.xy, b.xy);
col += pal(float(bit) * 0.25 + 0.1) * (smoothstep(px * 1.5, 0.0, d) + 0.002 / (d + 0.004)) * (0.6 + 0.4 * (a.z + b.z));
}
col += vec3(1.0) * smoothstep(0.012, 0.008, length(uv - a.xy));
}
fragColor = vec4(1.0 - exp(-col), 1.0);
}More More GLSL examples
Snowflakes · Maurer rose · Spirograph · Field lines · Black hole · Low poly · 10 PRINT · Invaders