← 每日 shader~/adventure-log/shaders/2026-10-10

浪花来回的晴日

浪花来回的晴日秋日晴空下,浪一层层涌上暖色沙滩,又拖着蕾丝般的泡沫轻轻退去。 · 晴 15–25°C
源码top-down shoreline swash: phased noise-edged wave fronts with lacy foam, wet-sand band, drifting jittered-grid sun glints
2026-10-10.frag
precision mediump float;
uniform vec2 u_resolution;
uniform float u_time;

float hash(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}
float noise(vec2 p){
  vec2 i=floor(p);vec2 f=fract(p);vec2 u=f*f*(3.0-2.0*f);
  return mix(mix(hash(i),hash(i+vec2(1.0,0.0)),u.x),mix(hash(i+vec2(0.0,1.0)),hash(i+vec2(1.0,1.0)),u.x),u.y);
}
float fbm(vec2 p){
  float v=0.0;float a=0.5;
  for(int i=0;i<4;i++){v+=a*noise(p);p=p*2.03+vec2(1.7,9.2);a*=0.5;}
  return v;
}

void main(){
  vec2 uv=gl_FragCoord.xy/u_resolution.xy;
  float asp=u_resolution.x/u_resolution.y;
  vec2 p=vec2(uv.x*asp,uv.y);
  float t=u_time;
  float d=p.y-0.18*p.x+0.03*(fbm(p*2.0)-0.5);

  vec3 sandA=vec3(0.95,0.84,0.66);
  vec3 sandB=vec3(0.86,0.71,0.53);
  float g=fbm(p*7.0);
  vec3 col=mix(sandB,sandA,g);
  float wet=smoothstep(0.28,0.5,d);
  col=mix(col,vec3(0.66,0.53,0.40)+0.06*g,wet*0.75);

  vec3 shallow=vec3(0.38,0.80,0.76);
  vec3 deep=vec3(0.09,0.40,0.58);
  vec3 foamC=vec3(0.97,0.95,0.90);
  col=mix(col,deep,smoothstep(0.72,1.1,d)*0.6);

  for(int k=0;k<3;k++){
    float fk=float(k);
    float ph=fract(t*0.055+fk*0.3333);
    float amp=smoothstep(0.0,0.22,ph)*(1.0-smoothstep(0.22,1.0,ph));
    float e=0.68-0.32*amp+0.07*(noise(vec2(p.x*3.2+fk*5.3,fk*2.0+t*0.08))-0.5);
    float w=d-e;
    float water=smoothstep(0.0,0.02,w);
    vec3 wc=mix(shallow,deep,smoothstep(0.0,0.45,w));
    col=mix(col,wc,water*(0.3+0.55*smoothstep(0.0,0.25,w)));
    float edgeFoam=exp(-pow(w/0.02,2.0));
    float lace=smoothstep(0.48,0.68,noise(p*vec2(13.0,20.0)+vec2(fk*11.0,-t*0.15)));
    lace*=exp(-max(w,0.0)/0.07)*step(0.0,w);
    float foam=(edgeFoam*0.9+lace*0.7)*(1.0-0.55*ph);
    col=mix(col,foamC,clamp(foam,0.0,1.0)*0.85);
  }

  float cr=sin(d*22.0+t*0.9+2.0*noise(p*3.0));
  col+=vec3(0.06,0.08,0.07)*smoothstep(0.6,1.0,cr)*smoothstep(0.62,0.9,d);

  vec2 gq=(p+vec2(t*0.015,t*0.006))*16.0;
  vec2 id=floor(gq);
  vec2 f=fract(gq)-0.5;
  float h=hash(id);
  vec2 off=(vec2(hash(id+3.1),hash(id+7.7))-0.5)*0.5;
  float r=length(f-off);
  float tw=pow(0.5+0.5*sin(t*1.2+h*6.283),5.0);
  float gl=smoothstep(0.24,0.0,r)*tw*step(0.55,h)*smoothstep(0.64,0.88,d);
  col+=vec3(1.0,0.93,0.78)*gl*0.55;

  vec2 sp=uv-vec2(0.1,1.05);
  float sun=exp(-dot(sp,sp)*2.2);
  col+=vec3(0.10,0.07,0.02)*sun;
  col*=mix(vec3(1.03,1.0,0.95),vec3(0.97,1.0,1.03),uv.x);
  vec2 vq=uv-0.5;
  col*=0.9+0.1*smoothstep(0.75,0.2,length(vq*vec2(1.0,1.2)));
  col=clamp(col,0.0,0.97);
  gl_FragColor=vec4(col,1.0);
}