shader_type spatial; render_mode unshaded, shadows_disabled; uniform vec3 local_flow_direction = vec3(1.0, 0.0, 0.0); uniform vec4 water_tint : source_color = vec4(0.25, 0.68, 0.75, 0.55); uniform vec4 foam_tint : source_color = vec4(0.88, 0.98, 0.95, 0.93); varying vec2 world_xz; varying vec2 downstream; void vertex() { world_xz = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xz; downstream = normalize((MODEL_MATRIX * vec4(local_flow_direction, 0.0)).xz); } float cell_random(vec2 cell) { vec3 p = fract(cell.xyx * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yzx + 33.33); return fract((p.x + p.y) * p.z); } float foam_strokes(vec2 stream) { // World-space lanes carry irregular strokes across same-direction tiles. // The lateral offset between lanes keeps them from forming rows of dots. vec2 cell_size = vec2(0.52, 0.25); vec2 grid = stream / cell_size; grid.x += cell_random(vec2(floor(grid.y), 4.8)); vec2 cell = floor(grid); vec2 center = vec2( mix(0.32, 0.68, cell_random(cell + vec2(1.4, 0.0))), mix(0.3, 0.7, cell_random(cell + vec2(0.0, 6.2))) ); vec2 offset = (fract(grid) - center) * cell_size; float half_length = mix(0.062, 0.147, cell_random(cell + vec2(7.3, 3.2))); float width = mix(0.015, 0.032, cell_random(cell + vec2(4.7, 8.2))); float along = offset.x / half_length; float curve = 0.013 * (along * along - 0.5); float taper = mix(0.5, 1.0, smoothstep(-0.85, 0.48, along)); float dist = length(vec2(along, (offset.y - curve) / (width * taper))); float edge = clamp(fwidth(dist), 0.11, 0.5); float brightness = mix(0.52, 1.0, cell_random(cell + vec2(3.5, 0.0))); return (1.0 - smoothstep(0.92 - edge, 0.92 + edge, dist)) * brightness; } void fragment() { vec2 across = vec2(-downstream.y, downstream.x); vec2 stream = vec2(dot(world_xz, downstream), dot(world_xz, across)); // Presentation speed gives the eye time to follow one stroke across a tile. // Water contact forces are defined independently in behavior.gd. float foam = foam_strokes(stream - vec2(TIME * 0.94, 0.0)); float ripple = sin(stream.x * 14.0 + sin(stream.y * 15.0) - TIME * 2.3); float ripple_highlight = smoothstep(0.4, 0.97, ripple) * 0.11; vec3 water_color = mix(water_tint.rgb, foam_tint.rgb, ripple_highlight); ALBEDO = mix(water_color, foam_tint.rgb, foam); ALPHA = mix(water_tint.a, foam_tint.a, foam); }