Voronoi Celadon Crackle Glaze shader

voronoi-celadon-crackle-glaze.glsl · 823 lines · GLSL ES 3.00 · MIT

Voronoi Celadon Crackle GlazeSci-Fi & Noise
Voronoi Celadon Crackle Glaze WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 823 linesSPEC GLSL ES 3.00

Seamless PNG Texture Baker
1-Click Engine Shader Export
WebGL2 .glsl
.glsl
Godot 4 .gdshader
Three.js GLSL3

Engine shader code & wrappers

Cellular & Ripple Fields
voronoi-celadon-crackle-glaze.glsl (823 lines)
#version 300 es
// Voronoi Celadon Crackle Glaze (voronoi-celadon-crackle-glaze.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ceramics/lib/01_crazed_celadon_crackle_glaze.glsl
// License: MIT (Copyright 2026 Gokay Aydogan) + MIT/CC0 helpers — https://pixelfx.io/LICENSE-SHADERS.txt
// Uniforms: uResolution (vec2), uTime (float), uOpen (0..1), uLightMode (0..3), uCamMode (0..1)
// Study 01: Crazed Celadon Crackle Glaze (Guan / Longquan Stoneware)
// 3D hollow wheel-thrown celadon stoneware bowl specimen with beveled stratified
// cutaway (exposing buff stoneware clay core + thick translucent jade-green glaze
// layer) and unglazed iron-toasted foot-ring grounded on a studio bench. Thick
// vitreous celadon glaze pools deeper in concave curves and throwing-rib troughs,
// with a two-generation Voronoi tension-crack network stained by dark iron/tea
// oxide and true 5-slice internal parallax depth through the glaze layer.
// uOpen (0..1) increases craze staining and secondary/tertiary crack density.
precision highp float;
precision highp int;

uniform vec2 uResolution;
uniform float uTime;
uniform float uOpen;
uniform int uLightMode;
uniform int uCamMode;

out vec4 fragColor;

const float PI  = 3.14159265;
const float FAR = 18.0;

float sq(float x) { return x * x; }
float sat(float x) { return clamp(x, 0.0, 1.0); }
vec3 sat(vec3 x) { return clamp(x, 0.0, 1.0); }
mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, s, -s, c); }

// Register-only hashes (no sine, no local arrays)
float hash12(vec2 p) {
    vec3 p3 = fract(vec3(p.xyx) * 0.1031);
    p3 += dot(p3, p3.yzx + 33.33);
    return fract((p3.x + p3.y) * p3.z);
}

vec2 hash22(vec2 p) {
    vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
    p3 += dot(p3, p3.yzx + 33.33);
    return fract((p3.xx + p3.yz) * p3.zy);
}

float hash13(vec3 p) {
    uvec3 k = uvec3(ivec3(floor(p)));
    uint v = (k.x * 2246822519u) ^ (k.y * 3266489917u) ^ (k.z * 668265263u);
    v = (v ^ (v >> 13u)) * 2246822519u;
    return float(v >> 8u) / 16777216.0;
}

float vnoise(vec2 p) {
    vec2 i = floor(p);
    vec2 f = p - i;
    vec2 u = f * f * (3.0 - 2.0 * f);
    float a = hash12(i);
    float b = hash12(i + vec2(1.0, 0.0));
    float c = hash12(i + vec2(0.0, 1.0));
    float d = hash12(i + vec2(1.0, 1.0));
    return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}

float fbm2(vec2 p) {
    float s = 0.0;
    float a = 0.5;
    mat2 m = mat2(0.80, 0.60, -0.60, 0.80);
    for (int i = 0; i < 4; i++) {
        s += a * vnoise(p);
        p = m * p * 2.03 + vec2(13.7, 29.1);
        a *= 0.5;
    }
    return s;
}

float smin(float a, float b, float k) {
    float h = max(k - abs(a - b), 0.0) / max(k, 1e-5);
    return min(a, b) - h * h * k * 0.25;
}

float smax(float a, float b, float k) {
    return -smin(-a, -b, k);
}

// Smooth circular jittered dot field (zero grid-square artifacts)
float roundSpeck(vec2 p, float density, float rad) {
    vec2 ip = floor(p);
    vec2 fp = p - ip;
    float h = hash12(ip);
    vec2 ctr = 0.22 + 0.56 * hash22(ip + vec2(17.3, 9.1));
    float d = length(fp - ctr);
    return smoothstep(rad, rad * 0.25, d) * smoothstep(1.0 - density, 1.0 - density + 0.08, h);
}

// Parametric state: uOpen (0..1) increases craze staining & crack density
float stateOpen() {
    float drift = (uTime != 0.0) ? 0.015 * sin(uTime * 0.9) : 0.0;
    return sat(uOpen + drift);
}

// Exact Voronoi edge distance: returns vec3(edgeDist, cellHash, distToSite)
vec3 voronoiCrack(vec2 x) {
    vec2 n = floor(x);
    vec2 f = x - n;

    vec2 mr = vec2(0.0);
    vec2 mg = vec2(0.0);
    float md = 8.0;

    for (int j = -1; j <= 1; j++) {
        for (int i = -1; i <= 1; i++) {
            vec2 g = vec2(float(i), float(j));
            vec2 o = hash22(n + g);
            vec2 r = g + 0.14 + 0.72 * o - f;
            float d = dot(r, r);
            if (d < md) {
                md = d;
                mr = r;
                mg = g;
            }
        }
    }

    float edge = 8.0;
    for (int j = -1; j <= 1; j++) {
        for (int i = -1; i <= 1; i++) {
            vec2 g = mg + vec2(float(i), float(j));
            vec2 o = hash22(n + g);
            vec2 r = g + 0.14 + 0.72 * o - f;
            vec2 dr = r - mr;
            float dr2 = dot(dr, dr);
            if (dr2 > 1e-5) {
                float d = 0.5 * (dot(r, r) - md) * inversesqrt(dr2);
                edge = min(edge, d);
            }
        }
    }

    float cid = hash12(n + mg);
    return vec3(max(edge, 0.0), cid, sqrt(max(md, 0.0)));
}

// Two-generation tension-crack network in glaze surface coordinates
// x = primary crack dist ("tiexian"), y = secondary crack dist ("jinsi"), z/w = cell hashes
vec4 crazeNetwork(vec2 uv) {
    vec2 warp = vec2(
        vnoise(uv * 2.1 + vec2(4.2, 1.7)) - 0.5,
        vnoise(uv * 2.1 + vec2(9.6, 6.3)) - 0.5
    ) * 0.13;
    vec2 q = uv + warp;

    // Generation 1: coarse primary tension polygons
    vec3 v1 = voronoiCrack(q * 3.25);

    // Generation 2: finer secondary craze network subdividing primary plates
    vec2 q2 = rot2(0.52) * q * 7.1 + vec2(v1.y * 5.7, v1.y * 3.1);
    vec2 w2 = vec2(
        vnoise(q2 * 0.65 + 2.3) - 0.5,
        vnoise(q2 * 0.65 + 7.9) - 0.5
    ) * 0.16;
    vec3 v2 = voronoiCrack(q2 + w2);

    return vec4(v1.x, v2.x, v1.y, v2.y);
}

// Exterior glaze drip-line height as a function of azimuth
float exteriorGlazeLine(float ang) {
    float w1 = 0.016 * sin(ang * 5.0 + 0.7);
    float w2 = 0.010 * cos(ang * 11.0 - 1.3);
    float w3 = 0.007 * sin(ang * 19.0 + 2.4);
    float drip = -0.022 * pow(sat(0.5 + 0.5 * sin(ang * 4.0 - 0.9)), 6.0)
                 -0.015 * pow(sat(0.5 + 0.5 * sin(ang * 7.0 + 1.8)), 8.0);
    return 0.155 + w1 + w2 + w3 + drip;
}

// Hollow wheel-thrown Song celadon bowl outer profile radius R_out(y) for y in [0.08, 0.58]
float bowlOuterR(float y) {
    float t = sat((y - 0.08) / 0.50);
    return 0.55 + 0.50 * pow(max(t, 1e-4), 0.54) - 0.02 * t * t;
}

// Bowl wall thickness (clay + glaze) tapering smoothly from foot toward rim
float bowlWallThick(float y) {
    float t = sat((y - 0.08) / 0.50);
    return mix(0.095, 0.068, t);
}

// Interior concave well floor height y_floor(r)
float bowlFloorY(float r) {
    return 0.155 + 0.065 * sq(sat(r / 0.62));
}

// Clean angled cutaway plane on front-right quadrant to expose hollow bowl wall cross-section
// Positive = removed wedge
float cutawayPlane(vec3 p) {
    vec2 cutN = normalize(vec2(0.56, 0.83));
    return dot(p.xz, cutN) - 0.38;
}

// Local glaze thickness (in world units: thin over rim lip, thick pooled in concave well & drip welt)
float glazeThicknessAt(vec3 p) {
    float r = length(p.xz);
    float ang = atan(p.z, p.x + 1e-7);

    // Concave interior well pooling (thickest around interior floor & lower wall curve)
    float rIn = bowlOuterR(clamp(p.y, 0.08, 0.58)) - bowlWallThick(clamp(p.y, 0.08, 0.58));
    float inWell = smoothstep(0.05, -0.02, r - rIn - 0.04) * smoothstep(0.52, 0.22, p.y);
    float wellPool = (0.028 * exp(-sq((r - 0.36) / 0.38)) + 0.016 * exp(-sq(r / 0.32))) * (0.45 + 0.55 * inWell);

    // Rim thinning: molten glaze draws back slightly over the rounded rim lip
    float rimDist = length(vec2(r - 0.995, p.y - 0.565));
    float rimThin = smoothstep(0.015, 0.14, rimDist);

    // Subtle pooling in throwing-rib troughs
    float ribTrough = 0.004 * (0.5 - 0.5 * sin(r * 38.0 + p.y * 48.0));

    // Thick pooling exterior glaze welt bead right above the unglazed foot
    float gLine = exteriorGlazeLine(ang);
    float extWelt = 0.016 * exp(-sq((p.y - (gLine + 0.028)) / 0.036)) * smoothstep(0.55, 0.78, r);

    return clamp((0.012 + wellPool + ribTrough + extWelt) * (0.38 + 0.62 * rimThin), 0.009, 0.056);
}

// Seamless surface UV parameterization for crackle across interior well, rim & exterior belly
vec2 celadonSurfaceUV(vec3 p) {
    float r = length(p.xz);
    float s = 1.0 + 0.32 * smoothstep(0.42, 1.04, r) + 0.52 * max(0.0, p.y - 0.15);
    return p.xz * s;
}

// Distance-only hollow celadon bowl + unglazed foot-ring + beveled cutaway SDF
// Returns vec2(dist, matId)
// matId:
//   1.0 = glazed celadon surface (concave interior well, rounded rim, glazed exterior belly)
//   2.0 = unglazed stoneware foot-ring & lower base
//   3.0 = beveled cutaway cross-section (stratified clay core + thick glaze layer)
vec2 mapScene(vec3 p) {
    float r = length(p.xz);
    float ang = atan(p.z, p.x + 1e-7);

    float yClamped = clamp(p.y, 0.08, 0.58);
    float rOut = bowlOuterR(yClamped);
    float wallT = bowlWallThick(yClamped);
    float rIn = rOut - wallT;

    // Subtle concentric wheel-throwing ribs on exterior and interior walls
    float ribExt = 0.0032 * sin(p.y * 54.0 + 0.5 * sin(ang * 2.0)) * smoothstep(0.15, 0.25, p.y) * smoothstep(0.57, 0.48, p.y);
    float ribInt = 0.0028 * sin(r * 42.0 + p.y * 28.0) * smoothstep(0.08, 0.22, r) * smoothstep(0.98, 0.84, r);

    // Thick pooling glaze welt bead along exterior glaze terminus
    float gLine = exteriorGlazeLine(ang);
    float glazeMaskExt = smoothstep(gLine - 0.008, gLine + 0.014, p.y);
    float weltBead = 0.013 * exp(-sq((p.y - (gLine + 0.022)) / 0.024)) * smoothstep(0.48, 0.66, r);
    float glazeStep = 0.008 * glazeMaskExt + weltBead;

    // --- 1. Solid outer bowl hull ---
    float dOuterWall = (r - (rOut + ribExt + glazeStep)) * 0.78;
    float dTopRim    = p.y - 0.58;
    float dBodyBot   = 0.075 - p.y;
    float dHull      = smax(dOuterWall, dTopRim, 0.030);
    dHull            = smax(dHull, dBodyBot, 0.028);

    // --- 2. Carve out the HOLLOW concave interior bowl cavity ---
    // Air cavity is { r < rIn AND p.y > yFloor }.
    // Smooth union of cavity boundaries: negative inside solid wall/floor, positive inside hollow air!
    float yFloor = bowlFloorY(r) + ribInt;
    float dFromInnerWall = (rIn - ribInt - r) * 0.78; // > 0 inside hollow cavity
    float dFromFloor     = (p.y - yFloor) * 0.86;     // > 0 above interior floor
    float dCarveAir      = smin(dFromInnerWall, dFromFloor, 0.14); // smooth concave interior bowl curve!
    float dBowl          = smax(dHull, dCarveAir, 0.028); // rounded lip where rim meets interior wall

    // --- 3. Unglazed stoneware foot-ring grounded on studio bench (y = 0) ---
    float dFootRad   = abs(r - 0.525) - 0.056;
    float dFootY     = max(-p.y + 0.002, p.y - 0.115);
    float dFoot      = smax(dFootRad, dFootY, 0.012);
    float dUnderBase = max(r - 0.50, max(0.055 - p.y, p.y - 0.125));
    float dFootAll   = smin(dFoot, dUnderBase, 0.014);

    float dVessel = smin(dBowl, dFootAll, 0.016);

    // --- 4. Beveled cutaway slice exposing the hollow U-shaped wall cross-section ---
    float dCut = cutawayPlane(p);
    float dFinal = smax(dVessel, dCut, 0.008);

    // --- 5. Subtle 3D meso-relief for primary craze crack seams on glazed surface ---
    float isCut = smoothstep(-0.014, -0.001, dCut - dVessel);
    bool onFoot = (p.y < gLine + 0.004) && (dCarveAir < -0.035);
    float nearSurf = smoothstep(0.055, 0.01, abs(dFinal));
    if (nearSurf > 0.001 && isCut < 0.5 && !onFoot) {
        vec2 cUV = celadonSurfaceUV(p);
        vec4 cr = crazeNetwork(cUV);
        float primarySeam = 1.0 - smoothstep(0.0, 0.030, cr.x);
        float plateDome = smoothstep(0.0, 0.16, cr.x);
        dFinal += (0.0024 * primarySeam - 0.0007 * plateDome) * nearSurf;
    }

    // Material ID classification
    float matId = 1.0;
    if (dCut > dVessel - 0.007) {
        matId = 3.0; // Beveled stratified cutaway cross-section
    } else if (p.y < gLine && dCarveAir < -0.03) {
        matId = 2.0; // Unglazed stoneware foot-ring & base
    }

    return vec2(dFinal * 0.72, matId);
}

float mapDist(vec3 p) {
    return mapScene(p).x;
}

vec3 calcNormal(vec3 p, float t) {
    float eps = max(0.00058, 0.00028 * t);
    vec2 e = vec2(1.0, -1.0) * 0.57735027 * eps;
    return normalize(
        e.xyy * mapDist(p + e.xyy) +
        e.yyx * mapDist(p + e.yyx) +
        e.yxy * mapDist(p + e.yxy) +
        e.xxx * mapDist(p + e.xxx)
    );
}

vec2 trace(vec3 ro, vec3 rd, float maxT) {
    float t = 0.01;
    for (int i = 0; i < 160; i++) {
        vec3 p = ro + rd * t;
        vec2 h = mapScene(p);
        float hitEps = max(0.00038, 0.00024 * t);
        if (h.x < hitEps) {
            return vec2(t, h.y);
        }
        t += max(0.00038, h.x);
        if (t > maxT) break;
    }
    return vec2(maxT, -1.0);
}

float softShadow(vec3 p, vec3 l, float maxT) {
    float t = 0.014;
    float res = 1.0;
    for (int i = 0; i < 36; i++) {
        float h = mapDist(p + l * t);
        res = min(res, clamp(6.0 * h / max(t, 1e-4), 0.04, 1.0));
        if (res < 0.045) break;
        t += clamp(h * 0.85, 0.009, 0.18);
        if (t > maxT) break;
    }
    return res;
}

float calcAO(vec3 p, vec3 n) {
    float ao = 1.0;
    for (int i = 1; i <= 4; i++) {
        float h = 0.020 * float(i * i);
        float d = mapDist(p + n * h);
        ao -= max(0.0, h - d) / max(h, 1e-4) * (0.24 / float(i));
    }
    return clamp(ao, 0.14, 1.0);
}

// Analytical studio contact shadow under foot-ring & overhanging bowl belly
float groundContactShadow(vec3 p, vec3 keyDir) {
    float r = length(p.xz);
    float dCut = cutawayPlane(p);
    float footD = max(r - 0.59, dCut);
    float contact = smoothstep(-0.03, 0.08, footD);

    vec2 shift = -keyDir.xz * 0.22;
    vec3 ps = vec3(p.x - shift.x, 0.0, p.z - shift.y);
    float bowlD = max(length(ps.xz) - 1.04, cutawayPlane(ps));
    float canopy = smoothstep(-0.14, 0.42, bowlD);

    return (0.18 + 0.82 * contact) * (0.48 + 0.52 * canopy);
}

// Procedural studio environment with crisp softboxes & strong negative-fill flags
vec3 studioSky(vec3 d, vec3 p, float rough) {
    float neutral = (uLightMode == 1) ? 1.0 : 0.0;

    vec3 baseLow  = mix(vec3(0.022, 0.026, 0.032), vec3(0.032), neutral);
    vec3 baseHigh = mix(vec3(0.16, 0.19, 0.22), vec3(0.20), neutral);
    vec3 c = mix(baseLow, baseHigh, smoothstep(-0.20, 0.85, d.y));

    vec3 a = normalize(d + vec3(0.06 * p.x, 0.02 * p.y, 0.06 * p.z));
    vec2 uv = a.xz / max(0.15, a.y);
    float blur = 0.032 + rough * 0.85;
    float above = smoothstep(0.03, 0.22, a.y);

    // Tighter high-contrast studio softboxes + black negative-fill flags for crisp vitreous modeling
    float keyPanel = 1.0 - smoothstep(-blur, blur, max(abs(uv.x + 0.54) - 0.46, abs(uv.y + 0.22) - 0.64));
    float rimStrip = 1.0 - smoothstep(-blur, blur, max(abs(uv.x - 1.24) - 0.15, abs(uv.y - 0.22) - 1.44));
    float negFlag1 = 1.0 - smoothstep(-blur, blur, max(abs(uv.y - 1.28) - 0.30, abs(uv.x) - 1.75));
    float negFlag2 = 1.0 - smoothstep(-blur, blur, max(abs(uv.x - 0.38) - 0.24, abs(uv.y + 0.08) - 1.15));

    float az = atan(a.z, a.x + 1e-7);
    float sideWin = exp(-sq((az + 0.96) / (0.08 + rough * 0.48))) *
                    smoothstep(-0.55, -0.10, a.y) * (1.0 - smoothstep(0.45, 0.80, a.y));

    vec3 keyCol = mix(vec3(2.25, 2.14, 1.98), vec3(1.95), neutral);
    vec3 rimCol = mix(vec3(1.38, 1.62, 1.98), vec3(1.52), neutral);
    vec3 winCol = mix(vec3(1.20, 1.28, 1.38), vec3(1.22), neutral);

    if (uLightMode == 2) {
        keyPanel *= 0.20;
        sideWin *= 2.6;
    } else if (uLightMode == 3) {
        keyPanel *= 0.15;
        rimStrip *= 2.3;
        c *= 0.42;
    }

    c += winCol * sideWin * 0.68;
    float flagAtten = (1.0 - 0.86 * negFlag1 * above) * (1.0 - 0.72 * negFlag2 * above);
    return c * flagAtten + above * (keyCol * keyPanel + rimCol * rimStrip);
}

// GGX microfacet specular
float ggxSpec(vec3 n, vec3 v, vec3 l, float rough) {
    vec3 h = normalize(v + l);
    float ndl = max(dot(n, l), 0.0);
    float ndv = max(dot(n, v), 0.01);
    float ndh = max(dot(n, h), 0.0);
    float a2 = max(0.0018, pow(max(rough, 0.032), 4.0));
    float denom = PI * sq(ndh * ndh * (a2 - 1.0) + 1.0);
    return min(7.0, (a2 / max(denom, 1e-5)) * ndl / max(4.0 * (ndl + 0.12) * (ndv + 0.12), 1e-4));
}

void getLightRig(vec3 p, out vec3 keyDir, out vec3 keyCol, out vec3 fillDir, out vec3 fillCol, out vec3 rimDir, out vec3 rimCol) {
    if (uLightMode == 1) {
        keyDir  = normalize(vec3(-2.4, 3.6, 2.0) - p * 0.2);
        keyCol  = vec3(1.25);
        fillDir = normalize(vec3(2.8, 1.7, 0.8));
        fillCol = vec3(0.32);
        rimDir  = normalize(vec3(0.6, 1.9, -2.9));
        rimCol  = vec3(0.45);
    } else if (uLightMode == 2) {
        keyDir  = normalize(vec3(-3.8, 0.85, 0.65));
        keyCol  = vec3(1.65, 1.52, 1.35);
        fillDir = normalize(vec3(2.4, 1.1, 1.4));
        fillCol = vec3(0.14, 0.17, 0.22);
        rimDir  = normalize(vec3(1.2, 0.9, -2.8));
        rimCol  = vec3(0.32, 0.38, 0.46);
    } else if (uLightMode == 3) {
        keyDir  = normalize(vec3(-1.0, 1.35, -3.4));
        keyCol  = vec3(1.90, 1.72, 1.48);
        fillDir = normalize(vec3(-1.8, 2.2, 2.4));
        fillCol = vec3(0.15, 0.18, 0.22);
        rimDir  = normalize(vec3(2.4, 1.2, -2.5));
        rimCol  = vec3(1.15, 1.30, 1.48);
    } else {
        keyDir  = normalize(vec3(-2.3, 3.4, 2.1) - p * 0.2);
        keyCol  = vec3(1.30, 1.22, 1.10);
        fillDir = normalize(vec3(2.8, 1.7, 0.7));
        fillCol = vec3(0.26, 0.34, 0.42);
        rimDir  = normalize(vec3(0.7, 1.8, -3.0));
        rimCol  = vec3(0.52, 0.62, 0.70);
    }
}

// Shade unglazed iron-toasted stoneware clay (foot-ring & stratified cutaway core)
vec3 shadeStoneware(vec3 p, vec3 n, vec3 v, vec3 keyDir, vec3 keyCol, vec3 fillDir, vec3 fillCol, vec3 rimDir, vec3 rimCol, float sh, float ao, float gLine, bool isCutCore) {
    // Tier 3: fwidth-filtered round quartz grog & iron specks (no grid squares)
    vec2 grogUV = vec2(atan(p.z, p.x + 1e-7) * 7.5, p.y * 15.0) + p.xz * 11.0;
    float fwGrog = min(fwidth(grogUV.x) + fwidth(grogUV.y), 4.0);
    float grogFilter = 1.0 - smoothstep(0.35, 1.6, fwGrog);

    float clayGrain = fbm2(p.xz * 18.0 + p.y * 22.0);
    float grogSpeck = roundSpeck(grogUV * 12.0, 0.26, 0.26) * grogFilter;
    float darkIron  = roundSpeck(grogUV * 8.5 + vec2(17.3, 5.1), 0.18, 0.22) * grogFilter;

    // Pale gray-buff stoneware core on cutaway, warmer kiln-toasted buff on exterior foot
    vec3 clay = isCutCore
        ? mix(vec3(0.46, 0.43, 0.38), vec3(0.56, 0.52, 0.46), clayGrain)
        : mix(vec3(0.38, 0.32, 0.27), vec3(0.48, 0.41, 0.34), clayGrain);

    // Kiln-toasted iron-oxide flash ("huoshihong") just below the exterior glaze terminus
    if (!isCutCore) {
        float flashBand = exp(-sq((p.y - (gLine - 0.016)) / 0.032));
        clay = mix(clay, vec3(0.54, 0.27, 0.14), 0.68 * flashBand);
    }
    clay = mix(clay, vec3(0.68, 0.64, 0.58), 0.32 * grogSpeck);
    clay = mix(clay, vec3(0.14, 0.10, 0.08), 0.52 * darkIron);

    vec3 t1 = normalize(cross(n, vec3(0.0, 1.0, 0.01)));
    vec3 t2 = cross(n, t1);
    float gn1 = (vnoise(grogUV * 11.0) - 0.5) * grogFilter;
    float gn2 = (vnoise(grogUV * 11.0 + 5.4) - 0.5) * grogFilter;
    n = normalize(n + 0.09 * (gn1 * t1 + gn2 * t2));

    if (uLightMode == 1) {
        clay = vec3(isCutCore ? 0.48 : 0.38) * (0.92 + 0.14 * clayGrain);
    }

    float ndl = max(dot(n, keyDir), 0.0);
    float ndf = max(dot(n, fillDir) * 0.5 + 0.5, 0.0);
    float ndr = max(dot(n, rimDir), 0.0);
    vec3 hemi = mix(vec3(0.045, 0.042, 0.040), vec3(0.14, 0.145, 0.155), 0.5 + 0.5 * n.y);
    if (uLightMode == 3) hemi *= 0.45;

    vec3 diff = clay * (keyCol * ndl * sh + fillCol * ndf * 0.52 + rimCol * ndr * 0.30 + hemi);
    float cosI = sat(dot(n, v));
    float F = 0.03 + 0.97 * pow(max(1.0 - cosI, 1e-5), 5.0);
    float spec = ggxSpec(n, v, keyDir, 0.68) * sh;
    vec3 env = studioSky(reflect(-v, n), p, 0.72) * 0.24;
    return max(vec3(0.0), ao * diff + F * (env + keyCol * spec * 0.35));
}

// Shade thick translucent celadon glaze with 5-slice parallax crackle & Beer-Lambert absorption
vec3 shadeCeladon(vec3 p, vec3 n, vec3 rd, float t, float matId) {
    vec3 v = -rd;
    vec3 keyDir, keyCol, fillDir, fillCol, rimDir, rimCol;
    getLightRig(p, keyDir, keyCol, fillDir, fillCol, rimDir, rimCol);

    float sh = softShadow(p + n * 0.003, keyDir, 2.8);
    float ao = calcAO(p, n);
    float open = stateOpen();
    float ang = atan(p.z, p.x + 1e-7);
    float gLine = exteriorGlazeLine(ang);

    // 2.0: Unglazed stoneware foot-ring
    if (matId > 1.5 && matId < 2.5) {
        return shadeStoneware(p, n, v, keyDir, keyCol, fillDir, fillCol, rimDir, rimCol, sh, ao, gLine, false);
    }

    // 3.0: Beveled stratified cutaway cross-section exposing buff stoneware core + thick jade glaze skin
    if (matId > 2.5) {
        float r = length(p.xz);
        float yClamped = clamp(p.y, 0.08, 0.58);
        float rOut = bowlOuterR(yClamped);
        float wallT = bowlWallThick(yClamped);
        float rIn = rOut - wallT;
        float yFloor = bowlFloorY(r);

        // Signed depth inward from the glazed surfaces (interior wall, interior floor, rim, glazed exterior)
        float dFromIntWall = max(0.0, r - rIn);
        float dFromFloor   = max(0.0, yFloor - p.y);
        float dFromInterior = (r < rIn + 0.14 && p.y < yFloor + 0.14)
            ? max(dFromIntWall, dFromFloor)
            : min(dFromIntWall, dFromFloor);
        // More exact interior distance to the hollow concave curve:
        float dIntSurf = max(0.0, -smin((rIn - r) * 0.78, (p.y - yFloor) * 0.86, 0.14));
        float dExtSurf = (p.y > gLine) ? max(0.0, (rOut + 0.010) - r) : 1.0;
        float dRimSurf = max(0.0, 0.58 - p.y);
        float dToGlazeSurf = min(min(dIntSurf, dExtSurf), dRimSurf);

        // Thick vitreous glaze skin (~0.018..0.026 on interior & exterior, thinner at rim)
        float skinThick = mix(0.022, 0.014, smoothstep(0.42, 0.57, p.y));
        float glazeBand = 1.0 - smoothstep(skinThick - 0.003, skinThick + 0.002, dToGlazeSurf);
        // Subtle dark clay-glaze interface line (iron-silicate reaction zone)
        float interfaceLine = exp(-sq((dToGlazeSurf - skinThick) / 0.0035));

        vec3 clayCol = shadeStoneware(p, n, v, keyDir, keyCol, fillDir, fillCol, rimDir, rimCol, sh, ao, gLine, true);
        if (glazeBand < 0.01) {
            return clayCol * (1.0 - 0.38 * interfaceLine);
        }

        // Translucent jade-emerald vitreous glaze cross-section layer
        vec3 jadeSection = (uLightMode == 1) ? vec3(0.36) : vec3(0.14, 0.34, 0.25);
        float ndl = max(dot(n, keyDir), 0.0);
        float cosI = sat(dot(n, v));
        float F = 0.045 + 0.955 * pow(max(1.0 - cosI, 1e-5), 5.0);
        vec3 env = studioSky(reflect(rd, n), p, 0.10);
        float spec = ggxSpec(n, v, keyDir, 0.10) * sh;
        vec3 glazeCol = ao * jadeSection * (keyCol * ndl * sh * 0.90 + fillCol * 0.45 + vec3(0.07, 0.10, 0.09))
                      + F * (env * 0.85 + keyCol * spec);
        return mix(clayCol * (1.0 - 0.38 * interfaceLine), max(glazeCol, vec3(0.0)), glazeBand);
    }

    // --- 1.0: Thick Translucent Vitreous Celadon Glaze ---
    float glazeThick = glazeThicknessAt(p);
    vec2 baseUV = celadonSurfaceUV(p);

    // Refracted view ray inside silicate glaze (IOR = 1.52)
    vec3 refrDir = refract(rd, n, 1.0 / 1.52);
    if (dot(refrDir, refrDir) < 1e-4) refrDir = rd;
    vec3 refrTan = refrDir - n * dot(refrDir, n);
    float cosT = max(abs(dot(refrDir, n)), 0.26);

    float uvFW = clamp(length(fwidth(baseUV)), 0.0004, 0.06);

    // 5-slice internal parallax integration through the thick celadon glaze layer
    float crackStainAccum = 0.0;
    vec3  crackTintAccum  = vec3(0.0);
    float bubbleAccum     = 0.0;
    float surfacePrimary  = 0.0;
    float surfaceSecondary = 0.0;
    float cellShade       = 0.5;

    float stainStrength  = mix(0.76, 1.0, open);
    float secDensityMask = mix(0.48, 0.98, open);

    for (int s = 0; s < 5; s++) {
        float frac = (float(s) + 0.12) / 5.0;
        float depth = frac * glazeThick * 1.55;
        vec3 slicePos = p + refrTan * (depth / cosT);
        vec2 sliceUV = celadonSurfaceUV(slicePos);

        vec4 cr = crazeNetwork(sliceUV);
        if (s == 0) cellShade = cr.z;

        // Primary crack ("tiexian"): crisp dark iron-oxide fissure
        float w1 = max(0.012 + 0.009 * open, uvFW * 2.8);
        float c1 = 1.0 - smoothstep(0.0, w1, cr.x);
        float halo1 = (1.0 - smoothstep(0.0, w1 * 3.8, cr.x)) * mix(0.22, 0.50, open);

        // Secondary crack ("jinsi"): finer golden-amber network modulated by uOpen
        float secActive = smoothstep(1.0 - secDensityMask, 1.0 - secDensityMask + 0.22, cr.w);
        float w2 = max(0.011 + 0.006 * open, uvFW * 5.0);
        float c2 = (1.0 - smoothstep(0.0, w2, cr.y)) * secActive;

        if (s == 0) {
            surfacePrimary = c1;
            surfaceSecondary = c2;
        }

        float depthWeight = exp(-frac * 1.25) * 0.48;
        vec3 col1 = mix(vec3(0.09, 0.075, 0.062), vec3(0.035, 0.025, 0.020), open);
        vec3 col2 = mix(vec3(0.32, 0.23, 0.13), vec3(0.12, 0.075, 0.042), open);

        float sliceAlpha = sat(c1 * 0.95 + halo1 * 0.38 + c2 * 0.70);
        vec3 sliceCol = (col1 * (c1 + halo1 * 0.38) + col2 * c2 * 0.76) / max(c1 + halo1 * 0.38 + c2 * 0.76, 1e-4);

        float contrib = (1.0 - crackStainAccum) * sliceAlpha * depthWeight * stainStrength;
        crackTintAccum += sliceCol * contrib;
        crackStainAccum = sat(crackStainAccum + contrib);

        // Smooth circular suspended kiln micro-bubbles ("spittle") inside mid-glaze
        if (s >= 1 && s <= 3) {
            vec2 bUV = sliceUV * 26.0 + vec2(float(s) * 19.3, float(s) * 7.1);
            float bFilter = 1.0 - smoothstep(0.008, 0.028, uvFW);
            float bDot = roundSpeck(bUV, 0.14, 0.18) * bFilter;
            bubbleAccum += bDot * 0.18 * exp(-frac * 1.1);
        }
    }

    // Tier 3: fwidth-filtered tertiary micro-craze hairlines
    vec2 mUV = rot2(-0.42) * baseUV * 15.5;
    float fwMicro = min(length(fwidth(mUV)), 4.0);
    float microRes = 1.0 - smoothstep(0.45, 1.8, fwMicro);
    vec3 vMicro = voronoiCrack(mUV);
    float microCrack = (1.0 - smoothstep(0.0, 0.035, vMicro.x)) * microRes * mix(0.18, 0.62, open);

    // Subtle shading normal tilt along crack lips for crisp specular catch-lights
    vec3 nGlaze = n;
    if (surfacePrimary > 0.01 || surfaceSecondary > 0.01) {
        vec3 t1 = normalize(cross(n, vec3(0.0, 0.0, 1.0) + vec3(0.01, 0.0, 0.0)));
        vec3 t2 = cross(n, t1);
        float eN = 0.0025;
        vec4 crX = crazeNetwork(baseUV + vec2(eN, 0.0));
        vec4 crY = crazeNetwork(baseUV + vec2(0.0, eN));
        vec4 cr0 = crazeNetwork(baseUV);
        float gx = (crX.x - cr0.x) / eN;
        float gy = (crY.x - cr0.x) / eN;
        nGlaze = normalize(n - (0.052 * surfacePrimary + 0.022 * surfaceSecondary) * (gx * t1 + gy * t2));
    }

    // Underlying stoneware body seen through the translucent glaze (parallax-shifted, smooth round specks)
    vec3 bodyPos = p + refrTan * (glazeThick / cosT);
    float clayVar = fbm2(bodyPos.xz * 7.5 + bodyPos.y * 9.0);
    vec3 clayUnder = mix(vec3(0.36, 0.35, 0.31), vec3(0.46, 0.44, 0.39), clayVar);
    float speckFilter = 1.0 - smoothstep(0.012, 0.040, uvFW);
    float ironSpeck = roundSpeck(bodyPos.xz * 28.0 + vec2(3.7, 11.2), 0.11, 0.20) * speckFilter;
    clayUnder = mix(clayUnder, vec3(0.13, 0.10, 0.08), 0.55 * ironSpeck);

    // Physically based Beer-Lambert Fe2+ celadon depth absorption:
    // Pale misty celadon on thin rim lip -> deep rich translucent jade-emerald in pooled concave well!
    float lightCosT = max(dot(n, keyDir), 0.28);
    float opticalPath = glazeThick * (1.0 / cosT + 1.0 / lightCosT) * 16.5;
    vec3 sigmaCeladon = vec3(2.35, 0.72, 1.12);
    vec3 transmittance = exp(-sigmaCeladon * opticalPath);

    // Rich Song celadon jade opalescent internal scatter
    vec3 jadeScatterCol = vec3(0.14, 0.33, 0.25) * (0.92 + 0.14 * cellShade);
    vec3 glazeBody = clayUnder * transmittance + jadeScatterCol * (vec3(1.0) - transmittance) * 0.88;
    // Delicate opalescent micro-bubbles catch soft internal light
    glazeBody += vec3(0.16, 0.26, 0.22) * sat(bubbleAccum);

    // Composite stained multi-layer parallax crack walls & tertiary micro-craze
    vec3 crackFinalCol = crackTintAccum / max(crackStainAccum, 1e-4);
    glazeBody = mix(glazeBody, crackFinalCol, sat(crackStainAccum * 1.22));
    glazeBody = mix(glazeBody, vec3(0.12, 0.085, 0.055), microCrack * 0.50);

    // Warm iron-toasted rim tint right at the exterior glaze drip boundary
    float dripEdge = exp(-sq((p.y - (gLine + 0.010)) / 0.024)) * smoothstep(0.50, 0.72, length(p.xz));
    glazeBody = mix(glazeBody, vec3(0.34, 0.29, 0.19), 0.38 * dripEdge);

    // Neutral-light grayscale override (uLightMode == 1)
    if (uLightMode == 1) {
        glazeBody = vec3(0.42) * (1.0 - 0.32 * crackStainAccum) * (1.0 - 0.14 * microCrack);
    }

    // Internal diffuse + translucent bounce lighting
    float ndl = max(dot(n, keyDir), 0.0);
    float ndlWrap = sat((dot(n, keyDir) + 0.24) / 1.24);
    float ndf = max(dot(n, fillDir) * 0.5 + 0.5, 0.0);
    float ndr = max(dot(n, rimDir), 0.0);
    vec3 hemi = mix(vec3(0.038, 0.050, 0.045), vec3(0.14, 0.17, 0.16), 0.5 + 0.5 * n.y);
    if (uLightMode == 1) hemi = mix(vec3(0.05), vec3(0.16), 0.5 + 0.5 * n.y);
    if (uLightMode == 3) hemi *= 0.42;

    // Rim transmission glow through the thin celadon lip in backlit mode
    float thinRim = 1.0 - smoothstep(0.009, 0.024, glazeThick);
    float backDot = pow(max(sat(dot(v, -keyDir + n * 0.35)), 1e-5), 2.8);
    vec3 rimGlow = ((uLightMode == 1) ? vec3(0.36) : vec3(0.42, 0.78, 0.62)) * keyCol * backDot * thinRim * (uLightMode == 3 ? 1.45 : 0.25);

    vec3 diffuse = glazeBody * (
        keyCol * mix(ndl, ndlWrap, 0.35) * sh * 0.88 +
        fillCol * ndf * 0.48 +
        rimCol * ndr * 0.34 +
        hemi
    ) + rimGlow;

    // Crisp vitreous dielectric Fresnel clearcoat (IOR = 1.52 -> F0 = 0.044)
    float cosI = sat(dot(nGlaze, v));
    float fresnel = 0.044 + 0.956 * pow(max(1.0 - cosI, 1e-5), 5.0);

    float roughCoat = 0.040 + 0.14 * surfacePrimary + 0.06 * surfaceSecondary;
    float roughSoft = 0.22;

    vec3 refl = reflect(rd, nGlaze);
    vec3 envSharp = studioSky(refl, p, roughCoat);
    vec3 envSoft  = studioSky(refl, p, roughSoft);

    float specKey  = ggxSpec(nGlaze, v, keyDir, roughCoat) * sh;
    float specSoft = ggxSpec(nGlaze, v, keyDir, roughSoft) * sh;
    float specFill = ggxSpec(nGlaze, v, fillDir, 0.15);
    float specRim  = ggxSpec(nGlaze, v, rimDir, roughCoat);

    vec3 specDirect = keyCol * (specKey * 0.92 + specSoft * 0.20) +
                      fillCol * specFill * 0.42 +
                      rimCol * specRim * (uLightMode == 3 ? 1.60 : 0.62);
    vec3 specEnv = mix(envSharp, envSoft, 0.14) * (0.46 + 0.54 * sh);

    float crackGlint = (surfacePrimary * 0.55 + surfaceSecondary * 0.25) * pow(max(sat(dot(n, normalize(v + keyDir))), 1e-5), 16.0) * sh;
    vec3 glintCol = ((uLightMode == 1) ? vec3(0.35) : vec3(0.68, 0.86, 0.76)) * keyCol * crackGlint * 0.24;

    vec3 col = ao * diffuse * (1.0 - 0.5 * fresnel) + fresnel * (specEnv * 0.96 + specDirect) + glintCol;
    return max(col, vec3(0.0));
}

// Studio bench shading (y = 0)
vec3 shadeBench(vec3 p, vec3 rd) {
    vec3 keyDir, keyCol, fillDir, fillCol, rimDir, rimCol;
    getLightRig(p, keyDir, keyCol, fillDir, fillCol, rimDir, rimCol);

    float grain = hash13(p * 220.0) - 0.5;
    vec3 baseCol = (uLightMode == 1)
        ? vec3(0.24) * (1.0 + 0.015 * grain)
        : vec3(0.18, 0.19, 0.205) * (1.0 + 0.018 * grain);

    float contact = groundContactShadow(p, keyDir);
    float raySh = softShadow(p + vec3(0.0, 0.004, 0.0), keyDir, 3.0);
    float sh = min(contact, 0.25 + 0.75 * raySh);

    float r2 = dot(p.xz - vec2(-0.15, 0.10), p.xz - vec2(-0.15, 0.10));
    float pool = 0.44 + 0.62 * exp(-0.18 * r2);

    vec3 n = vec3(0.0, 1.0, 0.0);
    float spec = ggxSpec(n, -rd, keyDir, 0.56) * sh * 0.12;
    vec3 env = studioSky(reflect(rd, n), p, 0.64) * 0.038 * sh;

    vec3 col = baseCol * (0.28 + 0.72 * sh) * pool * (uLightMode == 3 ? 0.55 : 1.0) + keyCol * spec + env;
    float fog = smoothstep(5.5, 16.0, length(p.xz));
    vec3 bg = (uLightMode == 1) ? vec3(0.10) : vec3(0.070, 0.078, 0.088);
    return mix(col, bg, fog);
}

// ACES Filmic Tone Mapping
vec3 acesToneMap(vec3 x) {
    const float a = 2.51;
    const float b = 0.03;
    const float c = 2.43;
    const float d = 0.59;
    const float e = 0.14;
    return sat((x * (a * x + b)) / max(x * (c * x + d) + e, vec3(1e-5)));
}

vec3 render(vec2 offset) {
    // uCamMode 0 = Hero 3/4 view showing hollow concave jade well, stratified cutaway wall & foot-ring
    // uCamMode 1 = ~2.5x macro close-up on concave parallax crackle, pooled glaze & cutaway edge
    vec3 eye, at;
    float focal;
    if (uCamMode == 1) {
        eye   = vec3(0.46, 1.18, 1.06);
        at    = vec3(-0.04, 0.24, 0.02);
        focal = 3.70;
    } else {
        eye   = vec3(0.76, 1.98, 2.34);
        at    = vec3(-0.02, 0.28, 0.02);
        focal = 2.55;
    }

    vec3 fwd = normalize(at - eye);
    vec3 right = normalize(cross(fwd, vec3(0.0, 1.0, 0.0)));
    vec3 up = cross(right, fwd);

    float scale = max(1.0, min(uResolution.y, uResolution.x * 0.75));
    vec2 uv = (2.0 * (gl_FragCoord.xy + offset) - uResolution) / scale;
    vec3 rd = normalize(focal * fwd + uv.x * right + uv.y * up);

    float groundT = (rd.y < -0.001) ? min(FAR, -eye.y / rd.y) : FAR;
    vec2 hit = trace(eye, rd, groundT);

    if (hit.y < 0.0) {
        if (groundT >= FAR) {
            return (uLightMode == 1) ? vec3(0.10) : vec3(0.070, 0.078, 0.088);
        }
        vec3 gp = eye + rd * groundT;
        return shadeBench(gp, rd);
    }

    vec3 p = eye + rd * hit.x;
    vec3 n = calcNormal(p, hit.x);
    return shadeCeladon(p, n, rd, hit.x, hit.y);
}

void main() {
    // 2x rotated-grid supersampling for crisp crackle hairlines & specular highlights
    vec3 c0 = render(vec2(-0.24, 0.18));
    vec3 c1 = render(vec2( 0.24,-0.18));
    vec3 linear = max(vec3(0.0), 0.5 * (c0 + c1));
    float expScale = (uCamMode == 1) ? 0.78 : ((uLightMode == 2 || uLightMode == 3) ? 1.02 : 0.90);
    vec3 mapped = acesToneMap(linear * expScale);
    vec3 srgb = pow(max(mapped, vec3(0.0)), vec3(1.0 / 2.2));
    fragColor = vec4(sat(srgb), 1.0);
}

Mathematical models & shader specifications

Identifiervoronoi-celadon-crackle-glaze
CategorySci-Fi, Plasma & Noise Shaders · Cellular & Ripple Fields
Upstream studyceramics/lib/01_crazed_celadon_crackle_glaze.glsl (commit 4750467)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime, uOpen, uLightMode, uCamMode
Source size823 lines · 33.1 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT ice sprite sheets
LicenseMIT License + CC0 / MIT Helpers

Physical & shading models implemented

Voronoi/Worley cellular fields (Voronoi 1908; Worley 1996); GGX microfacet specular (Trowbridge–Reitz 1975; Walter et al. 2007); Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation

Adapted upstream mathematical helpers

David Hoskins, hash · Krzysztof Narkowicz, filmic curve · Inigo Quilez, quadratic distance blend · Inigo Quilez, tetrahedral SDF normal

All sci-fi & noise shaders
OLED Subpixel Matrix WebGL2 procedural shaderAnimated

Diamond PenTile RGB emitter array for close-up cybernetic visors, HUD screens, and holo-panels.

Sci-Fi & Noise