diff --git a/examples/weather.cpp b/examples/weather.cpp index 18b9de1e..24030e33 100644 --- a/examples/weather.cpp +++ b/examples/weather.cpp @@ -73,8 +73,8 @@ struct weather_app const float heating = 323.f * (std::exp(cooling * dt) - 1.f) / dt; const float water_heating_factor = 0.9f; const float coriolis = 0.001f; - const float coriolis_bands = 6.f; - const float band_force = 0.00001f; + const float coriolis_bands = 24.f; + const float band_force = 0.00004f; const float friction = 0.f; const float slope_friction = 1.f; const float slope_force = 0.001f; @@ -287,6 +287,9 @@ struct weather_app // Velocity & temperature advection for (int i = 0; i < N; ++i) { + new_velocity_(i, 0) = velocity_(i, 0); + new_velocity_(i, N - 1) = velocity_(i, N - 1); + new_temperature_(i, 0) = temperature_(i, 0); new_temperature_(i, N - 1) = temperature_(i, N - 1); @@ -295,6 +298,9 @@ struct weather_app if (!periodic_x) { + new_velocity_(0, i) = velocity_(0, i); + new_velocity_(N - 1, i) = velocity_(N - 1, i); + new_temperature_(0, i) = temperature_(0, i); new_temperature_(N - 1, i) = temperature_(N - 1, i); @@ -316,7 +322,7 @@ struct weather_app p[0] = math::clamp(p[0], {0.f, N - 1.f}); int ix = std::floor(p[0]); - int iy = std::min(N - 1, std::floor(p[1])); + int iy = std::min(N - 2, std::floor(p[1])); if (!periodic_x) ix = std::min(N - 1, ix); @@ -348,9 +354,7 @@ struct weather_app std::swap(humidity_, new_humidity_); // Apply velocity diffusion - for (int y = 0; y < N; ++y) - for (int x = 0; x < N; ++x) - new_velocity_(x, y) = velocity_(x, y); + std::copy(velocity_.begin(), velocity_.end(), new_velocity_.begin()); for (int y = 1; y < N - 1; ++y) { for (int x = xmin; x < xmax; ++x) @@ -402,13 +406,13 @@ struct weather_app [[maybe_unused]] math::vector terrain_gradient { - (std::max(0.f, terrain_(x + 1, y)) - std::max(0.f, terrain_(x - 1, y))) / 2.f, - (std::max(0.f, terrain_(x, y + 1)) - std::max(0.f, terrain_(x, y - 1))) / 2.f, + (std::max(0.f, terrain_(wrap(x + 1), y)) - std::max(0.f, terrain_(wrap(x - 1), y))) / 2.f, + (std::max(0.f, terrain_(wrap(x), y + 1)) - std::max(0.f, terrain_(wrap(x), y - 1))) / 2.f, }; [[maybe_unused]] math::vector temperature_gradient { - (temperature_(x + 1, y) - temperature_(x - 1, y)) / 2.f, + (temperature_(wrap(x + 1), y) - temperature_(wrap(x - 1), y)) / 2.f, (temperature_(x, y + 1) - temperature_(x, y - 1)) / 2.f, }; @@ -746,7 +750,7 @@ struct weather_app { // color = gfx::blend(color, map_color(precipitation_(x, y), {1.f, 1.f, 1.f, -1.f}, {1.f, 1.f, 1.f, 1.f})); - float alpha = 2.f / (1.f + std::exp(- 0.1f * precipitation_(x, y))) - 1.f; + float alpha = 2.f / (1.f + std::exp(- 0.5f * precipitation_(x, y))) - 1.f; gfx::color_4f cloud_color{1.f, 1.f, 1.f, alpha * 0.875f};