1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Adjust LOD selection metrics to use attribute error

- Revert meshoptimizer patch; the metric used for LOD selection now
incorporates attribute error
- Since LOD selection is now aware of attribute deviation, we don't
need to use a higher normal weight
- To prevent normal creases from creating input triangles with very
large normal deviation, reduce default normal merge threshold
- Since we now use combined metric to select LODs, we never need LODs
with error>1 as these should not be selected if the mesh is visible.
This commit is contained in:
Arseny Kapoulkine
2025-05-18 17:38:54 +03:00
parent c3ae6aa10b
commit 6190d412d3
4 changed files with 6 additions and 19 deletions

View File

@@ -2080,7 +2080,7 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/shadow_meshes", PROPERTY_HINT_ENUM, "Default,Enable,Disable"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/lightmap_uv", PROPERTY_HINT_ENUM, "Default,Enable,Disable"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/lods", PROPERTY_HINT_ENUM, "Default,Enable,Disable"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "lods/normal_merge_angle", PROPERTY_HINT_RANGE, "0,180,0.1,degrees"), 60.0f));
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "lods/normal_merge_angle", PROPERTY_HINT_RANGE, "0,180,1,degrees"), 20.0f));
} break;
case INTERNAL_IMPORT_CATEGORY_MATERIAL: {
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "use_external/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
@@ -2514,7 +2514,7 @@ Node *ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_
//do mesh processing
bool generate_lods = p_generate_lods;
float merge_angle = 60.0f;
float merge_angle = 20.0f;
bool create_shadow_meshes = p_create_shadow_meshes;
bool bake_lightmaps = p_light_bake_mode == LIGHT_BAKE_STATIC_LIGHTMAPS;
String save_to_file;

View File

@@ -443,8 +443,8 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, Array p_bone_transf
float attrib_weights[attrib_count] = {};
// Give more weight to normal preservation
attrib_weights[0] = attrib_weights[1] = attrib_weights[2] = 2.0f;
// Give some weight to normal preservation
attrib_weights[0] = attrib_weights[1] = attrib_weights[2] = 1.0f;
// Give some weight to colors but only if present to avoid redundant computations during simplification
if (colors_ptr) {
@@ -474,7 +474,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, Array p_bone_transf
unsigned int index_target = 12; // Start with the smallest target, 4 triangles
unsigned int last_index_count = 0;
const float max_mesh_error = FLT_MAX; // We don't want to limit by error, just by index target
const float max_mesh_error = 1.0f; // we only need LODs that can be selected by error threshold
float mesh_error = 0.0f;
while (index_target < index_count) {

View File

@@ -1,13 +0,0 @@
diff --git a/thirdparty/meshoptimizer/simplifier.cpp b/thirdparty/meshoptimizer/simplifier.cpp
index af64cbda49..8a7072fe4e 100644
--- a/thirdparty/meshoptimizer/simplifier.cpp
+++ b/thirdparty/meshoptimizer/simplifier.cpp
@@ -2048,7 +2048,7 @@ size_t meshopt_simplifyEdge(unsigned int* destination, const unsigned int* indic
// result_error is quadratic; we need to remap it back to linear
if (out_result_error)
- *out_result_error = sqrtf(result_error) * error_scale;
+ *out_result_error = sqrtf(vertex_error) * error_scale;
return result_count;
}

View File

@@ -2048,7 +2048,7 @@ size_t meshopt_simplifyEdge(unsigned int* destination, const unsigned int* indic
// result_error is quadratic; we need to remap it back to linear
if (out_result_error)
*out_result_error = sqrtf(vertex_error) * error_scale;
*out_result_error = sqrtf(result_error) * error_scale;
return result_count;
}