Iridescent Fish Scales shader

iridescent-fish-scales.glsl · 127 lines · GLSL ES 3.00 · MIT

Iridescent Fish ScalesFabrics & Organic
Iridescent Fish Scales WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 127 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

Bark, Scales & Flora
iridescent-fish-scales.glsl (127 lines)
#version 300 es
// Iridescent Fish Scales (iridescent-fish-scales.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/animal/lib/13_fish_scales.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-animal-lib-13-fish-scales
// Fish scales
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); }

// A patch of the flank between the dorsal pigmentation and the silver belly.
// The cylindrical section foreshortens the rows at the upper silhouette.
vec3 study(vec2 p){
    vec2 body=rot(-.135)*p*.94-vec2(.36,.005);
    float mid=.044-.023*body.x*body.x;
    float radius=.804+.147*body.x-.10*body.x*body.x;
    float v=(body.y-mid)/radius;
    float curve=asin(clamp(v,-.996,.996));
    float z=sqrt(max(.006,1.-v*v));
    vec3 backdrop=mix(vec3(.096,.176,.173),vec3(.33,.41,.347),.69*stone(p*2.)+.18*(1.-p.y));
    if(abs(v)>1.) return backdrop;
    vec2 q=vec2(body.x+.06*curve*curve,curve);
    q=vec2(q.y*5.25,q.x*5.2+.23*cos(q.y*2.4));
    float view=sin(.83*uTime);
    float freckle=stone(p*109.);
    float pigment=stone(body*vec2(3.8,12.));
    vec3 skin=mix(vec3(.68,.71,.65),vec3(.12,.234,.198),smoothstep(-.55,.88,v));
    skin=mix(skin,vec3(.102,.151,.142),.48*exp(-pow(abs((curve-.12-.044*sin(body.x*3.))*8.),2.))*(.48+.72*pigment));
    vec3 surf=skin*.64;
    for(int j=-1;j<=2;j++){
        float row=floor(q.y/.62)+float(j);
        float phase=.5*mod(row,2.);
        float col=floor(q.x-phase+.5);
        for(int i=-1;i<=1;i++){
            vec2 id=vec2(col+float(i),row);
            float k=randCell(id+6.);
            vec2 s=q-vec2(id.x+phase,row*.62)-.085*vec2(k-.5,randCell(id+24.)-.5);
            vec2 e=s/vec2(.63+.059*k,.76+.068*k);
            float r=length(e);
            if(r>1.03)continue;
            float ring=cos(95.*length(e+vec2(.01,-.19))+1.7*field(s*4.+id));
            float spoke=pow(.5+.5*cos(atan(e.x,e.y+.002)*49.+4.*k),9.);
            float mantle=smoothstep(.65,.985,r);
            vec3 n=normalize(vec3(.14*e.y+.03*sin(curve*7.),v+.13*e.x,z+.07*(1.-r)));
            vec3 h=normalize(vec3(-.28+.42*view,.08,.90));
            float pearl=pow(max(0.,dot(n,h)),23.);
            float flash=exp(-pow(abs(curve+.22+.17*view+.14*e.y+.19*e.x+.06*k)*4.5,2.));
            float streak=exp(-pow(abs((dot(n,normalize(vec3(-.27,.51,.85)))-.957)*32.),2.));
            vec3 nacre=mix(vec3(.41,.82,.86),vec3(.98,.71,.39),.5+.5*cos(4.1*curve+.82*e.x+.48*k+view));
            vec3 bed=skin*(.63+.33*z+.11*k+.11*freckle);
            bed*=1.-.4*smoothstep(.54,.83,field(18.*e+id))*smoothstep(-.32,.61,v);
            vec3 plate=bed+nacre*(pearl*(.19+.39*k)+.24*flash+.10*streak);
            float pore=length((s-vec2(.065,-.29))*vec2(1.8,1.));
            if(id.x==0.)plate*=1.-.51*exp(-pore*pore*193.);
            plate+=.022*ring-.021*spoke+.026*(freckle-.5);
            // A hyaline lamina transmits the underlying neighbour at the free rim.
            vec3 film=mix(surf,plate,.27)+.075*nacre*(.44+.56*pearl);
            plate=mix(plate,film,mantle*.91);
            plate+=nacre*.19*exp(-pow(abs((r-.958)*60.),2.))*max(0.,-.75*e.y-.42*e.x);
            plate*=1.-.26*exp(-pow(abs((r-.991)*65.),2.));
            surf=mix(surf,plate,inside(r-1.,.010));
        }
    }
    // Smooth opercular bone overlaps the foremost scale row. The raised
    // cheek shares the light that travels across the flank.
    float gill=body.x-(.635+.28*v*v-.045*v+.021*sin(v*5.));
    float cheek=smoothstep(-.006,.012,gill);
    float cheekArc=length((body-vec2(1.15,.02))/vec2(.58,.78));
    float ridge=exp(-pow(abs(gill-.015)*81.,2.))-.66*exp(-pow(abs(gill+.009)*83.,2.));
    vec3 plate=mix(vec3(.59,.626,.536),vec3(.215,.333,.271),smoothstep(-.62,.77,v));
    plate+=vec3(.28,.29,.224)*exp(-pow(abs(cheekArc-.76+.087*view)*3.7,2.));
    plate+=.19*ridge+.065*(stone(body*65.)-.5);
    surf=mix(surf,plate,cheek);
    // A folded pectoral fin lies forward of the lateral line. Its narrow
    // membrane reveals the scales and casts a displaced shadow on the flank.
    vec2 fin=rot(-.28)*(body-vec2(.79,-.22));
    float t=-fin.x/.86;
    float span=.29*pow(clamp(t,0.,1.),.84)+.025;
    float arch=.075*sin(clamp(t,0.,1.)*3.14);
    float fan=(fin.y-arch)/span;
    float end=1.-.27*fan*fan+.035*fan;
    float silhouette=max(max(-t,t-end+.019*cos(31.*fan)*smoothstep(.62,.98,t)),abs(fan)-1.);
    float shadowD=max(max(-t,t-end),abs((fin.y-arch+.042)/span)-1.);
    surf*=1.-.27*exp(-max(0.,shadowD)*12.)*smoothstep(.0,.19,t);
    float ribs=(fan*.5+.5)*14.+.29*t*t;
    float rib=exp(-pow(abs(fract(ribs)-.50)*9.,2.));
    float splitRib=exp(-pow(abs(fract(2.*ribs+.17)-.5)*10.,2.))*smoothstep(.44,.92,t);
    vec3 membrane=mix(surf,vec3(.32,.29,.208),.27+.23*(1.-clamp(t,0.,1.)));
    membrane+=vec3(.176,.148,.098)*(rib+.39*splitRib)*(.78+.22*cos(t*112.));
    surf=mix(surf,membrane,inside(silhouette,pixel()/.22));
    return mix(backdrop,surf,inside(abs(v)-1.,pixel()));
}

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

Identifieriridescent-fish-scales
CategoryFabrics & Organic Shaders · Bark, Scales & Flora
Upstream studyanimal/lib/13_fish_scales.glsl (commit main)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime
Source size127 lines · 6.1 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT water 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 fabrics & organic shaders
Sphagnum Forest Moss WebGL2 procedural shaderAnimated

Dense cushion of star-shaped emerald sphagnum moss heads glistening with capillary moisture.

Fabrics & Organic
Quilted Padded Fabric WebGL2 procedural shaderPBR Study

Diamond-stitched gambeson / flight-suit padding with pillows puffing between taut thread seams.

Fabrics & Organic