Use existing humidity

This commit is contained in:
Joshua Barretto 2022-07-08 20:18:07 +01:00
parent 28bc9db198
commit 6c4b10d881
4 changed files with 24 additions and 32 deletions

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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::<Vec<_>>(),
),
@ -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_::<f64>() + 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,

View File

@ -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<world::World>>,
WriteExpect<'a, WeatherSim>,
WriteExpect<'a, WeatherGrid>,
Write<'a, SysScheduler<Self>>,
@ -25,13 +23,13 @@ impl<'a> System<'a> for Sys {
fn run(
_job: &mut common_ecs::Job<Self>,
(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);
}
}
}