Porous Travertine Stone shader

porous-travertine-stone.glsl · 107 lines · GLSL ES 3.00 · MIT

Porous Travertine StoneStone & Masonry
Porous Travertine Stone WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 107 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
porous-travertine-stone.glsl (107 lines)
#version 300 es
// Porous Travertine Stone (porous-travertine-stone.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/05_porous_travertine.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-05-porous-travertine
// Porous travertine
precision highp float;
precision highp int;
uniform vec2 uResolution;
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); }

float noiseVolume(vec3 p){
    vec3 cell=floor(p),f=fract(p);f=f*f*(3.-2.*f);
    vec2 k=cell.xy+cell.z*vec2(71.,113.);
    float a=mix(mix(randCell(k),randCell(k+vec2(1,0)),f.x),mix(randCell(k+vec2(0,1)),randCell(k+1.),f.x),f.y);
    k+=vec2(71.,113.);
    float b=mix(mix(randCell(k),randCell(k+vec2(1,0)),f.x),mix(randCell(k+vec2(0,1)),randCell(k+1.),f.x),f.y);
    return mix(a,b,f.z);
}
float bed(vec3 p){return p.z+.051*sin(3.*p.x+.86*p.y)+.024*sin(7.2*p.x-.9*p.y)+.24*p.y;}
float pores(vec3 p){
    vec3 q=vec3(p.x,p.y,bed(p));
    return .53*noiseVolume(q*vec3(4.6,8.,15.))+.29*noiseVolume(q*vec3(11.,15.,26.)+4.)
        +.12*noiseVolume(q*42.+9.)+.06*noiseVolume(q*95.)
        +.040*sin(q.z*46.)-.622;
}
float hull(vec3 p){
    vec3 d=abs(p)-vec3(.99,.66,.218);
    float chamfer=max(d.x+d.z+.023,max(d.y+d.z+.023,d.x+d.y+.038))*.707;
    return max(chamfer,max(d.x,max(d.y,d.z)));
}
float surface(vec3 p){return max(hull(p),pores(p)*.12);}
vec3 study(vec2 uv){
    vec3 eye=normalize(vec3(.43,-.81,.75));
    vec3 right=normalize(cross(vec3(0,0,1),eye)),up=cross(eye,right);
    vec3 origin=right*uv.x+up*(uv.y-.015)+eye*3.;
    vec3 ray=-eye, lamp=normalize(vec3(-.51,-.38,.79));
    vec3 floorPos=origin+ray*((-.221-origin.z)/ray.z);
    vec2 sh=floorPos.xy+vec2(-.033,.036);
    vec2 sid=abs(sh)-vec2(1.,.67);
    float shadow=exp(-length(max(sid,0.))*11.);
    vec3 ground=vec3(.38,.350,.300)*(.94+.065*field(floorPos.xy*90.))*(1.-.48*shadow);
    vec3 v1=(-vec3(1.,.67,.224)-origin)/ray,v2=(vec3(1.,.67,.224)-origin)/ray;
    vec3 enter=min(v1,v2),leave=max(v1,v2);
    float t=max(enter.x,max(enter.y,enter.z)),end=min(leave.x,min(leave.y,leave.z));
    if(t>end)return ground;
    float start=t;vec3 hit=origin+t*ray;
    for(int i=0;i<97;i++){
        hit=origin+t*ray;
        float d=surface(hit);
        if(d<.00055||t>end)break;
        t+=max(.00125,min(.020,.61*d));
    }
    if(t>end ||surface(hit)>.003)return ground;
    const float e=.0015;
    vec3 gradient=vec3(surface(hit+vec3(e,0,0))-surface(hit-vec3(e,0,0)),
        surface(hit+vec3(0,e,0))-surface(hit-vec3(0,e,0)),
        surface(hit+vec3(0,0,e))-surface(hit-vec3(0,0,e)));
    vec3 n=normalize(gradient+1e-7);
    float lumen=1.;
    for(int j=1;j<=6;j++){
        float stepL=float(j)*.012;
        lumen=min(lumen,smoothstep(-.002,.006,surface(hit+n*.003+lamp*stepL)));
    }
    float strata=bed(hit),lime=noiseVolume(hit*71.);
    float ribbon=field(vec2(hit.x*2.5+hit.y,strata*52.));
    vec3 calcite=mix(vec3(.621,.486,.331),vec3(.918,.835,.695),.26+.63*ribbon);
    float fineBed=field(vec2(hit.x*2.3+hit.y*1.7,strata*125.));
    calcite+=.068*(lime-.5)+.063*(fineBed-.5)+.018*sin(strata*205.+2.*ribbon);
    float depth=t-start;
    calcite*=.47+.51*max(0.,dot(n,lamp))*(.39+.61*lumen)+.075*max(0.,n.z);
    calcite*=.38+.62*exp(-23.*depth);
    return calcite;
}

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

Identifierporous-travertine-stone
CategoryStone & Masonry Shaders · Minerals & Gems
Upstream studyminerals/lib/05_porous_travertine.glsl (commit main)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size107 lines · 4.4 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT holy 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