diff --git a/rendering/common/gpuparticles.cpp b/rendering/common/gpuparticles.cpp index d0c6243c2..4324b362b 100644 --- a/rendering/common/gpuparticles.cpp +++ b/rendering/common/gpuparticles.cpp @@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Globals.h" #include "utilities/Logs.h" #include "utilities/Timer.h" +#include "world/worldgeometry.h" namespace gfx { @@ -51,6 +52,15 @@ double constexpr WIND_SHARE{0.5}; // the camera faster than this from a frame to the next was moved, not driven or flown double constexpr CAMERA_JUMP{120.0}; +// a step of the camera in the local axes of the body at the camera, which the precipitation falls in; the step itself on the plane +glm::dvec3 local_step(glm::dvec3 const &Step) +{ + auto const &body{world_geometry::current_body()}; + if (!body.curved()) + return Step; + return world_geometry::local_frame(body, Global.pCamera.Pos) * Step; +} + } // namespace bool gpu_particles::init() @@ -257,11 +267,16 @@ std::size_t gpu_particles::render_precipitation(view const &View, bool const Sno m_time = std::fmod(m_time + seconds, 3600.0); if (m_camerastarted) { - auto const velocity{(View.camera - m_lastcamera) / seconds}; + auto const velocity{local_step(View.camera - m_lastcamera) / seconds}; if (glm::length(velocity) < CAMERA_JUMP) m_cameravelocity = glm::mix(m_cameravelocity, velocity, 1.0 - std::exp(-10.0 * seconds)); } } + // the rain and the snow fall in the local axes of the body at the camera, and their boxes go with its place in them + if (m_camerastarted && (glm::length(View.camera - m_lastcamera) < 10000.0)) + m_place += local_step(View.camera - m_lastcamera); + else + m_place = View.camera; m_lastcamera = View.camera; m_camerastarted = true; } @@ -284,10 +299,11 @@ std::size_t gpu_particles::render_precipitation(view const &View, bool const Sno auto const second{static_cast(count * BOX_SHARE[0])}; auto const third{static_cast(count * (BOX_SHARE[0] + BOX_SHARE[1]))}; draw.counts = glm::uvec4{second, third, count, Snow ? 1u : 0u}; + auto const place{world_geometry::current_body().curved() ? m_place + local_step(View.camera - m_lastcamera) : View.camera}; for (std::size_t box = 0; box < BOX_SIZE.size(); ++box) { auto const size{static_cast(BOX_SIZE[box])}; - draw.offsets[box] = glm::vec4{glm::vec3{glm::mod(m_drift[box] - glm::mod(View.camera, size), size)}, static_cast(m_fall[box])}; + draw.offsets[box] = glm::vec4{glm::vec3{glm::mod(m_drift[box] - glm::mod(place, size), size)}, static_cast(m_fall[box])}; } draw.sizes = glm::vec4{BOX_SIZE[0], BOX_SIZE[1], BOX_SIZE[2], 0.f}; auto const velocity{glm::vec3{glm::dvec3{simulation::Environment.wind()} * WIND_SHARE - m_cameravelocity}}; diff --git a/rendering/common/gpuparticles.h b/rendering/common/gpuparticles.h index 42b41f33a..bc7d2bf62 100644 --- a/rendering/common/gpuparticles.h +++ b/rendering/common/gpuparticles.h @@ -177,6 +177,9 @@ class gpu_particles glm::dvec3 m_lastcamera{0.0}; glm::dvec3 m_cameravelocity{0.0}; bool m_camerastarted{false}; + // the place of the camera the boxes of the precipitation go with, in the local axes of the body at the camera: on a curved body + // the steps of the camera turned into them (as gfx::weather_state::place()); on the plane the camera itself, which isn't kept here + glm::dvec3 m_place{0.0}; std::size_t m_precipitationdrawn{0}; std::uint32_t m_precipitationcount{0}; bool m_precipitationsnow{false}; diff --git a/rendering/particles.cpp b/rendering/particles.cpp index 07e96d6b9..e1a0f6dec 100644 --- a/rendering/particles.cpp +++ b/rendering/particles.cpp @@ -17,6 +17,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Logs.h" #include "vehicle/smoke.h" #include "vehicle/DynObj.h" +#include "world/worldgeometry.h" void @@ -381,8 +382,19 @@ smoke_source::update( smoke_particle &Particle, bounding_box &Boundingbox, doubl Particle.velocity.y = std::max( static_cast(0.25 * ( 2.f - Global.Overcast )), Particle.velocity.y ); // put a cap on deceleration } - Particle.position += Particle.velocity * static_cast( Timedelta ); - Particle.position += 0.1f * Particle.age * simulation::Environment.wind() * static_cast( Timedelta ); + auto const climb { Particle.velocity * static_cast( Timedelta ) }; + auto const drift { 0.1f * Particle.age * simulation::Environment.wind() * static_cast( Timedelta ) }; + if( auto const &body { world_geometry::current_body() }; body.curved() ) { + // the velocities and the wind are in the local axes of the body (x to the west, y up, z to the north), the position in + // the world's + auto const toworld { glm::transpose( world_geometry::local_frame( body, Particle.position ) ) }; + Particle.position += toworld * glm::dvec3 { climb }; + Particle.position += toworld * glm::dvec3 { drift }; + } + else { + Particle.position += climb; + Particle.position += drift; + } // m_velocitymodifier.update( Particle.velocity, Timedelta ); Particle.age += static_cast(Timedelta); diff --git a/shaders/ogl46/particles_precipitation.comp b/shaders/ogl46/particles_precipitation.comp index bb450975b..66e28f156 100644 --- a/shaders/ogl46/particles_precipitation.comp +++ b/shaders/ogl46/particles_precipitation.comp @@ -57,18 +57,21 @@ void main() place.xz += amplitude * sin(angle); move.xz += amplitude * frequency * cos(angle); } - // within the box around the camera - vec3 world = mod(place, size) - 0.5 * size; + // within the box around the camera, in the local axes of the body at the camera, which the rain and the snow fall in + // (gl::scene_ubs::world_frame); the identity on the plane + mat3 toworld = transpose(mat3(world_frame)); + vec3 local = mod(place, size) - 0.5 * size; float opacity = timing.z; // fading at the walls of the box, where the particles wrap around, and right at the camera - vec3 walls = abs(world) / (0.5 * size); + vec3 walls = abs(local) / (0.5 * size); opacity *= 1.0 - smoothstep(0.7, 1.0, max(max(walls.x, walls.y), walls.z)); - opacity *= smoothstep(0.15, 0.6, length(world)); + opacity *= smoothstep(0.15, 0.6, length(local)); + vec3 world = toworld * local; // none under the roofs, the bridges, in the tunnels opacity *= 1.0 - sky_occlusion_cover(world); if (opacity <= 0.002) return; - vec3 tail = -move * timing.y; + vec3 tail = -(toworld * move) * timing.y; float streak = length(tail); if (streak > 3.0) tail *= 3.0 / streak; diff --git a/shaders/vk14/particles_precipitation.comp b/shaders/vk14/particles_precipitation.comp index 917f63c5e..07484ba19 100644 --- a/shaders/vk14/particles_precipitation.comp +++ b/shaders/vk14/particles_precipitation.comp @@ -64,18 +64,21 @@ void main() place.xz += amplitude * sin(angle); move.xz += amplitude * frequency * cos(angle); } - // within the box around the camera - vec3 world = mod(place, size) - 0.5 * size; + // within the box around the camera, in the local axes of the body at the camera, which the rain and the snow fall in + // (gl::scene_ubs::world_frame); the identity on the plane + mat3 toworld = transpose(mat3(world_frame)); + vec3 local = mod(place, size) - 0.5 * size; float opacity = timing.z; // fading at the walls of the box, where the particles wrap around, and right at the camera - vec3 walls = abs(world) / (0.5 * size); + vec3 walls = abs(local) / (0.5 * size); opacity *= 1.0 - smoothstep(0.7, 1.0, max(max(walls.x, walls.y), walls.z)); - opacity *= smoothstep(0.15, 0.6, length(world)); + opacity *= smoothstep(0.15, 0.6, length(local)); + vec3 world = toworld * local; // none under the roofs, the bridges, in the tunnels opacity *= 1.0 - sky_occlusion_cover(world); if (opacity <= 0.002) return; - vec3 tail = -move * timing.y; + vec3 tail = -(toworld * move) * timing.y; float streak = length(tail); if (streak > 3.0) tail *= 3.0 / streak;