ShaderToyにいい実装があったので,自分なりにパラメータ調整したやつ。
// Based on: https://www.shadertoy.com/view/3d3yRj // See also: KdotJPG's https://www.shadertoy.com/view/wlc3zr float water_caustics(vec3 pos, float thickness) { vec4 n = snoise( pos ); pos -= thickness*n.xyz; n = snoise( pos ); pos -= thickness*n.xyz; n = snoise( pos ); pos -= thickness*n.xyz; n = snoise( pos ); return n.w; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 p = (-iResolution.xy + 2.0*fragCoord) / iResolution.y; // camera matrix vec3 ww = normalize(-vec3(0., 1., 0.8)); vec3 uu = normalize(cross(ww, vec3(0., 1., 0.))); vec3 vv = normalize(cross(uu,ww)); vec3 rd = p.x*uu + p.y*vv + 1.5*ww; // view ray vec3 pos = -ww + rd*(ww.y/rd.y); // raytrace plane pos.y = iTime*0.25; // animate noise slice pos *= 3.; // tiling frequency float w = mix(water_caustics(pos, 0.085), water_caustics(pos + 1.0, 0.085), 0.5); // noise [-1..+1] -> color float intensity = exp(w*2.5 - 1.); fragColor = vec4(vec3(intensity), 1.); }
ちなみに元にしたコードは,https://www.shadertoy.com/view/ssfBDfにあります。