From 337383feaa93d1784ef72ea317c06699490d13c0 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 18 Nov 2019 10:02:05 +0000 Subject: [PATCH] Faster cloud reflections --- assets/voxygen/shaders/figure-frag.glsl | 2 +- assets/voxygen/shaders/fluid-frag.glsl | 7 +++++-- assets/voxygen/shaders/include/sky.glsl | 24 ++++++++++++------------ assets/voxygen/shaders/skybox-frag.glsl | 2 +- assets/voxygen/shaders/sprite-frag.glsl | 2 +- assets/voxygen/shaders/terrain-frag.glsl | 2 +- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl index 88d757817e..0069e98d64 100644 --- a/assets/voxygen/shaders/figure-frag.glsl +++ b/assets/voxygen/shaders/figure-frag.glsl @@ -39,7 +39,7 @@ void main() { vec3 surf_color = illuminate(srgb_to_linear(model_col.rgb * f_col), light, diffuse_light, ambient_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, f_pos, true); + vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, 0.5, true); vec3 color = mix(surf_color, fog_color, fog_level); tgt_color = vec4(color, 1.0); diff --git a/assets/voxygen/shaders/fluid-frag.glsl b/assets/voxygen/shaders/fluid-frag.glsl index 2f77d300f1..464f63fb75 100644 --- a/assets/voxygen/shaders/fluid-frag.glsl +++ b/assets/voxygen/shaders/fluid-frag.glsl @@ -47,6 +47,7 @@ float wave_height(vec3 pos) { (texture(t_waves, pos.yx * 0.1 + warp.yx - tick.x * 0.1).x - 0.5) * 0.5 + (texture(t_noise, pos.yx * 0.3 + warp.xy * 0.5 + tick.x * 0.1).x - 0.5) * 0.2 + (texture(t_noise, pos.yx * 0.3 + warp.yx * 0.5 - tick.x * 0.1).x - 0.5) * 0.2 + + (texture(t_noise, pos.yx * 1.0 + warp.yx * 0.0 - tick.x * 0.1).x - 0.5) * 0.05 + 0.0 ); @@ -115,13 +116,15 @@ void main() { float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); vec3 fog_color = vec3(0); if (fog_level > 0.0) - fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, true); + fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, 0.25, true); 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, vec3(-100000), false) * f_light; + vec3 reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, vec3(-100000), 0.5, false) * f_light; + // Tint + reflect_color = mix(reflect_color, surf_color, 0.6); // 0 = 100% reflection, 1 = translucent water float passthrough = pow(dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag), 0.5); diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index 9619ede16e..1749dd5f8b 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -114,7 +114,7 @@ float is_star_at(vec3 dir) { return 0.0; } -const float CLOUD_AVG_HEIGHT = 900.0; +const float CLOUD_AVG_HEIGHT = 1125.0; const float CLOUD_HEIGHT_MIN = CLOUD_AVG_HEIGHT - 100.0; const float CLOUD_HEIGHT_MAX = CLOUD_AVG_HEIGHT + 100.0; const float CLOUD_THRESHOLD = 0.3; @@ -131,25 +131,25 @@ float vsum(vec3 v) { vec2 cloud_at(vec3 pos) { float tick_offs = 0.0 - + texture(t_noise, pos.xy * 0.0001).x - + texture(t_noise, pos.xy * 0.000003).x * 10.0; + + texture(t_noise, pos.xy * 0.0001).x * 1.0 + + texture(t_noise, pos.xy * 0.000003).x * 5.0; float value = ( 0.0 - + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0003 - tick.x * 0.003 + tick_offs).x - + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0009 + tick.x * 0.01).x * 0.5 + + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0003 - tick.x * 0.002 + tick_offs).x + + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0009 + tick.x * 0.005).x * 0.5 + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0025 - tick.x * 0.02).x * 0.25 + texture(t_noise, pos.xy / CLOUD_SCALE * 0.0075 - tick.x * 0.03).x * 0.07 ) / 2.85; float density = max((value - CLOUD_THRESHOLD) - abs(pos.z - CLOUD_AVG_HEIGHT) / 800.0, 0.0) * CLOUD_DENSITY; - float shade = 0.5 - min(pow(max(CLOUD_AVG_HEIGHT - pos.z, 0.0), 0.5), 1.0) / 1.0; + float shade = 1.0 - min(pow(max(CLOUD_AVG_HEIGHT - pos.z, 0.0), 0.5) * 0.5, 1.0) / 0.75; return vec2(shade, density / (1.0 + vsum(abs(pos - cam_pos.xyz)) / 10000)); } -vec4 get_cloud_color(vec3 dir, float time_of_day, float max_dist) { +vec4 get_cloud_color(vec3 dir, float time_of_day, float max_dist, float quality) { const float INCR = 0.05; float mind = (CLOUD_HEIGHT_MIN - cam_pos.z) / dir.z; @@ -158,9 +158,9 @@ vec4 get_cloud_color(vec3 dir, float time_of_day, float max_dist) { float start = max(min(mind, maxd), 0.0); float delta = abs(mind - maxd); - float incr = min(INCR + start / 100000.0, INCR * 2.0); + float incr = min(INCR + start / 100000.0, INCR * 2.0) / quality; - float fuzz = texture(t_noise, dir.xy * 1000000.0).x * 1.75 * incr * delta; + float fuzz = texture(t_noise, dir.xy * 100000.0).x * 1.75 * incr * delta; if (delta <= 0.0) { return vec4(0); @@ -191,7 +191,7 @@ vec4 get_cloud_color(vec3 dir, float time_of_day, float max_dist) { return vec4(vec3(cloud_shade), 1.0 - passthrough / (1.0 + delta * 0.0003)); } -vec3 get_sky_color(vec3 dir, float time_of_day, vec3 f_pos, bool with_stars) { +vec3 get_sky_color(vec3 dir, float time_of_day, vec3 f_pos, float quality, bool with_stars) { // Sky color vec3 sun_dir = get_sun_dir(time_of_day); vec3 moon_dir = get_moon_dir(time_of_day); @@ -267,8 +267,8 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 f_pos, bool with_stars) { vec3 moon_light = clamp(moon_halo + moon_surf, vec3(0), vec3(clamp(dir.z * 3.0, 0, 1))); // Clouds - vec4 clouds = get_cloud_color(dir, time_of_day, distance(cam_pos.xyz, f_pos)); - clouds.rgb *= get_sun_brightness(sun_dir) * (sun_halo + get_sun_color(sun_dir)) + get_moon_brightness(moon_dir) * (moon_halo + get_moon_color(moon_dir)); + vec4 clouds = get_cloud_color(dir, time_of_day, distance(cam_pos.xyz, f_pos), quality); + clouds.rgb *= get_sun_brightness(sun_dir) * (sun_halo * 2.5 + get_sun_color(sun_dir)) + get_moon_brightness(moon_dir) * (moon_halo * 2.5 + get_moon_color(moon_dir)); return mix(sky_color + sun_light + moon_light, clouds.rgb, clouds.a); } diff --git a/assets/voxygen/shaders/skybox-frag.glsl b/assets/voxygen/shaders/skybox-frag.glsl index d1d47152bc..9249f6c304 100644 --- a/assets/voxygen/shaders/skybox-frag.glsl +++ b/assets/voxygen/shaders/skybox-frag.glsl @@ -13,5 +13,5 @@ uniform u_locals { out vec4 tgt_color; void main() { - tgt_color = vec4(get_sky_color(normalize(f_pos), time_of_day.x, vec3(-100000), true), 1.0); + tgt_color = vec4(get_sky_color(normalize(f_pos), time_of_day.x, vec3(-100000), 1.0, true), 1.0); } diff --git a/assets/voxygen/shaders/sprite-frag.glsl b/assets/voxygen/shaders/sprite-frag.glsl index 50add1e0d7..776b8f1cbc 100644 --- a/assets/voxygen/shaders/sprite-frag.glsl +++ b/assets/voxygen/shaders/sprite-frag.glsl @@ -27,7 +27,7 @@ void main() { vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_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, f_pos, true); + vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, 0.5, true); vec3 color = mix(surf_color, fog_color, fog_level); tgt_color = vec4(color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (RENDER_DIST - FADE_DIST)) / FADE_DIST, 0, 1)); diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 534f3afbc1..73723cc3c4 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -42,7 +42,7 @@ void main() { float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); vec3 fog_color = vec3(0); if (fog_level > 0.0) - fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, true); + fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, f_pos, 0.5, true); vec3 color = mix(surf_color, fog_color, fog_level); tgt_color = vec4(color, 1.0);