Banded Agate Geode Slice shader

banded-agate-geode-slice.glsl · 129 lines · GLSL ES 3.00 · MIT

Banded Agate Geode SliceStone & Masonry
Banded Agate Geode Slice WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 129 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

Minerals & Gems
banded-agate-geode-slice.glsl (129 lines)
#version 300 es
// Banded Agate Geode Slice (banded-agate-geode-slice.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/01_agate_slice_with_bands_growing_inward_from_a_cavity.glsl
// License: MIT (Copyright 2026 Gokay Aydogan) + MIT/CC0 helpers — https://pixelfx.io/LICENSE-SHADERS.txt
// Uniforms: uResolution (vec2), uTime (float)
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-minerals-lib-01-agate-slice-with-bands-growing-inward-from-a-cavity
// Agate slice with bands growing inward from a cavity
precision highp float;
precision highp int;
uniform vec2 uResolution;
uniform float uTime;
out vec4 fragColor;

const float TAU = 6.28318530718;
mat2 rot(float a) { return mat2(cos(a),sin(a),-sin(a),cos(a)); }
// randCell uses the two multiply/xorshift rounds of Austin Appleby’s public-domain
// fmix32 from MurmurHash3: https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
float randCell(vec2 id) {
    uvec2 k=uvec2(ivec2(floor(id)));
    uint b=(k.x*1664525u+1013904223u) ^ (k.y*747796405u);
    b=(b^(b>>16u))*2246822519u;
    b=(b^(b>>13u))*3266489917u;
    return float(b>>8u)*(1./16777216.);
}
float field(vec2 p) {
    vec2 k=floor(p), s=fract(p);
    s=s*s*(3.-2.*s);
    return mix(mix(randCell(k),randCell(k+vec2(1,0)),s.x),
               mix(randCell(k+vec2(0,1)),randCell(k+1.),s.x),s.y);
}
float stone(vec2 p) {
    mat2 octave=mat2(1.82,1.07,-1.07,1.82);
    float v=.55*field(p);
    p=octave*p+8.3; v+=.26*field(p);
    p=octave*p+5.7; v+=.13*field(p);
    return v+.06*field(octave*p);
}
float pixel() { return 2./min(uResolution.x,uResolution.y); }
float inside(float d,float w) { return 1.-smoothstep(-w,w,d); }

// Two oblique intersections with a sawn nodule. The rear surface is visible
// in the central vug and under the unpolished outside rind.
vec2 boundaries(vec2 q){
    float a=atan(q.y,q.x);
    float rind=length(q)-(.96+.096*cos(3.*a-.52)+.054*cos(5.*a)+.046*sin(2.*a));
    vec2 e=(q+vec2(.18,-.13))*vec2(1.,1.20);
    float b=atan(e.y,e.x);
    float cavity=length(e)-(.207+.079*cos(3.*b-.2)+.037*sin(5.*b)+.020*cos(7.*b));
    return vec2(rind+.047*(stone(q*14.)-.5),cavity);
}
vec3 banded(vec2 q,float radial){
    float a=atan(q.y,q.x);
    float f=radial+.016*sin(19.*radial+2.*a)+.013*stone(q*11.);
    float cloud=stone(q*vec2(12.,7.));
    // Broad, smoky silica alternates with iron-rich opaque laminae.
    float iron=smoothstep(.30,.75,field(vec2(12.5*f+.3,2.1)));
    vec3 mineral=mix(vec3(.315,.312,.365),vec3(.59,.237,.075),iron);
    mineral=mix(mineral,vec3(.91,.713,.394),.41*field(vec2(f*34.,19.)));
    float phase=f*200.+1.8*sin(61.*f);
    float band=pow(.5+.5*cos(phase),5.)*(.27+.64*iron);
    float filtered=exp(-pow(abs(pixel()*174.),2.));
    mineral=mix(mineral,vec3(.98,.88,.73),band*filtered*.74);
    mineral+=.095*(cloud-.5)+.078*field(vec2(60.*f,2.));
    return mineral;
}
vec3 study(vec2 p){
    vec2 s=rot(-.27)*(p-vec2(.00,.045))/vec2(1.14,.735);
    vec2 delta=vec2(-.061,.154);
    vec2 b=boundaries(s);
    float growth=.093*(1.-cos(uTime));
    float grit=stone(s*90.);
    float outer=b.x+.010*(grit-.5);
    float inner=b.y+growth+.015*(grit-.5);
    vec3 ground=vec3(.274,.246,.214)*(.86+.15*stone(p*9.));
    float contact=boundaries(s+delta*1.25+vec2(-.04,.055)).x;
    ground*=1.-.50*exp(-max(0.,contact)*9.);
    float optical=inner/max(.12,inner-outer);
    // Botryoidal silica nucleates around several protuberances on the wall.
    // Colliding fronts produce cusps and bays in the fortification bands.
    float knobs=min(length(s-vec2(-.66,.61))-.185,length((s-vec2(.55,.58))*vec2(1.05,.91))-.175);
    knobs=min(knobs,length(s-vec2(.39,-.76))-.13);
    float depth=min(-outer,knobs);
    optical=mix(optical,1.-1.18*depth,smoothstep(.08,.65,optical));
    vec3 stoneFace=banded(s,optical);
    vec2 below=s+vec2(.018,-.011);
    vec2 bb=boundaries(below);
    float local=(bb.y+growth)/max(.12,bb.y+growth-bb.x);
    float transparent=.18*(1.-smoothstep(.43,.80,field(vec2(optical*12.,2.1))));
    stoneFace=mix(stoneFace,banded(below,local)*vec3(.84,.77,.69),transparent);
    float sheen=exp(-pow(abs((p.y+.37*p.x-.28)*3.2),2.));
    stoneFace+=vec3(.11,.12,.13)*sheen;
    stoneFace+=vec3(.055,.040,.014)*exp(-23.*abs(knobs))*grit;
    float rind=smoothstep(.94,1.01,optical+.063*(grit-.5));
    vec3 bark=mix(vec3(.19,.124,.094),vec3(.58,.39,.25),stone(s*37.));
    stoneFace=mix(stoneFace,bark*(.60+.65*grit),rind);
    if(max(outer,-inner)<=0.){
        float nearEdge=max(outer,-inner);
        vec3 border=mix(bark,vec3(.78,.69,.57),step(outer,-inner));
        stoneFace=mix(stoneFace,border,.74*smoothstep(-.019,0.,nearEdge));
        return stoneFace+.18*vec3(.90,.83,.71)*exp(-pow(abs(inner-.013)*91.,2.))*grit;
    }
    // Locate the first wall crossing and refine it inside that interval.
    float last=0.;
    for(int i=1;i<=16;i++){
        float h=float(i)/16.;
        vec2 b2=boundaries(s+delta*h);
        if(max(b2.x,-b2.y-growth)>0.) {last=h;continue;}
        float back=h;
        for(int j=0;j<6;j++){
            float mid=.5*(last+back);
            vec2 b3=boundaries(s+delta*mid);
            if(max(b3.x,-b3.y-growth)>0.)last=mid;else back=mid;
        }
        vec2 wall=s+delta*back;
        vec2 wallCoord=vec2(atan(wall.y,wall.x)*1.7,back*.25);
        float chip=stone(wallCoord*57.);
        bool vug=-b2.y-growth>b2.x;
        vec3 side=vug?mix(vec3(.27,.206,.178),vec3(.86,.80,.72),chip):
                      mix(vec3(.167,.106,.081),vec3(.47,.316,.236),chip);
        float bounce=vug?1.-.38*smoothstep(.12,1.,back):1.;
        return side*bounce*(.63+.21*(1.-back)+.12*wall.y);
    }
    return ground;
}

void main() {
    vec2 p = (2.0 * gl_FragCoord.xy - uResolution) / min(uResolution.x, uResolution.y);
    // Two diagonally staggered samples soften subpixel grain and crystal boundaries.
    vec2 offset = vec2(0.28, -0.19) * pixel();
    vec3 rgb = (study(p - offset) + study(p + offset)) * 0.5;
    fragColor = vec4(clamp(rgb, 0.0, 1.0), 1.0);
}

Mathematical models & shader specifications

Identifierbanded-agate-geode-slice
CategoryStone & Masonry Shaders · Minerals & Gems
Upstream studyminerals/lib/01_agate_slice_with_bands_growing_inward_from_a_cavity.glsl (commit main)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime
Source size129 lines · 5.6 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT pickups sprite sheets
LicenseMIT License + CC0 / MIT Helpers

Physical & shading models implemented

Procedural signed-distance and analytic surface shading

Adapted upstream mathematical helpers

randCell adapts the two xorshift/multiply mixing rounds with a 2D seed, modified constants and truncated output (Public domain). Austin Appleby, MurmurHash3, fmix32

All stone & masonry shaders