diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index b3412d558f..0242ccc824 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -113,8 +113,7 @@ void main() { // called each iteration of the loop. With the current implementation // of rain_dir this has issues with being in a place where it doesn't rain // and seeing rain. - float rain = rain_density_at(cam_wpos.xy); - if (medium.x == MEDIUM_AIR && rain > 0.0) { + if (medium.x == MEDIUM_AIR && rain_density > 0.0) { float rain_dist = 50.0; for (int i = 0; i < 4; i ++) { float old_rain_dist = rain_dist; @@ -141,7 +140,7 @@ void main() { if (dot(rpos * vec3(1, 1, 0.5), rpos) < 1.0) { break; } - float rain_density = rain * rain_occlusion_at(cam_pos.xyz + rpos.xyz) * 10.0; + float rain_density = rain_density * rain_occlusion_at(cam_pos.xyz + rpos.xyz) * 10.0; if (rain_density < 0.001 || fract(hash(fract(vec4(cell, rain_dist, 0) * 0.01))) > rain_density) { continue; diff --git a/assets/voxygen/shaders/fluid-frag/shiny.glsl b/assets/voxygen/shaders/fluid-frag/shiny.glsl index 20c6b7160e..f99d30bf60 100644 --- a/assets/voxygen/shaders/fluid-frag/shiny.glsl +++ b/assets/voxygen/shaders/fluid-frag/shiny.glsl @@ -149,7 +149,6 @@ void main() { wave_sample_dist / slope ); - float rain_density = rain_density_at(f_pos.xy + focus_off.xy) * rain_occlusion_at(f_pos.xyz) * 50.0; if (rain_density > 0 && surf_norm.z > 0.5) { vec3 drop_density = vec3(2, 2, 2); vec3 drop_pos = wave_pos + vec3(0, 0, -time_of_day.x * 0.025); @@ -158,7 +157,7 @@ void main() { drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0)); vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z)); - if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density) { + if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 50.0) { vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0); vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density; diff --git a/assets/voxygen/shaders/include/rain_occlusion.glsl b/assets/voxygen/shaders/include/rain_occlusion.glsl index 78d5c7d8b7..ceef0c8bf3 100644 --- a/assets/voxygen/shaders/include/rain_occlusion.glsl +++ b/assets/voxygen/shaders/include/rain_occlusion.glsl @@ -14,7 +14,8 @@ uniform u_rain_occlusion { mat4 rain_occlusion_texture_mat; mat4 rel_rain_dir_mat; float integrated_rain_vel; - vec3 occlusion_dummy; // Fix alignment. + float rain_density; + vec2 occlusion_dummy; // Fix alignment. }; float rain_occlusion_at(in vec3 fragPos) diff --git a/assets/voxygen/shaders/rain-occlusion-directed-vert.glsl b/assets/voxygen/shaders/rain-occlusion-directed-vert.glsl index f0feb6891c..ba3889d2ae 100644 --- a/assets/voxygen/shaders/rain-occlusion-directed-vert.glsl +++ b/assets/voxygen/shaders/rain-occlusion-directed-vert.glsl @@ -30,7 +30,8 @@ uniform u_rain_occlusion { mat4 rain_occlusion_texture_mat; mat4 rel_rain_dir_mat; float integrated_rain_vel; - vec3 occlusion_dummy; // Fix alignment. + float rain_density; + vec2 occlusion_dummy; // Fix alignment. }; /* Accurate packed shadow maps for many lights at once! diff --git a/assets/voxygen/shaders/rain-occlusion-figure-vert.glsl b/assets/voxygen/shaders/rain-occlusion-figure-vert.glsl index 800a74b6b3..fe64700e79 100644 --- a/assets/voxygen/shaders/rain-occlusion-figure-vert.glsl +++ b/assets/voxygen/shaders/rain-occlusion-figure-vert.glsl @@ -32,7 +32,8 @@ uniform u_rain_occlusion { mat4 texture_mat; mat4 rel_rain_dir_mat; float integrated_rain_vel; - vec3 occlusion_dummy; // Fix alignment. + float rain_density; + vec2 occlusion_dummy; // Fix alignment. }; /* Accurate packed shadow maps for many lights at once! diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index e37eac610f..d495fbd1b3 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -231,12 +231,11 @@ void main() { vec3 k_d = vec3(1.0); vec3 k_s = vec3(R_s); - vec3 pos = f_pos + focus_off.xyz; - float rain_density = rain_density_at(pos.xy) * rain_occlusion_at(f_pos.xyz) * 50.0; // Toggle to see rain_occlusion // tgt_color = vec4(rain_occlusion_at(f_pos.xyz), 0.0, 0.0, 1.0); // return; if (rain_density > 0 && !faces_fluid && f_norm.z > 0.5) { + vec3 pos = f_pos + focus_off.xyz; vec3 drop_density = vec3(2, 2, 2); vec3 drop_pos = pos + vec3(pos.zz, 0) + vec3(0, 0, -tick.x * 1.0); drop_pos.z += noise_2d(floor(drop_pos.xy * drop_density.xy) * 13.1) * 10; @@ -244,7 +243,7 @@ void main() { drop_pos.z *= 0.5 + hash_fast(uvec3(cell2d, 0)); vec3 cell = vec3(cell2d, floor(drop_pos.z * drop_density.z)); - if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density) { + if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 50.0) { vec3 off = vec3(hash_fast(uvec3(cell * 13)), hash_fast(uvec3(cell * 5)), 0); vec3 near_cell = (cell + 0.5 + (off - 0.5) * 0.5) / drop_density; diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 5795d6727f..ab65b6d843 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -3656,7 +3656,7 @@ fn handle_weather_zone( add_zone(weather::Weather { cloud: 0.3, rain: 0.3, - wind: Vec2::new(15.0,20.0), + wind: Vec2::new(15.0, 20.0), }); Ok(()) }, diff --git a/voxygen/src/render/pipelines/rain_occlusion.rs b/voxygen/src/render/pipelines/rain_occlusion.rs index 8e44ef0a53..86e30255f4 100644 --- a/voxygen/src/render/pipelines/rain_occlusion.rs +++ b/voxygen/src/render/pipelines/rain_occlusion.rs @@ -14,8 +14,9 @@ pub struct Locals { rel_rain_dir_mat: [[f32; 4]; 4], /// A value to offset the rain, to make it move over time. integrated_rain_vel: f32, + rain_density: f32, // To keep 16-byte-aligned. - occlusion_dummy: [f32; 3], + occlusion_dummy: [f32; 2], } /// Make sure Locals is 16-byte-aligned. const _: () = assert!(core::mem::size_of::() % 16 == 0); @@ -25,6 +26,7 @@ impl Locals { rain_occlusion_matrices: Mat4, rain_occlusion_texture_mat: Mat4, rel_rain_dir_mat: Mat4, + rain_density: f32, integrated_rain_vel: f32, ) -> Self { Self { @@ -32,7 +34,8 @@ impl Locals { rain_occlusion_texture_mat: rain_occlusion_texture_mat.into_col_arrays(), rel_rain_dir_mat: rel_rain_dir_mat.into_col_arrays(), integrated_rain_vel, - occlusion_dummy: [0.0; 3], + rain_density, + occlusion_dummy: [0.0; 2], } } } diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 09eef58402..3014a45eca 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -1027,12 +1027,16 @@ impl Scene { shadow_mat, texture_mat, rel_rain_dir_mat, + weather.rain, self.integrated_rain_vel, ); renderer.update_consts(&mut self.data.rain_occlusion_mats, &[rain_occlusion_locals]); - } else { + } else if self.integrated_rain_vel > 0.0 { self.integrated_rain_vel = 0.0; + // Need to set rain to zero + let rain_occlusion_locals = RainOcclusionLocals::default(); + renderer.update_consts(&mut self.data.rain_occlusion_mats, &[rain_occlusion_locals]); } let sun_dir = scene_data.get_sun_dir();