Better lightning rates, fixed shaders

This commit is contained in:
Joshua Barretto
2022-07-10 13:44:11 +01:00
parent 3b758cc7b0
commit 47b236b1f0
2 changed files with 56 additions and 37 deletions

View File

@ -3,6 +3,7 @@
#include "sky.glsl" #include "sky.glsl"
#ifdef POINT_GLOW_FACTOR
void apply_point_glow_light(Light L, vec3 wpos, vec3 dir, float max_dist, inout vec3 color) { void apply_point_glow_light(Light L, vec3 wpos, vec3 dir, float max_dist, inout vec3 color) {
vec3 light_pos = L.light_pos.xyz; vec3 light_pos = L.light_pos.xyz;
// Project light_pos to dir line // Project light_pos to dir line
@ -41,6 +42,7 @@ void apply_point_glow_light(Light L, vec3 wpos, vec3 dir, float max_dist, inout
// Constant, *should* const fold // Constant, *should* const fold
* POINT_GLOW_FACTOR; * POINT_GLOW_FACTOR;
} }
#endif
vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color) { vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color) {
#ifndef POINT_GLOW_FACTOR #ifndef POINT_GLOW_FACTOR
@ -53,8 +55,10 @@ vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color) {
apply_point_glow_light(L, wpos, dir, max_dist, color); apply_point_glow_light(L, wpos, dir, max_dist, color);
} }
#endif #endif
if (tick.x - last_lightning.w < 5.0) {
// Apply lightning // Apply lightning
apply_point_glow_light(Light(last_lightning.xyzw + vec4(0, 0, LIGHTNING_HEIGHT, 0), vec4(vec3(0.2, 0.4, 1) * lightning_intensity() * 0.003, 1)), wpos, dir, max_dist, color); apply_point_glow_light(Light(last_lightning.xyzw + vec4(0, 0, LIGHTNING_HEIGHT, 0), vec4(vec3(0.2, 0.4, 1) * lightning_intensity() * 0.003, 1)), wpos, dir, max_dist, color);
}
return color; return color;
} }

View File

@ -125,22 +125,37 @@ impl WeatherSim {
let time_scale = 100_000.0; let time_scale = 100_000.0;
let spos = (pos / space_scale).with_z(time as f64 / time_scale); let spos = (pos / space_scale).with_z(time as f64 / time_scale);
let pressure = let scale = 10_000.0;
(base_nz.get(spos.into_array()) * 0.5 + 1.0).clamped(0.0, 1.0) as f32 + 0.55 let avg_scale = 20_000.0;
let avg_delay = 250_000.0;
let pressure = ((base_nz.get(
(pos / avg_scale)
.with_z(time as f64 / avg_delay)
.into_array(),
) + base_nz.get(
(pos / (avg_scale * 0.25))
.with_z(time as f64 / (avg_delay * 0.25))
.into_array(),
) * 0.5)
* 0.5
+ 1.0)
.clamped(0.0, 1.0) as f32
+ 0.55
- self.consts[point].humidity * 0.6; - self.consts[point].humidity * 0.6;
const RAIN_CLOUD_THRESHOLD: f32 = 0.25; const RAIN_CLOUD_THRESHOLD: f32 = 0.25;
cell.cloud = (1.0 - pressure).max(0.0) * 0.5; cell.cloud = (1.0 - pressure).max(0.0) * 0.5;
cell.rain = ((1.0 - pressure - RAIN_CLOUD_THRESHOLD).max(0.0) cell.rain = ((1.0 - pressure - RAIN_CLOUD_THRESHOLD).max(0.0)
* self.consts[point].humidity) * self.consts[point].humidity
.powf(0.5); * 2.5)
.powf(1.5);
cell.wind = Vec2::new( cell.wind = Vec2::new(
rain_nz.get(spos.into_array()).powi(3) as f32, rain_nz.get(spos.into_array()).powi(3) as f32,
rain_nz.get((spos + 1.0).into_array()).powi(3) as f32, rain_nz.get((spos + 1.0).into_array()).powi(3) as f32,
) * 200.0 ) * 200.0
* (1.0 - pressure); * (1.0 - pressure);
if cell.rain > 0.1 && cell.cloud > 0.12 && thread_rng().gen_bool(0.01) { if cell.rain > 0.2 && cell.cloud > 0.15 && thread_rng().gen_bool(0.01) {
outcomes.emit_now(Outcome::Lightning { outcomes.emit_now(Outcome::Lightning {
pos: wpos.map(|e| e as f32).with_z(self.consts[point].alt), pos: wpos.map(|e| e as f32).with_z(self.consts[point].alt),
}); });