From 6c4b10d881976c1b3fb44ff6a0a7a77641b0f2f8 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 20:18:07 +0100 Subject: [PATCH] Use existing humidity --- assets/voxygen/shaders/clouds-frag.glsl | 22 ++++++++++------------ assets/voxygen/shaders/terrain-frag.glsl | 2 +- server/src/weather/sim.rs | 24 ++++++++++-------------- server/src/weather/tick.rs | 8 +++----- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 7f9c885086..9508d24382 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -92,10 +92,10 @@ void main() { vec3 rorigin = cam_pos.xyz + focus_off.xyz + 0.5; vec3 rpos = vec3(0.0); float t = 0.0; - for (int i = 0; i < 6; i ++) { + for (int i = 0; i < 8; i ++) { const float PLANCK = 0.01; - float scale = min(pow(2, ceil(t / 2.0)), 32); - vec2 deltas = (step(vec2(0), dir2d) - fract(rpos.xy / scale)) / dir2d; + float scale = min(pow(2, ceil(t / 3.0)), 32); + vec2 deltas = (step(vec2(0), dir2d) - fract(rpos.xy / scale + 100.0)) / dir2d; float jump = max(min(deltas.x, deltas.y) * scale, PLANCK); t += jump; rpos = rorigin + adjusted_dir * t; @@ -104,21 +104,19 @@ void main() { vec3 wall_pos = vec3((diff.x > diff.y) ? rpos.xy : rpos.yx, rpos.z + integrated_rain_vel); wall_pos.xz *= vec2(4, 0.3); wall_pos.z += hash(fract(vec4(floor(wall_pos.xy + vec2(0, 0.5)), 1000, 0) * 0.1)); - if (abs(hash(vec4(floor(wall_pos.xyz), 0))) > rain_density) { - continue; - } float depth_adjust = abs(hash(vec4(floor(wall_pos.xyz), 2000))); float wpos_dist = t - jump * depth_adjust; vec3 wpos = cam_pos.xyz + dir * wpos_dist; + float density = rain_density * 3.0 * rain_occlusion_at(wpos); + if (density < 0.001 || fract(hash(vec4(floor(wall_pos.xyz), 0))) > density) { continue; } + if (wpos_dist > dist) { break; } - if (rain_occlusion_at(wpos) > 0.5) { - if (length((fract(wall_pos.xz) - 0.5)) < 0.1 + pow(max(0.0, wpos_dist - (dist - 0.25)) / 0.25, 4.0) * 0.2) { - float alpha = 0.9 * clamp((wpos_dist - 1.0) * 0.5, 0.0, 1.0); - float light = sqrt(dot(color.rgb, vec3(1))) + (get_sun_brightness() + get_moon_brightness()) * 0.01; - color.rgb = mix(color.rgb, vec3(0.2, 0.3, 0.5) * light, alpha); - } + if (length((fract(wall_pos.xz) - 0.5)) < 0.1 + pow(max(0.0, wpos_dist - (dist - 0.25)) / 0.25, 4.0) * 0.2) { + float alpha = 0.5 * clamp((wpos_dist - 1.0) * 0.5, 0.0, 1.0); + float light = sqrt(dot(color.rgb, vec3(1))) + (get_sun_brightness() + get_moon_brightness()) * 0.01; + color.rgb = mix(color.rgb, vec3(0.2, 0.3, 0.5) * light, alpha); } } } diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 9f7738dddd..78c5923c7c 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -244,7 +244,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 * rain_occlusion_at(f_pos.xyz) * 50.0) { + if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 10.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/weather/sim.rs b/server/src/weather/sim.rs index d12b474e27..a6ff3cc0ab 100644 --- a/server/src/weather/sim.rs +++ b/server/src/weather/sim.rs @@ -19,7 +19,7 @@ struct WeatherZone { } struct CellConsts { - rain_factor: f32, + humidity: f32, } pub struct WeatherSim { @@ -49,8 +49,8 @@ impl WeatherSim { } } let average_humid = humid_sum / (CHUNKS_PER_CELL * CHUNKS_PER_CELL) as f32; - let rain_factor = (4.0 * average_humid.powf(0.2)).min(1.0); - CellConsts { rain_factor } + let humidity = average_humid.powf(0.2).min(1.0); + CellConsts { humidity } }) .collect::>(), ), @@ -82,7 +82,7 @@ impl WeatherSim { } // Time step is cell size / maximum wind speed - pub fn tick(&mut self, world: &World, time_of_day: &TimeOfDay, out: &mut WeatherGrid) { + pub fn tick(&mut self, time_of_day: &TimeOfDay, out: &mut WeatherGrid) { let time = time_of_day.0; let base_nz = Turbulence::new( @@ -105,11 +105,6 @@ impl WeatherSim { } else { let wpos = cell_to_wpos_center(point); - let humid = world - .sim() - .get_wpos(wpos) - .map_or(1.0, |c| c.get_environment().humid); - let pos = wpos.as_::() + time as f64 * 0.1; let space_scale = 7_500.0; @@ -117,13 +112,14 @@ impl WeatherSim { let spos = (pos / space_scale).with_z(time as f64 / time_scale); let pressure = - (base_nz.get(spos.into_array()) * 0.5 + 1.0).clamped(0.0, 1.0) as f32 + 0.4 - - humid * 0.5; + (base_nz.get(spos.into_array()) * 0.5 + 1.0).clamped(0.0, 1.0) as f32 + 0.55 + - self.consts[point].humidity * 0.6; - const RAIN_CLOUD_THRESHOLD: f32 = 0.2; + const RAIN_CLOUD_THRESHOLD: f32 = 0.25; cell.cloud = (1.0 - pressure).max(0.0) * 0.5; - cell.rain = (1.0 - pressure - RAIN_CLOUD_THRESHOLD).max(0.0) - * self.consts[point].rain_factor; + cell.rain = ((1.0 - pressure - RAIN_CLOUD_THRESHOLD).max(0.0) + * self.consts[point].humidity) + .powf(0.5); cell.wind = Vec2::new( rain_nz.get(spos.into_array()).powi(3) as f32, rain_nz.get((spos + 1.0).into_array()).powi(3) as f32, diff --git a/server/src/weather/tick.rs b/server/src/weather/tick.rs index 8dcfe2e94f..db5154b73c 100644 --- a/server/src/weather/tick.rs +++ b/server/src/weather/tick.rs @@ -1,7 +1,6 @@ use common::{resources::TimeOfDay, weather::WeatherGrid}; use common_ecs::{Origin, Phase, System}; -use specs::{Read, ReadExpect, Write, WriteExpect}; -use std::sync::Arc; +use specs::{Read, Write, WriteExpect}; use crate::sys::SysScheduler; @@ -13,7 +12,6 @@ pub struct Sys; impl<'a> System<'a> for Sys { type SystemData = ( Read<'a, TimeOfDay>, - ReadExpect<'a, Arc>, WriteExpect<'a, WeatherSim>, WriteExpect<'a, WeatherGrid>, Write<'a, SysScheduler>, @@ -25,13 +23,13 @@ impl<'a> System<'a> for Sys { fn run( _job: &mut common_ecs::Job, - (game_time, world, mut sim, mut grid, mut scheduler): Self::SystemData, + (game_time, mut sim, mut grid, mut scheduler): Self::SystemData, ) { if scheduler.should_run() { if grid.size() != sim.size() { *grid = WeatherGrid::new(sim.size()); } - sim.tick(&world, &game_time, &mut grid); + sim.tick(&game_time, &mut grid); } } }