diff --git a/assets/voxygen/shaders/fluid-frag.glsl b/assets/voxygen/shaders/fluid-frag.glsl index 12393caeb7..2d4f3bae7b 100644 --- a/assets/voxygen/shaders/fluid-frag.glsl +++ b/assets/voxygen/shaders/fluid-frag.glsl @@ -27,6 +27,32 @@ vec3 warp_normal(vec3 norm, vec3 pos, float time) { + smooth_rand(pos * 0.25, time * 0.25) * 0.1); } +float wave_height(vec3 pos) { + vec3 big_warp = ( + texture(t_waves, fract(pos.xy * 0.03 + tick.x * 0.01)).xyz * 0.5 + + texture(t_waves, fract(pos.yx * 0.03 - tick.x * 0.01)).xyz * 0.5 + + vec3(0) + ); + + vec3 warp = ( + texture(t_waves, fract(pos.yx * 0.1 + tick.x * 0.02)).xyz * 0.3 + + texture(t_waves, fract(pos.yx * 0.1 - tick.x * 0.02)).xyz * 0.3 + + vec3(0) + ); + + float height = ( + (texture(t_waves, pos.xy * 0.03 + big_warp.xy + tick.x * 0.05).y - 0.5) * 1.0 + + (texture(t_waves, pos.yx * 0.03 + big_warp.yx - tick.x * 0.05).y - 0.5) * 1.0 + + (texture(t_waves, pos.xy * 0.1 + warp.xy + tick.x * 0.1).x - 0.5) * 0.5 + + (texture(t_waves, pos.yx * 0.1 + warp.yx - tick.x * 0.1).x - 0.5) * 0.5 + + (texture(t_waves, pos.yx * 0.3 + warp.xy * 0.5 + tick.x * 0.1).x - 0.5) * 0.2 + + (texture(t_waves, pos.yx * 0.3 + warp.yx * 0.5 - tick.x * 0.1).x - 0.5) * 0.2 + + 0.0 + ); + + return pow(abs(height), 0.5) * sign(height) * 3.0; +} + void main() { // First 3 normals are negative, next 3 are positive vec3 normals[6] = vec3[]( vec3(-1,0,0), vec3(0,-1,0), vec3(0,0,-1), vec3(1,0,0), vec3(0,1,0), vec3(0,0,1) ); @@ -38,6 +64,9 @@ void main() { // Use an array to avoid conditional branching vec3 f_norm = normals[norm_axis + norm_dir]; + vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); + float frag_dist = length(f_pos - cam_pos.xyz); + /* // Round the position to the nearest triangular grid cell vec3 hex_pos = f_pos * 2.0; @@ -58,22 +87,27 @@ void main() { } vec3 c_norm = cross(f_norm, b_norm); - vec3 nmap = normalize( - (srgb_to_linear(texture(t_waves, fract(f_pos.xy * 0.3 + tick.x * 0.04)).rgb) - 0.0) * 0.05 - + (srgb_to_linear(texture(t_waves, fract(f_pos.xy * 0.1 - tick.x * 0.08)).rgb) - 0.0) * 0.1 - + (srgb_to_linear(texture(t_waves, fract(-f_pos.yx * 0.06 - tick.x * 0.1)).rgb) - 0.0) * 0.1 - + (srgb_to_linear(texture(t_waves, fract(-f_pos.yx * 0.03 - tick.x * 0.01)).rgb) - 0.0) * 0.2 - + vec3(0, 0, 0.0) + float wave00 = wave_height(f_pos); + float wave10 = wave_height(f_pos + vec3(0.1, 0, 0)); + float wave01 = wave_height(f_pos + vec3(0, 0.1, 0)); + + float slope = abs(wave00 - wave10) * abs(wave00 - wave01); + vec3 nmap = vec3( + -(wave10 - wave00) / 0.1, + -(wave01 - wave00) / 0.1, + 0.1 / slope ); + nmap = mix(vec3(0, 0, 1), normalize(nmap), clamp(2.0 / pow(frag_dist, 0.5), 0, 1)); + vec3 norm = f_norm * nmap.z + b_norm * nmap.x + c_norm * nmap.y; vec3 light, diffuse_light, ambient_light; - get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0); - float point_shadow = shadow_at(f_pos, f_norm); + get_sun_diffuse(norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0); + float point_shadow = shadow_at(f_pos, norm); diffuse_light *= f_light * point_shadow; ambient_light *= f_light, point_shadow; - vec3 point_light = light_at(f_pos, f_norm); + vec3 point_light = light_at(f_pos, norm); light += point_light; diffuse_light += point_light; vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light); @@ -81,15 +115,13 @@ void main() { 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, true); - vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); 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, false) * f_light; - //reflect_color = vec3(reflect_color.r + reflect_color.g + reflect_color.b) / 3.0; // 0 = 100% reflection, 1 = translucent water - float passthrough = pow(dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag), 0.3); + float passthrough = pow(dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag), 0.5); vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 4.0 / (1.0 + diffuse_light * 2.0)), passthrough); diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index 6eb3ff8602..59a27f00a8 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -150,7 +150,7 @@ vec3 get_sky_color(vec3 dir, float time_of_day, bool with_stars) { const vec3 SUN_SURF_COLOR = vec3(1.5, 0.9, 0.35) * 200.0; vec3 sun_halo = pow(max(dot(dir, -sun_dir) + 0.1, 0.0), 8.0) * sun_halo_color; - vec3 sun_surf = pow(max(dot(dir, -sun_dir) - 0.0045, 0.0), 1000.0) * SUN_SURF_COLOR; + vec3 sun_surf = pow(max(dot(dir, -sun_dir) - 0.001, 0.0), 3000.0) * SUN_SURF_COLOR; vec3 sun_light = (sun_halo + sun_surf) * clamp(dir.z * 10.0, 0, 1); return sky_color + sun_light; diff --git a/assets/voxygen/texture/waves.png b/assets/voxygen/texture/waves.png index 3083b00a86..645ce35b9e 100644 --- a/assets/voxygen/texture/waves.png +++ b/assets/voxygen/texture/waves.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9beac98bc31b98390c7d0f3bba959831d7734518d521d4f2fe10d96d0756ea66 -size 15547 +oid sha256:8c4ba0fb9bc5ee9a06936e7d8e4fc67058ebd36300983cd766de68e1d222e2c2 +size 19586 diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 54eff15a53..3a7c93f6bf 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -755,7 +755,7 @@ impl Terrain { waves: renderer .create_texture( &assets::load_expect("voxygen.texture.waves"), - Some(gfx::texture::FilterMethod::Bilinear), + Some(gfx::texture::FilterMethod::Trilinear), Some(gfx::texture::WrapMode::Tile), ) .expect("Failed to create wave texture"),