Skip to content

Commit

Permalink
Document issue with partitionned mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Jun 12, 2024
1 parent d4b833b commit cab1b7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/classes/VoxelMeshSDF.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
</member>
<member name="partition_subdiv" type="int" setter="set_partition_subdiv" getter="get_partition_subdiv" default="32">
Controls how many subdivisions to use across the baking area when using the [constant BAKE_MODE_ACCURATE_PARTITIONED] and [constant BAKE_MODE_APPROX_FLOODFILL] modes.
When using [constant BAKE_MODE_ACCURATE_PARTITIONED], that value may be proportionally adjusted based on the amount of triangles the mesh has, due to an imperfection of the algorithm. If the mesh has few triangles, lower values will perform better. If it has a lot of small triangles, higher values will perform better. However, if triangles are large or few and the value is big, this will also potentially create artifacts.
</member>
</members>
<signals>
Expand Down
12 changes: 12 additions & 0 deletions edition/mesh_sdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,18 @@ void compute_near_chunks(ChunkGrid &chunk_grid) {
// This is to account for the fact the closest chunk might contain a triangle further away than
// a closer triangle found in a farther chunk.

// TODO This creates artifacts when the mesh has few/big triangles and subdivision is high.
// A diagonal triangle D could have an AABB so large that it intersects many chunks while not
// relatively being close to them. Yet, 2 chunks away (>sqrt(3)) there could be a chunk intersected by
// an axis-aligned triangle A that would be closer than D. Yet it won't be detected.
//
// To fix this we could:
// - Increase the margin we use to add more triangles? That might work but reduce efficiency.
// - Instead of using AABBs to figure if a triangle is in a chunk, we could attempt a box/triangle
// intersection, or 3D rasterization. Then we could keep using the sqrt(3) margin since we know if
// a triangle is in a chunk, and if we pick any point on the sides of hat chunk, the distance from
// that point to the triangle is always closer than the diagonal of that chunk.

const int margin_distance_squared =
math::squared(sqrtf(closest_chunk_distance_squared) + math::SQRT3_32);

Expand Down

0 comments on commit cab1b7e

Please sign in to comment.