fix: extracted blend logic to evaluate_at
This commit is contained in:
parent
ac139f01b6
commit
c17b513b34
2 changed files with 10 additions and 9 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ public:
|
|||
GDENUM(BlendMode, Add, Subtract, Override);
|
||||
|
||||
protected:
|
||||
float blend(float under, float over, float weight);
|
||||
float blend(float under, float over);
|
||||
|
||||
public:
|
||||
virtual float evaluate_at(Vector2 world_coordinate, float before);
|
||||
|
||||
private:
|
||||
float blend_distance{ 1.0 };
|
||||
float blend_distance{ 10.0 };
|
||||
BlendMode blend_mode{ Add };
|
||||
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue