diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index a1bd62e889..672535b7d5 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -70,9 +70,8 @@ void main() { vec3 dir = (wpos - cam_pos.xyz) / dist; // Apply clouds - #if (CLOUD_MODE != CLOUD_MODE_NONE) - color.rgb = get_cloud_color(color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0); - #else + color.rgb = get_cloud_color(color.rgb, dir, cam_pos.xyz, time_of_day.x, dist, 1.0); + #if (CLOUD_MODE == CLOUD_MODE_NONE) color.rgb = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb); #endif diff --git a/assets/voxygen/shaders/fluid-frag/cheap.glsl b/assets/voxygen/shaders/fluid-frag/cheap.glsl index 6247522baa..45ce196dad 100644 --- a/assets/voxygen/shaders/fluid-frag/cheap.glsl +++ b/assets/voxygen/shaders/fluid-frag/cheap.glsl @@ -185,8 +185,11 @@ void main() { // float reflected_light_point = /*length*/(diffuse_light_point.r) + f_light * point_shadow; // reflected_light += k_d * (diffuse_light_point + f_light * point_shadow * shade_frac) + specular_light_point; - float passthrough = clamp(dot(cam_norm, -cam_to_frag) * 1.0 - 0.2, 0, 1); - float min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b)); + float passthrough = clamp(dot(f_norm, -cam_to_frag), 0, 1); + float min_refl = 0.0; + if (medium.x != 1) { + min_refl = min(emitted_light.r, min(emitted_light.g, emitted_light.b)); + } vec3 surf_color = illuminate(max_light, view_dir, water_color * /* fog_color * */emitted_light, /*surf_color * */water_color * reflected_light); // vec4 color = vec4(surf_color, passthrough * 1.0 / (1.0 + min_refl));// * (1.0 - /*log(1.0 + cam_attenuation)*//*cam_attenuation*/1.0 / (2.0 - log_cam))); diff --git a/assets/voxygen/shaders/fluid-frag/shiny.glsl b/assets/voxygen/shaders/fluid-frag/shiny.glsl index 6917e09d49..a33a0ea67c 100644 --- a/assets/voxygen/shaders/fluid-frag/shiny.glsl +++ b/assets/voxygen/shaders/fluid-frag/shiny.glsl @@ -170,7 +170,6 @@ void main() { vec3 refract_ray_dir = refract(cam_to_frag/*-view_dir*/, norm, 1.0 / n2); vec3 sun_view_dir = view_dir;///*sign(cam_pos.z - fluid_alt) * view_dir;*/cam_pos.z <= fluid_alt ? -view_dir : view_dir; // vec3 sun_view_dir = cam_pos.z <= fluid_alt ? -view_dir : view_dir; - vec3 beam_view_dir = reflect_ray_dir;//cam_pos.z <= fluid_alt ? -refract_ray_dir : reflect_ray_dir; /* vec4 reflect_ray_dir4 = view_mat * vec4(reflect_ray_dir, 1.0); reflect_ray_dir = normalize(vec3(reflect_ray_dir4) / reflect_ray_dir4.w); */ // vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); diff --git a/assets/voxygen/shaders/include/cloud/none.glsl b/assets/voxygen/shaders/include/cloud/none.glsl index dc8a10a871..5d52deb96d 100644 --- a/assets/voxygen/shaders/include/cloud/none.glsl +++ b/assets/voxygen/shaders/include/cloud/none.glsl @@ -1,3 +1,8 @@ +#include + vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, float time_of_day, float max_dist, float quality) { + // Underwater light attenuation + surf_color = water_diffuse(surf_color, dir, max_dist); + return surf_color; } diff --git a/assets/voxygen/shaders/include/cloud/regular.glsl b/assets/voxygen/shaders/include/cloud/regular.glsl index 1d658aacdc..67fdea8fe8 100644 --- a/assets/voxygen/shaders/include/cloud/regular.glsl +++ b/assets/voxygen/shaders/include/cloud/regular.glsl @@ -272,19 +272,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of #endif // Underwater light attenuation - if (medium.x == 1) { - float f_alt = alt_at(cam_pos.xy); - float fluid_alt = max(cam_pos.z + 1, floor(f_alt + 1)); - - float water_dist = clamp((fluid_alt - cam_pos.z) / pow(max(dir.z, 0), 10), 0, max_dist); - - //float fade = 1.0 - clamp(water_dist * 0.01, 0, 1);//pow(0.97, water_dist); - float fade = pow(0.98, water_dist); - - surf_color.rgb = mix(vec3(0, 0.5, 1) - * (get_sun_brightness() * get_sun_color() + get_moon_brightness() * get_moon_color()) - / max(1.0, (fluid_alt - cam_pos.z) * 0.5 - dir.z * 5), surf_color.rgb, fade/*pow(fade, 4)*/); - } + surf_color.rgb = water_diffuse(surf_color.rgb, dir, max_dist); // Apply point glow surf_color = apply_point_glow(origin, dir, max_dist, surf_color); diff --git a/assets/voxygen/shaders/include/lod.glsl b/assets/voxygen/shaders/include/lod.glsl index e7d76c4dd6..169f4115af 100644 --- a/assets/voxygen/shaders/include/lod.glsl +++ b/assets/voxygen/shaders/include/lod.glsl @@ -382,4 +382,21 @@ vec3 lod_col(vec2 pos) { } #endif +vec3 water_diffuse(vec3 color, vec3 dir, float max_dist) { + if (medium.x == 1) { + float f_alt = alt_at(cam_pos.xy); + float fluid_alt = max(cam_pos.z + 1, floor(f_alt + 1)); + + float water_dist = clamp((fluid_alt - cam_pos.z) / pow(max(dir.z, 0), 5), 0, max_dist); + + float fade = pow(0.97, water_dist); + + return mix(vec3(0.0, 0.2, 0.5) + * (get_sun_brightness() * get_sun_color() + get_moon_brightness() * get_moon_color()) + * pow(0.99, max((fluid_alt - cam_pos.z) * 12.0 - dir.z * 200, 0)), color.rgb, fade); + } else { + return color; + } +} + #endif diff --git a/assets/voxygen/shaders/include/srgb.glsl b/assets/voxygen/shaders/include/srgb.glsl index 118221a137..5b03d169e1 100644 --- a/assets/voxygen/shaders/include/srgb.glsl +++ b/assets/voxygen/shaders/include/srgb.glsl @@ -650,4 +650,5 @@ vec3 greedy_extract_col_light_glow(texture2D t_col_light, sampler s_col_light, v uint f_attr; return greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_light, f_glow, f_attr); } + #endif diff --git a/assets/voxygen/shaders/postprocess-frag.glsl b/assets/voxygen/shaders/postprocess-frag.glsl index c3811bf7fe..40cce6ecf7 100644 --- a/assets/voxygen/shaders/postprocess-frag.glsl +++ b/assets/voxygen/shaders/postprocess-frag.glsl @@ -194,7 +194,7 @@ void main() { #ifdef EXPERIMENTAL_UNDERWARPER vec2 uv = uv; if (medium.x == 1) { - uv += sin(uv.yx * 30 + tick.xx * 1.0) * 0.005; + uv += sin(uv.yx * 40 + tick.xx * 1.0) * 0.003; } #endif diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index b34939dfd3..6e71061e6c 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -286,7 +286,13 @@ void main() { reflected_light *= f_light; max_light *= f_light; - #ifdef EXPERIMENTAL_CAUSTICS + // TODO: Apply AO after this + vec3 glow = glow_light(f_pos) * (pow(f_glow, 3) * 5 + pow(f_glow, 2.0) * 2); + reflected_light += glow * pow(max(dot(face_norm, f_norm), 0), 2); + + max_light += lights_at(f_pos, f_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); + + #ifndef EXPERIMENTAL_NOCAUSTICS #if (FLUID_MODE == FLUID_MODE_SHINY) if (faces_fluid) { vec3 wpos = f_pos + focus_off.xyz; @@ -294,17 +300,13 @@ void main() { reflected_light += max(1.0 - pow(abs(noise_3d(vec3(spos.xy, tick.x * 0.1 + dot(sin(wpos.xy * 0.8), vec2(1)) * 0.05)) - 0.5) * 10, 0.001), 0) * 500 * cam_attenuation - * sun_diffuse; + * max(dot(f_norm, -sun_dir.xyz), 0) + * sun_diffuse + * sun_info.shadow; } #endif #endif - // TODO: Apply AO after this - vec3 glow = glow_light(f_pos) * (pow(f_glow, 3) * 5 + pow(f_glow, 2.0) * 2); - reflected_light += glow * pow(max(dot(face_norm, f_norm), 0), 2); - - max_light += lights_at(f_pos, f_norm, view_dir, mu, cam_attenuation, fluid_alt, k_a, k_d, k_s, alpha, f_norm, 1.0, emitted_light, reflected_light); - // float f_ao = 1.0; // float ao = /*pow(f_ao, 0.5)*/f_ao * 0.9 + 0.1; diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index ea515a8cd1..10b8617f12 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -223,15 +223,15 @@ impl Block { // minimum block, attenuation #[inline] - pub fn get_max_sunlight(&self) -> (u8, u8) { + pub fn get_max_sunlight(&self) -> (u8, f32) { match self.kind() { - BlockKind::Water => (1, 1), - BlockKind::Leaves => (9, 255), - BlockKind::Wood => (6, 2), - BlockKind::Snow => (6, 2), - BlockKind::Ice => (4, 2), - _ if self.is_opaque() => (0, 255), - _ => (0, 0), + BlockKind::Water => (0, 0.4), + BlockKind::Leaves => (9, 255.0), + BlockKind::Wood => (6, 2.0), + BlockKind::Snow => (6, 2.0), + BlockKind::Ice => (4, 2.0), + _ if self.is_opaque() => (0, 255.0), + _ => (0, 0.0), } } diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 81f22cbad7..8e13ee8cce 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -68,19 +68,19 @@ fn calc_light + ReadVol + Debug>( if is_sunlight { for x in 0..outer.size().w { for y in 0..outer.size().h { - let mut light = SUNLIGHT; + let mut light = SUNLIGHT as f32; for z in (0..outer.size().d).rev() { let (min_light, attenuation) = vol_cached .get(outer.min + Vec3::new(x, y, z)) - .map_or((0, 0), |b| b.get_max_sunlight()); + .map_or((0, 0.0), |b| b.get_max_sunlight()); - if light > min_light { - light = light.saturating_sub(attenuation).max(min_light); + if light > min_light as f32 { + light = (light - attenuation).max(min_light as f32); } - light_map[lm_idx(x, y, z)] = light; + light_map[lm_idx(x, y, z)] = light.floor() as u8; - if light == 0 { + if light <= 0.0 { break; } else { prop_que.push_back((x as u8, y as u8, z as u16)); @@ -103,7 +103,7 @@ fn calc_light + ReadVol + Debug>( .ok() .map_or(false, |b| b.is_fluid()) { - *dest = src - 1; + *dest = src.saturating_sub(1); // Can't propagate further if *dest > 1 { prop_que.push_back((pos.x as u8, pos.y as u8, pos.z as u16)); @@ -111,7 +111,7 @@ fn calc_light + ReadVol + Debug>( } else { *dest = OPAQUE; } - } else if *dest < src - 1 { + } else if *dest < src.saturating_sub(1) { *dest = src - 1; // Can't propagate further if *dest > 1 { diff --git a/voxygen/src/render/mod.rs b/voxygen/src/render/mod.rs index c02ac5fd74..81818ffd7c 100644 --- a/voxygen/src/render/mod.rs +++ b/voxygen/src/render/mod.rs @@ -429,6 +429,6 @@ pub enum ExperimentalShader { ProceduralLodDetail, /// Add a warping effect when underwater. Underwarper, - /// Add caustics to underwater terrain. - Caustics, + /// Remove caustics from underwater terrain when shiny water is enabled. + NoCaustics, }