Iridescent Labradorite Stone shader

iridescent-labradorite-stone.glsl · 148 lines · GLSL ES 3.00 · MIT

Iridescent Labradorite StoneStone & Masonry
Iridescent Labradorite Stone WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 148 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
iridescent-labradorite-stone.glsl (148 lines)
#version 300 es
// Iridescent Labradorite Stone (iridescent-labradorite-stone.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/14_labradorite.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-14-labradorite
// Labradorite
precision highp float;
precision highp int;
uniform vec2 uResolution;
uniform float uTime;
out vec4 fragColor;

float hash2(vec2 cell) {
    uvec2 v = uvec2(ivec2(floor(cell)));
    uint n = (v.x * 1597334677u) ^ (v.y * 3812015801u);
    n = (n ^ (n >> 16u)) * 2246822519u;
    return float(n ^ (n >> 13u)) / 4294967296.;
}

float noise2(vec2 p) {
    vec2 cell = floor(p), f = fract(p);
    f = f*f*(3.-2.*f);
    return mix(mix(hash2(cell),hash2(cell+vec2(1,0)),f.x),
               mix(hash2(cell+vec2(0,1)),hash2(cell+1.),f.x), f.y);
}

float cloud(vec2 p) {
    return .52*noise2(p)+.27*noise2(p*2.13+5.)+.14*noise2(p*4.37-9.)+.07*noise2(p*9.17);
}

mat2 rot(float a) { return mat2(cos(a),sin(a),-sin(a),cos(a)); }

vec2 frame() {
    return (2.*gl_FragCoord.xy-uResolution.xy)/min(uResolution.y,uResolution.x*.9);
}

// Polished section on a rough cleavage fragment. Coordinates and face normals are
// shared by the optical domains, so an oblique sightline samples the twins below the polish.
float rim(vec2 p){
    float d=-9.;
    for(int i=0;i<11;i++){
        float k=float(i),a=k*.57119866+.12*sin(k*13.);
        vec2 n=vec2(cos(a),sin(a));
        d=max(d,(dot(p/vec2(1.02,.77),n)-(.86+.18*hash2(vec2(33.,k))))*.78);
    }
    return d;
}
float cut(vec3 p){
    float y=.24+.12*p.x-.055*p.z;
    float jag=cloud(p.xz*9.+p.y*3.)-.5;
    float edge=rim(p.xz)+.085*jag+.012*(noise2(p.xz*58.)-.5);
    float upper=p.y-y;
    float seam=max(edge,upper);
    seam=max(seam,(edge+.64*upper+.045)*.78);
    float base=max(-.174-p.y,(edge-.49*(p.y-.06))*.86);
    return max(seam,base);
}
float intersectStone(vec3 o,vec3 d,float maxT){
    float t=0.;
    for(int i=0;i<78;i++){
        float dist=cut(o+t*d);
        if(dist<.0004 || t>maxT)break;
        t+=max(.0003,.86*dist);
    }
    return t;
}
vec3 spectral(float nm){
    vec3 delta=(nm-vec3(607.,532.,457.))/vec3(43.,35.,33.);
    return .026+exp(-.5*delta*delta);
}
vec3 domain(vec2 uv,vec3 halfV,float depth){
    vec2 st=rot(.81)*uv;
    // Fault-bounded packets have a distinct mean orientation and layer spacing.
    float fault=st.x+.14*st.y+.041*(cloud(st*10.)-.5);
    float j=floor((fault+.24)*4.1);
    float twin=hash2(vec2(j,13.));
    float layer=st.y+.12*st.x+.095*twin+.024*cloud(st*11.);
    float fine=floor(layer*47.);
    float zoning=cloud(vec2(st.x*1.4,st.y*4.2));
    vec2 unit=st*vec2(2.1,7.6),cell=floor(unit),fraction=fract(unit);
    float best=20.,nextBest=20.,packet=0.;
    for(int y=-1;y<=1;y++)for(int x=-1;x<=1;x++){
        vec2 off=vec2(x,y),key=cell+off;
        vec2 site=off+.16+.68*vec2(hash2(key+10.),hash2(key+31.));
        float dist=dot(site-fraction,site-fraction);
        if(dist<best){nextBest=best;best=dist;packet=hash2(key+73.);}
        else nextBest=min(nextBest,dist);
    }
    float spacing=142.+50.*smoothstep(-.57,.53,layer)+7.*twin+5.*zoning+13.*(packet-.48);
    vec3 g=normalize(vec3(.12*(twin-.5)+.16*st.x+.10,-.05+.16*st.y,1.).xzy);
    // The illuminated face is polished near the plane of the lamellar flash.
    float delta=halfV.x-g.x+.48*st.x+.09*sin(st.y*6.)+.16*twin-.02;
    delta+=.14*(packet-.5);
    float flash=exp(-delta*delta/.045)*(.39+.54*zoning+.19*hash2(vec2(fine,j)));
    float wavelength=2.*1.55*spacing*clamp(dot(g,halfV),.70,1.);
    vec3 spectralRGB=spectral(wavelength);
    float seam=abs(fract((fault+.24)*4.1)-.5);
    float split=.5-abs(fract(layer*47.)-.5);
    float lines=.81+.19*smoothstep(.008,.08,split);
    float window=.58+.42*smoothstep(.07,.43,packet);
    float boundary=smoothstep(.005,.113,nextBest-best);
    float feldspar=.63+.49*smoothstep(.27,.73,noise2(vec2(layer*289.,st.x*15.)+packet));
    return spectralRGB*flash*lines*window*(.60+.4*boundary)*feldspar*(.73+.27*smoothstep(.012,.04,seam))*
           (1.-.28*depth);
}
vec3 sampleRock(vec2 film){
    float tchange=sin(uTime*.94);
    vec3 v=normalize(vec3(.29+.50*tchange,1.64,1.13)),right=normalize(cross(vec3(0,1,0),v)),up=cross(v,right);
    vec3 o=v*4.65,d=normalize(-v*4.65+film.x*right+film.y*up);
    float ground=(-.178-o.y)/d.y,t=intersectStone(o,d,ground);
    vec3 p=o+d*min(t,ground),light=normalize(vec3(-.70+.42*tchange,1.,-.45));
    if(t>=ground){
        float cavity=exp(-max(0.,rim(p.xz))*9.);
        return vec3(.089,.081,.073)*(.89+.18*cloud(p.xz*5.))*(1.-.54*cavity);
    }
    float e=.0015;
    vec3 n=normalize(vec3(cut(p+vec3(e,0,0))-cut(p-vec3(e,0,0)),cut(p+vec3(0,e,0))-cut(p-vec3(0,e,0)),cut(p+vec3(0,0,e))-cut(p-vec3(0,0,e))));
    float grit=cloud(p.xz*9.+p.y*12.);
    if(n.y<.86){
        vec2 side=vec2((p.x+.45*p.z)*25.,p.y*115.+5.*cloud(p.xz*13.));
        float cleave=noise2(side),grain=noise2((p.xz+p.y)*170.);
        vec3 rough=mix(vec3(.039,.043,.042),vec3(.18,.185,.165),grit*.53+cleave*.36);
        rough*=.48+.59*max(0.,dot(n,light));
        return rough+.03*pow(grain,7.)*(.3+max(0.,dot(n,v)));
    }
    vec3 ray=refract(d,n,1./1.55),insideL=-refract(-light,n,1./1.55);
    vec3 hv=normalize(insideL-ray);
    vec3 body=vec3(.012,.023,.027)*(.61+.8*grit),fire=vec3(0);
    for(int k=0;k<4;k++){
        float depth=.011+.030*float(k);
        fire+=domain(p.xz+ray.xz*depth/max(.18,-ray.y),hv,float(k)/4.)*(.35-.068*float(k));
    }
    float fissure=p.x+.52*p.z-.085+.038*cloud(p.xz*16.);
    float secondary=.73*p.x-.81*p.z+.27+.023*cloud(p.xz*19.);
    float fracture=(.35+.65*smoothstep(.002,.012,abs(fissure)))*(.62+.38*smoothstep(.001,.006,abs(secondary)));
    vec3 r=reflect(d,n);
    float polish=exp(-pow(abs((r.x+.25)/.50),4.)-pow(abs((r.z+.54)/.16),4.));
    float solid=cloud(p.xz*19.+p.y*4.);
    float inclusions=pow(noise2(rot(.68)*p.xz*vec2(223.,43.)),9.);
    vec3 c=(body*(.68+.64*solid)+fire*vec3(.79,.94,1.07))*(1.-.81*inclusions)*fracture;
    c+=vec3(.20,.20,.18)*exp(-abs(fissure-.009)*430.)*(.32+.68*grit);
    float groove=noise2(rot(.72)*p.xz*vec2(36.,390.));
    float sky=.010*polish+.012*exp(-pow(abs((r.x+.34)/.18),4.)-pow(abs((r.z+.20)/.56),4.));
    return c*(.93+.11*groove)+.003+sky;
}
void main(){
    vec2 p=frame()*.98;vec2 jitter=vec2(.42,.30)/uResolution.y;
    vec3 c=.5*(sampleRock(p+jitter)+sampleRock(p-jitter));
    fragColor=vec4(pow(c/(.95+.33*c),vec3(.4545)),1);
}

Mathematical models & shader specifications

Identifieriridescent-labradorite-stone
CategoryStone & Masonry Shaders · Minerals & Gems
Upstream studyminerals/lib/14_labradorite.glsl (commit main)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime
Source size148 lines · 6.2 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT arcane sprite sheets
LicenseMIT License + CC0 / MIT Helpers

Physical & shading models implemented

Procedural signed-distance and analytic surface shading

Adapted upstream mathematical helpers

Standalone GLSL ES 3.00 math primitives

All stone & masonry shaders