More lightning position variety

This commit is contained in:
Joshua Barretto 2022-07-13 21:45:37 +01:00
parent 25c55b6a25
commit f48665366b
7 changed files with 38 additions and 28 deletions

View File

@ -242,7 +242,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
int i; int i;
#if (CLOUD_MODE >= CLOUD_MODE_MEDIUM) #if (CLOUD_MODE >= CLOUD_MODE_MEDIUM)
#ifdef EXPERIMENTAL_RAINBOWS #ifndef EXPERIMENTAL_NORAINBOWS
// TODO: Make it a double rainbow // TODO: Make it a double rainbow
float rainbow_t = (0.7 - dot(sun_dir.xyz, dir)) * 8 / 0.05; float rainbow_t = (0.7 - dot(sun_dir.xyz, dir)) * 8 / 0.05;
int rainbow_c = int(floor(rainbow_t)); int rainbow_c = int(floor(rainbow_t));
@ -285,7 +285,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of
// Rainbow // Rainbow
#if (CLOUD_MODE >= CLOUD_MODE_MEDIUM) #if (CLOUD_MODE >= CLOUD_MODE_MEDIUM)
#ifdef EXPERIMENTAL_RAINBOWS #ifndef EXPERIMENTAL_NORAINBOWS
if (rainbow_c >= 0 && rainbow_c < 8) { if (rainbow_c >= 0 && rainbow_c < 8) {
vec3 colors[9] = { vec3 colors[9] = {
surf_color, surf_color,

View File

@ -55,7 +55,8 @@ 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) { float time_since_lightning = tick.x - last_lightning.w;
if (time_since_lightning < MAX_LIGHTNING_PERIOD) {
// 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);
} }

View File

@ -233,6 +233,7 @@ DirectionalLight get_moon_info(vec4 _dir, float shade_frac/*, vec4 light_pos[2]*
} }
const float LIGHTNING_HEIGHT = 25.0; const float LIGHTNING_HEIGHT = 25.0;
const float MAX_LIGHTNING_PERIOD = 5.0;
float lightning_intensity() { float lightning_intensity() {
float time_since_lightning = tick.x - last_lightning.w; float time_since_lightning = tick.x - last_lightning.w;
@ -247,7 +248,7 @@ float lightning_intensity() {
vec3 lightning_at(vec3 wpos) { vec3 lightning_at(vec3 wpos) {
float time_since_lightning = tick.x - last_lightning.w; float time_since_lightning = tick.x - last_lightning.w;
if (time_since_lightning < 5.0) { if (time_since_lightning < MAX_LIGHTNING_PERIOD) {
vec3 diff = wpos + focus_off.xyz - (last_lightning.xyz + vec3(0, 0, LIGHTNING_HEIGHT)); vec3 diff = wpos + focus_off.xyz - (last_lightning.xyz + vec3(0, 0, LIGHTNING_HEIGHT));
float dist = length(diff); float dist = length(diff);
return vec3(0.5, 0.8, 1.0) return vec3(0.5, 0.8, 1.0)

View File

@ -246,17 +246,7 @@ void main() {
if (rain_occlusion_at(f_pos.xyz + vec3(0, 0, 0.25)) > 0.5) { if (rain_occlusion_at(f_pos.xyz + vec3(0, 0, 0.25)) > 0.5) {
#ifdef EXPERIMENTAL_WETNESS #ifdef EXPERIMENTAL_WETNESS
float puddle = clamp((noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.1) - 0.5) * 20.0, 0.0, 1.0);// * pow(rain_density, 0.05); float puddle = clamp((noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.03) - 0.5) * 20.0, 0.0, 1.0) * min(rain_density * 10.0, 1.0);
float h = (noise_2d((f_pos.xy + focus_off.xy) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3) + (noise_2d((f_pos.xy + focus_off.xy) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
float hx = (noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3) + (noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
float hy = (noise_2d((f_pos.xy + focus_off.xy + vec2(0, 0.1)) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3) + (noise_2d((f_pos.xy + focus_off.xy + vec2(0, 0.1)) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
f_norm.xy += mix(vec2(0), vec2(h - hx, h - hy) / 0.1 * 0.03, puddle);
alpha = mix(1.0, 0.2, puddle);
f_col.rgb *= mix(1.0, 0.7, puddle);
/* k_a += 1.0; */
/* k_d += 1.0; */
k_s = mix(k_s, vec3(0.7, 0.7, 1.0), puddle);
#else #else
const float puddle = 1.0; const float puddle = 1.0;
#endif #endif
@ -271,6 +261,11 @@ void main() {
k_a += distort; k_a += distort;
k_d += distort; k_d += distort;
k_s += distort; k_s += distort;
#ifdef EXPERIMENTAL_WETNESS
/* puddle = mix(puddle, 1.0, distort * 10); */
#endif
f_norm.xy += (drop_pos - near_cell).xy f_norm.xy += (drop_pos - near_cell).xy
* max(1.0 - abs(dist - drop_rad) * 30, 0) * max(1.0 - abs(dist - drop_rad) * 30, 0)
* 500.0 * 500.0
@ -279,9 +274,20 @@ void main() {
* max(drop_pos.z - near_cell.z, 0); * max(drop_pos.z - near_cell.z, 0);
} }
/* k_s = vec3(1); */ #ifdef EXPERIMENTAL_WETNESS
/* k_d = vec3(0); */ if (puddle > 0.0) {
/* alpha = 0.3; */ float h = (noise_2d((f_pos.xy + focus_off.xy) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
+ (noise_2d((f_pos.xy + focus_off.xy) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
float hx = (noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
+ (noise_2d((f_pos.xy + focus_off.xy + vec2(0.1, 0)) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
float hy = (noise_2d((f_pos.xy + focus_off.xy + vec2(0, 0.1)) * 0.3) - 0.5) * sin(tick.x * 8.0 + f_pos.x * 3)
+ (noise_2d((f_pos.xy + focus_off.xy + vec2(0, 0.1)) * 0.6) - 0.5) * sin(tick.x * 3.5 - f_pos.y * 6);
f_norm.xy += mix(vec2(0), vec2(h - hx, h - hy) / 0.1 * 0.03, puddle);
alpha = mix(1.0, 0.2, puddle);
f_col.rgb *= mix(1.0, 0.7, puddle);
k_s = mix(k_s, vec3(0.7, 0.7, 1.0), puddle);
}
#endif
} }
} }
#endif #endif

View File

@ -23,7 +23,6 @@ struct WeatherZone {
struct CellConsts { struct CellConsts {
humidity: f32, humidity: f32,
alt: f32,
} }
pub struct WeatherSim { pub struct WeatherSim {
@ -55,10 +54,6 @@ impl WeatherSim {
let average_humid = humid_sum / (CHUNKS_PER_CELL * CHUNKS_PER_CELL) as f32; let average_humid = humid_sum / (CHUNKS_PER_CELL * CHUNKS_PER_CELL) as f32;
CellConsts { CellConsts {
humidity: average_humid.powf(0.2).min(1.0), humidity: average_humid.powf(0.2).min(1.0),
alt: world
.sim()
.get_alt_approx(cell_to_wpos_center(p.map(|e| e as i32)))
.unwrap_or(world::CONFIG.sea_level),
} }
}) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
@ -96,6 +91,7 @@ impl WeatherSim {
time_of_day: &TimeOfDay, time_of_day: &TimeOfDay,
outcomes: &EventBus<Outcome>, outcomes: &EventBus<Outcome>,
out: &mut WeatherGrid, out: &mut WeatherGrid,
world: &World,
) { ) {
let time = time_of_day.0; let time = time_of_day.0;
@ -155,8 +151,11 @@ impl WeatherSim {
* (1.0 - pressure); * (1.0 - pressure);
if cell.rain > 0.2 && cell.cloud > 0.15 && thread_rng().gen_bool(0.01) { if cell.rain > 0.2 && cell.cloud > 0.15 && thread_rng().gen_bool(0.01) {
let wpos = wpos.map(|e| {
e as f32 + thread_rng().gen_range(-1.0..1.0) * CELL_SIZE as f32 * 0.5
});
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.with_z(world.sim().get_alt_approx(wpos.as_()).unwrap_or(0.0)),
}); });
} }
} }

View File

@ -1,6 +1,8 @@
use common::{event::EventBus, outcome::Outcome, resources::TimeOfDay, weather::WeatherGrid}; use common::{event::EventBus, outcome::Outcome, resources::TimeOfDay, weather::WeatherGrid};
use common_ecs::{Origin, Phase, System}; use common_ecs::{Origin, Phase, System};
use specs::{Read, ReadExpect, Write, WriteExpect}; use specs::{Read, ReadExpect, Write, WriteExpect};
use std::sync::Arc;
use world::World;
use crate::sys::SysScheduler; use crate::sys::SysScheduler;
@ -16,6 +18,7 @@ impl<'a> System<'a> for Sys {
WriteExpect<'a, WeatherGrid>, WriteExpect<'a, WeatherGrid>,
Write<'a, SysScheduler<Self>>, Write<'a, SysScheduler<Self>>,
ReadExpect<'a, EventBus<Outcome>>, ReadExpect<'a, EventBus<Outcome>>,
ReadExpect<'a, Arc<World>>,
); );
const NAME: &'static str = "weather::tick"; const NAME: &'static str = "weather::tick";
@ -24,13 +27,13 @@ impl<'a> System<'a> for Sys {
fn run( fn run(
_job: &mut common_ecs::Job<Self>, _job: &mut common_ecs::Job<Self>,
(game_time, mut sim, mut grid, mut scheduler, outcomes): Self::SystemData, (game_time, mut sim, mut grid, mut scheduler, outcomes, world): Self::SystemData,
) { ) {
if scheduler.should_run() { if scheduler.should_run() {
if grid.size() != sim.size() { if grid.size() != sim.size() {
*grid = WeatherGrid::new(sim.size()); *grid = WeatherGrid::new(sim.size());
} }
sim.tick(&game_time, &outcomes, &mut grid); sim.tick(&game_time, &outcomes, &mut grid, &world);
} }
} }
} }

View File

@ -476,8 +476,8 @@ pub enum ExperimentalShader {
/// Display grid lines to visualize the distribution of shadow map texels /// Display grid lines to visualize the distribution of shadow map texels
/// for the directional light from the sun. /// for the directional light from the sun.
DirectionalShadowMapTexelGrid, DirectionalShadowMapTexelGrid,
/// Enable rainbows /// Disable rainbows
Rainbows, NoRainbows,
/// Make objects appear wet when appropriate. /// Make objects appear wet when appropriate.
Wetness, Wetness,
} }