Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/wip5.8.0' into wip5.8.0webport
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Oct 16, 2024
2 parents a426c31 + 0d3faae commit 4a779f2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
36 changes: 31 additions & 5 deletions src/client/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down
7 changes: 6 additions & 1 deletion src/client/fm_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapBlockMesh>(&mdat, m_camera_offset);
block->setFarMesh(mbmsh, step);
Expand Down
2 changes: 1 addition & 1 deletion src/client/fm_farmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
11 changes: 8 additions & 3 deletions src/client/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/client/mapblock_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a779f2

Please sign in to comment.