From fc80a6278c305129d4223d942d8d3602d2225cd6 Mon Sep 17 00:00:00 2001 From: DaforLynx Date: Thu, 7 Jul 2022 16:09:13 -0700 Subject: [PATCH 001/116] Fixing looping issues --- assets/voxygen/audio/ambient.ron | 8 ++++---- assets/voxygen/audio/soundtrack.ron | 8 ++++---- voxygen/src/audio/ambient.rs | 7 ++----- voxygen/src/audio/mod.rs | 4 ++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/assets/voxygen/audio/ambient.ron b/assets/voxygen/audio/ambient.ron index a1fb6a9d48..b4a619df07 100644 --- a/assets/voxygen/audio/ambient.ron +++ b/assets/voxygen/audio/ambient.ron @@ -2,22 +2,22 @@ tracks: [ ( path: "voxygen.audio.ambience.wind", - length: 14.203, + length: 14.17, tag: Wind, ), ( path: "voxygen.audio.ambience.rain", - length: 17.0, + length: 16.97, tag: Rain, ), ( path:"voxygen.audio.ambience.thunder", - length: 32.0, + length: 31.97, tag: Thunder, ), ( path:"voxygen.audio.ambience.leaves", - length: 26.0, + length: 25.97, tag: Leaves, ), ] diff --git a/assets/voxygen/audio/soundtrack.ron b/assets/voxygen/audio/soundtrack.ron index 6a0958c4af..0bdc506e1f 100644 --- a/assets/voxygen/audio/soundtrack.ron +++ b/assets/voxygen/audio/soundtrack.ron @@ -641,8 +641,8 @@ biomes: [], site: Some(Dungeon), segments: [ - ("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-start", 56.0, Transition(Explore, Combat(High)), Some(Combat(High))), - ("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-loop", 54.0, Activity(Combat(High)), None), + ("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-start", 55.97, Transition(Explore, Combat(High)), Some(Combat(High))), + ("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-loop", 53.97, Activity(Combat(High)), None), ("voxygen.audio.soundtrack.combat.barred_paths.barred_paths-end", 6.0, Transition(Combat(High), Explore), None), ], ), @@ -653,8 +653,8 @@ biomes: [], site: Some(Dungeon), segments: [ - ("voxygen.audio.soundtrack.combat.reversal.reversal-start", 60.0, Transition(Explore, Combat(High)), Some(Combat(High))), - ("voxygen.audio.soundtrack.combat.reversal.reversal-loop", 60.0, Activity(Combat(High)), None), + ("voxygen.audio.soundtrack.combat.reversal.reversal-start", 59.97, Transition(Explore, Combat(High)), Some(Combat(High))), + ("voxygen.audio.soundtrack.combat.reversal.reversal-loop", 59.97, Activity(Combat(High)), None), ("voxygen.audio.soundtrack.combat.reversal.reversal-end", 4.0, Transition(Combat(High), Explore), None), ], ), diff --git a/voxygen/src/audio/ambient.rs b/voxygen/src/audio/ambient.rs index 8382a43be7..21f6db1fb7 100644 --- a/voxygen/src/audio/ambient.rs +++ b/voxygen/src/audio/ambient.rs @@ -79,20 +79,17 @@ impl AmbientMgr { // Update with sfx volume channel.set_volume(ambience_volume); - // Set the duration of the loop to whatever the current value is (0.0 by - // default) - // If the sound should loop at this point: if channel.began_playing.elapsed().as_secs_f32() > channel.next_track_change { let track = ambience.tracks.iter().find(|track| track.tag == tag); - // Set the channel's start point at this instant + // Set the channel's start point to this instant channel.began_playing = Instant::now(); if let Some(track) = track { // Set loop duration to the one specified in the ron channel.next_track_change = track.length; // Play the file of the current tag at the current multiplier; let current_multiplier = channel.multiplier; - audio.play_ambient(tag, &track.path, current_multiplier); + audio.play_ambient(tag, &track.path, current_multiplier * ambience_volume); } }; diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 482b8d0d20..0a63d90772 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -312,11 +312,11 @@ impl AudioFrontend { &mut self, channel_tag: AmbientChannelTag, sound: &str, - volume_multiplier: f32, + volume: f32, ) { if self.audio_stream.is_some() { if let Some(channel) = self.get_ambient_channel(channel_tag) { - channel.set_volume(volume_multiplier); + channel.set_volume(volume); channel.play(load_ogg(sound)); } } From 0d1bf3efe6f75d4077d6ef07b9394aa6488a605a Mon Sep 17 00:00:00 2001 From: DaforLynx Date: Thu, 7 Jul 2022 16:10:51 -0700 Subject: [PATCH 002/116] fmt --- voxygen/src/audio/mod.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 0a63d90772..bd0db0b614 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -308,12 +308,7 @@ impl AudioFrontend { } /// Plays a file at a given volume in the channel with a given tag - fn play_ambient( - &mut self, - channel_tag: AmbientChannelTag, - sound: &str, - volume: f32, - ) { + fn play_ambient(&mut self, channel_tag: AmbientChannelTag, sound: &str, volume: f32) { if self.audio_stream.is_some() { if let Some(channel) = self.get_ambient_channel(channel_tag) { channel.set_volume(volume); From eae917ee8f28fb839d2bae210aae738583bf8066 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 14:47:43 +0100 Subject: [PATCH 003/116] Use DDA for rain rendering --- assets/voxygen/shaders/clouds-frag.glsl | 47 ++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 01faedb424..cdf87016b2 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -82,6 +82,43 @@ void main() { #if (CLOUD_MODE == CLOUD_MODE_NONE) color.rgb = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb); + #elif (0 == 0) + if (medium.x == MEDIUM_AIR && rain_density > 0.0) { + vec3 cam_wpos = cam_pos.xyz + focus_off.xyz; + + vec3 adjusted_dir = (vec4(dir, 0) * rain_dir_mat).xyz; + + vec2 dir2d = adjusted_dir.xy; + vec3 rpos = vec3(0); + float t = 0.0; + for (int i = 0; i < 10; i ++) {//t * (length(dir2d) + 0.25) < 30.0) { + 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; + t += max(min(deltas.x, deltas.y) * scale, PLANCK); + rpos = cam_wpos + adjusted_dir * t; + vec3 wpos = cam_pos.xyz + focus_off.xyz + dir * t; + + vec2 diff = abs(round(rpos.xy) - rpos.xy); + vec3 wall_pos = vec3((diff.x > diff.y) ? rpos.xy : rpos.yx, rpos.z + integrated_rain_vel * 0.5); + wall_pos.xz *= vec2(4, 0.3); + wall_pos.z += hash(fract(vec4(floor(wall_pos.xy + vec2(0, 0.5)), 0, 0) * 0.1)); + if (abs(hash(vec4(floor(wall_pos.xyz), 0))) > rain_density) { + continue; + } + + if (rain_occlusion_at(wpos - focus_off.xyz) > 0.0 && t > 1 && t < dist) { + if (length((fract(wall_pos.xz) - 0.5)) < 0.1) { + float drop_size = 0.001; + float alpha = sign(max(1 - length(rpos / drop_size * 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, 0.9); + + /* color.rgb = mix(color.rgb, vec3(0.5, 0.5, 1), 0.5); */ + } + } + } + } #else vec3 old_color = color.rgb; @@ -92,17 +129,17 @@ void main() { float z = (-1 / (abs(adjusted_dir.z) - 1) - 1) * sign(adjusted_dir.z); // normalize xy to get a 2d direction vec2 dir_2d = normalize(adjusted_dir.xy); - // sort of map cylinder around the camera to 2d grid + // sort of map cylinder around the camera to 2d grid vec2 view_pos = vec2(atan2(dir_2d.x, dir_2d.y), z); // compute camera position in the world vec3 cam_wpos = cam_pos.xyz + focus_off.xyz; - - // Rain density is now only based on the cameras current position. + + // Rain density is now only based on the cameras current position. // This could be affected by a setting where rain_density_at is instead // called each iteration of the loop. With the current implementation // of rain_dir this has issues with being in a place where it doesn't rain - // and seeing rain. + // and seeing rain. float rain_density = rain_density * 1.0; if (medium.x == MEDIUM_AIR && rain_density > 0.0) { float rain_dist = 50.0; @@ -130,7 +167,7 @@ void main() { ); float dist_to_rain = drop_depth / length(dir.xy); - vec3 rpos = dir * dist_to_rain; + vec3 rpos = dir * dist_to_rain; if (dist < dist_to_rain || cam_wpos.z + rpos.z > CLOUD_AVG_ALT) { continue; } From d5c0e878d71b57703fa4b0aeb531354b4967f605 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 15:09:38 +0100 Subject: [PATCH 004/116] Adjusted depths --- assets/voxygen/shaders/clouds-frag.glsl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index cdf87016b2..1c81b2aa72 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -89,25 +89,28 @@ void main() { vec3 adjusted_dir = (vec4(dir, 0) * rain_dir_mat).xyz; vec2 dir2d = adjusted_dir.xy; - vec3 rpos = vec3(0); + vec3 rpos = vec3(0.0); float t = 0.0; for (int i = 0; i < 10; i ++) {//t * (length(dir2d) + 0.25) < 30.0) { 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; - t += max(min(deltas.x, deltas.y) * scale, PLANCK); + float jump = max(min(deltas.x, deltas.y) * scale, PLANCK); + t += jump; rpos = cam_wpos + adjusted_dir * t; - vec3 wpos = cam_pos.xyz + focus_off.xyz + dir * t; vec2 diff = abs(round(rpos.xy) - rpos.xy); vec3 wall_pos = vec3((diff.x > diff.y) ? rpos.xy : rpos.yx, rpos.z + integrated_rain_vel * 0.5); wall_pos.xz *= vec2(4, 0.3); - wall_pos.z += hash(fract(vec4(floor(wall_pos.xy + vec2(0, 0.5)), 0, 0) * 0.1)); + 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; } - if (rain_occlusion_at(wpos - focus_off.xyz) > 0.0 && t > 1 && t < dist) { + float depth_adjust = abs(hash(vec4(floor(wall_pos.xyz), 2000))); + vec3 wpos = cam_pos.xyz + dir * (t - jump * depth_adjust); + + if (rain_occlusion_at(wpos) > 0.0 && t > 1 && t < dist) { if (length((fract(wall_pos.xz) - 0.5)) < 0.1) { float drop_size = 0.001; float alpha = sign(max(1 - length(rpos / drop_size * 0.1), 0)); From 32fe997506a0cae2dc41bc85199d6bbefe9007fa Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 16:07:15 +0100 Subject: [PATCH 005/116] Use tilted origin for rain --- assets/voxygen/shaders/clouds-frag.glsl | 3 ++- assets/voxygen/shaders/figure-frag.glsl | 19 +++++++++++-------- assets/voxygen/shaders/terrain-frag.glsl | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 1c81b2aa72..43802e721f 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -89,6 +89,7 @@ void main() { vec3 adjusted_dir = (vec4(dir, 0) * rain_dir_mat).xyz; vec2 dir2d = adjusted_dir.xy; + vec3 rorigin = (vec4(cam_wpos, 0) * rain_dir_mat).xyz; vec3 rpos = vec3(0.0); float t = 0.0; for (int i = 0; i < 10; i ++) {//t * (length(dir2d) + 0.25) < 30.0) { @@ -97,7 +98,7 @@ void main() { vec2 deltas = (step(vec2(0), dir2d) - fract(rpos.xy / scale)) / dir2d; float jump = max(min(deltas.x, deltas.y) * scale, PLANCK); t += jump; - rpos = cam_wpos + adjusted_dir * t; + rpos = rorigin + adjusted_dir * t; vec2 diff = abs(round(rpos.xy) - rpos.xy); vec3 wall_pos = vec3((diff.x > diff.y) ? rpos.xy : rpos.yx, rpos.z + integrated_rain_vel * 0.5); diff --git a/assets/voxygen/shaders/figure-frag.glsl b/assets/voxygen/shaders/figure-frag.glsl index 140fdee912..299ffb433f 100644 --- a/assets/voxygen/shaders/figure-frag.glsl +++ b/assets/voxygen/shaders/figure-frag.glsl @@ -164,6 +164,17 @@ void main() { vec3 surf_color = /*srgb_to_linear*/f_col; float alpha = 1.0; const float n2 = 1.5; + + + // This is a silly hack. It's not true reflectance (see below for that), but gives the desired + // effect without breaking the entire lighting model until we come up with a better way of doing + // reflectivity that accounts for physical surroundings like the ground + if ((material & (1u << 1u)) > 0u) { + vec3 reflect_ray_dir = reflect(cam_to_frag, f_norm); + surf_color *= dot(vec3(1.0) - abs(fract(reflect_ray_dir * 1.5) * 2.0 - 1.0) * 0.85, vec3(1)); + alpha = 0.1; + } + const float R_s2s0 = pow((1.0 - n2) / (1.0 + n2), 2); const float R_s1s0 = pow((1.3325 - n2) / (1.3325 + n2), 2); const float R_s2s1 = pow((1.0 - 1.3325) / (1.0 + 1.3325), 2); @@ -174,14 +185,6 @@ void main() { vec3 k_d = vec3(1.0); vec3 k_s = vec3(R_s); - // This is a silly hack. It's not true reflectance (see below for that), but gives the desired - // effect without breaking the entire lighting model until we come up with a better way of doing - // reflectivity that accounts for physical surroundings like the ground - if ((material & (1u << 1u)) > 0u) { - vec3 reflect_ray_dir = reflect(cam_to_frag, f_norm); - surf_color *= dot(vec3(1.0) - abs(fract(reflect_ray_dir * 1.5) * 2.0 - 1.0) * 0.85, vec3(1)); - } - vec3 emitted_light, reflected_light; // Make voxel shadows block the sun and moon diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 2c821f9cf4..9f7738dddd 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -300,7 +300,7 @@ void main() { vec3 two_down = f_pos - offset_two; // Adjust this to change the size of the grid cells relative to the - // number of shadow texels + // number of shadow texels float grid_cell_to_texel_ratio = 32.0; vec2 shadowTexSize = textureSize(sampler2D(t_directed_shadow_maps, s_directed_shadow_maps), 0) / grid_cell_to_texel_ratio; @@ -320,7 +320,7 @@ void main() { return; } #endif - + float max_light = 0.0; // After shadows are computed, we use a refracted sun and moon direction. From 23aea724661692827f351be7ab7016384b84eb5a Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 16:09:36 +0100 Subject: [PATCH 006/116] Fixed fall rate --- assets/voxygen/shaders/clouds-frag.glsl | 2 +- common/src/weather.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 43802e721f..46df151caa 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -101,7 +101,7 @@ void main() { rpos = rorigin + adjusted_dir * t; vec2 diff = abs(round(rpos.xy) - rpos.xy); - vec3 wall_pos = vec3((diff.x > diff.y) ? rpos.xy : rpos.yx, rpos.z + integrated_rain_vel * 0.5); + 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) { diff --git a/common/src/weather.rs b/common/src/weather.rs index b2e163be3a..15008774bf 100644 --- a/common/src/weather.rs +++ b/common/src/weather.rs @@ -42,7 +42,7 @@ impl Weather { // Get the rain velocity for this weather pub fn rain_vel(&self) -> Vec3 { - const FALL_RATE: f32 = 50.0; + const FALL_RATE: f32 = 30.0; Vec3::new(self.wind.x, self.wind.y, -FALL_RATE) } } From 853d622e197e39b71510a2e1ccba018b563e50e6 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 16:41:31 +0100 Subject: [PATCH 007/116] Better fall rate --- assets/voxygen/shaders/clouds-frag.glsl | 15 +++++++-------- common/src/weather.rs | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 46df151caa..7a22a47711 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -92,7 +92,7 @@ void main() { vec3 rorigin = (vec4(cam_wpos, 0) * rain_dir_mat).xyz; vec3 rpos = vec3(0.0); float t = 0.0; - for (int i = 0; i < 10; i ++) {//t * (length(dir2d) + 0.25) < 30.0) { + for (int i = 0; i < 6; 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; @@ -109,16 +109,15 @@ void main() { } float depth_adjust = abs(hash(vec4(floor(wall_pos.xyz), 2000))); - vec3 wpos = cam_pos.xyz + dir * (t - jump * depth_adjust); + float wpos_dist = t - jump * depth_adjust; + vec3 wpos = cam_pos.xyz + dir * wpos_dist; - if (rain_occlusion_at(wpos) > 0.0 && t > 1 && t < dist) { + if (wpos_dist > dist) { break; } + if (rain_occlusion_at(wpos) > 0.5) { if (length((fract(wall_pos.xz) - 0.5)) < 0.1) { - float drop_size = 0.001; - float alpha = sign(max(1 - length(rpos / drop_size * 0.1), 0)); + 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, 0.9); - - /* color.rgb = mix(color.rgb, vec3(0.5, 0.5, 1), 0.5); */ + color.rgb = mix(color.rgb, vec3(0.2, 0.3, 0.5) * light, alpha); } } } diff --git a/common/src/weather.rs b/common/src/weather.rs index 15008774bf..be39dc73a3 100644 --- a/common/src/weather.rs +++ b/common/src/weather.rs @@ -42,7 +42,7 @@ impl Weather { // Get the rain velocity for this weather pub fn rain_vel(&self) -> Vec3 { - const FALL_RATE: f32 = 30.0; + const FALL_RATE: f32 = 20.0; Vec3::new(self.wind.x, self.wind.y, -FALL_RATE) } } From 28bc9db198e7891a195cfdd88f9390166248756b Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 18:09:13 +0100 Subject: [PATCH 008/116] Better cloud cover --- assets/voxygen/shaders/clouds-frag.glsl | 6 +++--- common/src/weather.rs | 2 +- server/src/weather/sim.rs | 20 +++++++++++++------- server/src/weather/tick.rs | 8 +++++--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 7a22a47711..7f9c885086 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -89,7 +89,7 @@ void main() { vec3 adjusted_dir = (vec4(dir, 0) * rain_dir_mat).xyz; vec2 dir2d = adjusted_dir.xy; - vec3 rorigin = (vec4(cam_wpos, 0) * rain_dir_mat).xyz; + 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 ++) { @@ -114,8 +114,8 @@ void main() { if (wpos_dist > dist) { break; } if (rain_occlusion_at(wpos) > 0.5) { - if (length((fract(wall_pos.xz) - 0.5)) < 0.1) { - float alpha = 0.5 * clamp((wpos_dist - 1.0) * 0.5, 0.0, 1.0); + 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); } diff --git a/common/src/weather.rs b/common/src/weather.rs index be39dc73a3..15008774bf 100644 --- a/common/src/weather.rs +++ b/common/src/weather.rs @@ -42,7 +42,7 @@ impl Weather { // Get the rain velocity for this weather pub fn rain_vel(&self) -> Vec3 { - const FALL_RATE: f32 = 20.0; + const FALL_RATE: f32 = 30.0; Vec3::new(self.wind.x, self.wind.y, -FALL_RATE) } } diff --git a/server/src/weather/sim.rs b/server/src/weather/sim.rs index 50612bcbc8..d12b474e27 100644 --- a/server/src/weather/sim.rs +++ b/server/src/weather/sim.rs @@ -9,7 +9,7 @@ use world::World; use crate::weather::WEATHER_DT; -fn cell_to_wpos(p: Vec2) -> Vec2 { p * CELL_SIZE as i32 } +fn cell_to_wpos_center(p: Vec2) -> Vec2 { p * CELL_SIZE as i32 + CELL_SIZE as i32 / 2 } #[derive(Clone)] struct WeatherZone { @@ -49,7 +49,7 @@ impl WeatherSim { } } let average_humid = humid_sum / (CHUNKS_PER_CELL * CHUNKS_PER_CELL) as f32; - let rain_factor = (2.0 * average_humid.powf(0.2)).min(1.0); + let rain_factor = (4.0 * average_humid.powf(0.2)).min(1.0); CellConsts { rain_factor } }) .collect::>(), @@ -82,7 +82,7 @@ impl WeatherSim { } // Time step is cell size / maximum wind speed - pub fn tick(&mut self, time_of_day: &TimeOfDay, out: &mut WeatherGrid) { + pub fn tick(&mut self, world: &World, time_of_day: &TimeOfDay, out: &mut WeatherGrid) { let time = time_of_day.0; let base_nz = Turbulence::new( @@ -103,7 +103,12 @@ impl WeatherSim { self.zones[point] = None; } } else { - let wpos = cell_to_wpos(point); + 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; @@ -112,10 +117,11 @@ 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; + (base_nz.get(spos.into_array()) * 0.5 + 1.0).clamped(0.0, 1.0) as f32 + 0.4 + - humid * 0.5; - const RAIN_CLOUD_THRESHOLD: f32 = 0.26; - cell.cloud = (1.0 - pressure) * 0.5; + const RAIN_CLOUD_THRESHOLD: f32 = 0.2; + 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.wind = Vec2::new( diff --git a/server/src/weather/tick.rs b/server/src/weather/tick.rs index db5154b73c..8dcfe2e94f 100644 --- a/server/src/weather/tick.rs +++ b/server/src/weather/tick.rs @@ -1,6 +1,7 @@ use common::{resources::TimeOfDay, weather::WeatherGrid}; use common_ecs::{Origin, Phase, System}; -use specs::{Read, Write, WriteExpect}; +use specs::{Read, ReadExpect, Write, WriteExpect}; +use std::sync::Arc; use crate::sys::SysScheduler; @@ -12,6 +13,7 @@ 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>, @@ -23,13 +25,13 @@ impl<'a> System<'a> for Sys { fn run( _job: &mut common_ecs::Job, - (game_time, mut sim, mut grid, mut scheduler): Self::SystemData, + (game_time, world, mut sim, mut grid, mut scheduler): Self::SystemData, ) { if scheduler.should_run() { if grid.size() != sim.size() { *grid = WeatherGrid::new(sim.size()); } - sim.tick(&game_time, &mut grid); + sim.tick(&world, &game_time, &mut grid); } } } From 6c4b10d881976c1b3fb44ff6a0a7a77641b0f2f8 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 20:18:07 +0100 Subject: [PATCH 009/116] 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); } } } From 4b738c8b8fab864d94348cdc52a685d1f22bf61d Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 20:22:09 +0100 Subject: [PATCH 010/116] Balanced rain intensity --- assets/voxygen/shaders/clouds-frag.glsl | 2 +- assets/voxygen/shaders/terrain-frag.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 9508d24382..856ec51a52 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -109,7 +109,7 @@ void main() { 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); + float density = rain_density * rain_occlusion_at(wpos); if (density < 0.001 || fract(hash(vec4(floor(wall_pos.xyz), 0))) > density) { continue; } if (wpos_dist > dist) { break; } diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 78c5923c7c..fc30a29813 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) * 10.0) { + if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz) * 2.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; From 90d2ceab2e5a0b35287409c96f5c9465ba8bdce9 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 20:40:08 +0100 Subject: [PATCH 011/116] Fixed rain clipping issue --- assets/voxygen/shaders/clouds-frag.glsl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 856ec51a52..baaea6b925 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -92,9 +92,9 @@ 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 < 8; i ++) { + while (t < 64.0) { const float PLANCK = 0.01; - float scale = min(pow(2, ceil(t / 3.0)), 32); + float scale = min(pow(2, ceil(t / 2.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; @@ -105,7 +105,7 @@ void main() { 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)); - float depth_adjust = abs(hash(vec4(floor(wall_pos.xyz), 2000))); + float depth_adjust = fract(hash(vec4(floor(wall_pos.xyz), 2000))); float wpos_dist = t - jump * depth_adjust; vec3 wpos = cam_pos.xyz + dir * wpos_dist; @@ -115,8 +115,8 @@ void main() { if (wpos_dist > dist) { break; } 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); + float light = dot(color.rgb, vec3(1)) + 0.1 + (get_sun_brightness() + get_moon_brightness()) * 0.3; + color.rgb = mix(color.rgb, vec3(0.1, 0.2, 0.5) * light, alpha); } } } From 622b67d24eb8201b3ebb9aa843a68e2c309d4f41 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 20:49:51 +0100 Subject: [PATCH 012/116] Relative offset fix --- assets/voxygen/shaders/clouds-frag.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index baaea6b925..9866e65b28 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -83,7 +83,7 @@ void main() { #if (CLOUD_MODE == CLOUD_MODE_NONE) color.rgb = apply_point_glow(cam_pos.xyz + focus_off.xyz, dir, dist, color.rgb); #elif (0 == 0) - if (medium.x == MEDIUM_AIR && rain_density > 0.0) { + if (medium.x == MEDIUM_AIR && rain_density > 0.001) { vec3 cam_wpos = cam_pos.xyz + focus_off.xyz; vec3 adjusted_dir = (vec4(dir, 0) * rain_dir_mat).xyz; @@ -110,7 +110,7 @@ void main() { vec3 wpos = cam_pos.xyz + dir * wpos_dist; float density = rain_density * rain_occlusion_at(wpos); - if (density < 0.001 || fract(hash(vec4(floor(wall_pos.xyz), 0))) > density) { continue; } + if (fract(hash(vec4(floor(wall_pos.xyz), 0))) > density) { continue; } if (wpos_dist > dist) { break; } 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) { From 4531a4e3f9a8a9b230ad3597edfb73f0e5aa62d8 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 23:26:33 +0100 Subject: [PATCH 013/116] Added lightning --- assets/voxygen/audio/sfx.ron | 6 +++++ .../voxygen/audio/sfx/ambient/lightning_1.ogg | 3 +++ assets/voxygen/shaders/clouds-frag.glsl | 2 +- .../shaders/include/cloud/regular.glsl | 2 +- assets/voxygen/shaders/include/globals.glsl | 1 + assets/voxygen/shaders/include/sky.glsl | 20 +++++++++++++- common/src/outcome.rs | 6 +++++ server/src/weather/sim.rs | 26 ++++++++++++++++--- server/src/weather/tick.rs | 9 ++++--- voxygen/src/audio/sfx/mod.rs | 11 ++++++++ voxygen/src/render/pipelines/mod.rs | 7 +++++ voxygen/src/scene/mod.rs | 6 +++++ voxygen/src/scene/particle.rs | 11 ++++++++ voxygen/src/scene/simple.rs | 1 + 14 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 assets/voxygen/audio/sfx/ambient/lightning_1.ogg diff --git a/assets/voxygen/audio/sfx.ron b/assets/voxygen/audio/sfx.ron index d527537436..9dba82e21f 100644 --- a/assets/voxygen/audio/sfx.ron +++ b/assets/voxygen/audio/sfx.ron @@ -1169,5 +1169,11 @@ ], threshold: 1.0, ), + Lightning: ( + files: [ + "voxygen.audio.sfx.ambient.lightning_1", + ], + threshold: 1.0, + ), } ) diff --git a/assets/voxygen/audio/sfx/ambient/lightning_1.ogg b/assets/voxygen/audio/sfx/ambient/lightning_1.ogg new file mode 100644 index 0000000000..546d7d11fe --- /dev/null +++ b/assets/voxygen/audio/sfx/ambient/lightning_1.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:caabc3e9d9066d710ca970189770040c82bd9588fa8911a77adbaa20f222a87f +size 59431 diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 9866e65b28..54364c8106 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -110,7 +110,7 @@ void main() { vec3 wpos = cam_pos.xyz + dir * wpos_dist; float density = rain_density * rain_occlusion_at(wpos); - if (fract(hash(vec4(floor(wall_pos.xyz), 0))) > density) { continue; } + if (fract(hash(vec4(floor(wall_pos.xyz), 0))) >= density) { continue; } if (wpos_dist > dist) { break; } 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) { diff --git a/assets/voxygen/shaders/include/cloud/regular.glsl b/assets/voxygen/shaders/include/cloud/regular.glsl index ddb4a2f552..412f463340 100644 --- a/assets/voxygen/shaders/include/cloud/regular.glsl +++ b/assets/voxygen/shaders/include/cloud/regular.glsl @@ -300,7 +300,7 @@ vec3 get_cloud_color(vec3 surf_color, vec3 dir, vec3 origin, const float time_of }; float h = max(0.0, min(pos.z, 900.0 - pos.z) / 450.0); float rain = rain_density_at(pos.xy) * pow(h, 0.1); - + float sun = sun_access * get_sun_brightness(); float energy = pow(rain * sun * min(cdist / 500.0, 1.0), 2.0) * 0.4; diff --git a/assets/voxygen/shaders/include/globals.glsl b/assets/voxygen/shaders/include/globals.glsl index cc75645b39..445f44d8f9 100644 --- a/assets/voxygen/shaders/include/globals.glsl +++ b/assets/voxygen/shaders/include/globals.glsl @@ -19,6 +19,7 @@ layout(std140, set = 0, binding = 0) uniform u_globals { uvec4 medium; ivec4 select_pos; vec4 gamma_exposure; + vec4 last_lightning; float ambiance; // 0 - FirstPerson // 1 - ThirdPerson diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index 167ae6b407..30732dbe9c 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -431,13 +431,31 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve } #endif + float time_since_lightning = tick.x - last_lightning.w; + vec3 lightning = vec3(0.0); + if (time_since_lightning < 5.0) { + vec3 diff = wpos + focus_off.xyz - (last_lightning.xyz + vec3(0, 0, 250)); + float dist = length(diff); + lightning = vec3(0.5, 0.8, 1.0) + // Strength + * 1000000 + // Flash + * max(0.0, 1.0 - time_since_lightning * 1.0) + // Reverb + * max(sin(time_of_day.x * 0.4), 0.0) + // Direction + * (dot(norm, diff / dist) + 1.0) + // Attenuation + / pow(50.0 + dist, 2); + } + reflected_light = R_t_r * ( (1.0 - SUN_AMBIANCE) * sun_chroma * sun_shadow * (light_reflection_factor(norm, dir, sun_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting) /*+ light_reflection_factor(norm, dir, normalize(sun_dir + vec3(0.0, 0.1, 0.0)), k_d, k_s, alpha) + light_reflection_factor(norm, dir, normalize(sun_dir - vec3(0.0, 0.1, 0.0)), k_d, k_s, alpha)*/) + (1.0 - MOON_AMBIANCE) * moon_chroma * moon_shadow * 1.0 * /*4.0 * */light_reflection_factor(norm, dir, moon_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting) + emission - ); + ) + lightning; /* light = sun_chroma + moon_chroma + PERSISTENT_AMBIANCE; diffuse_light = diff --git a/common/src/outcome.rs b/common/src/outcome.rs index 69ef8fb3da..70efed9c5b 100644 --- a/common/src/outcome.rs +++ b/common/src/outcome.rs @@ -27,6 +27,9 @@ pub enum Outcome { is_attack: bool, reagent: Option, // How can we better define this? }, + Lightning { + pos: Vec3, + }, ProjectileShot { pos: Vec3, body: comp::Body, @@ -99,6 +102,8 @@ impl Outcome { pub fn get_pos(&self) -> Option> { match self { Outcome::Explosion { pos, .. } + // TODO: Include this, but allow it to be sent to clients when outside of the VD + // | Outcome::Lightning { pos } | Outcome::ProjectileShot { pos, .. } | Outcome::ProjectileHit { pos, .. } | Outcome::Beam { pos, .. } @@ -113,6 +118,7 @@ impl Outcome { Outcome::BreakBlock { pos, .. } => Some(pos.map(|e| e as f32 + 0.5)), Outcome::ExpChange { .. } | Outcome::ComboChange { .. } + | Outcome::Lightning { .. } | Outcome::SkillPointGain { .. } => None, } } diff --git a/server/src/weather/sim.rs b/server/src/weather/sim.rs index a6ff3cc0ab..70a1441c81 100644 --- a/server/src/weather/sim.rs +++ b/server/src/weather/sim.rs @@ -1,9 +1,12 @@ use common::{ + event::EventBus, grid::Grid, + outcome::Outcome, resources::TimeOfDay, weather::{Weather, WeatherGrid, CELL_SIZE, CHUNKS_PER_CELL}, }; use noise::{NoiseFn, SuperSimplex, Turbulence}; +use rand::prelude::*; use vek::*; use world::World; @@ -20,6 +23,7 @@ struct WeatherZone { struct CellConsts { humidity: f32, + alt: f32, } pub struct WeatherSim { @@ -49,8 +53,13 @@ impl WeatherSim { } } let average_humid = humid_sum / (CHUNKS_PER_CELL * CHUNKS_PER_CELL) as f32; - let humidity = average_humid.powf(0.2).min(1.0); - CellConsts { humidity } + CellConsts { + 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::>(), ), @@ -82,7 +91,12 @@ impl WeatherSim { } // Time step is cell size / maximum wind speed - pub fn tick(&mut self, time_of_day: &TimeOfDay, out: &mut WeatherGrid) { + pub fn tick( + &mut self, + time_of_day: &TimeOfDay, + outcomes: &EventBus, + out: &mut WeatherGrid, + ) { let time = time_of_day.0; let base_nz = Turbulence::new( @@ -125,6 +139,12 @@ impl WeatherSim { rain_nz.get((spos + 1.0).into_array()).powi(3) as f32, ) * 200.0 * (1.0 - pressure); + + if cell.rain > 0.02 && cell.cloud > 0.05 && thread_rng().gen_bool(0.01) { + outcomes.emit_now(Outcome::Lightning { + pos: wpos.map(|e| e as f32).with_z(self.consts[point].alt), + }); + } } } } diff --git a/server/src/weather/tick.rs b/server/src/weather/tick.rs index db5154b73c..7e3273fd1d 100644 --- a/server/src/weather/tick.rs +++ b/server/src/weather/tick.rs @@ -1,6 +1,6 @@ -use common::{resources::TimeOfDay, weather::WeatherGrid}; +use common::{event::EventBus, outcome::Outcome, resources::TimeOfDay, weather::WeatherGrid}; use common_ecs::{Origin, Phase, System}; -use specs::{Read, Write, WriteExpect}; +use specs::{Read, ReadExpect, Write, WriteExpect}; use crate::sys::SysScheduler; @@ -15,6 +15,7 @@ impl<'a> System<'a> for Sys { WriteExpect<'a, WeatherSim>, WriteExpect<'a, WeatherGrid>, Write<'a, SysScheduler>, + ReadExpect<'a, EventBus>, ); const NAME: &'static str = "weather::tick"; @@ -23,13 +24,13 @@ impl<'a> System<'a> for Sys { fn run( _job: &mut common_ecs::Job, - (game_time, mut sim, mut grid, mut scheduler): Self::SystemData, + (game_time, mut sim, mut grid, mut scheduler, outcomes): Self::SystemData, ) { if scheduler.should_run() { if grid.size() != sim.size() { *grid = WeatherGrid::new(sim.size()); } - sim.tick(&game_time, &mut grid); + sim.tick(&game_time, &outcomes, &mut grid); } } } diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index b23e978c6e..1d502226bb 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -190,6 +190,7 @@ pub enum SfxEvent { PoiseChange(PoiseState), GroundSlam, Utterance(UtteranceKind, VoiceKind), + Lightning, } #[derive(Copy, Clone, Debug, PartialEq, Deserialize, Hash, Eq)] @@ -432,6 +433,16 @@ impl SfxMgr { underwater, ); }, + Outcome::Lightning { pos } => { + let sfx_trigger_item = triggers.get_key_value(&SfxEvent::Lightning); + // TODO: Don't use UI sfx, add a way to control position falloff + audio.emit_ui_sfx( + sfx_trigger_item, + Some( + (1.0 - pos.distance(audio.listener.pos) / 10_000.0).clamped(0.0, 1.0) * 3.0, + ), + ); + }, Outcome::GroundSlam { pos, .. } => { let sfx_trigger_item = triggers.get_key_value(&SfxEvent::GroundSlam); audio.emit_sfx(sfx_trigger_item, *pos, Some(2.0), underwater); diff --git a/voxygen/src/render/pipelines/mod.rs b/voxygen/src/render/pipelines/mod.rs index 3ddd7252e6..5cd5ecbc2e 100644 --- a/voxygen/src/render/pipelines/mod.rs +++ b/voxygen/src/render/pipelines/mod.rs @@ -64,6 +64,7 @@ pub struct Globals { medium: [u32; 4], select_pos: [i32; 4], gamma_exposure: [f32; 4], + last_lightning: [f32; 4], ambiance: f32, cam_mode: u32, sprite_render_distance: f32, @@ -108,6 +109,7 @@ impl Globals { select_pos: Option>, gamma: f32, exposure: f32, + last_lightning: (Vec3, f64), ambiance: f32, cam_mode: CameraMode, sprite_render_distance: f32, @@ -156,6 +158,10 @@ impl Globals { .unwrap_or_else(Vec4::zero) .into_array(), gamma_exposure: [gamma, exposure, 0.0, 0.0], + last_lightning: last_lightning + .0 + .with_w(last_lightning.1 as f32) + .into_array(), ambiance: ambiance.clamped(0.0, 1.0), cam_mode: cam_mode as u32, sprite_render_distance, @@ -202,6 +208,7 @@ impl Default for Globals { None, 1.0, 1.0, + (Vec3::zero(), -1000.0), 1.0, CameraMode::ThirdPerson, 250.0, diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 76ff9aaeaf..a194856953 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -108,6 +108,7 @@ pub struct Scene { ambient_mgr: AmbientMgr, integrated_rain_vel: f32, + last_lightning: Option<(Vec3, f64)>, } pub struct SceneData<'a> { @@ -325,6 +326,7 @@ impl Scene { ambience: ambient::load_ambience_items(), }, integrated_rain_vel: 0.0, + last_lightning: None, } } @@ -426,6 +428,9 @@ impl Scene { .handle_outcome(outcome, audio, scene_data.client, underwater); match outcome { + Outcome::Lightning { pos } => { + self.last_lightning = Some((*pos, scene_data.state.get_time())); + }, Outcome::Explosion { pos, power, @@ -689,6 +694,7 @@ impl Scene { self.select_pos.map(|e| e - focus_off.map(|e| e as i32)), scene_data.gamma, scene_data.exposure, + self.last_lightning.unwrap_or((Vec3::zero(), -1000.0)), scene_data.ambiance, self.camera.get_mode(), scene_data.sprite_render_distance as f32 - 20.0, diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index 5f9c424d39..6aa5dc46ed 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -62,6 +62,17 @@ impl ParticleMgr { let mut rng = rand::thread_rng(); match outcome { + Outcome::Lightning { pos } => { + self.particles.resize_with(self.particles.len() + 400, || { + Particle::new_directed( + Duration::from_secs_f32(rng.gen_range(2.0..3.0)), + time, + ParticleMode::GunPowderSpark, + *pos + Vec3::new(0.0, 0.0, rng.gen_range(250.0..1500.0)), + *pos, + ) + }); + }, Outcome::Explosion { pos, power, diff --git a/voxygen/src/scene/simple.rs b/voxygen/src/scene/simple.rs index 7e5d284e30..84b079c2a1 100644 --- a/voxygen/src/scene/simple.rs +++ b/voxygen/src/scene/simple.rs @@ -273,6 +273,7 @@ impl Scene { None, scene_data.gamma, scene_data.exposure, + (Vec3::zero(), -1000.0), scene_data.ambiance, self.camera.get_mode(), 250.0, From 6796fe27452a27467d58e122ab1fdb3b489046c3 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 8 Jul 2022 23:45:08 +0100 Subject: [PATCH 014/116] Better lightning attenuation --- voxygen/src/audio/sfx/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index 1d502226bb..7351c1e05d 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -434,14 +434,14 @@ impl SfxMgr { ); }, Outcome::Lightning { pos } => { - let sfx_trigger_item = triggers.get_key_value(&SfxEvent::Lightning); - // TODO: Don't use UI sfx, add a way to control position falloff - audio.emit_ui_sfx( - sfx_trigger_item, - Some( - (1.0 - pos.distance(audio.listener.pos) / 10_000.0).clamped(0.0, 1.0) * 3.0, - ), - ); + let power = (1.0 - pos.distance(audio.listener.pos) / 3_500.0) + .clamped(0.0, 1.0) + .powf(0.5); + if power > 0.0 { + let sfx_trigger_item = triggers.get_key_value(&SfxEvent::Lightning); + // TODO: Don't use UI sfx, add a way to control position falloff + audio.emit_ui_sfx(sfx_trigger_item, Some(power * 3.0)); + } }, Outcome::GroundSlam { pos, .. } => { let sfx_trigger_item = triggers.get_key_value(&SfxEvent::GroundSlam); From 6d1b46956d8b2a52aa9ccb658c80535688ad7826 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 9 Jul 2022 00:14:59 +0100 Subject: [PATCH 015/116] Better storms --- server/src/weather/sim.rs | 2 +- voxygen/src/audio/sfx/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/weather/sim.rs b/server/src/weather/sim.rs index 70a1441c81..9371f09d70 100644 --- a/server/src/weather/sim.rs +++ b/server/src/weather/sim.rs @@ -140,7 +140,7 @@ impl WeatherSim { ) * 200.0 * (1.0 - pressure); - if cell.rain > 0.02 && cell.cloud > 0.05 && thread_rng().gen_bool(0.01) { + if cell.rain > 0.1 && cell.cloud > 0.12 && thread_rng().gen_bool(0.01) { outcomes.emit_now(Outcome::Lightning { pos: wpos.map(|e| e as f32).with_z(self.consts[point].alt), }); diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index 7351c1e05d..a19bc38ab5 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -434,9 +434,9 @@ impl SfxMgr { ); }, Outcome::Lightning { pos } => { - let power = (1.0 - pos.distance(audio.listener.pos) / 3_500.0) + let power = (1.0 - pos.distance(audio.listener.pos) / 6_000.0) .clamped(0.0, 1.0) - .powf(0.5); + .powf(0.75); if power > 0.0 { let sfx_trigger_item = triggers.get_key_value(&SfxEvent::Lightning); // TODO: Don't use UI sfx, add a way to control position falloff From edc27204164bcebbc8cfe823805b2a96111c1197 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 9 Jul 2022 00:39:18 +0100 Subject: [PATCH 016/116] Better lightning effect --- .../voxygen/shaders/include/point_glow.glsl | 80 ++++++++++--------- assets/voxygen/shaders/include/sky.glsl | 47 ++++++----- 2 files changed, 72 insertions(+), 55 deletions(-) diff --git a/assets/voxygen/shaders/include/point_glow.glsl b/assets/voxygen/shaders/include/point_glow.glsl index 11b08e302d..8fc29c08e5 100644 --- a/assets/voxygen/shaders/include/point_glow.glsl +++ b/assets/voxygen/shaders/include/point_glow.glsl @@ -1,6 +1,47 @@ #ifndef POINT_GLOW_GLSL #define POINT_GLOW_GLSL +#include "sky.glsl" + +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); + + 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 + + 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 + + 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; +} + vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color) { #ifndef POINT_GLOW_FACTOR return color; @@ -9,44 +50,11 @@ vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color) { // Only access the array once Light L = lights[i]; - 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); - - vec3 difference = light_pos - nearest; - float distance_2 = dot(difference, difference); - if (distance_2 > 100000.0) { - continue; - } - - #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); - - #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; - - const float LIGHT_AMBIANCE = 0.025; - color += light_color - * 0.002 - // Constant, *should* const fold - * POINT_GLOW_FACTOR; + 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.5, 0.8, 1) * lightning_intensity() * 0.003, 1)), wpos, dir, max_dist, color); return color; } diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index 30732dbe9c..9549873a49 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -232,6 +232,33 @@ DirectionalLight get_moon_info(vec4 _dir, float shade_frac/*, vec4 light_pos[2]* return DirectionalLight(/*dir, */shadow, block/*, get_moon_color(dir), get_moon_brightness(dir)*/); } +const float LIGHTNING_HEIGHT = 350.0; + +float lightning_intensity() { + float time_since_lightning = tick.x - last_lightning.w; + return + // Strength + 1000000 + // Flash + * max(0.0, 1.0 - time_since_lightning * 1.0) + // Reverb + * max(sin(time_of_day.x * 0.4), 0.0); +} + +vec3 lightning_at(vec3 wpos) { + float time_since_lightning = tick.x - last_lightning.w; + if (time_since_lightning < 5.0) { + vec3 diff = wpos + focus_off.xyz - (last_lightning.xyz + vec3(0, 0, LIGHTNING_HEIGHT)); + float dist = length(diff); + return vec3(0.5, 0.8, 1.0) + * lightning_intensity() + // Attenuation + / pow(50.0 + dist, 2); + } else { + return vec3(0.0); + } +} + // // Calculates extra emission and reflectance (due to sunlight / moonlight). // // // // reflectence = k_a * i_a + i_a,persistent @@ -431,31 +458,13 @@ float get_sun_diffuse2(DirectionalLight sun_info, DirectionalLight moon_info, ve } #endif - float time_since_lightning = tick.x - last_lightning.w; - vec3 lightning = vec3(0.0); - if (time_since_lightning < 5.0) { - vec3 diff = wpos + focus_off.xyz - (last_lightning.xyz + vec3(0, 0, 250)); - float dist = length(diff); - lightning = vec3(0.5, 0.8, 1.0) - // Strength - * 1000000 - // Flash - * max(0.0, 1.0 - time_since_lightning * 1.0) - // Reverb - * max(sin(time_of_day.x * 0.4), 0.0) - // Direction - * (dot(norm, diff / dist) + 1.0) - // Attenuation - / pow(50.0 + dist, 2); - } - reflected_light = R_t_r * ( (1.0 - SUN_AMBIANCE) * sun_chroma * sun_shadow * (light_reflection_factor(norm, dir, sun_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting) /*+ light_reflection_factor(norm, dir, normalize(sun_dir + vec3(0.0, 0.1, 0.0)), k_d, k_s, alpha) + light_reflection_factor(norm, dir, normalize(sun_dir - vec3(0.0, 0.1, 0.0)), k_d, k_s, alpha)*/) + (1.0 - MOON_AMBIANCE) * moon_chroma * moon_shadow * 1.0 * /*4.0 * */light_reflection_factor(norm, dir, moon_dir, k_d, k_s, alpha, voxel_norm, voxel_lighting) + emission - ) + lightning; + ) + lightning_at(wpos); /* light = sun_chroma + moon_chroma + PERSISTENT_AMBIANCE; diffuse_light = From 836fe2b1c604878f89133ed6a31f761782bae7ca Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 9 Jul 2022 01:59:18 +0100 Subject: [PATCH 017/116] Proper lightning --- assets/voxygen/shaders/include/sky.glsl | 2 +- assets/voxygen/shaders/particle-vert.glsl | 14 +++++++++++++- common/src/cmd.rs | 5 +++++ server/src/cmd.rs | 18 ++++++++++++++++++ voxygen/src/render/pipelines/particle.rs | 1 + voxygen/src/scene/particle.rs | 8 ++++---- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/assets/voxygen/shaders/include/sky.glsl b/assets/voxygen/shaders/include/sky.glsl index 9549873a49..5b96d8fb6a 100644 --- a/assets/voxygen/shaders/include/sky.glsl +++ b/assets/voxygen/shaders/include/sky.glsl @@ -232,7 +232,7 @@ DirectionalLight get_moon_info(vec4 _dir, float shade_frac/*, vec4 light_pos[2]* return DirectionalLight(/*dir, */shadow, block/*, get_moon_color(dir), get_moon_brightness(dir)*/); } -const float LIGHTNING_HEIGHT = 350.0; +const float LIGHTNING_HEIGHT = 25.0; float lightning_intensity() { float time_since_lightning = tick.x - last_lightning.w; diff --git a/assets/voxygen/shaders/particle-vert.glsl b/assets/voxygen/shaders/particle-vert.glsl index b230abb7d7..c617155605 100644 --- a/assets/voxygen/shaders/particle-vert.glsl +++ b/assets/voxygen/shaders/particle-vert.glsl @@ -41,7 +41,6 @@ const int SMOKE = 0; const int FIRE = 1; const int GUN_POWDER_SPARK = 2; const int SHRAPNEL = 3; - const int FIREWORK_BLUE = 4; const int FIREWORK_GREEN = 5; const int FIREWORK_PURPLE = 6; @@ -76,6 +75,7 @@ const int DEATH = 34; const int ENERGY_BUFFING = 35; const int WEB_STRAND = 36; const int BLACK_SMOKE = 37; +const int LIGHTNING = 38; // meters per second squared (acceleration) const float earth_gravity = 9.807; @@ -602,6 +602,18 @@ void main() { spin_in_axis(perp_axis, asin(inst_dir.z / length(inst_dir)) + PI / 2.0) ); break; + case LIGHTNING: + f_reflect = 0.0; + perp_axis = normalize(cross(inst_dir, vec3(0.0, 0.0, 1.0))); + float z = (start_pos + inst_dir * percent()).z; + vec3 start_off = vec3(abs(fract(vec3(vec2(z) * vec2(0.015, 0.01), 0)) - 0.5) * z * 0.5); + attr = Attr( + inst_dir * percent() + start_off, + vec3(16.0), + vec4(10.0, 30.0, 50.0, 1.0),// * (1.0 - length(inst_dir) * 0.1), + identity()//spin_in_axis(perp_axis, asin(inst_dir.z / length(inst_dir)) + PI / 2.0) + ); + break; default: attr = Attr( linear_motion( diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 3d13aad316..ec9f79845b 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -305,6 +305,7 @@ pub enum ServerChatCommand { CreateLocation, DeleteLocation, WeatherZone, + Lightning, } impl ServerChatCommand { @@ -703,6 +704,9 @@ impl ServerChatCommand { "Create a weather zone", Some(Admin), ), + ServerChatCommand::Lightning => { + cmd(vec![], "Lightning strike at current position", Some(Admin)) + }, } } @@ -781,6 +785,7 @@ impl ServerChatCommand { ServerChatCommand::CreateLocation => "create_location", ServerChatCommand::DeleteLocation => "delete_location", ServerChatCommand::WeatherZone => "weather_zone", + ServerChatCommand::Lightning => "lightning", } } diff --git a/server/src/cmd.rs b/server/src/cmd.rs index ab65b6d843..91f76f7716 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -40,6 +40,7 @@ use common::{ link::Is, mounting::Rider, npc::{self, get_npc_name}, + outcome::Outcome, parse_cmd_args, resources::{BattleMode, PlayerPhysicsSettings, Time, TimeOfDay}, terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize}, @@ -192,6 +193,7 @@ fn do_command( ServerChatCommand::CreateLocation => handle_create_location, ServerChatCommand::DeleteLocation => handle_delete_location, ServerChatCommand::WeatherZone => handle_weather_zone, + ServerChatCommand::Lightning => handle_lightning, }; handler(server, client, target, args, cmd) @@ -3666,3 +3668,19 @@ fn handle_weather_zone( Err(action.help_string()) } } + +fn handle_lightning( + server: &mut Server, + client: EcsEntity, + _target: EcsEntity, + args: Vec, + action: &ServerChatCommand, +) -> CmdResult<()> { + let pos = position(server, client, "player")?.0; + server + .state + .ecs() + .read_resource::>() + .emit_now(Outcome::Lightning { pos }); + Ok(()) +} diff --git a/voxygen/src/render/pipelines/particle.rs b/voxygen/src/render/pipelines/particle.rs index 91eef06251..384feb5b45 100644 --- a/voxygen/src/render/pipelines/particle.rs +++ b/voxygen/src/render/pipelines/particle.rs @@ -88,6 +88,7 @@ pub enum ParticleMode { EnergyBuffing = 35, WebStrand = 36, BlackSmoke = 37, + Lightning = 38, } impl ParticleMode { diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index 6aa5dc46ed..d922adcd5b 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -63,12 +63,12 @@ impl ParticleMgr { match outcome { Outcome::Lightning { pos } => { - self.particles.resize_with(self.particles.len() + 400, || { + self.particles.resize_with(self.particles.len() + 500, || { Particle::new_directed( - Duration::from_secs_f32(rng.gen_range(2.0..3.0)), + Duration::from_secs_f32(rng.gen_range(0.5..1.0)), time, - ParticleMode::GunPowderSpark, - *pos + Vec3::new(0.0, 0.0, rng.gen_range(250.0..1500.0)), + ParticleMode::Lightning, + *pos + Vec3::new(0.0, 0.0, rng.gen_range(0.0..600.0)), *pos, ) }); From 6fea7205faa5614c69e8ec954bc55126fab8a744 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 9 Jul 2022 02:08:55 +0100 Subject: [PATCH 018/116] Better lightning at distance --- assets/voxygen/shaders/particle-vert.glsl | 2 +- voxygen/src/scene/particle.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/voxygen/shaders/particle-vert.glsl b/assets/voxygen/shaders/particle-vert.glsl index c617155605..7b1557ac61 100644 --- a/assets/voxygen/shaders/particle-vert.glsl +++ b/assets/voxygen/shaders/particle-vert.glsl @@ -609,7 +609,7 @@ void main() { vec3 start_off = vec3(abs(fract(vec3(vec2(z) * vec2(0.015, 0.01), 0)) - 0.5) * z * 0.5); attr = Attr( inst_dir * percent() + start_off, - vec3(16.0), + vec3(max(3.0, 0.05 * length(start_pos + inst_dir * percent()))), vec4(10.0, 30.0, 50.0, 1.0),// * (1.0 - length(inst_dir) * 0.1), identity()//spin_in_axis(perp_axis, asin(inst_dir.z / length(inst_dir)) + PI / 2.0) ); diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index d922adcd5b..44480fd300 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -63,7 +63,7 @@ impl ParticleMgr { match outcome { Outcome::Lightning { pos } => { - self.particles.resize_with(self.particles.len() + 500, || { + self.particles.resize_with(self.particles.len() + 800, || { Particle::new_directed( Duration::from_secs_f32(rng.gen_range(0.5..1.0)), time, From 85a292a854e9ca915d60c71ef72b20cd4576d957 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 9 Jul 2022 02:16:13 +0100 Subject: [PATCH 019/116] Always take origin as lightning end point --- assets/voxygen/shaders/particle-vert.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/voxygen/shaders/particle-vert.glsl b/assets/voxygen/shaders/particle-vert.glsl index 7b1557ac61..847f914eca 100644 --- a/assets/voxygen/shaders/particle-vert.glsl +++ b/assets/voxygen/shaders/particle-vert.glsl @@ -605,8 +605,8 @@ void main() { case LIGHTNING: f_reflect = 0.0; perp_axis = normalize(cross(inst_dir, vec3(0.0, 0.0, 1.0))); - float z = (start_pos + inst_dir * percent()).z; - vec3 start_off = vec3(abs(fract(vec3(vec2(z) * vec2(0.015, 0.01), 0)) - 0.5) * z * 0.5); + float z = inst_dir.z * (percent() - 1.0); + vec3 start_off = vec3(abs(fract(vec3(vec2(z) * vec2(0.015, 0.01), 0)) - 0.5) * z * 0.35); attr = Attr( inst_dir * percent() + start_off, vec3(max(3.0, 0.05 * length(start_pos + inst_dir * percent()))), From 3b758cc7b09a8ecd3f09f69aa3cb124cbbb6d9e1 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 9 Jul 2022 02:25:24 +0100 Subject: [PATCH 020/116] Minor colour tweak --- assets/voxygen/shaders/include/point_glow.glsl | 2 +- assets/voxygen/shaders/particle-vert.glsl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/voxygen/shaders/include/point_glow.glsl b/assets/voxygen/shaders/include/point_glow.glsl index 8fc29c08e5..a2da7ad0ea 100644 --- a/assets/voxygen/shaders/include/point_glow.glsl +++ b/assets/voxygen/shaders/include/point_glow.glsl @@ -54,7 +54,7 @@ vec3 apply_point_glow(vec3 wpos, vec3 dir, float max_dist, vec3 color) { } #endif // Apply lightning - apply_point_glow_light(Light(last_lightning.xyzw + vec4(0, 0, LIGHTNING_HEIGHT, 0), vec4(vec3(0.5, 0.8, 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; } diff --git a/assets/voxygen/shaders/particle-vert.glsl b/assets/voxygen/shaders/particle-vert.glsl index 847f914eca..8359e87409 100644 --- a/assets/voxygen/shaders/particle-vert.glsl +++ b/assets/voxygen/shaders/particle-vert.glsl @@ -606,11 +606,11 @@ void main() { f_reflect = 0.0; perp_axis = normalize(cross(inst_dir, vec3(0.0, 0.0, 1.0))); float z = inst_dir.z * (percent() - 1.0); - vec3 start_off = vec3(abs(fract(vec3(vec2(z) * vec2(0.015, 0.01), 0)) - 0.5) * z * 0.35); + vec3 start_off = vec3(abs(fract(vec3(vec2(z) * vec2(0.015, 0.01), 0)) - 0.5) * z * 0.4); attr = Attr( inst_dir * percent() + start_off, vec3(max(3.0, 0.05 * length(start_pos + inst_dir * percent()))), - vec4(10.0, 30.0, 50.0, 1.0),// * (1.0 - length(inst_dir) * 0.1), + vec4(10.0, 20.0, 50.0, 1.0),// * (1.0 - length(inst_dir) * 0.1), identity()//spin_in_axis(perp_axis, asin(inst_dir.z / length(inst_dir)) + PI / 2.0) ); break; From 47b236b1f02d8e5832a315d1bc554c5b75c7f033 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 10 Jul 2022 13:44:11 +0100 Subject: [PATCH 021/116] Better lightning rates, fixed shaders --- .../voxygen/shaders/include/point_glow.glsl | 66 ++++++++++--------- server/src/weather/sim.rs | 27 ++++++-- 2 files changed, 56 insertions(+), 37 deletions(-) diff --git a/assets/voxygen/shaders/include/point_glow.glsl b/assets/voxygen/shaders/include/point_glow.glsl index a2da7ad0ea..96b03abdcf 100644 --- a/assets/voxygen/shaders/include/point_glow.glsl +++ b/assets/voxygen/shaders/include/point_glow.glsl @@ -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; } diff --git a/server/src/weather/sim.rs b/server/src/weather/sim.rs index 9371f09d70..c63980bff3 100644 --- a/server/src/weather/sim.rs +++ b/server/src/weather/sim.rs @@ -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), }); From fc21b54f020e7b1e1418239acfca041dd9ae772e Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 10 Jul 2022 13:53:31 +0100 Subject: [PATCH 022/116] Better rain performance --- assets/voxygen/shaders/clouds-frag.glsl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 54364c8106..5062756704 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -92,8 +92,8 @@ void main() { vec3 rorigin = cam_pos.xyz + focus_off.xyz + 0.5; vec3 rpos = vec3(0.0); float t = 0.0; + const float PLANCK = 0.01; while (t < 64.0) { - 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 + 100.0)) / dir2d; float jump = max(min(deltas.x, deltas.y) * scale, PLANCK); @@ -103,17 +103,17 @@ void main() { vec2 diff = abs(round(rpos.xy) - rpos.xy); 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)); + wall_pos.z += hash_two(uvec2(wall_pos.xy + vec2(0, 0.5))); - float depth_adjust = fract(hash(vec4(floor(wall_pos.xyz), 2000))); + float depth_adjust = fract(hash_two(uvec2(wall_pos.xz))); float wpos_dist = t - jump * depth_adjust; vec3 wpos = cam_pos.xyz + dir * wpos_dist; - float density = rain_density * rain_occlusion_at(wpos); - if (fract(hash(vec4(floor(wall_pos.xyz), 0))) >= density) { continue; } - if (wpos_dist > dist) { break; } 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 density = rain_density * rain_occlusion_at(wpos); + if (fract(hash_two(uvec2(wall_pos.xz))) >= density) { continue; } + float alpha = 0.5 * clamp((wpos_dist - 1.0) * 0.5, 0.0, 1.0); float light = dot(color.rgb, vec3(1)) + 0.1 + (get_sun_brightness() + get_moon_brightness()) * 0.3; color.rgb = mix(color.rgb, vec3(0.1, 0.2, 0.5) * light, alpha); From af04843a2013a00dc400893610423ea000512f33 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sat, 9 Jul 2022 22:54:01 +0100 Subject: [PATCH 023/116] Re-enabled mimalloc for non msvc builds --- .cargo/config | 6 ++++++ .gitlab/scripts/env.sh | 3 +++ .gitlab/scripts/windows-x86_64.sh | 6 ++++++ server-cli/Cargo.toml | 2 +- server-cli/src/main.rs | 2 +- voxygen/Cargo.toml | 2 +- voxygen/anim/Cargo.toml | 2 +- voxygen/anim/src/lib.rs | 2 +- voxygen/src/main.rs | 1 - 9 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.cargo/config b/.cargo/config index 3e8860a59c..c694936e59 100644 --- a/.cargo/config +++ b/.cargo/config @@ -3,6 +3,12 @@ rustflags = [ "-C", "link-arg=-fuse-ld=gold", ] +[target.x86_64-pc-windows-gnu] +rustflags = [ + # Required for mimalloc + "-C", "link-arg=-lpsapi", +] + [alias] # tools cmd-doc-gen = "run --features=bin_cmd_doc_gen --bin cmd_doc_gen" diff --git a/.gitlab/scripts/env.sh b/.gitlab/scripts/env.sh index fc9c02167b..7241ab322c 100644 --- a/.gitlab/scripts/env.sh +++ b/.gitlab/scripts/env.sh @@ -2,5 +2,8 @@ # exports default env variables in CI export DISABLE_GIT_LFS_CHECK=true export VELOREN_ASSETS="assets" + +# When updating RUSTFLAGS here, windows-x86_64.sh must also be updated as it sets them independently export RUSTFLAGS="-D warnings" + export SHADERC_LIB_DIR=/shaderc/combined/ diff --git a/.gitlab/scripts/windows-x86_64.sh b/.gitlab/scripts/windows-x86_64.sh index 1f3a2d967b..b72594f907 100755 --- a/.gitlab/scripts/windows-x86_64.sh +++ b/.gitlab/scripts/windows-x86_64.sh @@ -2,4 +2,10 @@ update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix export VELOREN_USERDATA_STRATEGY=executable + +# RUSTFLAGS is set here in addition to env.sh (which is used for all targets not just windows) due to +# https://github.com/rust-lang/cargo/issues/5376 which prevents the windows-specific rustflags set in +# .cargo/config from being applied +export RUSTFLAGS="-D warnings -C link-arg=-lpsapi" + time cargo build --target=x86_64-pc-windows-gnu --release --no-default-features --features default-publish diff --git a/server-cli/Cargo.toml b/server-cli/Cargo.toml index 84cea7e4d3..3bdc9f0b65 100644 --- a/server-cli/Cargo.toml +++ b/server-cli/Cargo.toml @@ -43,7 +43,7 @@ tracing = { version = "0.1", default-features = false } ron = {version = "0.7", default-features = false} serde = {version = "1.0", features = [ "rc", "derive" ]} -[target.'cfg(all(windows, target_env="msvc"))'.dependencies] +[target.'cfg(windows)'.dependencies] mimalloc = "0.1.29" [dependencies.tui] diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index 1e0875e340..e88c6d7572 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -2,7 +2,7 @@ #![deny(clippy::clone_on_ref_ptr)] #![feature(bool_to_option)] -#[cfg(all(target_os = "windows", target_env = "msvc"))] +#[cfg(target_os = "windows")] #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 007f2f0332..c6b4ca7b61 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -138,7 +138,7 @@ dispatch = "0.1.4" [target.'cfg(windows)'.build-dependencies] winres = "0.1" -[target.'cfg(all(windows, target_env="msvc"))'.dependencies] +[target.'cfg(windows)'.dependencies] mimalloc = "0.1.29" # Mumble diff --git a/voxygen/anim/Cargo.toml b/voxygen/anim/Cargo.toml index 0a6b1ebcf3..9c4a7a2b07 100644 --- a/voxygen/anim/Cargo.toml +++ b/voxygen/anim/Cargo.toml @@ -21,5 +21,5 @@ voxygen-dynlib = {package = "veloren-voxygen-dynlib", path = "../dynlib", option # Hot Reloading lazy_static = {version = "1.4.0", optional = true} -[target.'cfg(all(windows, target_env="msvc"))'.dependencies] +[target.'cfg(windows)'.dependencies] mimalloc = "0.1.29" diff --git a/voxygen/anim/src/lib.rs b/voxygen/anim/src/lib.rs index b5f7b96b56..e3aa8d44f9 100644 --- a/voxygen/anim/src/lib.rs +++ b/voxygen/anim/src/lib.rs @@ -4,7 +4,7 @@ #[cfg(all(feature = "be-dyn-lib", feature = "use-dyn-lib"))] compile_error!("Can't use both \"be-dyn-lib\" and \"use-dyn-lib\" features at once"); -#[cfg(all(target_os = "windows", target_env = "msvc", feature = "be-dyn-lib"))] +#[cfg(all(target_os = "windows", feature = "be-dyn-lib"))] #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 3b66bbb74c..86c43540aa 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -4,7 +4,6 @@ #[cfg(all( target_os = "windows", - target_env = "msvc", not(feature = "tracy-memory"), not(feature = "hot-egui") ))] From d4906f55bc66f6dde958f4d4f434998ca30d9ce5 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 10 Jul 2022 16:40:49 +0100 Subject: [PATCH 024/116] Fixed rain occlusion issues --- assets/voxygen/shaders/clouds-frag.glsl | 13 ++++++++----- voxygen/src/render/pipelines/rain_occlusion.rs | 2 +- voxygen/src/scene/terrain.rs | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index 5062756704..3df9916756 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -93,11 +93,14 @@ void main() { vec3 rpos = vec3(0.0); float t = 0.0; const float PLANCK = 0.01; - while (t < 64.0) { + while (true) { float scale = min(pow(2, ceil(t / 2.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; + + if (t >= 64.0) { break; } + rpos = rorigin + adjusted_dir * t; vec2 diff = abs(round(rpos.xy) - rpos.xy); @@ -105,18 +108,18 @@ void main() { wall_pos.xz *= vec2(4, 0.3); wall_pos.z += hash_two(uvec2(wall_pos.xy + vec2(0, 0.5))); - float depth_adjust = fract(hash_two(uvec2(wall_pos.xz))); + float depth_adjust = fract(hash_two(uvec2(wall_pos.xz) + 500u)); float wpos_dist = t - jump * depth_adjust; vec3 wpos = cam_pos.xyz + dir * wpos_dist; if (wpos_dist > dist) { break; } 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 density = rain_density * rain_occlusion_at(wpos); - if (fract(hash_two(uvec2(wall_pos.xz))) >= density) { continue; } + if (fract(hash_two(uvec2(wall_pos.xz) + 1000u)) >= density) { continue; } float alpha = 0.5 * clamp((wpos_dist - 1.0) * 0.5, 0.0, 1.0); - float light = dot(color.rgb, vec3(1)) + 0.1 + (get_sun_brightness() + get_moon_brightness()) * 0.3; - color.rgb = mix(color.rgb, vec3(0.1, 0.2, 0.5) * light, alpha); + float light = dot(color.rgb, vec3(1)) + 0.05 + (get_sun_brightness() + get_moon_brightness()) * 0.2; + color.rgb = mix(color.rgb, vec3(0.3, 0.35, 0.5) * light, alpha); } } } diff --git a/voxygen/src/render/pipelines/rain_occlusion.rs b/voxygen/src/render/pipelines/rain_occlusion.rs index 9963b4ccae..9aae08ecd1 100644 --- a/voxygen/src/render/pipelines/rain_occlusion.rs +++ b/voxygen/src/render/pipelines/rain_occlusion.rs @@ -195,7 +195,7 @@ impl RainOcclusionPipeline { topology: wgpu::PrimitiveTopology::TriangleList, strip_index_format: None, front_face: wgpu::FrontFace::Ccw, - cull_mode: Some(wgpu::Face::Front), + cull_mode: Some(wgpu::Face::Back), clamp_depth: true, polygon_mode: wgpu::PolygonMode::Fill, conservative: false, diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index ee5d729783..e9b6b3ce34 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -48,7 +48,7 @@ const SPRITE_LOD_LEVELS: usize = 5; // For rain occlusion we only need to render the closest chunks. /// How many chunks are maximally rendered for rain occlusion. -pub const RAIN_OCCLUSION_CHUNKS: usize = 9; +pub const RAIN_OCCLUSION_CHUNKS: usize = 25; #[derive(Clone, Copy, Debug)] struct Visibility { From 4e854a28ff4c32403e67fafaba61e078d9c85a86 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 10 Jul 2022 16:56:45 +0100 Subject: [PATCH 025/116] Fixed occlusion bias --- assets/voxygen/shaders/include/rain_occlusion.glsl | 4 +--- assets/voxygen/shaders/terrain-frag.glsl | 2 +- server/src/weather/sim.rs | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/assets/voxygen/shaders/include/rain_occlusion.glsl b/assets/voxygen/shaders/include/rain_occlusion.glsl index 5f525c282f..95cc07c33a 100644 --- a/assets/voxygen/shaders/include/rain_occlusion.glsl +++ b/assets/voxygen/shaders/include/rain_occlusion.glsl @@ -20,9 +20,7 @@ uniform u_rain_occlusion { float rain_occlusion_at(in vec3 fragPos) { - float bias = -0.2; - - vec4 rain_pos = rain_occlusion_texture_mat * vec4(fragPos, 1.0) - vec4(0, 0, bias, 0); + vec4 rain_pos = rain_occlusion_texture_mat * vec4(fragPos, 1.0); float visibility = textureProj(sampler2DShadow(t_directed_occlusion_maps, s_directed_occlusion_maps), rain_pos); diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index fc30a29813..b95b7d7bdd 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) * 2.0) { + if (fract(hash(fract(vec4(cell, 0) * 0.01))) < rain_density * rain_occlusion_at(f_pos.xyz + vec3(0, 0, 0.25)) * 2.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 c63980bff3..96d9642ebf 100644 --- a/server/src/weather/sim.rs +++ b/server/src/weather/sim.rs @@ -148,7 +148,7 @@ impl WeatherSim { cell.rain = ((1.0 - pressure - RAIN_CLOUD_THRESHOLD).max(0.0) * self.consts[point].humidity * 2.5) - .powf(1.5); + .powf(0.75); 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, From 6233db8682c4b480a5468d0523947ba342dcef57 Mon Sep 17 00:00:00 2001 From: Awkor <2327050-Awkor@users.noreply.gitlab.com> Date: Sun, 10 Jul 2022 21:46:30 +0200 Subject: [PATCH 026/116] Bump shaderc version to 0.8.0 --- Cargo.lock | 24 ++++++++++++++++++++---- voxygen/Cargo.toml | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f7a3ca6d3..a632387b23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4916,6 +4916,15 @@ dependencies = [ "petgraph 0.5.1", ] +[[package]] +name = "roxmltree" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "921904a62e410e37e215c40381b7117f830d9d89ba60ab5236170541dd25646b" +dependencies = [ + "xmlparser", +] + [[package]] name = "rstar" version = "0.9.2" @@ -5363,9 +5372,9 @@ dependencies = [ [[package]] name = "shaderc" -version = "0.6.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50b8aeaae10b9bda5cba66736a7e265f67698e912e1cc6a4678acba286e22be9" +checksum = "80e6fe602a861622769530a23bc40bfba31adbf186d0c8412e83f5519c5d6bee" dependencies = [ "libc", "shaderc-sys", @@ -5373,12 +5382,13 @@ dependencies = [ [[package]] name = "shaderc-sys" -version = "0.6.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b12d7c62d6732884c9dfab587503fa3a795b108df152415a89da23812d4737e" +checksum = "3794498651f8173d0afbc0bb8aca45ced111098227e755dde4c0ef2888c8d0bf" dependencies = [ "cmake", "libc", + "roxmltree", ] [[package]] @@ -7875,6 +7885,12 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" +[[package]] +name = "xmlparser" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "114ba2b24d2167ef6d67d7d04c8cc86522b87f490025f39f0303b7db5bf5e3d8" + [[package]] name = "yasna" version = "0.5.0" diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index c6b4ca7b61..ddf0292050 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -58,7 +58,7 @@ winit = {version = "0.25.0", features = ["serde"]} wgpu = { version = "=0.8.0", features = ["trace", "cross"] } wgpu-profiler = { git = "https://github.com/Imberflur/wgpu-profiler", tag = "wgpu-0.8" } bytemuck = { version="1.4", features=["derive"] } -shaderc = "0.6.2" +shaderc = "0.8.0" # cmake crate used by shaderc, newer version 0.1.46 uses a new cmake command that is not available in our CI cmake version # see https://github.com/alexcrichton/cmake-rs/issues/131 cmake = "=0.1.45" From 3f0f1c423c30acfb9285f25e563ca927f6df4a69 Mon Sep 17 00:00:00 2001 From: Socksonme <9944708-Socksonme@users.noreply.gitlab.com> Date: Tue, 12 Jul 2022 21:01:47 +0000 Subject: [PATCH 027/116] Small fixes --- common/src/outcome.rs | 3 +- server/src/events/entity_manipulation.rs | 80 ++++++++++++------------ voxygen/src/audio/sfx/mod.rs | 7 ++- voxygen/src/hud/mod.rs | 3 +- 4 files changed, 49 insertions(+), 44 deletions(-) diff --git a/common/src/outcome.rs b/common/src/outcome.rs index 69ef8fb3da..1325ac75f8 100644 --- a/common/src/outcome.rs +++ b/common/src/outcome.rs @@ -1,4 +1,4 @@ -use crate::{combat::DamageContributor, comp, uid::Uid}; +use crate::{combat::DamageContributor, comp, uid::Uid, DamageSource}; use comp::{beam, item::Reagent, poise::PoiseState, skillset::SkillGroupKind, UtteranceKind}; use hashbrown::HashSet; use serde::{Deserialize, Serialize}; @@ -10,6 +10,7 @@ pub struct HealthChangeInfo { pub crit: bool, pub target: Uid, pub by: Option, + pub cause: Option, pub instance: u64, } diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index cdb9ec07e9..0b078e962e 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -81,6 +81,7 @@ pub fn handle_health_change(server: &Server, entity: EcsEntity, change: HealthCh amount: change.amount, by: change.by, target: *uid, + cause: change.cause, crit: change.crit, instance: change.instance, }, @@ -571,48 +572,47 @@ pub fn handle_land_on_ground(server: &Server, entity: EcsEntity, vel: Vec3) let stats = ecs.read_storage::(); let time = ecs.read_resource::