fix: extracted blend logic to evaluate_at

This commit is contained in:
Sara Gerretsen 2026-02-22 22:50:07 +01:00
parent ac139f01b6
commit c17b513b34
2 changed files with 10 additions and 9 deletions

View file

@ -8,11 +8,7 @@ void TerrainModifier::_bind_methods() {
BIND_PROPERTY(Variant::FLOAT, blend_distance);
}
float TerrainModifier::blend(float under, float over, float weight) {
if (weight <= 0.0) {
return under;
}
over = Math::lerp(under, over, weight);
float TerrainModifier::blend(float under, float over) {
float const difference{ under - over };
float const distance{ Math::abs(difference) };
// .25 because we need half of each half of the blend range to be used
@ -43,7 +39,7 @@ float TerrainModifier::blend(float under, float over, float weight) {
float TerrainModifier::evaluate_at(Vector2 world_coordinate, float before) {
Vector3 const global_position{ get_global_position() };
world_coordinate -= { global_position.x, global_position.z };
return blend(before, 0.0, 1.0);
return blend(before, 0.0);
}
void TerrainModifierDistance::_bind_methods() {
@ -67,7 +63,12 @@ float TerrainModifierDistance::evaluate_at(Vector2 world_coordinate, float befor
float const weight_offset{
std::clamp(distance, this->distance_weight_curve->get_min_domain(), this->distance_weight_curve->get_max_domain())
};
return blend(before, this->distance_height_curve->sample_baked(height_offset) + get_global_position().y, this->distance_weight_curve->sample_baked(weight_offset));
float weight{ this->distance_weight_curve->sample_baked(weight_offset) };
if (weight <= 0.f) {
return before;
} else {
return Math::lerp(before, blend(before, this->distance_height_curve->sample_baked(height_offset) + get_global_position().y), weight);
}
}
PackedStringArray TerrainModifierDistance::get_configuration_warnings() const {