PBR StudyRiven dark-grey roof slates with cleaved foliar micro-steps and chipped lower edges.
iridescent-labradorite-stone.glsl · 148 lines · GLSL ES 3.00 · MIT
#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);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Iridescent Labradorite Stone — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/14_labradorite.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-14-labradorite
// Labradorite
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.*pfx_frag_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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor){
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);
}
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;
// Iridescent Labradorite Stone — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/14_labradorite.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-14-labradorite
// Labradorite
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.*pfx_frag_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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor){
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);
}
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;
}
// Iridescent Labradorite Stone — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/14_labradorite.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-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);
}
`;
export function createIridescentLabradoriteStoneMaterial(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 | iridescent-labradorite-stone |
|---|---|
| Category | Stone & Masonry Shaders · Minerals & Gems |
| Upstream study | minerals/lib/14_labradorite.glsl (commit main) |
| Animation cycle | Continuous procedural uTime |
| Declared uniforms | uResolution, uTime |
| Source size | 148 lines · 6.2 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT arcane sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Procedural signed-distance and analytic surface shading
Standalone GLSL ES 3.00 math primitives
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.
PBR StudyUnmortared fieldstone courses wedged with chinking stones and deep recessed shadow joints.
PBR StudyMediterranean barrel mission tiles in warm kiln-fired terracotta with weathered lichen variation.
PBR StudyRounded granite street setts polished smooth on their crowns with sandy compacted joints.
AnimatedCrushed basalt road aggregate in dark bitumen binder crossed by glossy poured-tar crack sealant.