From 749ec15bf9b237284bdb6f924fc880fb6e6c3b6d Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 17 Aug 2019 23:20:07 +0100 Subject: [PATCH] Cleanup, comments --- assets/voxygen/shaders/fluid-frag.glsl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/assets/voxygen/shaders/fluid-frag.glsl b/assets/voxygen/shaders/fluid-frag.glsl index f4cbade5fa..8d060ca3da 100644 --- a/assets/voxygen/shaders/fluid-frag.glsl +++ b/assets/voxygen/shaders/fluid-frag.glsl @@ -18,31 +18,39 @@ out vec4 tgt_color; #include #include +vec3 warp_normal(vec3 norm, vec3 pos, float time) { + return normalize(norm + + smooth_rand(pos * 1.0, time * 1.0) * 0.05 + + smooth_rand(pos * 0.25, time * 0.25) * 0.1); +} + void main() { /* + // Round the position to the nearest triangular grid cell vec3 hex_pos = f_pos * 2.0; hex_pos = hex_pos + vec3(hex_pos.y * 1.4 / 3.0, hex_pos.y * 0.1, 0); if (fract(hex_pos.x) > fract(hex_pos.y)) { hex_pos += vec3(1.0, 1.0, 0); } - hex_pos = f_pos;//floor(hex_pos); + hex_pos = floor(hex_pos); */ - vec3 warped_norm = normalize(f_norm - + smooth_rand(f_pos * 1.0, tick.x * 1.0) * 0.05 - + smooth_rand(f_pos * 0.25, tick.x * 0.25) * 0.1); + vec3 norm = warp_normal(f_norm, f_pos, tick.x); - vec3 light = get_sun_diffuse(warped_norm, time_of_day.x) * f_light + light_at(f_pos, warped_norm); + vec3 light = get_sun_diffuse(norm, time_of_day.x) * f_light + light_at(f_pos, norm); vec3 surf_color = f_col * light; float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x); vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); - vec3 reflect_ray_dir = reflect(cam_to_frag, warped_norm); + vec3 reflect_ray_dir = reflect(cam_to_frag, norm); + // Hack to prevent the reflection ray dipping below the horizon and creating weird blue spots in the water reflect_ray_dir.z = max(reflect_ray_dir.z, 0.05); + vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x) * f_light; - float passthrough = pow(dot(faceforward(warped_norm, warped_norm, cam_to_frag), -cam_to_frag), 1.0); + // 0 = 100% reflection, 1 = translucent water + float passthrough = pow(dot(faceforward(norm, norm, cam_to_frag), -cam_to_frag), 1.0); vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, 0.5 / (1.0 + light * 2.0)), passthrough);