PBR StudyCoarse plutonic rock mosaic of pink orthoclase feldspar, smoky quartz, and glinting black biotite.
porous-travertine-stone.glsl · 107 lines · GLSL ES 3.00 · MIT
#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);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Porous Travertine Stone — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/05_porous_travertine.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-05-porous-travertine
// Porous travertine
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 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;
// Porous Travertine Stone — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/05_porous_travertine.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-05-porous-travertine
// Porous travertine
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 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;
}
// Porous Travertine Stone — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/minerals/lib/05_porous_travertine.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-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);
}
`;
export function createPorousTravertineStoneMaterial(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 | porous-travertine-stone |
|---|---|
| Category | Stone & Masonry Shaders · Minerals & Gems |
| Upstream study | minerals/lib/05_porous_travertine.glsl (commit main) |
| Animation cycle | Static analytical PBR surface |
| Declared uniforms | uResolution |
| Source size | 107 lines · 4.4 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT holy 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
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.
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.