mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-18 06:49:18 +02:00
Choose terrain levels from what the screen can resolve
Levels changed at fixed distances - 512 m, 1 km, 2 km and on - whatever the window, the field of view or the zoom. Now a level is used out to the distance where one of its sample spacings covers terraindetail pixels on screen, 3 by default, which follows from the viewport height and the vertical field of view with the zoom applied; each level doubles the spacing, so each doubles the distance. Zooming in or a taller window pushes detail further, a coarser setting pulls it in. The finest range never drops below four tile sides, which the morphing needs to close the seams. Levels and morphing both follow the finest range the last scan used, so they always agree, and a change of more than a percent - a zoom, a resize - triggers a rescan. tools/terraincook/seamcheck.py now also tries finest ranges of 5.7 and 11.3 tiles, and finds no gap in any of them. terraindetail is in the ini and on a slider in the debug panel; the panel's level table and the residency line in the log show the resulting ranges. On baltyk the current window works out to 484 m, so the 512 m minimum applies and nothing changes by default; a scenery setting terraindetail 1 got 1349 m, and the samples on the gpu went from 3 MB to 10 MB with it.
This commit is contained in:
@@ -8,6 +8,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
module;
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
@@ -19,20 +20,29 @@ export module eu07.rendering.terrainstatus;
|
||||
|
||||
export {
|
||||
|
||||
// distance out to which a terrain tile is drawn at its finest level, in tile sides; each
|
||||
// further level doubles it. four sides is 512 m for the usual 128 m tile. the ranges are
|
||||
// measured in tiles rather than metres because the morphing below only closes the seams
|
||||
// when a level's range is several tiles long, whatever the tile size
|
||||
// Which level a tile is drawn at follows from what its samples look like on screen: a level is
|
||||
// used out to the distance where one of its sample spacings covers the detail setting in
|
||||
// pixels. Each level doubles the spacing, so each doubles that distance too. Pixelsperunit is
|
||||
// the viewport height over twice the tangent of half the vertical field of view - what a
|
||||
// metre at a metre's distance spans - so zooming in or a taller window pushes detail further.
|
||||
//
|
||||
// The finest range never drops below four tile sides, whatever the screen: the morphing below
|
||||
// only closes the seams when a level's range is several tiles long.
|
||||
inline constexpr double terrain_finest_tiles { 4.0 };
|
||||
|
||||
inline double
|
||||
terrain_finest_range( double const Gridstep, double const Tilesize, double const Pixelsperunit, double const Detail ) {
|
||||
return std::max( terrain_finest_tiles * Tilesize, Gridstep * Pixelsperunit / std::max( 0.1, Detail ) );
|
||||
}
|
||||
|
||||
// how far the camera may move before the tiles in range and their levels are worked out
|
||||
// again, in tile sides
|
||||
inline constexpr double terrain_rescan_tiles { 0.25 };
|
||||
|
||||
// the distance up to which a level is used, for tiles of the given side
|
||||
// the distance up to which a level is used, given the finest level's range
|
||||
inline double
|
||||
terrain_level_distance( std::uint32_t const Level, double const Tilesize ) {
|
||||
return terrain_finest_tiles * Tilesize * std::pow( 2.0, Level );
|
||||
terrain_level_distance( std::uint32_t const Level, double const Finest ) {
|
||||
return Finest * std::pow( 2.0, Level );
|
||||
}
|
||||
|
||||
// A tile morphs into the next level over a band at the far end of its level's range. Two
|
||||
@@ -42,19 +52,20 @@ terrain_level_distance( std::uint32_t const Level, double const Tilesize ) {
|
||||
// was at the last rescan while the morph follows the camera every frame; and it is a fifth
|
||||
// of the range wide, which keeps the coarser tile's band, a whole range further out, clear of
|
||||
// any edge a finer tile can reach. Both were settled by a geometric test over random camera
|
||||
// positions and three tile sizes, which finds no gap with these values and finds them at
|
||||
// every level boundary with a band ending at the range itself.
|
||||
// positions, three tile sizes and several finest ranges (tools/terraincook/seamcheck.py),
|
||||
// which finds no gap with these values and finds them at every level boundary with a band
|
||||
// ending at the range itself.
|
||||
inline constexpr double terrain_morph_band { 0.2 };
|
||||
|
||||
// the distances, from the camera, over which a level L tile morphs into level L+1
|
||||
inline double
|
||||
terrain_morph_end( std::uint32_t const Level, double const Tilesize ) {
|
||||
return terrain_level_distance( Level, Tilesize ) - terrain_rescan_tiles * Tilesize;
|
||||
terrain_morph_end( std::uint32_t const Level, double const Finest, double const Tilesize ) {
|
||||
return terrain_level_distance( Level, Finest ) - terrain_rescan_tiles * Tilesize;
|
||||
}
|
||||
|
||||
inline double
|
||||
terrain_morph_begin( std::uint32_t const Level, double const Tilesize ) {
|
||||
return terrain_morph_end( Level, Tilesize ) - terrain_morph_band * terrain_level_distance( Level, Tilesize );
|
||||
terrain_morph_begin( std::uint32_t const Level, double const Finest, double const Tilesize ) {
|
||||
return terrain_morph_end( Level, Finest, Tilesize ) - terrain_morph_band * terrain_level_distance( Level, Finest );
|
||||
}
|
||||
|
||||
// what one terrain field's streamer is doing, kept by the field and read by the debug panel
|
||||
@@ -75,6 +86,7 @@ struct terrain_field_status {
|
||||
float gridstep { 0.f };
|
||||
float tilesize { 0.f };
|
||||
float range { 0.f };
|
||||
float finest { 0.f }; // range of the finest level, from the screen
|
||||
std::uint32_t levels { 0 };
|
||||
std::size_t backlog { 0 }; // tiles the loader has queued or finished and not handed over
|
||||
terrain_statistics stats;
|
||||
|
||||
Reference in New Issue
Block a user