Skip to content

Commit

Permalink
Allow to disable transparency sorting entirely (minetest#15101)
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Sep 2, 2024
1 parent 0c4f03d commit f23d745
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1854,8 +1854,9 @@ shader_path (Shader path) path
# OpenGL is the default for desktop, and OGLES2 for Android.
video_driver (Video driver) enum ,opengl,opengl3,ogles2

# Distance in nodes at which transparency depth sorting is enabled
# Use this to limit the performance impact of transparency depth sorting
# Distance in nodes at which transparency depth sorting is enabled.
# Use this to limit the performance impact of transparency depth sorting.
# Set to 0 to disable it entirely.
transparency_sorting_distance (Transparency Sorting Distance) int 16 0 128

# Radius of cloud area stated in number of 64 node cloud squares.
Expand Down
18 changes: 12 additions & 6 deletions src/client/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,9 @@ void ClientMap::updateTransparentMeshBuffers()
ScopeProfiler sp(g_profiler, "CM::updateTransparentMeshBuffers", SPT_AVG);
u32 sorted_blocks = 0;
u32 unsorted_blocks = 0;
bool transparency_sorting_enabled = m_cache_transparency_sorting_distance > 0;
f32 sorting_distance = m_cache_transparency_sorting_distance * BS;


// Update the order of transparent mesh buffers in each mesh
for (auto it = m_drawlist.begin(); it != m_drawlist.end(); it++) {
MapBlock *block = it->second;
Expand All @@ -1323,13 +1323,19 @@ void ClientMap::updateTransparentMeshBuffers()

if (m_needs_update_transparent_meshes ||
blockmesh->getTransparentBuffers().size() == 0) {
bool do_sort_block = transparency_sorting_enabled;

if (do_sort_block) {
v3f mesh_sphere_center = intToFloat(block->getPosRelative(), BS)
+ blockmesh->getBoundingSphereCenter();
f32 mesh_sphere_radius = blockmesh->getBoundingRadius();
f32 distance_sq = m_camera_position.getDistanceFromSQ(mesh_sphere_center);

v3f mesh_sphere_center = intToFloat(block->getPosRelative(), BS)
+ blockmesh->getBoundingSphereCenter();
f32 mesh_sphere_radius = blockmesh->getBoundingRadius();
f32 distance_sq = m_camera_position.getDistanceFromSQ(mesh_sphere_center);
if (distance_sq > std::pow(sorting_distance + mesh_sphere_radius, 2.0f))
do_sort_block = false;
}

if (distance_sq <= std::pow(sorting_distance + mesh_sphere_radius, 2.0f)) {
if (do_sort_block) {
blockmesh->updateTransparentBuffers(m_camera_position, block->getPos());
++sorted_blocks;
} else {
Expand Down

0 comments on commit f23d745

Please sign in to comment.