diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index d87510c0b..25cc62c35 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -1245,7 +1245,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) // Mesh animation if (pass == scene::ESNRP_SOLID) { // Pretty random but this should work somewhat nicely - bool faraway = false; //d >= BS * 50; + bool faraway = d >= BS * 50; + + if (is_far) + faraway = false; + if (block_mesh->isAnimationForced() || !faraway || mesh_animate_count < (m_control.range_all ? 200 : 50)) { @@ -1614,10 +1618,13 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver, auto block = i.second; // If the mesh of the block happened to get deleted, ignore it - auto mapBlockMesh = block->getLodMesh(getLodStep(m_control, getNodeBlockPos(m_camera_position_node), block->getPos(), speedf), true); + auto mapBlockMesh = block->getLodMesh(getLodStep(m_control, getNodeBlockPos(m_camera_position_node), block_pos, speedf), true); - //if (!mapBlockMesh) - // mapBlockMesh = block->getFarMesh(getFarStep(m_control, getNodeBlockPos(m_far_blocks_last_cam_pos), block->getPos())); +#if FARMESH_SHADOWS + if (!mapBlockMesh) { + mapBlockMesh = block->getFarMesh(getFarStep(m_control, getNodeBlockPos(far_blocks_last_cam_pos), block_pos )); + } +#endif if (!mapBlockMesh) continue; @@ -1793,6 +1800,18 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, } } +#if FARMESH_SHADOWS + { + const auto lock = m_far_blocks.lock_shared_rec(); + for (const auto &[pos, block] : m_far_blocks) { + if (far_iteration_clean && block->far_iteration < far_iteration_clean) { + } else if (block->far_iteration >= far_iteration_use) { + m_drawlist_shadow.emplace(pos, block); + } + } + } +#endif + m_drawlist_shadow_current = !m_drawlist_shadow_current; g_profiler->avg("SHADOW MapBlock meshes in range [#]", blocks_in_range_with_mesh); @@ -1819,7 +1838,14 @@ void ClientMap::updateTransparentMeshBuffers() // Update the order of transparent mesh buffers in each mesh for (auto it = m_drawlist.begin(); it != m_drawlist.end(); it++) { auto block = it->second; - const auto block_mesh = block->getLodMesh(getLodStep(m_control, getNodeBlockPos(m_camera_position_node), block->getPos(), speedf)); + auto block_mesh = block->getLodMesh(getLodStep(m_control, getNodeBlockPos(m_camera_position_node), block->getPos(), speedf)); + +#if FARMESH_SHADOWS + if (!block_mesh) { + block_mesh = block->getFarMesh(getFarStep(m_control, getNodeBlockPos(far_blocks_last_cam_pos), block->getPos())); + } +#endif + if (!block_mesh) continue; diff --git a/src/client/fm_client.cpp b/src/client/fm_client.cpp index f6528791a..9b348ee37 100644 --- a/src/client/fm_client.cpp +++ b/src/client/fm_client.cpp @@ -154,7 +154,12 @@ void Client::createFarMesh(MapBlockP &block) const auto &blockpos_actual = block->getPos(); const auto &m_camera_offset = m_camera->getOffset(); const auto &step = block->far_step; - MeshMakeData mdat(m_client, false, 0, step, &m_client->far_container); +#if FARMESH_SHADOWS + static const auto m_cache_enable_shaders = g_settings->getBool("enable_shaders"); +#else + static const auto m_cache_enable_shaders = false; +#endif + MeshMakeData mdat(m_client, m_cache_enable_shaders, 0, step, &m_client->far_container); mdat.m_blockpos = blockpos_actual; const auto mbmsh = std::make_shared(&mdat, m_camera_offset); block->setFarMesh(mbmsh, step); diff --git a/src/client/fm_farmesh.h b/src/client/fm_farmesh.h index e7324d634..36cda5ccd 100644 --- a/src/client/fm_farmesh.h +++ b/src/client/fm_farmesh.h @@ -41,7 +41,7 @@ class Server; // #define FARMESH_FAST 1 // #define FARMESH_DEBUG 1 // One dirction, one thread, no neighborhoods - +// #define FARMESH_SHADOWS 1 // Unfinished class FarMesh { diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index b54946771..f1b985dd2 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -803,8 +803,9 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): tex.MagFilter = video::ETMAGF_NEAREST; }); - if (data->far_step <= 0) - if (m_enable_shaders) { +#if !FARMESH_SHADOWS + if (data->far_step <= 0) +#endif material.MaterialType = m_shdrsrc->getShaderInfo( p.layer.shader_id).material; p.layer.applyMaterialOptionsWithShaders(material); @@ -819,7 +820,11 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): scene::SMeshBuffer *buf = new scene::SMeshBuffer(); buf->Material = material; - if (p.layer.isTransparent() && data->far_step <= 0) { + if (p.layer.isTransparent() +#if !FARMESH_SHADOWS + && data->far_step <= 0 +#endif + ) { buf->append(&p.vertices[0], p.vertices.size(), nullptr, 0); MeshTriangle t; diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index c54f61eb2..e88e749af 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -54,15 +54,15 @@ struct MeshMakeData // fm: NodeContainer & m_vmanip; - u16 side_length_data; - int lod_step; - int far_step; + const u16 side_length_data; + const int lod_step; + const int far_step; const int fscale; - int range = 1; - bool no_draw = false; - unsigned int timestamp = 0; - bool debug = false; + int range {1}; + bool no_draw {}; + unsigned int timestamp {}; + bool debug {}; explicit MeshMakeData(Client *client, bool use_shaders , int lod_step = 0