Skip to content

Commit e8716ff

Browse files
committedAug 23, 2019
Restore approximate occlusion check
While less precise, it worked better which is what matters in the end.
1 parent b14aa30 commit e8716ff

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed
 

Diff for: ‎src/map.cpp

+12-25
Original file line numberDiff line numberDiff line change
@@ -1033,21 +1033,11 @@ void Map::removeNodeTimer(v3s16 p)
10331033
}
10341034

10351035
bool Map::isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target,
1036-
const core::aabbox3d<s16> &block_bounds, float step, float stepfac, float offset,
1037-
u32 needed_count)
1036+
float step, float stepfac, float offset, float end_offset, u32 needed_count)
10381037
{
1039-
// Worst-case safety distance to keep to the target position
1040-
// Anything smaller than the mapblock diagonal could result in in self-occlusion
1041-
// Diagonal = sqrt(1*1 + 1*1 + 1*1)
1042-
const static float BLOCK_DIAGONAL = BS * MAP_BLOCKSIZE * 1.732f;
1043-
10441038
v3f direction = intToFloat(pos_target - pos_camera, BS);
10451039
float distance = direction.getLength();
10461040

1047-
// Disable occlusion culling for near mapblocks in underground
1048-
if (distance < BLOCK_DIAGONAL)
1049-
return false;
1050-
10511041
// Normalize direction vector
10521042
if (distance > 0.0f)
10531043
direction /= distance;
@@ -1056,17 +1046,10 @@ bool Map::isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target,
10561046
u32 count = 0;
10571047
bool is_valid_position;
10581048

1059-
for (; offset < distance; offset += step) {
1049+
for (; offset < distance + end_offset; offset += step) {
10601050
v3f pos_node_f = pos_origin_f + direction * offset;
10611051
v3s16 pos_node = floatToInt(pos_node_f, BS);
10621052

1063-
if (offset > distance - BLOCK_DIAGONAL) {
1064-
// Do accurate position checks:
1065-
// Check whether the node is inside the current mapblock
1066-
if (block_bounds.isPointInside(pos_node))
1067-
return false;
1068-
}
1069-
10701053
MapNode node = getNode(pos_node, &is_valid_position);
10711054

10721055
if (is_valid_position &&
@@ -1098,10 +1081,7 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes)
10981081
v3s16(-1, -1, -1) * bs2,
10991082
};
11001083

1101-
// Minimal and maximal positions in the mapblock
1102-
core::aabbox3d<s16> block_bounds = block->getBox();
1103-
1104-
v3s16 pos_blockcenter = block_bounds.MinEdge + (MAP_BLOCKSIZE / 2);
1084+
v3s16 pos_blockcenter = block->getPosRelative() + (MAP_BLOCKSIZE / 2);
11051085

11061086
// Starting step size, value between 1m and sqrt(3)m
11071087
float step = BS * 1.2f;
@@ -1110,14 +1090,21 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes)
11101090

11111091
float start_offset = BS * 1.0f;
11121092

1093+
// The occlusion search of 'isOccluded()' must stop short of the target
1094+
// point by distance 'end_offset' to not enter the target mapblock.
1095+
// For the 8 mapblock corners 'end_offset' must therefore be the maximum
1096+
// diagonal of a mapblock, because we must consider all view angles.
1097+
// sqrt(1^2 + 1^2 + 1^2) = 1.732
1098+
float end_offset = -BS * MAP_BLOCKSIZE * 1.732f;
1099+
11131100
// to reduce the likelihood of falsely occluded blocks
11141101
// require at least two solid blocks
11151102
// this is a HACK, we should think of a more precise algorithm
11161103
u32 needed_count = 2;
11171104

11181105
for (const v3s16 &dir : dir9) {
1119-
if (!isOccluded(cam_pos_nodes, pos_blockcenter + dir, block_bounds,
1120-
step, stepfac, start_offset, needed_count))
1106+
if (!isOccluded(cam_pos_nodes, pos_blockcenter + dir, step, stepfac,
1107+
start_offset, end_offset, needed_count))
11211108
return false;
11221109
}
11231110
return true;

Diff for: ‎src/map.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ class Map /*: public NodeContainer*/
311311
const NodeDefManager *m_nodedef;
312312

313313
bool isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target,
314-
const core::aabbox3d<s16> &block_bounds, float step, float stepfac,
315-
float offset, u32 needed_count);
314+
float step, float stepfac, float start_offset, float end_offset,
315+
u32 needed_count);
316316

317317
private:
318318
f32 m_transforming_liquid_loop_count_multiplier = 1.0f;

0 commit comments

Comments
 (0)
Please sign in to comment.