AnimatedMetallic brass-gold fool’s gold cubes with orthogonal crystal striations in matrix rock.
banded-agate-geode-slice.glsl · 129 lines · GLSL ES 3.00 · MIT
#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);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Banded Agate Geode Slice — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/01_agate_slice_with_bands_growing_inward_from_a_cavity.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 1;
uniform bool u_luma_alpha_key = false;
// 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
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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 p = (2.0 * pfx_frag_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);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float out_alpha = study_col.a * COLOR.a;
if (u_luma_alpha_key) {
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
out_alpha *= smoothstep(0.035, 0.22, luma);
}
COLOR = vec4(tinted, out_alpha);
}
shader_type spatial;
render_mode cull_disabled;
// Banded Agate Geode Slice — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/01_agate_slice_with_bands_growing_inward_from_a_cavity.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 1;
uniform bool u_luma_alpha_key = false;
// 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
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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 p = (2.0 * pfx_frag_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);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
ALBEDO = tinted;
ROUGHNESS = clamp(0.85 - luma * 0.45, 0.08, 0.96);
METALLIC = 0.04;
EMISSION = tinted * 0.0;
}
// Banded Agate Geode Slice — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/01_agate_slice_with_bands_growing_inward_from_a_cavity.glsl (MIT License)
import * as THREE from 'three';
const vertexShader = /* glsl */ `
out vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const fragmentShader = /* glsl */ `
// 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);
}
`;
export function createBandedAgateGeodeSliceMaterial(width = 1024, height = 1024) {
const material = new THREE.ShaderMaterial({
glslVersion: THREE.GLSL3,
vertexShader,
fragmentShader,
uniforms: {
uResolution: { value: new THREE.Vector2(width, height) },
uTime: { value: 1.2 },
uOpen: { value: 0.0 },
uLightMode: { value: 0 },
uCamMode: { value: 1 },
},
});
return {
material,
update(elapsedSeconds) {
material.uniforms.uTime.value = elapsedSeconds * 1.0;
},
resize(nextW, nextH) {
material.uniforms.uResolution.value.set(nextW, nextH);
},
};
}
| Identifier | banded-agate-geode-slice |
|---|---|
| Category | Stone & Masonry Shaders · Minerals & Gems |
| Upstream study | minerals/lib/01_agate_slice_with_bands_growing_inward_from_a_cavity.glsl (commit main) |
| Animation cycle | Continuous procedural uTime |
| Declared uniforms | uResolution, uTime |
| Source size | 129 lines · 5.6 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT pickups sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Procedural signed-distance and analytic surface shading
randCell adapts the two xorshift/multiply mixing rounds with a 2D seed, modified constants and truncated output (Public domain). Austin Appleby, MurmurHash3, fmix32
AnimatedMetallic brass-gold fool’s gold cubes with orthogonal crystal striations in matrix rock.
PBR StudyBanded cream limestone slab pitted with elongated gas-escape vugs and calcite layers.
PBR StudyCoarse plutonic rock mosaic of pink orthoclase feldspar, smoky quartz, and glinting black biotite.
AnimatedDark feldspar slab flashing vivid peacock-blue and gold labradorescence across twin lamellae.
PBR StudyRiven dark-grey roof slates with cleaved foliar micro-steps and chipped lower edges.
PBR StudyCathedral seeded glass panes joined by soldered H-profile lead cames with backlit color.