diff --git a/assets/voxygen/shaders/fluid-frag/cheap.glsl b/assets/voxygen/shaders/fluid-frag/cheap.glsl index f405fdd039..922135e500 100644 --- a/assets/voxygen/shaders/fluid-frag/cheap.glsl +++ b/assets/voxygen/shaders/fluid-frag/cheap.glsl @@ -131,6 +131,9 @@ void main() { vec3 emitted_light, reflected_light; + // Prevent the sky affecting light when underground + float not_underground = clamp((f_pos.z - f_alt) / 128.0 + 1.0, 0.0, 1.0); + // float point_shadow = shadow_at(f_pos, f_norm); // vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); // vec3 emitted_light, reflected_light; @@ -143,6 +146,8 @@ void main() { // vec3 surf_color = /*srgb_to_linear*/(vec3(0.4, 0.7, 2.0)); float max_light = 0.0; max_light += get_sun_diffuse2(sun_info, moon_info, f_norm, /*time_of_day.x*//*-cam_to_frag*/sun_view_dir/*view_dir*/, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, /*vec3(0.0)*/k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); + emitted_light *= not_underground; + reflected_light *= not_underground; // reflected_light *= f_light * point_shadow * shade_frac; // emitted_light *= f_light * point_shadow * max(shade_frac, MIN_SHADOW); // max_light *= f_light * point_shadow * shade_frac; diff --git a/assets/voxygen/shaders/fluid-frag/shiny.glsl b/assets/voxygen/shaders/fluid-frag/shiny.glsl index 67aae23766..ad5f462774 100644 --- a/assets/voxygen/shaders/fluid-frag/shiny.glsl +++ b/assets/voxygen/shaders/fluid-frag/shiny.glsl @@ -179,6 +179,10 @@ void main() { vec3 reflect_color = get_sky_color(/*reflect_ray_dir*/beam_view_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, true); reflect_color = get_cloud_color(reflect_color, reflect_ray_dir, cam_pos.xyz, time_of_day.x, 100000.0, 0.1); reflect_color *= f_light; + + // Prevent the sky affecting light when underground + float not_underground = clamp((f_pos.z - f_alt) / 128.0 + 1.0, 0.0, 1.0); + reflect_color *= not_underground; // /*const */vec3 water_color = srgb_to_linear(vec3(0.2, 0.5, 1.0)); // /*const */vec3 water_color = srgb_to_linear(vec3(0.8, 0.9, 1.0)); // NOTE: Linear RGB, attenuation coefficients for water at roughly R, G, B wavelengths. @@ -254,6 +258,8 @@ void main() { float max_light = 0.0; max_light += get_sun_diffuse2(sun_info, moon_info, norm, /*time_of_day.x*/sun_view_dir, f_pos, mu, cam_attenuation, fluid_alt, k_a/* * (shade_frac * 0.5 + light_frac * 0.5)*/, vec3(k_d), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); + emitted_light *= not_underground; + reflected_light *= not_underground; // Apply cloud layer to sky // reflected_light *= /*water_color_direct * */reflect_color * f_light * point_shadow * shade_frac; // emitted_light *= /*water_color_direct*//*ambient_attenuation * */f_light * point_shadow * max(shade_frac, MIN_SHADOW); diff --git a/assets/voxygen/shaders/include/cloud/regular.glsl b/assets/voxygen/shaders/include/cloud/regular.glsl index 85fee047c6..889147e9c2 100644 --- a/assets/voxygen/shaders/include/cloud/regular.glsl +++ b/assets/voxygen/shaders/include/cloud/regular.glsl @@ -16,7 +16,7 @@ float cloud_broad(vec3 pos) { } // Returns vec4(r, g, b, density) -vec4 cloud_at(vec3 pos, float dist, out vec3 emission) { +vec4 cloud_at(vec3 pos, float dist, out vec3 emission, out float not_underground) { // Natural attenuation of air (air naturally attenuates light that passes through it) // Simulate the atmosphere thinning as you get higher. Not physically accurate, but then // it can't be since Veloren's world is flat, not spherical. @@ -134,7 +134,7 @@ vec4 cloud_at(vec3 pos, float dist, out vec3 emission) { //moon_access *= suppress_mist; // Prevent clouds and mist appearing underground (but fade them out gently) - float not_underground = clamp(1.0 - (alt - (pos.z - focus_off.z)) / 80.0 + dist * 0.001, 0, 1); + not_underground = clamp(1.0 - (alt - (pos.z - focus_off.z)) / 80.0 + dist * 0.001, 0, 1); sun_access *= not_underground; moon_access *= not_underground; float vapor_density = (mist + cloud) * not_underground; @@ -220,8 +220,9 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of cdist = step_to_dist(trunc(dist_to_step(cdist - 0.25, quality)), quality); vec3 emission; + float not_underground; // Used to prevent sunlight leaking underground // `sample` is a reserved keyword - vec4 sample_ = cloud_at(origin + dir * ldist * splay, ldist, emission); + vec4 sample_ = cloud_at(origin + dir * ldist * splay, ldist, emission, not_underground); vec2 density_integrals = max(sample_.zw, vec2(0)); @@ -239,7 +240,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of // Add the directed light light scattered into the camera by the clouds and the atmosphere (global illumination) sun_color * sun_scatter * get_sun_brightness() * (sun_access * (1.0 - cloud_darken) /*+ sky_color * global_scatter_factor*/) + moon_color * moon_scatter * get_moon_brightness() * (moon_access * (1.0 - cloud_darken) /*+ sky_color * global_scatter_factor*/) + - sky_light * (1.0 - global_darken) + + sky_light * (1.0 - global_darken) * not_underground + emission * density_integrals.y; } diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index cd209c2a4f..d5dafb6253 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -57,7 +57,7 @@ vec3 glow_light(vec3 pos) { #if (SHADOW_MODE <= SHADOW_MODE_NONE) return GLOW_COLOR; #else - return GLOW_COLOR * (1.0 + (noise_3d(vec3(pos.xy * 0.005, tick.x * 0.5)) - 0.5) * 1.0); + return GLOW_COLOR * (1.0 + (noise_3d(vec3(pos.xy * 0.005, tick.x * 0.5)) - 0.5) * 0.5); #endif } diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index aa5b0e89a2..35c9691390 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -253,8 +253,12 @@ void main() { // Computing light attenuation from water. vec3 emitted_light, reflected_light; + + // Prevent the sky affecting light when underground + float not_underground = clamp((f_pos.z - f_alt) / 128.0 + 1.0, 0.0, 1.0); + // To account for prior saturation - /*float */f_light = faces_fluid ? 1.0 : f_light * sqrt(f_light); + /*float */f_light = faces_fluid ? not_underground : f_light * sqrt(f_light); emitted_light = vec3(1.0); reflected_light = vec3(1.0);