mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 06:35:21 +01:00
feat(world): the rain, the snow and the smoke rise and fall against the vertical of the body
Step 4 of docs/world-format-eu07.md, its fourth part. The boxes of the precipitation around the camera are kept in the local axes of the body at the camera: they go with the steps of the camera turned into those axes, and a particle is turned into the axes of the world (world_frame) before it's lit, culled and drawn. The smoke worked out on the CPU keeps its velocities and the wind in the local axes of the body at the particle, and turns each step into the axes of the world. On the plane nothing is turned: the camera, the steps and the boxes are the ones they were.
This commit is contained in:
@@ -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<std::uint32_t>(count * BOX_SHARE[0])};
|
||||
auto const third{static_cast<std::uint32_t>(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<double>(BOX_SIZE[box])};
|
||||
draw.offsets[box] = glm::vec4{glm::vec3{glm::mod(m_drift[box] - glm::mod(View.camera, size), size)}, static_cast<float>(m_fall[box])};
|
||||
draw.offsets[box] = glm::vec4{glm::vec3{glm::mod(m_drift[box] - glm::mod(place, size), size)}, static_cast<float>(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}};
|
||||
|
||||
@@ -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};
|
||||
|
||||
+14
-2
@@ -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<float>( static_cast<float>(0.25 * ( 2.f - Global.Overcast )), Particle.velocity.y ); // put a cap on deceleration
|
||||
}
|
||||
|
||||
Particle.position += Particle.velocity * static_cast<float>( Timedelta );
|
||||
Particle.position += 0.1f * Particle.age * simulation::Environment.wind() * static_cast<float>( Timedelta );
|
||||
auto const climb { Particle.velocity * static_cast<float>( Timedelta ) };
|
||||
auto const drift { 0.1f * Particle.age * simulation::Environment.wind() * static_cast<float>( 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<float>(Timedelta);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user