Here's a carefully crafted GLSL shader for ShaderToy, designed specifically to render a realistic animated water surface according to your requirements. Copy and paste this shader into ShaderToy, and it should work as-is:
────────────────────────────────────────────────────────────────────
glslCopy// ShaderToy shader: realistic water surface animation with rolling waves, reflections, and horizon.
#define AA 2
// Hash function for randomness
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
// 2D Noise function (smooth noise)
float noise(in vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = ff (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);
}
// FBM (fractal motion)
float fbm(vec2 p) {
float z = 2.0;
float rz = 0.0;
vec2 bp = p;
for(float i = 1.0; i < 6.0; i++) {
rz += abs(noise(bp) - 0.5) / z;
z *= 2.0;
bp *= 2.0;
}
return rz;
}
// Compute height of wave at position p and time t
float waterHeight(vec2 p, float t) {
float height = fbm(p0.5 + vec2(0.0, -t 0.05));
height += fbm(p1.0 + vec2(t 0.1, 0.0))0.5;
height += fbm(p 2.0 - vec2(0.0, t*0.2))*0.25;
return height * 0.5;
}
// Surface normal computation
vec3 getNormal(vec2 p, float t) {
const float eps = 0.01;
float h = , t);
float hx = waterHeight(p + vec2(eps,0.0), t);
float = waterHeight(p + vec2(0.0,eps), t);
vec3 normal = normalize(vec3(h - hx, eps, h - hy));
return normal;
}
// Sun and sky color
vec3 getSky(vec3 rd) {
float sun = pow(max(dot(rd, normalize(vec3(0.0, 0.15, 1.0))), 0.0), 64.0);
vec3 skyCol = mix(vec3(0.6,0.75,0.85), vec3(0.1,0.3,0.6), rd.y*0.5+0.5);
return skyCol + sun * vec3(1.0,0.9,0.7)*2.0;
}
// Main render function
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord.xy / iResolution.xy) * 2.0 - 1.0;
uv.x *= iResolution.x / iResolution.y;
code Copy code
// Camera setup
vec3 ro = vec3(0.0, 3.0, iTime * 1.0);
vec3 rd = normalize(vec3(uv.x, uv.y - 0.3, -1.5));
float camHeight = 2.0;
ro.y = camHeight;
// Intersection with water plane (y = 0)
float t = (ro.y - 0.0) / -rd.y;
vec3 pos = ro + rd * t;
// Adjust water height based on position
float height = waterHeight(pos.xz, iTime);
pos.y = height;
// Recalculate normal at intersection point
vec3 normal = getNormal(pos.xz, iTime);
// Reflect ray to sample sky
vec3 reflectedRay = reflect(rd, normal);
vec3 sky = getSky(reflectedRay);
// Fresnel term for realistic reflections
float fresnel = pow(1.0 - max(dot(-rd, normal), 0.0), 3.0) * 0.65;
// Water color
vec3 waterColor = vec3(0.02, 0.2, 0.3);
vec3 col = mix(waterColor, sky, fresnel);
// Specular highlights (sun reflections)
vec3 sunDir = <REDACTED>));
float specular = pow(max(dot(reflect(-sunDir, normal), -rd), 0.0), 256.0);
col += vec3(1.0,0.9,0.7) * specular * 0.8;
// Gamma correction
col = pow(col, vec3(0.4545));
fragColor = vec4(col, 1.0);
}
How this Shader Works:
Camera: Set to look down from above at an off-perpendicular angle, showing the horizon clearly.
Wave Generation: Utilizes multiple octaves of fractal motion (FBM) for realistic, complex, and non-repeating waves.
Surface Normals: Calculated numerically, allowing detailed lighting and reflection accuracy.
Reflections and Sun Highlights: Uses Fresnel reflections and specular highlights to enhance realism.
Sky Gradient: Simple yet realistic color gradation to discern sky from water clearly.
Camera: Set to look down from above at an off-perpendicular angle, showing the horizon clearly.
Wave Generation: Utilizes multiple octaves of fractal motion (FBM) for realistic, complex, and non-repeating waves.
Surface Normals: Calculated numerically, allowing detailed lighting and reflection accuracy.
Reflections and Sun Highlights: Uses Fresnel reflections and specular highlights to enhance realism.
Sky Gradient: Simple yet realistic color gradation to discern sky from water clearly.
Drop it directly intoShaderToyto see the effect in action!