mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Better lightning rates, fixed shaders
This commit is contained in:
parent
3b758cc7b0
commit
47b236b1f0
@ -3,44 +3,46 @@
|
||||
|
||||
#include "sky.glsl"
|
||||
|
||||
#ifdef POINT_GLOW_FACTOR
|
||||
void apply_point_glow_light(Light L, vec3 wpos, vec3 dir, float max_dist, inout vec3 color) {
|
||||
vec3 light_pos = L.light_pos.xyz;
|
||||
// Project light_pos to dir line
|
||||
float t = max(dot(light_pos - wpos, dir), 0);
|
||||
vec3 nearest = wpos + dir * min(t, max_dist);
|
||||
// Project light_pos to dir line
|
||||
float t = max(dot(light_pos - wpos, dir), 0);
|
||||
vec3 nearest = wpos + dir * min(t, max_dist);
|
||||
|
||||
vec3 difference = light_pos - nearest;
|
||||
float distance_2 = dot(difference, difference);
|
||||
//if (distance_2 > 100000.0) {
|
||||
// return;
|
||||
//}
|
||||
vec3 difference = light_pos - nearest;
|
||||
float distance_2 = dot(difference, difference);
|
||||
//if (distance_2 > 100000.0) {
|
||||
// return;
|
||||
//}
|
||||
|
||||
#if (CLOUD_MODE >= CLOUD_MODE_HIGH)
|
||||
vec3 _unused;
|
||||
float unused2;
|
||||
float spread = 1.0 / (1.0 + cloud_at(nearest, 0.0, _unused, unused2).z * 0.005);
|
||||
#else
|
||||
const float spread = 1.0;
|
||||
#endif
|
||||
#if (CLOUD_MODE >= CLOUD_MODE_HIGH)
|
||||
vec3 _unused;
|
||||
float unused2;
|
||||
float spread = 1.0 / (1.0 + cloud_at(nearest, 0.0, _unused, unused2).z * 0.005);
|
||||
#else
|
||||
const float spread = 1.0;
|
||||
#endif
|
||||
|
||||
float strength = pow(attenuation_strength_real(difference), spread);
|
||||
float strength = pow(attenuation_strength_real(difference), spread);
|
||||
|
||||
#ifdef EXPERIMENTAL_LOWGLOWNEARCAMERA
|
||||
vec3 cam_wpos = cam_pos.xyz + focus_pos.xyz + focus_off.xyz;
|
||||
vec3 cam_diff = light_pos - cam_wpos;
|
||||
float cam_dist_2 = dot(cam_diff, cam_diff);
|
||||
// 3 meters away glow returns to the maximum strength.
|
||||
strength *= clamp(cam_dist_2 / 9.0, 0.25, 1.0);
|
||||
#endif
|
||||
#ifdef EXPERIMENTAL_LOWGLOWNEARCAMERA
|
||||
vec3 cam_wpos = cam_pos.xyz + focus_pos.xyz + focus_off.xyz;
|
||||
vec3 cam_diff = light_pos - cam_wpos;
|
||||
float cam_dist_2 = dot(cam_diff, cam_diff);
|
||||
// 3 meters away glow returns to the maximum strength.
|
||||
strength *= clamp(cam_dist_2 / 9.0, 0.25, 1.0);
|
||||
#endif
|
||||
|
||||
vec3 light_color = srgb_to_linear(L.light_col.rgb) * strength;
|
||||
vec3 light_color = srgb_to_linear(L.light_col.rgb) * strength;
|
||||
|
||||
const float LIGHT_AMBIANCE = 0.025;
|
||||
color += light_color
|
||||
* 0.002
|
||||
// Constant, *should* const fold
|
||||
* POINT_GLOW_FACTOR;
|
||||
const float LIGHT_AMBIANCE = 0.025;
|
||||
color += light_color
|
||||
* 0.002
|
||||
// Constant, *should* const fold
|
||||
* POINT_GLOW_FACTOR;
|
||||
}
|
||||
#endif
|
||||
|
||||
vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color) {
|
||||
#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);
|
||||
}
|
||||
#endif
|
||||
// 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);
|
||||
if (tick.x - last_lightning.w < 5.0) {
|
||||
// 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);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
|
@ -125,22 +125,37 @@ impl WeatherSim {
|
||||
let time_scale = 100_000.0;
|
||||
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.55
|
||||
- self.consts[point].humidity * 0.6;
|
||||
let scale = 10_000.0;
|
||||
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;
|
||||
|
||||
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].humidity)
|
||||
.powf(0.5);
|
||||
* self.consts[point].humidity
|
||||
* 2.5)
|
||||
.powf(1.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,
|
||||
) * 200.0
|
||||
* (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 {
|
||||
pos: wpos.map(|e| e as f32).with_z(self.consts[point].alt),
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user