AnimatedOverlapping circular capillary wave rings from stochastic raindrops hitting calm dark water.
Water & Ice
deep-ocean-water-swell.glsl · 137 lines · GLSL ES 3.00 · MIT
#version 300 es
// Deep Ocean Water Swell (deep-ocean-water-swell.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/12_deep_water_swell.glsl
// License: MIT (Copyright 2026 Gokay Aydogan) + MIT/CC0 helpers — https://pixelfx.io/LICENSE-SHADERS.txt
// Uniforms: uResolution (vec2), uTime (float)
// Hash adapted from David Hoskins, Hash without Sine. See THIRD_PARTY_NOTICES.md.
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-liquids-lib-12-deep-water-swell
// Long-period open-ocean swell passing a small moored spar buoy.
// uResolution: framebuffer dimensions in pixels. Optional uTime: seconds (default 0).
precision highp float;
uniform vec2 uResolution;
uniform float uTime;
out vec4 fragColor;
const float PI=3.14159265;
vec2 frame() {
return (2.*gl_FragCoord.xy-uResolution)/min(uResolution.x,uResolution.y);
}
float hash(vec2 p) {
vec3 q=fract(p.xyx*vec3(.1031,.1030,.0973));
q+=dot(q,q.yzx+33.33);
return fract((q.x+q.y)*q.z);
}
float noise2(vec2 p) {
vec2 i=floor(p),f=fract(p);
f=f*f*(3.-2.*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.),f.x),f.y);
}
float terrain(vec2 p) {
mat2 m=mat2(1.62,1.19,-1.19,1.62);
return .54*noise2(p)+.27*noise2(m*p+7.1)+.13*noise2(m*m*p+19.)+
.06*noise2(m*m*m*p-8.3);
}
const vec3 sun=vec3(-.446,.225,.866);
float elevation(vec2 p,float t) {
float a=.72*p.y+.28*p.x-.91*t+.32*sin(.19*p.y-.23*p.x);
float b=.46*p.y-.34*p.x-.72*t;
float group=.84+.17*cos(.12*p.y+.11*p.x-.20*t);
return group*(.58*sin(a)-.091*cos(2.*a))+.24*sin(b)+
.11*sin(1.23*p.y+.39*p.x-1.16*t+1.1*sin(b))+
.047*sin(1.67*p.x-.54*p.y-1.39*t);
}
float smallWaves(vec2 p,float t) {
// Progressively shorter capillaries ride on the turning faces of the swell.
vec2 wind=vec2(.67,1.);
vec2 q=p+vec2(.13*sin(.91*p.y+.52*t),.11*sin(1.23*p.x));
float primary=terrain(q*vec2(3.3,6.8)-wind*.66*t);
float fine=noise2(q*vec2(12.4,17.2)+vec2(.85*t,-1.9*t));
return .045*primary+.009*fine;
}
vec3 sky(vec3 d,float t) {
float up=max(d.y,0.);
vec3 air=mix(vec3(.81,.83,.79),vec3(.31,.51,.67),smoothstep(0.,.68,up));
vec2 cloud=d.xz/max(.073,up+.068);
float deck=terrain(cloud*vec2(.59,1.6)+vec2(.016*t,4.));
float feather=terrain(cloud*vec2(1.9,3.1)-3.);
float cover=smoothstep(.36,.64,.83*deck+.17*feather)*smoothstep(.005,.15,up);
float sunlight=pow(max(0.,dot(d,sun)),12.);
vec3 cloudColor=mix(vec3(.62,.68,.69),vec3(.96,.91,.76),.36+.57*sunlight);
air=mix(air,cloudColor,.84*cover);
float solar=length(d-sun);
return air+vec3(.39,.27,.13)*exp(-4.6*solar)+
vec3(.91,.80,.54)*(1.-smoothstep(.016,.024,solar))*(1.-.74*cover);
}
float ball(vec3 ro,vec3 rd,vec3 center,vec3 scale) {
vec3 q=(ro-center)/scale,r=rd/scale;
float a=dot(r,r),b=dot(q,r),c=dot(q,q)-1.,h=b*b-a*c;
return h<=0.?200.:(-b-sqrt(h))/a;
}
vec3 shadeBuoy(vec3 pos,vec3 center,vec3 size,vec3 paint) {
vec3 n=normalize((pos-center)/(size*size));
return paint*(.52+.49*max(0.,dot(n,sun)))+
vec3(.88,.83,.70)*.15*pow(max(n.z*-.8+n.y*.25,0.),15.);
}
void main() {
float t=uTime+7.38; vec2 uv=frame();
vec3 ro=vec3(0.,1.71+.075*sin(.7*t),-1.3);
vec3 rd=normalize(vec3(uv.x,uv.y-.31,1.78));
float dist=.05,prev=0.; bool hit=false;
for(int i=0;i<145;i++) {
vec3 q=ro+rd*dist;
float gap=q.y-elevation(q.xz,t);
if(gap<.002) {hit=true;break;}
if(dist>115. || (q.y>1.13 && rd.y>=0.)) break;
prev=dist; dist+=max(.008,gap/max(.09,.68*length(rd.xz)-rd.y));
}
vec3 air=sky(rd,t),col=air;
if(hit) {
for(int j=0;j<6;j++) {
float m=.5*(prev+dist);vec3 q=ro+m*rd;
if(q.y>elevation(q.xz,t)) prev=m; else dist=m;
}
vec3 pos=ro+rd*dist; vec2 p=pos.xz;
float pixel=max(.008,dist/min(uResolution.x,uResolution.y));
vec2 e=vec2(pixel,0.);
vec2 slope=vec2(elevation(p+e,t)-elevation(p-e,t),
elevation(p+e.yx,t)-elevation(p-e.yx,t))/(2.*pixel);
vec2 rough=vec2(smallWaves(p+e,t)-smallWaves(p-e,t),
smallWaves(p+e.yx,t)-smallWaves(p-e.yx,t))/(2.*pixel);
vec3 n=normalize(vec3(-slope.x,1.,-slope.y)+
vec3(-rough.x,0.,-rough.y)*exp(-.023*dist));
vec3 ref=reflect(rd,n);
float fres=.033+.87*pow(1.-clamp(dot(n,-rd),0.,1.),4.);
float crest=smoothstep(-.65,.75,pos.y);
vec3 body=mix(vec3(.027,.124,.17),vec3(.066,.30,.32),crest);
col=mix(body,sky(normalize(vec3(ref.x,abs(ref.y),ref.z)),t),fres);
col+=vec3(1.,.87,.60)*pow(max(dot(ref,sun),0.),180.)*exp(-.035*dist);
col=mix(col,air,.75*smoothstep(32.,108.,dist));
} else dist=200.;
vec2 mooring=vec2(-2.33+.16*cos(.9*t),10.95+.18*sin(.8*t));
float heave=elevation(mooring,t);
vec3 center=vec3(mooring.x,heave+.025,mooring.y);
vec3 baseSize=vec3(.42,.34,.42);
float hull=ball(ro,rd,center,baseSize);
if(hull<dist) {
vec3 pos=ro+rd*hull;
vec3 paint=mix(vec3(.40,.13,.055),vec3(.88,.29,.075),smoothstep(.02,.12,pos.y-heave));
col=shadeBuoy(pos,center,baseSize,paint);dist=hull;
}
vec3 spar=center+vec3(.04*sin(t),.55,0.);
vec3 sparSize=vec3(.075,.59,.075);
float mast=ball(ro,rd,spar,sparSize);
if(mast<dist) {
dist=mast;
vec3 pos=ro+rd*mast;
float band=smoothstep(.62,.64,pos.y-heave)*(1.-smoothstep(.79,.81,pos.y-heave));
col=shadeBuoy(pos,spar,sparSize,mix(vec3(.93,.34,.065),vec3(.98,.92,.72),band));
}
vec3 lantern=spar+vec3(0.,.59,0.);
vec3 capSize=vec3(.105,.105,.105);
float cap=ball(ro,rd,lantern,capSize);
if(cap<dist) {
vec3 pos=ro+rd*cap;
vec3 paint=pos.y>lantern.y+.034?vec3(.41,.15,.066):vec3(.85,.72,.42);
col=shadeBuoy(pos,lantern,capSize,paint);
}
fragColor=vec4(col,1.);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Deep Ocean Water Swell — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/12_deep_water_swell.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;
// Hash adapted from David Hoskins, Hash without Sine. See THIRD_PARTY_NOTICES.md.
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-liquids-lib-12-deep-water-swell
// Long-period open-ocean swell passing a small moored spar buoy.
// uResolution: framebuffer dimensions in pixels. Optional uTime: seconds (default 0).
const float PI=3.14159265;
vec2 frame() {
return (2.*pfx_frag_xy-uResolution)/min(uResolution.x,uResolution.y);
}
float hash(vec2 p) {
vec3 q=fract(p.xyx*vec3(.1031,.1030,.0973));
q+=dot(q,q.yzx+33.33);
return fract((q.x+q.y)*q.z);
}
float noise2(vec2 p) {
vec2 i=floor(p),f=fract(p);
f=f*f*(3.-2.*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.),f.x),f.y);
}
float terrain(vec2 p) {
mat2 m=mat2(1.62,1.19,-1.19,1.62);
return .54*noise2(p)+.27*noise2(m*p+7.1)+.13*noise2(m*m*p+19.)+
.06*noise2(m*m*m*p-8.3);
}
const vec3 sun=vec3(-.446,.225,.866);
float elevation(vec2 p,float t) {
float a=.72*p.y+.28*p.x-.91*t+.32*sin(.19*p.y-.23*p.x);
float b=.46*p.y-.34*p.x-.72*t;
float group=.84+.17*cos(.12*p.y+.11*p.x-.20*t);
return group*(.58*sin(a)-.091*cos(2.*a))+.24*sin(b)+
.11*sin(1.23*p.y+.39*p.x-1.16*t+1.1*sin(b))+
.047*sin(1.67*p.x-.54*p.y-1.39*t);
}
float smallWaves(vec2 p,float t) {
// Progressively shorter capillaries ride on the turning faces of the swell.
vec2 wind=vec2(.67,1.);
vec2 q=p+vec2(.13*sin(.91*p.y+.52*t),.11*sin(1.23*p.x));
float primary=terrain(q*vec2(3.3,6.8)-wind*.66*t);
float fine=noise2(q*vec2(12.4,17.2)+vec2(.85*t,-1.9*t));
return .045*primary+.009*fine;
}
vec3 sky(vec3 d,float t) {
float up=max(d.y,0.);
vec3 air=mix(vec3(.81,.83,.79),vec3(.31,.51,.67),smoothstep(0.,.68,up));
vec2 cloud=d.xz/max(.073,up+.068);
float deck=terrain(cloud*vec2(.59,1.6)+vec2(.016*t,4.));
float feather=terrain(cloud*vec2(1.9,3.1)-3.);
float cover=smoothstep(.36,.64,.83*deck+.17*feather)*smoothstep(.005,.15,up);
float sunlight=pow(max(0.,dot(d,sun)),12.);
vec3 cloudColor=mix(vec3(.62,.68,.69),vec3(.96,.91,.76),.36+.57*sunlight);
air=mix(air,cloudColor,.84*cover);
float solar=length(d-sun);
return air+vec3(.39,.27,.13)*exp(-4.6*solar)+
vec3(.91,.80,.54)*(1.-smoothstep(.016,.024,solar))*(1.-.74*cover);
}
float ball(vec3 ro,vec3 rd,vec3 center,vec3 scale) {
vec3 q=(ro-center)/scale,r=rd/scale;
float a=dot(r,r),b=dot(q,r),c=dot(q,q)-1.,h=b*b-a*c;
return h<=0.?200.:(-b-sqrt(h))/a;
}
vec3 shadeBuoy(vec3 pos,vec3 center,vec3 size,vec3 paint) {
vec3 n=normalize((pos-center)/(size*size));
return paint*(.52+.49*max(0.,dot(n,sun)))+
vec3(.88,.83,.70)*.15*pow(max(n.z*-.8+n.y*.25,0.),15.);
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
float t=uTime+7.38; vec2 uv=frame();
vec3 ro=vec3(0.,1.71+.075*sin(.7*t),-1.3);
vec3 rd=normalize(vec3(uv.x,uv.y-.31,1.78));
float dist=.05,prev=0.; bool hit=false;
for(int i=0;i<145;i++) {
vec3 q=ro+rd*dist;
float gap=q.y-elevation(q.xz,t);
if(gap<.002) {hit=true;break;}
if(dist>115. || (q.y>1.13 && rd.y>=0.)) break;
prev=dist; dist+=max(.008,gap/max(.09,.68*length(rd.xz)-rd.y));
}
vec3 air=sky(rd,t),col=air;
if(hit) {
for(int j=0;j<6;j++) {
float m=.5*(prev+dist);vec3 q=ro+m*rd;
if(q.y>elevation(q.xz,t)) prev=m; else dist=m;
}
vec3 pos=ro+rd*dist; vec2 p=pos.xz;
float pixel=max(.008,dist/min(uResolution.x,uResolution.y));
vec2 e=vec2(pixel,0.);
vec2 slope=vec2(elevation(p+e,t)-elevation(p-e,t),
elevation(p+e.yx,t)-elevation(p-e.yx,t))/(2.*pixel);
vec2 rough=vec2(smallWaves(p+e,t)-smallWaves(p-e,t),
smallWaves(p+e.yx,t)-smallWaves(p-e.yx,t))/(2.*pixel);
vec3 n=normalize(vec3(-slope.x,1.,-slope.y)+
vec3(-rough.x,0.,-rough.y)*exp(-.023*dist));
vec3 ref=reflect(rd,n);
float fres=.033+.87*pow(1.-clamp(dot(n,-rd),0.,1.),4.);
float crest=smoothstep(-.65,.75,pos.y);
vec3 body=mix(vec3(.027,.124,.17),vec3(.066,.30,.32),crest);
col=mix(body,sky(normalize(vec3(ref.x,abs(ref.y),ref.z)),t),fres);
col+=vec3(1.,.87,.60)*pow(max(dot(ref,sun),0.),180.)*exp(-.035*dist);
col=mix(col,air,.75*smoothstep(32.,108.,dist));
} else dist=200.;
vec2 mooring=vec2(-2.33+.16*cos(.9*t),10.95+.18*sin(.8*t));
float heave=elevation(mooring,t);
vec3 center=vec3(mooring.x,heave+.025,mooring.y);
vec3 baseSize=vec3(.42,.34,.42);
float hull=ball(ro,rd,center,baseSize);
if(hull<dist) {
vec3 pos=ro+rd*hull;
vec3 paint=mix(vec3(.40,.13,.055),vec3(.88,.29,.075),smoothstep(.02,.12,pos.y-heave));
col=shadeBuoy(pos,center,baseSize,paint);dist=hull;
}
vec3 spar=center+vec3(.04*sin(t),.55,0.);
vec3 sparSize=vec3(.075,.59,.075);
float mast=ball(ro,rd,spar,sparSize);
if(mast<dist) {
dist=mast;
vec3 pos=ro+rd*mast;
float band=smoothstep(.62,.64,pos.y-heave)*(1.-smoothstep(.79,.81,pos.y-heave));
col=shadeBuoy(pos,spar,sparSize,mix(vec3(.93,.34,.065),vec3(.98,.92,.72),band));
}
vec3 lantern=spar+vec3(0.,.59,0.);
vec3 capSize=vec3(.105,.105,.105);
float cap=ball(ro,rd,lantern,capSize);
if(cap<dist) {
vec3 pos=ro+rd*cap;
vec3 paint=pos.y>lantern.y+.034?vec3(.41,.15,.066):vec3(.85,.72,.42);
col=shadeBuoy(pos,lantern,capSize,paint);
}
fragColor=vec4(col,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;
// Deep Ocean Water Swell — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/12_deep_water_swell.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;
// Hash adapted from David Hoskins, Hash without Sine. See THIRD_PARTY_NOTICES.md.
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-liquids-lib-12-deep-water-swell
// Long-period open-ocean swell passing a small moored spar buoy.
// uResolution: framebuffer dimensions in pixels. Optional uTime: seconds (default 0).
const float PI=3.14159265;
vec2 frame() {
return (2.*pfx_frag_xy-uResolution)/min(uResolution.x,uResolution.y);
}
float hash(vec2 p) {
vec3 q=fract(p.xyx*vec3(.1031,.1030,.0973));
q+=dot(q,q.yzx+33.33);
return fract((q.x+q.y)*q.z);
}
float noise2(vec2 p) {
vec2 i=floor(p),f=fract(p);
f=f*f*(3.-2.*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.),f.x),f.y);
}
float terrain(vec2 p) {
mat2 m=mat2(1.62,1.19,-1.19,1.62);
return .54*noise2(p)+.27*noise2(m*p+7.1)+.13*noise2(m*m*p+19.)+
.06*noise2(m*m*m*p-8.3);
}
const vec3 sun=vec3(-.446,.225,.866);
float elevation(vec2 p,float t) {
float a=.72*p.y+.28*p.x-.91*t+.32*sin(.19*p.y-.23*p.x);
float b=.46*p.y-.34*p.x-.72*t;
float group=.84+.17*cos(.12*p.y+.11*p.x-.20*t);
return group*(.58*sin(a)-.091*cos(2.*a))+.24*sin(b)+
.11*sin(1.23*p.y+.39*p.x-1.16*t+1.1*sin(b))+
.047*sin(1.67*p.x-.54*p.y-1.39*t);
}
float smallWaves(vec2 p,float t) {
// Progressively shorter capillaries ride on the turning faces of the swell.
vec2 wind=vec2(.67,1.);
vec2 q=p+vec2(.13*sin(.91*p.y+.52*t),.11*sin(1.23*p.x));
float primary=terrain(q*vec2(3.3,6.8)-wind*.66*t);
float fine=noise2(q*vec2(12.4,17.2)+vec2(.85*t,-1.9*t));
return .045*primary+.009*fine;
}
vec3 sky(vec3 d,float t) {
float up=max(d.y,0.);
vec3 air=mix(vec3(.81,.83,.79),vec3(.31,.51,.67),smoothstep(0.,.68,up));
vec2 cloud=d.xz/max(.073,up+.068);
float deck=terrain(cloud*vec2(.59,1.6)+vec2(.016*t,4.));
float feather=terrain(cloud*vec2(1.9,3.1)-3.);
float cover=smoothstep(.36,.64,.83*deck+.17*feather)*smoothstep(.005,.15,up);
float sunlight=pow(max(0.,dot(d,sun)),12.);
vec3 cloudColor=mix(vec3(.62,.68,.69),vec3(.96,.91,.76),.36+.57*sunlight);
air=mix(air,cloudColor,.84*cover);
float solar=length(d-sun);
return air+vec3(.39,.27,.13)*exp(-4.6*solar)+
vec3(.91,.80,.54)*(1.-smoothstep(.016,.024,solar))*(1.-.74*cover);
}
float ball(vec3 ro,vec3 rd,vec3 center,vec3 scale) {
vec3 q=(ro-center)/scale,r=rd/scale;
float a=dot(r,r),b=dot(q,r),c=dot(q,q)-1.,h=b*b-a*c;
return h<=0.?200.:(-b-sqrt(h))/a;
}
vec3 shadeBuoy(vec3 pos,vec3 center,vec3 size,vec3 paint) {
vec3 n=normalize((pos-center)/(size*size));
return paint*(.52+.49*max(0.,dot(n,sun)))+
vec3(.88,.83,.70)*.15*pow(max(n.z*-.8+n.y*.25,0.),15.);
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
float t=uTime+7.38; vec2 uv=frame();
vec3 ro=vec3(0.,1.71+.075*sin(.7*t),-1.3);
vec3 rd=normalize(vec3(uv.x,uv.y-.31,1.78));
float dist=.05,prev=0.; bool hit=false;
for(int i=0;i<145;i++) {
vec3 q=ro+rd*dist;
float gap=q.y-elevation(q.xz,t);
if(gap<.002) {hit=true;break;}
if(dist>115. || (q.y>1.13 && rd.y>=0.)) break;
prev=dist; dist+=max(.008,gap/max(.09,.68*length(rd.xz)-rd.y));
}
vec3 air=sky(rd,t),col=air;
if(hit) {
for(int j=0;j<6;j++) {
float m=.5*(prev+dist);vec3 q=ro+m*rd;
if(q.y>elevation(q.xz,t)) prev=m; else dist=m;
}
vec3 pos=ro+rd*dist; vec2 p=pos.xz;
float pixel=max(.008,dist/min(uResolution.x,uResolution.y));
vec2 e=vec2(pixel,0.);
vec2 slope=vec2(elevation(p+e,t)-elevation(p-e,t),
elevation(p+e.yx,t)-elevation(p-e.yx,t))/(2.*pixel);
vec2 rough=vec2(smallWaves(p+e,t)-smallWaves(p-e,t),
smallWaves(p+e.yx,t)-smallWaves(p-e.yx,t))/(2.*pixel);
vec3 n=normalize(vec3(-slope.x,1.,-slope.y)+
vec3(-rough.x,0.,-rough.y)*exp(-.023*dist));
vec3 ref=reflect(rd,n);
float fres=.033+.87*pow(1.-clamp(dot(n,-rd),0.,1.),4.);
float crest=smoothstep(-.65,.75,pos.y);
vec3 body=mix(vec3(.027,.124,.17),vec3(.066,.30,.32),crest);
col=mix(body,sky(normalize(vec3(ref.x,abs(ref.y),ref.z)),t),fres);
col+=vec3(1.,.87,.60)*pow(max(dot(ref,sun),0.),180.)*exp(-.035*dist);
col=mix(col,air,.75*smoothstep(32.,108.,dist));
} else dist=200.;
vec2 mooring=vec2(-2.33+.16*cos(.9*t),10.95+.18*sin(.8*t));
float heave=elevation(mooring,t);
vec3 center=vec3(mooring.x,heave+.025,mooring.y);
vec3 baseSize=vec3(.42,.34,.42);
float hull=ball(ro,rd,center,baseSize);
if(hull<dist) {
vec3 pos=ro+rd*hull;
vec3 paint=mix(vec3(.40,.13,.055),vec3(.88,.29,.075),smoothstep(.02,.12,pos.y-heave));
col=shadeBuoy(pos,center,baseSize,paint);dist=hull;
}
vec3 spar=center+vec3(.04*sin(t),.55,0.);
vec3 sparSize=vec3(.075,.59,.075);
float mast=ball(ro,rd,spar,sparSize);
if(mast<dist) {
dist=mast;
vec3 pos=ro+rd*mast;
float band=smoothstep(.62,.64,pos.y-heave)*(1.-smoothstep(.79,.81,pos.y-heave));
col=shadeBuoy(pos,spar,sparSize,mix(vec3(.93,.34,.065),vec3(.98,.92,.72),band));
}
vec3 lantern=spar+vec3(0.,.59,0.);
vec3 capSize=vec3(.105,.105,.105);
float cap=ball(ro,rd,lantern,capSize);
if(cap<dist) {
vec3 pos=ro+rd*cap;
vec3 paint=pos.y>lantern.y+.034?vec3(.41,.15,.066):vec3(.85,.72,.42);
col=shadeBuoy(pos,lantern,capSize,paint);
}
fragColor=vec4(col,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;
}
// Deep Ocean Water Swell — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/12_deep_water_swell.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 */ `
// Hash adapted from David Hoskins, Hash without Sine. See THIRD_PARTY_NOTICES.md.
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-liquids-lib-12-deep-water-swell
// Long-period open-ocean swell passing a small moored spar buoy.
// uResolution: framebuffer dimensions in pixels. Optional uTime: seconds (default 0).
precision highp float;
uniform vec2 uResolution;
uniform float uTime;
out vec4 fragColor;
const float PI=3.14159265;
vec2 frame() {
return (2.*gl_FragCoord.xy-uResolution)/min(uResolution.x,uResolution.y);
}
float hash(vec2 p) {
vec3 q=fract(p.xyx*vec3(.1031,.1030,.0973));
q+=dot(q,q.yzx+33.33);
return fract((q.x+q.y)*q.z);
}
float noise2(vec2 p) {
vec2 i=floor(p),f=fract(p);
f=f*f*(3.-2.*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.),f.x),f.y);
}
float terrain(vec2 p) {
mat2 m=mat2(1.62,1.19,-1.19,1.62);
return .54*noise2(p)+.27*noise2(m*p+7.1)+.13*noise2(m*m*p+19.)+
.06*noise2(m*m*m*p-8.3);
}
const vec3 sun=vec3(-.446,.225,.866);
float elevation(vec2 p,float t) {
float a=.72*p.y+.28*p.x-.91*t+.32*sin(.19*p.y-.23*p.x);
float b=.46*p.y-.34*p.x-.72*t;
float group=.84+.17*cos(.12*p.y+.11*p.x-.20*t);
return group*(.58*sin(a)-.091*cos(2.*a))+.24*sin(b)+
.11*sin(1.23*p.y+.39*p.x-1.16*t+1.1*sin(b))+
.047*sin(1.67*p.x-.54*p.y-1.39*t);
}
float smallWaves(vec2 p,float t) {
// Progressively shorter capillaries ride on the turning faces of the swell.
vec2 wind=vec2(.67,1.);
vec2 q=p+vec2(.13*sin(.91*p.y+.52*t),.11*sin(1.23*p.x));
float primary=terrain(q*vec2(3.3,6.8)-wind*.66*t);
float fine=noise2(q*vec2(12.4,17.2)+vec2(.85*t,-1.9*t));
return .045*primary+.009*fine;
}
vec3 sky(vec3 d,float t) {
float up=max(d.y,0.);
vec3 air=mix(vec3(.81,.83,.79),vec3(.31,.51,.67),smoothstep(0.,.68,up));
vec2 cloud=d.xz/max(.073,up+.068);
float deck=terrain(cloud*vec2(.59,1.6)+vec2(.016*t,4.));
float feather=terrain(cloud*vec2(1.9,3.1)-3.);
float cover=smoothstep(.36,.64,.83*deck+.17*feather)*smoothstep(.005,.15,up);
float sunlight=pow(max(0.,dot(d,sun)),12.);
vec3 cloudColor=mix(vec3(.62,.68,.69),vec3(.96,.91,.76),.36+.57*sunlight);
air=mix(air,cloudColor,.84*cover);
float solar=length(d-sun);
return air+vec3(.39,.27,.13)*exp(-4.6*solar)+
vec3(.91,.80,.54)*(1.-smoothstep(.016,.024,solar))*(1.-.74*cover);
}
float ball(vec3 ro,vec3 rd,vec3 center,vec3 scale) {
vec3 q=(ro-center)/scale,r=rd/scale;
float a=dot(r,r),b=dot(q,r),c=dot(q,q)-1.,h=b*b-a*c;
return h<=0.?200.:(-b-sqrt(h))/a;
}
vec3 shadeBuoy(vec3 pos,vec3 center,vec3 size,vec3 paint) {
vec3 n=normalize((pos-center)/(size*size));
return paint*(.52+.49*max(0.,dot(n,sun)))+
vec3(.88,.83,.70)*.15*pow(max(n.z*-.8+n.y*.25,0.),15.);
}
void main() {
float t=uTime+7.38; vec2 uv=frame();
vec3 ro=vec3(0.,1.71+.075*sin(.7*t),-1.3);
vec3 rd=normalize(vec3(uv.x,uv.y-.31,1.78));
float dist=.05,prev=0.; bool hit=false;
for(int i=0;i<145;i++) {
vec3 q=ro+rd*dist;
float gap=q.y-elevation(q.xz,t);
if(gap<.002) {hit=true;break;}
if(dist>115. || (q.y>1.13 && rd.y>=0.)) break;
prev=dist; dist+=max(.008,gap/max(.09,.68*length(rd.xz)-rd.y));
}
vec3 air=sky(rd,t),col=air;
if(hit) {
for(int j=0;j<6;j++) {
float m=.5*(prev+dist);vec3 q=ro+m*rd;
if(q.y>elevation(q.xz,t)) prev=m; else dist=m;
}
vec3 pos=ro+rd*dist; vec2 p=pos.xz;
float pixel=max(.008,dist/min(uResolution.x,uResolution.y));
vec2 e=vec2(pixel,0.);
vec2 slope=vec2(elevation(p+e,t)-elevation(p-e,t),
elevation(p+e.yx,t)-elevation(p-e.yx,t))/(2.*pixel);
vec2 rough=vec2(smallWaves(p+e,t)-smallWaves(p-e,t),
smallWaves(p+e.yx,t)-smallWaves(p-e.yx,t))/(2.*pixel);
vec3 n=normalize(vec3(-slope.x,1.,-slope.y)+
vec3(-rough.x,0.,-rough.y)*exp(-.023*dist));
vec3 ref=reflect(rd,n);
float fres=.033+.87*pow(1.-clamp(dot(n,-rd),0.,1.),4.);
float crest=smoothstep(-.65,.75,pos.y);
vec3 body=mix(vec3(.027,.124,.17),vec3(.066,.30,.32),crest);
col=mix(body,sky(normalize(vec3(ref.x,abs(ref.y),ref.z)),t),fres);
col+=vec3(1.,.87,.60)*pow(max(dot(ref,sun),0.),180.)*exp(-.035*dist);
col=mix(col,air,.75*smoothstep(32.,108.,dist));
} else dist=200.;
vec2 mooring=vec2(-2.33+.16*cos(.9*t),10.95+.18*sin(.8*t));
float heave=elevation(mooring,t);
vec3 center=vec3(mooring.x,heave+.025,mooring.y);
vec3 baseSize=vec3(.42,.34,.42);
float hull=ball(ro,rd,center,baseSize);
if(hull<dist) {
vec3 pos=ro+rd*hull;
vec3 paint=mix(vec3(.40,.13,.055),vec3(.88,.29,.075),smoothstep(.02,.12,pos.y-heave));
col=shadeBuoy(pos,center,baseSize,paint);dist=hull;
}
vec3 spar=center+vec3(.04*sin(t),.55,0.);
vec3 sparSize=vec3(.075,.59,.075);
float mast=ball(ro,rd,spar,sparSize);
if(mast<dist) {
dist=mast;
vec3 pos=ro+rd*mast;
float band=smoothstep(.62,.64,pos.y-heave)*(1.-smoothstep(.79,.81,pos.y-heave));
col=shadeBuoy(pos,spar,sparSize,mix(vec3(.93,.34,.065),vec3(.98,.92,.72),band));
}
vec3 lantern=spar+vec3(0.,.59,0.);
vec3 capSize=vec3(.105,.105,.105);
float cap=ball(ro,rd,lantern,capSize);
if(cap<dist) {
vec3 pos=ro+rd*cap;
vec3 paint=pos.y>lantern.y+.034?vec3(.41,.15,.066):vec3(.85,.72,.42);
col=shadeBuoy(pos,lantern,capSize,paint);
}
fragColor=vec4(col,1.);
}
`;
export function createDeepOceanWaterSwellMaterial(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 | deep-ocean-water-swell |
|---|---|
| Category | Water & Ice Shaders · Dynamic Liquids |
| Upstream study | liquids/lib/12_deep_water_swell.glsl (commit c3a6f6c) |
| Animation cycle | Continuous procedural uTime |
| Declared uniforms | uResolution, uTime |
| Source size | 137 lines · 5.6 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT water sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Procedural signed-distance and analytic surface shading
David Hoskins, hash
AnimatedOverlapping circular capillary wave rings from stochastic raindrops hitting calm dark water.
AnimatedClear shallow stream refracting submerged riverbed stones with stationary standing wave crests.
AnimatedVoronoi-stretched white surf foam webbing floating over aerated turquoise seawater.
AnimatedPolyhedral soap-bubble cluster with Plateau liquid borders and thin-film rainbow interference.
PBR StudyClear refractive ice stalactites with characteristic centimetre-scale horizontal growth ribs.
PBR StudyFeathery granular rime ice feathers accreting into freezing alpine wind.