mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 22:39:19 +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:
@@ -208,9 +208,8 @@ terrain_clipmap::build_palette() {
|
||||
std::uint32_t
|
||||
terrain_clipmap::level_for( double const Distance ) const {
|
||||
|
||||
auto const finest { terrain_level_distance( 0, m_reader.tilesize() ) };
|
||||
if( Distance <= finest ) { return 0; }
|
||||
auto const steps { static_cast<std::uint32_t>( std::log2( Distance / finest ) ) + 1 };
|
||||
if( Distance <= m_finest ) { return 0; }
|
||||
auto const steps { static_cast<std::uint32_t>( std::log2( Distance / m_finest ) ) + 1 };
|
||||
return std::min( steps, m_reader.levels() - 1 );
|
||||
}
|
||||
|
||||
@@ -265,11 +264,18 @@ terrain_clipmap::retire( resident_tile &Tile ) {
|
||||
m_stats.texturebytes -= std::min( m_stats.texturebytes, bytes );
|
||||
}
|
||||
|
||||
void
|
||||
terrain_clipmap::detail( double const Pixelsperunit, double const Pixels ) {
|
||||
|
||||
m_finestwanted = terrain_finest_range( m_reader.gridstep(), m_reader.tilesize(), Pixelsperunit, Pixels );
|
||||
}
|
||||
|
||||
void
|
||||
terrain_clipmap::scan( glm::dvec3 const &Viewpoint ) {
|
||||
|
||||
m_scanpoint = Viewpoint;
|
||||
m_scanrange = m_range;
|
||||
m_finest = ( m_finestwanted > 0.0 ? m_finestwanted : terrain_finest_tiles * m_reader.tilesize() );
|
||||
m_inrange.clear();
|
||||
m_wantedlevel.clear();
|
||||
|
||||
@@ -324,7 +330,12 @@ terrain_clipmap::update( glm::dvec3 const &Viewpoint ) {
|
||||
|
||||
auto const moved {
|
||||
glm::length( glm::dvec2 { Viewpoint.x - m_scanpoint.x, Viewpoint.z - m_scanpoint.z } ) };
|
||||
// a zoom or a resized window changes the levels; a change under a percent is not worth
|
||||
// redoing the scan for
|
||||
auto const detailchanged {
|
||||
( m_finestwanted > 0.0 ) && ( std::abs( m_finestwanted - m_finest ) > 0.01 * m_finest ) };
|
||||
if( ( m_range != m_scanrange )
|
||||
|| ( true == detailchanged )
|
||||
|| ( moved > m_reader.tilesize() * terrain_rescan_tiles ) ) {
|
||||
scan( Viewpoint );
|
||||
}
|
||||
@@ -446,7 +457,8 @@ terrain_clipmap::report_residency() {
|
||||
WriteLog(
|
||||
"Terrain: " + std::to_string( m_stats.resident ) + " tiles resident, "
|
||||
+ std::to_string( m_stats.texturebytes / 1048576 ) + " MB of samples, "
|
||||
+ std::to_string( m_stats.uploaded ) + " uploads so far" );
|
||||
+ std::to_string( m_stats.uploaded ) + " uploads so far, finest level out to "
|
||||
+ std::to_string( static_cast<int>( m_finest ) ) + " m" );
|
||||
}
|
||||
|
||||
void
|
||||
@@ -487,8 +499,8 @@ terrain_clipmap::render( glm::dvec3 const &Viewpoint ) {
|
||||
if( tile.level + 1 < m_reader.levels() ) {
|
||||
::glUniform2f(
|
||||
m_uniforms.morph,
|
||||
static_cast<float>( terrain_morph_begin( tile.level, tilesize ) ),
|
||||
static_cast<float>( terrain_morph_end( tile.level, tilesize ) ) );
|
||||
static_cast<float>( terrain_morph_begin( tile.level, m_finest, tilesize ) ),
|
||||
static_cast<float>( terrain_morph_end( tile.level, m_finest, tilesize ) ) );
|
||||
}
|
||||
else {
|
||||
// far enough to never be reached, with a band that does not divide by zero
|
||||
|
||||
Reference in New Issue
Block a user