AnimatedAdvancing and retreating beach wave sheet leaving wet darkened sand and lacy foam.
kelvin-ship-water-wake.glsl · 98 lines · GLSL ES 3.00 · MIT
#version 300 es
// Kelvin Ship Water Wake (kelvin-ship-water-wake.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/07_kelvin_ship_wake_behind_a_moving_point.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-07-kelvin-ship-wake-behind-a-moving-point
// An aerial tracking view of a pilot launch and its deep-water Kelvin wake.
// 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);
}
float sea(vec2 q,float t) {
vec2 world=q+vec2(0.,.42*t);
vec2 windCoord=world*vec2(6.,15.)+vec2(-.48*t,.66*t);
windCoord+=1.8*vec2(terrain(world*3.),terrain(world*3.+9.));
float wind=.009*terrain(windCoord)+.0035*noise2(windCoord*2.13+13.);
float aft=max(-q.y,.01),ratio=abs(q.x)/aft;
float root=sqrt(max(0.,1.-8.*ratio*ratio));
float k1=2.*ratio/(1.+root), k2=min(4.,(1.+root)/max(.006,4.*ratio));
float pa=33.*sqrt(1.+k1*k1)*(aft-abs(q.x)*k1);
float modulation=terrain(7.*world+vec2(.12*t,0.));
float pb=33.*sqrt(1.+k2*k2)*(aft-abs(q.x)*k2)+.48*(modulation-.5);
float pixel=2./min(uResolution.x,uResolution.y);
float filterB=exp(-.12*pow(33.*pixel*(1.+k2*k2),2.));
float fan=smoothstep(.04,.24,aft)*(1.-smoothstep(.32,.38,ratio))/(1.+.40*aft);
return wind+fan*(.012*sin(pa)+.008*sin(pb)*(.61+.66*modulation)*smoothstep(.08,.31,ratio)*filterB);
}
float rectangle(vec2 p,vec2 halfSize,float corner) {
vec2 d=abs(p)-halfSize+corner;
return length(max(d,0.))+min(max(d.x,d.y),0.)-corner;
}
vec3 vessel(vec2 q,vec3 ocean,float aa) {
vec2 p=q/vec2(.078,.222);
float beam=mix(.78,1.,smoothstep(-1.,-.48,p.y))*
sqrt(max(0.,1.-pow(clamp((p.y+.06)/1.06,0.,1.),1.5)));
float hull=max(abs(p.x)-beam,max(-p.y-.88,p.y-1.));
float edge=aa/.078;
vec3 deck=mix(vec3(.85,.80,.64),vec3(.49,.37,.22),.15+.15*noise2(q*170.));
deck=mix(deck,vec3(.083,.18,.19),1.-smoothstep(.035,.09,-hull));
deck=mix(deck,vec3(.92,.91,.80),1.-smoothstep(.015,.055,abs(hull+.13)));
float cabin=rectangle(p-vec2(0.,-.03),vec2(.65,.40),.09);
deck=mix(deck,vec3(.14,.23,.26),1.-smoothstep(-edge*.4,edge*.4,cabin));
float roof=rectangle(p-vec2(0.,-.11),vec2(.53,.25),.06);
deck=mix(deck,vec3(.86,.45,.19),1.-smoothstep(-edge*.4,edge*.4,roof));
float stripe=abs(p.x+.15)-.06;
deck=mix(deck,vec3(.94,.81,.51),.55*(1.-smoothstep(-edge,edge,stripe))*(1.-smoothstep(-edge,edge,roof)));
float hatch=length((p-vec2(0.,.53))/vec2(.25,.093));
deck=mix(deck,vec3(.21,.29,.28),1.-smoothstep(.8,1.,hatch));
float engine=rectangle(p-vec2(0.,-.84),vec2(.22,.12),.08);
deck=mix(deck,vec3(.13,.17,.18),1.-smoothstep(-edge,edge,engine));
return mix(ocean,deck,1.-smoothstep(-edge,edge,hull));
}
void main() {
vec2 uv=frame(); float t=uTime+3.18;
vec2 q=mat2(.88,.475,-.475,.88)*(uv-vec2(.27,.56+.055*sin(.71*t)));
float aa=2./min(uResolution.x,uResolution.y);
vec2 e=vec2(max(.002,aa*.63),0.);
vec2 g=vec2(sea(q+e,t)-sea(q-e,t),sea(q+e.yx,t)-sea(q-e.yx,t))/(2.*e.x);
vec3 n=normalize(vec3(-g,1.)),refl=reflect(normalize(vec3(-.08,.20,-.98)),n);
vec2 moving=q+vec2(0.,.42*t);
float shoal=terrain(moving*vec2(1.8,2.6));
vec3 col=mix(vec3(.046,.19,.21),vec3(.17,.42,.39),shoal);
float sky=smoothstep(-.72,.83,refl.y+.48*refl.x);
col+=vec3(.11,.18,.20)*sky;
col+=vec3(.43,.46,.40)*pow(max(dot(refl,normalize(vec3(-.49,.53,.69))),0.),26.);
float aft=max(0.,-q.y-.15);
float churnWidth=.025+.078*sqrt(aft);
float swirl=q.x+.034*sqrt(aft)*sin(12.*aft-2.8*t);
float stirred=exp(-swirl*swirl/(churnWidth*churnWidth))*exp(-1.3*aft)*smoothstep(.0,.065,aft);
vec2 f=vec2(q.x*48.,aft*24.-4.*t);
float turbulent=terrain(f+2.2*vec2(noise2(f*.28),noise2(f*.24+3.)));
float bow=exp(-abs(abs(q.x)-(.055+.26*max(0.,.10-q.y)))/(.008+.006*aft))
*smoothstep(-.70,-.13,q.y)*(1.-smoothstep(.04,.15,q.y));
float foam=stirred*smoothstep(.25,.66,turbulent)+bow*(.30+.62*turbulent);
col=mix(col,vec3(.83,.91,.84),clamp(foam*1.30,0.,.97));
fragColor=vec4(vessel(q,col,aa),1.);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Kelvin Ship Water Wake — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/07_kelvin_ship_wake_behind_a_moving_point.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-07-kelvin-ship-wake-behind-a-moving-point
// An aerial tracking view of a pilot launch and its deep-water Kelvin wake.
// 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);
}
float sea(vec2 q,float t) {
vec2 world=q+vec2(0.,.42*t);
vec2 windCoord=world*vec2(6.,15.)+vec2(-.48*t,.66*t);
windCoord+=1.8*vec2(terrain(world*3.),terrain(world*3.+9.));
float wind=.009*terrain(windCoord)+.0035*noise2(windCoord*2.13+13.);
float aft=max(-q.y,.01),ratio=abs(q.x)/aft;
float root=sqrt(max(0.,1.-8.*ratio*ratio));
float k1=2.*ratio/(1.+root), k2=min(4.,(1.+root)/max(.006,4.*ratio));
float pa=33.*sqrt(1.+k1*k1)*(aft-abs(q.x)*k1);
float modulation=terrain(7.*world+vec2(.12*t,0.));
float pb=33.*sqrt(1.+k2*k2)*(aft-abs(q.x)*k2)+.48*(modulation-.5);
float pixel=2./min(uResolution.x,uResolution.y);
float filterB=exp(-.12*pow(33.*pixel*(1.+k2*k2),2.));
float fan=smoothstep(.04,.24,aft)*(1.-smoothstep(.32,.38,ratio))/(1.+.40*aft);
return wind+fan*(.012*sin(pa)+.008*sin(pb)*(.61+.66*modulation)*smoothstep(.08,.31,ratio)*filterB);
}
float rectangle(vec2 p,vec2 halfSize,float corner) {
vec2 d=abs(p)-halfSize+corner;
return length(max(d,0.))+min(max(d.x,d.y),0.)-corner;
}
vec3 vessel(vec2 q,vec3 ocean,float aa) {
vec2 p=q/vec2(.078,.222);
float beam=mix(.78,1.,smoothstep(-1.,-.48,p.y))*
sqrt(max(0.,1.-pow(clamp((p.y+.06)/1.06,0.,1.),1.5)));
float hull=max(abs(p.x)-beam,max(-p.y-.88,p.y-1.));
float edge=aa/.078;
vec3 deck=mix(vec3(.85,.80,.64),vec3(.49,.37,.22),.15+.15*noise2(q*170.));
deck=mix(deck,vec3(.083,.18,.19),1.-smoothstep(.035,.09,-hull));
deck=mix(deck,vec3(.92,.91,.80),1.-smoothstep(.015,.055,abs(hull+.13)));
float cabin=rectangle(p-vec2(0.,-.03),vec2(.65,.40),.09);
deck=mix(deck,vec3(.14,.23,.26),1.-smoothstep(-edge*.4,edge*.4,cabin));
float roof=rectangle(p-vec2(0.,-.11),vec2(.53,.25),.06);
deck=mix(deck,vec3(.86,.45,.19),1.-smoothstep(-edge*.4,edge*.4,roof));
float stripe=abs(p.x+.15)-.06;
deck=mix(deck,vec3(.94,.81,.51),.55*(1.-smoothstep(-edge,edge,stripe))*(1.-smoothstep(-edge,edge,roof)));
float hatch=length((p-vec2(0.,.53))/vec2(.25,.093));
deck=mix(deck,vec3(.21,.29,.28),1.-smoothstep(.8,1.,hatch));
float engine=rectangle(p-vec2(0.,-.84),vec2(.22,.12),.08);
deck=mix(deck,vec3(.13,.17,.18),1.-smoothstep(-edge,edge,engine));
return mix(ocean,deck,1.-smoothstep(-edge,edge,hull));
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv=frame(); float t=uTime+3.18;
vec2 q=mat2(.88,.475,-.475,.88)*(uv-vec2(.27,.56+.055*sin(.71*t)));
float aa=2./min(uResolution.x,uResolution.y);
vec2 e=vec2(max(.002,aa*.63),0.);
vec2 g=vec2(sea(q+e,t)-sea(q-e,t),sea(q+e.yx,t)-sea(q-e.yx,t))/(2.*e.x);
vec3 n=normalize(vec3(-g,1.)),refl=reflect(normalize(vec3(-.08,.20,-.98)),n);
vec2 moving=q+vec2(0.,.42*t);
float shoal=terrain(moving*vec2(1.8,2.6));
vec3 col=mix(vec3(.046,.19,.21),vec3(.17,.42,.39),shoal);
float sky=smoothstep(-.72,.83,refl.y+.48*refl.x);
col+=vec3(.11,.18,.20)*sky;
col+=vec3(.43,.46,.40)*pow(max(dot(refl,normalize(vec3(-.49,.53,.69))),0.),26.);
float aft=max(0.,-q.y-.15);
float churnWidth=.025+.078*sqrt(aft);
float swirl=q.x+.034*sqrt(aft)*sin(12.*aft-2.8*t);
float stirred=exp(-swirl*swirl/(churnWidth*churnWidth))*exp(-1.3*aft)*smoothstep(.0,.065,aft);
vec2 f=vec2(q.x*48.,aft*24.-4.*t);
float turbulent=terrain(f+2.2*vec2(noise2(f*.28),noise2(f*.24+3.)));
float bow=exp(-abs(abs(q.x)-(.055+.26*max(0.,.10-q.y)))/(.008+.006*aft))
*smoothstep(-.70,-.13,q.y)*(1.-smoothstep(.04,.15,q.y));
float foam=stirred*smoothstep(.25,.66,turbulent)+bow*(.30+.62*turbulent);
col=mix(col,vec3(.83,.91,.84),clamp(foam*1.30,0.,.97));
fragColor=vec4(vessel(q,col,aa),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;
// Kelvin Ship Water Wake — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/07_kelvin_ship_wake_behind_a_moving_point.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-07-kelvin-ship-wake-behind-a-moving-point
// An aerial tracking view of a pilot launch and its deep-water Kelvin wake.
// 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);
}
float sea(vec2 q,float t) {
vec2 world=q+vec2(0.,.42*t);
vec2 windCoord=world*vec2(6.,15.)+vec2(-.48*t,.66*t);
windCoord+=1.8*vec2(terrain(world*3.),terrain(world*3.+9.));
float wind=.009*terrain(windCoord)+.0035*noise2(windCoord*2.13+13.);
float aft=max(-q.y,.01),ratio=abs(q.x)/aft;
float root=sqrt(max(0.,1.-8.*ratio*ratio));
float k1=2.*ratio/(1.+root), k2=min(4.,(1.+root)/max(.006,4.*ratio));
float pa=33.*sqrt(1.+k1*k1)*(aft-abs(q.x)*k1);
float modulation=terrain(7.*world+vec2(.12*t,0.));
float pb=33.*sqrt(1.+k2*k2)*(aft-abs(q.x)*k2)+.48*(modulation-.5);
float pixel=2./min(uResolution.x,uResolution.y);
float filterB=exp(-.12*pow(33.*pixel*(1.+k2*k2),2.));
float fan=smoothstep(.04,.24,aft)*(1.-smoothstep(.32,.38,ratio))/(1.+.40*aft);
return wind+fan*(.012*sin(pa)+.008*sin(pb)*(.61+.66*modulation)*smoothstep(.08,.31,ratio)*filterB);
}
float rectangle(vec2 p,vec2 halfSize,float corner) {
vec2 d=abs(p)-halfSize+corner;
return length(max(d,0.))+min(max(d.x,d.y),0.)-corner;
}
vec3 vessel(vec2 q,vec3 ocean,float aa) {
vec2 p=q/vec2(.078,.222);
float beam=mix(.78,1.,smoothstep(-1.,-.48,p.y))*
sqrt(max(0.,1.-pow(clamp((p.y+.06)/1.06,0.,1.),1.5)));
float hull=max(abs(p.x)-beam,max(-p.y-.88,p.y-1.));
float edge=aa/.078;
vec3 deck=mix(vec3(.85,.80,.64),vec3(.49,.37,.22),.15+.15*noise2(q*170.));
deck=mix(deck,vec3(.083,.18,.19),1.-smoothstep(.035,.09,-hull));
deck=mix(deck,vec3(.92,.91,.80),1.-smoothstep(.015,.055,abs(hull+.13)));
float cabin=rectangle(p-vec2(0.,-.03),vec2(.65,.40),.09);
deck=mix(deck,vec3(.14,.23,.26),1.-smoothstep(-edge*.4,edge*.4,cabin));
float roof=rectangle(p-vec2(0.,-.11),vec2(.53,.25),.06);
deck=mix(deck,vec3(.86,.45,.19),1.-smoothstep(-edge*.4,edge*.4,roof));
float stripe=abs(p.x+.15)-.06;
deck=mix(deck,vec3(.94,.81,.51),.55*(1.-smoothstep(-edge,edge,stripe))*(1.-smoothstep(-edge,edge,roof)));
float hatch=length((p-vec2(0.,.53))/vec2(.25,.093));
deck=mix(deck,vec3(.21,.29,.28),1.-smoothstep(.8,1.,hatch));
float engine=rectangle(p-vec2(0.,-.84),vec2(.22,.12),.08);
deck=mix(deck,vec3(.13,.17,.18),1.-smoothstep(-edge,edge,engine));
return mix(ocean,deck,1.-smoothstep(-edge,edge,hull));
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv=frame(); float t=uTime+3.18;
vec2 q=mat2(.88,.475,-.475,.88)*(uv-vec2(.27,.56+.055*sin(.71*t)));
float aa=2./min(uResolution.x,uResolution.y);
vec2 e=vec2(max(.002,aa*.63),0.);
vec2 g=vec2(sea(q+e,t)-sea(q-e,t),sea(q+e.yx,t)-sea(q-e.yx,t))/(2.*e.x);
vec3 n=normalize(vec3(-g,1.)),refl=reflect(normalize(vec3(-.08,.20,-.98)),n);
vec2 moving=q+vec2(0.,.42*t);
float shoal=terrain(moving*vec2(1.8,2.6));
vec3 col=mix(vec3(.046,.19,.21),vec3(.17,.42,.39),shoal);
float sky=smoothstep(-.72,.83,refl.y+.48*refl.x);
col+=vec3(.11,.18,.20)*sky;
col+=vec3(.43,.46,.40)*pow(max(dot(refl,normalize(vec3(-.49,.53,.69))),0.),26.);
float aft=max(0.,-q.y-.15);
float churnWidth=.025+.078*sqrt(aft);
float swirl=q.x+.034*sqrt(aft)*sin(12.*aft-2.8*t);
float stirred=exp(-swirl*swirl/(churnWidth*churnWidth))*exp(-1.3*aft)*smoothstep(.0,.065,aft);
vec2 f=vec2(q.x*48.,aft*24.-4.*t);
float turbulent=terrain(f+2.2*vec2(noise2(f*.28),noise2(f*.24+3.)));
float bow=exp(-abs(abs(q.x)-(.055+.26*max(0.,.10-q.y)))/(.008+.006*aft))
*smoothstep(-.70,-.13,q.y)*(1.-smoothstep(.04,.15,q.y));
float foam=stirred*smoothstep(.25,.66,turbulent)+bow*(.30+.62*turbulent);
col=mix(col,vec3(.83,.91,.84),clamp(foam*1.30,0.,.97));
fragColor=vec4(vessel(q,col,aa),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;
}
// Kelvin Ship Water Wake — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/07_kelvin_ship_wake_behind_a_moving_point.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-07-kelvin-ship-wake-behind-a-moving-point
// An aerial tracking view of a pilot launch and its deep-water Kelvin wake.
// 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);
}
float sea(vec2 q,float t) {
vec2 world=q+vec2(0.,.42*t);
vec2 windCoord=world*vec2(6.,15.)+vec2(-.48*t,.66*t);
windCoord+=1.8*vec2(terrain(world*3.),terrain(world*3.+9.));
float wind=.009*terrain(windCoord)+.0035*noise2(windCoord*2.13+13.);
float aft=max(-q.y,.01),ratio=abs(q.x)/aft;
float root=sqrt(max(0.,1.-8.*ratio*ratio));
float k1=2.*ratio/(1.+root), k2=min(4.,(1.+root)/max(.006,4.*ratio));
float pa=33.*sqrt(1.+k1*k1)*(aft-abs(q.x)*k1);
float modulation=terrain(7.*world+vec2(.12*t,0.));
float pb=33.*sqrt(1.+k2*k2)*(aft-abs(q.x)*k2)+.48*(modulation-.5);
float pixel=2./min(uResolution.x,uResolution.y);
float filterB=exp(-.12*pow(33.*pixel*(1.+k2*k2),2.));
float fan=smoothstep(.04,.24,aft)*(1.-smoothstep(.32,.38,ratio))/(1.+.40*aft);
return wind+fan*(.012*sin(pa)+.008*sin(pb)*(.61+.66*modulation)*smoothstep(.08,.31,ratio)*filterB);
}
float rectangle(vec2 p,vec2 halfSize,float corner) {
vec2 d=abs(p)-halfSize+corner;
return length(max(d,0.))+min(max(d.x,d.y),0.)-corner;
}
vec3 vessel(vec2 q,vec3 ocean,float aa) {
vec2 p=q/vec2(.078,.222);
float beam=mix(.78,1.,smoothstep(-1.,-.48,p.y))*
sqrt(max(0.,1.-pow(clamp((p.y+.06)/1.06,0.,1.),1.5)));
float hull=max(abs(p.x)-beam,max(-p.y-.88,p.y-1.));
float edge=aa/.078;
vec3 deck=mix(vec3(.85,.80,.64),vec3(.49,.37,.22),.15+.15*noise2(q*170.));
deck=mix(deck,vec3(.083,.18,.19),1.-smoothstep(.035,.09,-hull));
deck=mix(deck,vec3(.92,.91,.80),1.-smoothstep(.015,.055,abs(hull+.13)));
float cabin=rectangle(p-vec2(0.,-.03),vec2(.65,.40),.09);
deck=mix(deck,vec3(.14,.23,.26),1.-smoothstep(-edge*.4,edge*.4,cabin));
float roof=rectangle(p-vec2(0.,-.11),vec2(.53,.25),.06);
deck=mix(deck,vec3(.86,.45,.19),1.-smoothstep(-edge*.4,edge*.4,roof));
float stripe=abs(p.x+.15)-.06;
deck=mix(deck,vec3(.94,.81,.51),.55*(1.-smoothstep(-edge,edge,stripe))*(1.-smoothstep(-edge,edge,roof)));
float hatch=length((p-vec2(0.,.53))/vec2(.25,.093));
deck=mix(deck,vec3(.21,.29,.28),1.-smoothstep(.8,1.,hatch));
float engine=rectangle(p-vec2(0.,-.84),vec2(.22,.12),.08);
deck=mix(deck,vec3(.13,.17,.18),1.-smoothstep(-edge,edge,engine));
return mix(ocean,deck,1.-smoothstep(-edge,edge,hull));
}
void main() {
vec2 uv=frame(); float t=uTime+3.18;
vec2 q=mat2(.88,.475,-.475,.88)*(uv-vec2(.27,.56+.055*sin(.71*t)));
float aa=2./min(uResolution.x,uResolution.y);
vec2 e=vec2(max(.002,aa*.63),0.);
vec2 g=vec2(sea(q+e,t)-sea(q-e,t),sea(q+e.yx,t)-sea(q-e.yx,t))/(2.*e.x);
vec3 n=normalize(vec3(-g,1.)),refl=reflect(normalize(vec3(-.08,.20,-.98)),n);
vec2 moving=q+vec2(0.,.42*t);
float shoal=terrain(moving*vec2(1.8,2.6));
vec3 col=mix(vec3(.046,.19,.21),vec3(.17,.42,.39),shoal);
float sky=smoothstep(-.72,.83,refl.y+.48*refl.x);
col+=vec3(.11,.18,.20)*sky;
col+=vec3(.43,.46,.40)*pow(max(dot(refl,normalize(vec3(-.49,.53,.69))),0.),26.);
float aft=max(0.,-q.y-.15);
float churnWidth=.025+.078*sqrt(aft);
float swirl=q.x+.034*sqrt(aft)*sin(12.*aft-2.8*t);
float stirred=exp(-swirl*swirl/(churnWidth*churnWidth))*exp(-1.3*aft)*smoothstep(.0,.065,aft);
vec2 f=vec2(q.x*48.,aft*24.-4.*t);
float turbulent=terrain(f+2.2*vec2(noise2(f*.28),noise2(f*.24+3.)));
float bow=exp(-abs(abs(q.x)-(.055+.26*max(0.,.10-q.y)))/(.008+.006*aft))
*smoothstep(-.70,-.13,q.y)*(1.-smoothstep(.04,.15,q.y));
float foam=stirred*smoothstep(.25,.66,turbulent)+bow*(.30+.62*turbulent);
col=mix(col,vec3(.83,.91,.84),clamp(foam*1.30,0.,.97));
fragColor=vec4(vessel(q,col,aa),1.);
}
`;
export function createKelvinShipWaterWakeMaterial(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 | kelvin-ship-water-wake |
|---|---|
| Category | Water & Ice Shaders · Dynamic Liquids |
| Upstream study | liquids/lib/07_kelvin_ship_wake_behind_a_moving_point.glsl (commit c3a6f6c) |
| Animation cycle | Continuous procedural uTime |
| Declared uniforms | uResolution, uTime |
| Source size | 98 lines · 4.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 · Inigo Quilez, distance formulation
AnimatedAdvancing and retreating beach wave sheet leaving wet darkened sand and lacy foam.
AnimatedFree-surface Rankine whirlpool depression with spiral capillary ridges and Fresnel sky reflection.
AnimatedMulti-directional Gerstner ocean wave spectrum with subsurface teal scatter and sun glitter.
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.