forked from Mirrorlandia_minetest/minetest
Remove the 'loops' occlusion culler (#13169)
This commit is contained in:
parent
8478796226
commit
b8aaad4f1e
@ -628,11 +628,6 @@ update_last_checked (Last update check) string
|
|||||||
# Ex: 5.5.0 is 005005000
|
# Ex: 5.5.0 is 005005000
|
||||||
update_last_known (Last known version update) int 0
|
update_last_known (Last known version update) int 0
|
||||||
|
|
||||||
# Type of occlusion_culler
|
|
||||||
# "loops" is the legacy algorithm with nested loops and O(N^3) complexity
|
|
||||||
# "bfs" is the new algorithm based on breadth-first-search and side culling
|
|
||||||
occlusion_culler (Occlusion Culler) enum bfs bfs,loops
|
|
||||||
|
|
||||||
# Use raytraced occlusion culling in the new culler.
|
# Use raytraced occlusion culling in the new culler.
|
||||||
# This flag enables use of raytraced occlusion culling test
|
# This flag enables use of raytraced occlusion culling test
|
||||||
enable_raytraced_culling (Enable Raytraced Culling) bool true
|
enable_raytraced_culling (Enable Raytraced Culling) bool true
|
||||||
|
@ -103,23 +103,18 @@ ClientMap::ClientMap(
|
|||||||
m_cache_bilinear_filter = g_settings->getBool("bilinear_filter");
|
m_cache_bilinear_filter = g_settings->getBool("bilinear_filter");
|
||||||
m_cache_anistropic_filter = g_settings->getBool("anisotropic_filter");
|
m_cache_anistropic_filter = g_settings->getBool("anisotropic_filter");
|
||||||
m_cache_transparency_sorting_distance = g_settings->getU16("transparency_sorting_distance");
|
m_cache_transparency_sorting_distance = g_settings->getU16("transparency_sorting_distance");
|
||||||
m_new_occlusion_culler = g_settings->get("occlusion_culler") == "bfs";
|
|
||||||
g_settings->registerChangedCallback("occlusion_culler", on_settings_changed, this);
|
|
||||||
m_enable_raytraced_culling = g_settings->getBool("enable_raytraced_culling");
|
m_enable_raytraced_culling = g_settings->getBool("enable_raytraced_culling");
|
||||||
g_settings->registerChangedCallback("enable_raytraced_culling", on_settings_changed, this);
|
g_settings->registerChangedCallback("enable_raytraced_culling", on_settings_changed, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientMap::onSettingChanged(const std::string &name)
|
void ClientMap::onSettingChanged(const std::string &name)
|
||||||
{
|
{
|
||||||
if (name == "occlusion_culler")
|
|
||||||
m_new_occlusion_culler = g_settings->get("occlusion_culler") == "bfs";
|
|
||||||
if (name == "enable_raytraced_culling")
|
if (name == "enable_raytraced_culling")
|
||||||
m_enable_raytraced_culling = g_settings->getBool("enable_raytraced_culling");
|
m_enable_raytraced_culling = g_settings->getBool("enable_raytraced_culling");
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientMap::~ClientMap()
|
ClientMap::~ClientMap()
|
||||||
{
|
{
|
||||||
g_settings->deregisterChangedCallback("occlusion_culler", on_settings_changed, this);
|
|
||||||
g_settings->deregisterChangedCallback("enable_raytraced_culling", on_settings_changed, this);
|
g_settings->deregisterChangedCallback("enable_raytraced_culling", on_settings_changed, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +247,6 @@ private:
|
|||||||
|
|
||||||
void ClientMap::updateDrawList()
|
void ClientMap::updateDrawList()
|
||||||
{
|
{
|
||||||
if (m_new_occlusion_culler) {
|
|
||||||
ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
|
ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
|
||||||
|
|
||||||
m_needs_update_drawlist = false;
|
m_needs_update_drawlist = false;
|
||||||
@ -485,130 +479,9 @@ void ClientMap::updateDrawList()
|
|||||||
g_profiler->avg("MapBlocks examined [#]", blocks_visited);
|
g_profiler->avg("MapBlocks examined [#]", blocks_visited);
|
||||||
g_profiler->avg("MapBlocks drawn [#]", m_drawlist.size());
|
g_profiler->avg("MapBlocks drawn [#]", m_drawlist.size());
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
|
|
||||||
|
|
||||||
m_needs_update_drawlist = false;
|
|
||||||
|
|
||||||
for (auto &i : m_drawlist) {
|
|
||||||
MapBlock *block = i.second;
|
|
||||||
block->refDrop();
|
|
||||||
}
|
|
||||||
m_drawlist.clear();
|
|
||||||
|
|
||||||
v3s16 cam_pos_nodes = floatToInt(m_camera_position, BS);
|
|
||||||
|
|
||||||
v3s16 p_blocks_min;
|
|
||||||
v3s16 p_blocks_max;
|
|
||||||
getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);
|
|
||||||
|
|
||||||
// Number of blocks currently loaded by the client
|
|
||||||
u32 blocks_loaded = 0;
|
|
||||||
// Number of blocks with mesh in rendering range
|
|
||||||
u32 blocks_in_range_with_mesh = 0;
|
|
||||||
// Number of blocks occlusion culled
|
|
||||||
u32 blocks_occlusion_culled = 0;
|
|
||||||
|
|
||||||
// No occlusion culling when free_move is on and camera is inside ground
|
|
||||||
bool occlusion_culling_enabled = true;
|
|
||||||
if (m_control.allow_noclip) {
|
|
||||||
MapNode n = getNode(cam_pos_nodes);
|
|
||||||
if (n.getContent() == CONTENT_IGNORE || m_nodedef->get(n).solidness == 2)
|
|
||||||
occlusion_culling_enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
v3s16 camera_block = getContainerPos(cam_pos_nodes, MAP_BLOCKSIZE);
|
|
||||||
m_drawlist = std::map<v3s16, MapBlock*, MapBlockComparer>(MapBlockComparer(camera_block));
|
|
||||||
|
|
||||||
auto is_frustum_culled = m_client->getCamera()->getFrustumCuller();
|
|
||||||
|
|
||||||
// Uncomment to debug occluded blocks in the wireframe mode
|
|
||||||
// TODO: Include this as a flag for an extended debugging setting
|
|
||||||
//if (occlusion_culling_enabled && m_control.show_wireframe)
|
|
||||||
// occlusion_culling_enabled = porting::getTimeS() & 1;
|
|
||||||
|
|
||||||
for (const auto §or_it : m_sectors) {
|
|
||||||
MapSector *sector = sector_it.second;
|
|
||||||
v2s16 sp = sector->getPos();
|
|
||||||
|
|
||||||
blocks_loaded += sector->size();
|
|
||||||
if (!m_control.range_all) {
|
|
||||||
if (sp.X < p_blocks_min.X || sp.X > p_blocks_max.X ||
|
|
||||||
sp.Y < p_blocks_min.Z || sp.Y > p_blocks_max.Z)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
MapBlockVect sectorblocks;
|
|
||||||
sector->getBlocks(sectorblocks);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Loop through blocks in sector
|
|
||||||
*/
|
|
||||||
|
|
||||||
u32 sector_blocks_drawn = 0;
|
|
||||||
|
|
||||||
for (MapBlock *block : sectorblocks) {
|
|
||||||
/*
|
|
||||||
Compare block position to camera position, skip
|
|
||||||
if not seen on display
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!block->mesh) {
|
|
||||||
// Ignore if mesh doesn't exist
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
v3s16 block_coord = block->getPos();
|
|
||||||
v3f mesh_sphere_center = intToFloat(block->getPosRelative(), BS)
|
|
||||||
+ block->mesh->getBoundingSphereCenter();
|
|
||||||
f32 mesh_sphere_radius = block->mesh->getBoundingRadius();
|
|
||||||
// First, perform a simple distance check.
|
|
||||||
if (!m_control.range_all &&
|
|
||||||
mesh_sphere_center.getDistanceFrom(intToFloat(cam_pos_nodes, BS)) >
|
|
||||||
m_control.wanted_range * BS + mesh_sphere_radius)
|
|
||||||
continue; // Out of range, skip.
|
|
||||||
|
|
||||||
// Keep the block alive as long as it is in range.
|
|
||||||
block->resetUsageTimer();
|
|
||||||
blocks_in_range_with_mesh++;
|
|
||||||
|
|
||||||
// Frustum culling
|
|
||||||
// Only do coarse culling here, to account for fast camera movement.
|
|
||||||
// This is needed because this function is not called every frame.
|
|
||||||
constexpr float frustum_cull_extra_radius = 300.0f;
|
|
||||||
if (is_frustum_culled(mesh_sphere_center,
|
|
||||||
mesh_sphere_radius + frustum_cull_extra_radius))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Occlusion culling
|
|
||||||
if (occlusion_culling_enabled && isBlockOccluded(block, cam_pos_nodes)) {
|
|
||||||
blocks_occlusion_culled++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add to set
|
|
||||||
block->refGrab();
|
|
||||||
m_drawlist[block_coord] = block;
|
|
||||||
|
|
||||||
sector_blocks_drawn++;
|
|
||||||
} // foreach sectorblocks
|
|
||||||
|
|
||||||
if (sector_blocks_drawn != 0)
|
|
||||||
m_last_drawn_sectors.insert(sp);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_profiler->avg("MapBlock meshes in range [#]", blocks_in_range_with_mesh);
|
|
||||||
g_profiler->avg("MapBlocks occlusion culled [#]", blocks_occlusion_culled);
|
|
||||||
g_profiler->avg("MapBlocks drawn [#]", m_drawlist.size());
|
|
||||||
g_profiler->avg("MapBlocks loaded [#]", blocks_loaded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClientMap::touchMapBlocks()
|
void ClientMap::touchMapBlocks()
|
||||||
{
|
{
|
||||||
if (!m_new_occlusion_culler)
|
|
||||||
return;
|
|
||||||
|
|
||||||
v3s16 cam_pos_nodes = floatToInt(m_camera_position, BS);
|
v3s16 cam_pos_nodes = floatToInt(m_camera_position, BS);
|
||||||
|
|
||||||
v3s16 p_blocks_min;
|
v3s16 p_blocks_min;
|
||||||
|
@ -66,7 +66,6 @@ void set_default_settings()
|
|||||||
settings->setDefault("max_out_chat_queue_size", "20");
|
settings->setDefault("max_out_chat_queue_size", "20");
|
||||||
settings->setDefault("pause_on_lost_focus", "false");
|
settings->setDefault("pause_on_lost_focus", "false");
|
||||||
settings->setDefault("enable_split_login_register", "true");
|
settings->setDefault("enable_split_login_register", "true");
|
||||||
settings->setDefault("occlusion_culler", "bfs");
|
|
||||||
settings->setDefault("enable_raytraced_culling", "true");
|
settings->setDefault("enable_raytraced_culling", "true");
|
||||||
settings->setDefault("chat_weblink_color", "#8888FF");
|
settings->setDefault("chat_weblink_color", "#8888FF");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user