This commit is contained in:
Aria 2025-03-21 22:23:30 +11:00
commit 9c94d113d3
Signed by untrusted user who does not match committer: aria
GPG key ID: 19AB7AA462B8AB3B
10260 changed files with 1237388 additions and 0 deletions

View file

@ -0,0 +1,29 @@
#include "StarMixSelector.hpp"
#include "StarInterpolation.hpp"
namespace Star {
char const* const MixSelector::Name = "mix";
MixSelector::MixSelector(Json const& config, TerrainSelectorParameters const& parameters, TerrainDatabase const* database)
: TerrainSelector(Name, config, parameters) {
auto readSource = [&](Json const& sourceConfig) {
String type = sourceConfig.getString("type");
return database->createSelectorType(type, sourceConfig, parameters);
};
m_mixSource = readSource(config.get("mixSource"));
m_aSource = readSource(config.get("aSource"));
m_bSource = readSource(config.get("bSource"));
}
float MixSelector::get(int x, int y) const {
auto f = clamp(m_mixSource->get(x, y), -1.0f, 1.0f);
if (f == -1)
return m_aSource->get(x, y);
if (f == 1)
return m_bSource->get(x, y);
return lerp(f * 0.5f + 0.5f, m_aSource->get(x, y), m_bSource->get(x, y));
}
}