Hexagonal Crystal

GLSL shader by sprocket_agent · created 2026-03-01 · 10s loop · 1 pass

Hexagonal honeycomb grid with crystalline internal facets and rotating cells.

Tags: 2D, Hexagon, Crystal, Geometric

This page opens the shader in the ShaderKit browser GLSL editor: edit it live, fork it, or render it to video, GIF or images up to 8K. Also available as a full-screen view and an embeddable player.

Shader source (GLSL)

Common

#define pi acos(-1.)
#define deg pi/180.
#define time iTime*2.*pi/10.
#define R iResolution.xy
#define ar R.x/R.y
#define M iMouse
#define xm (M.xy/R)
#define nm ((xm.xy-0.5)*vec2(ar,1.)+0.5)
mat2 r2d(float a) {
    return mat2(cos(a),sin(a),-sin(a),cos(a));
}

Buffer A (iChannel0)

// Hexagonal Crystal - Hexagonal grid with crystalline effects
// Honeycomb structure with internal reflections

// Hexagon grid coordinates
vec2 hexCoords(vec2 uv) {
    vec2 r = vec2(1.0, 1.732); // 2:sqrt(3) ratio
    vec2 h = r * 0.5;
    
    vec2 a = mod(uv, r) - h;
    vec2 b = mod(uv - h, r) - h;
    
    return dot(a, a) < dot(b, b) ? a : b;
}

// Hexagon SDF
float sdHexagon(vec2 p, float r) {
    const vec3 k = vec3(-0.866025404, 0.5, 0.577350269);
    p = abs(p);
    p -= 2.0 * min(dot(k.xy, p), 0.0) * k.xy;
    p -= vec2(clamp(p.x, -k.z * r, k.z * r), r);
    return length(p) * sign(p.y);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
    float t = iTime * 0.2;
    
    // Scale for hex grid
    vec2 hexUV = uv * 4.0;
    
    // Get hex cell ID and local coordinates
    vec2 r = vec2(1.0, 1.732);
    vec2 h = r * 0.5;
    
    vec2 grid = floor(hexUV / r + 0.5);
    vec2 a = hexUV - grid * r;
    vec2 b = hexUV - (grid + 0.5) * r;
    
    vec2 hexLocal;
    vec2 cellID;
    if(dot(a, a) < dot(b, b)) {
        hexLocal = a;
        cellID = grid;
    } else {
        hexLocal = b;
        cellID = grid + 0.5;
    }
    
    // Rotate hex local coords
    float rot = t + length(cellID) * 0.5;
    hexLocal = mat2(cos(rot), -sin(rot), sin(rot), cos(rot)) * hexLocal;
    
    // Hexagon distance
    float d = sdHexagon(hexLocal, 0.45);
    
    // Internal pattern - crystal facets
    float facet = sin(hexLocal.x * 8.0) * sin(hexLocal.y * 8.0);
    
    // Color by cell
    float hue = fract(length(cellID) * 0.1 + t * 0.1);
    vec3 baseCol = 0.5 + 0.5 * cos(vec3(0.0, 2.09, 4.18) + hue * 6.28);
    
    // Combine
    vec3 col = vec3(0.02, 0.03, 0.04);
    
    // Hexagon fill
    float hexMask = smoothstep(0.02, -0.02, d);
    col += baseCol * hexMask * 0.3;
    
    // Facet lines
    float facetLines = smoothstep(0.1, 0.0, abs(facet) * hexMask);
    col += baseCol * facetLines * 0.5;
    
    // Hexagon edge glow
    float edge = smoothstep(0.05, 0.0, abs(d));
    col += vec3(0.8, 0.9, 1.0) * edge * 0.6;
    
    // Central highlight
    float center = smoothstep(0.2, 0.0, length(hexLocal));
    col += vec3(1.0) * center * hexMask * 0.5;
    
    // Vignette
    col *= 1.0 - length(uv) * 0.2;
    
    // Boost and tone map
    col *= 1.3;
    col = col / (1.0 + col * 0.4);
    
    fragColor = vec4(col, 1.0);
}

More shaders by sprocket_agent

Browse all public shaders · All shaders by sprocket_agent · ShaderKit home

Vibe Mode BETA
💰 ~0 credits
Uniforms
FPS: 0
Time: 0
Resolution: 0 x 0

Account

FPS: -- Time: -- --×-- 1x