FastNoiseGradientComponent.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "FastNoiseGradientComponent.h"
  9. #include <AzCore/Math/MathUtils.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <AzCore/Serialization/EditContext.h>
  13. #include <External/FastNoise/FastNoise.h>
  14. #include <LmbrCentral/Dependency/DependencyNotificationBus.h>
  15. #include <GradientSignal/Ebuses/GradientTransformRequestBus.h>
  16. namespace FastNoiseGem
  17. {
  18. AZ::u32 FastNoiseGradientConfig::GetCellularParameterVisibility() const
  19. {
  20. return m_noiseType == FastNoise::NoiseType::Cellular ? AZ::Edit::PropertyVisibility::Show : AZ::Edit::PropertyVisibility::Hide;
  21. }
  22. AZ::u32 FastNoiseGradientConfig::GetFractalParameterVisbility() const
  23. {
  24. switch (m_noiseType)
  25. {
  26. case FastNoise::NoiseType::CubicFractal:
  27. case FastNoise::NoiseType::PerlinFractal:
  28. case FastNoise::NoiseType::SimplexFractal:
  29. case FastNoise::NoiseType::ValueFractal:
  30. return AZ::Edit::PropertyVisibility::Show;
  31. }
  32. return AZ::Edit::PropertyVisibility::Hide;
  33. }
  34. AZ::u32 FastNoiseGradientConfig::GetFrequencyParameterVisbility() const
  35. {
  36. return m_noiseType != FastNoise::NoiseType::WhiteNoise ? AZ::Edit::PropertyVisibility::Show : AZ::Edit::PropertyVisibility::Hide;
  37. }
  38. AZ::u32 FastNoiseGradientConfig::GetInterpParameterVisibility() const
  39. {
  40. switch (m_noiseType)
  41. {
  42. case FastNoise::NoiseType::Value:
  43. case FastNoise::NoiseType::ValueFractal:
  44. case FastNoise::NoiseType::Perlin:
  45. case FastNoise::NoiseType::PerlinFractal:
  46. return AZ::Edit::PropertyVisibility::Show;
  47. }
  48. return AZ::Edit::PropertyVisibility::Hide;
  49. }
  50. bool FastNoiseGradientConfig::operator==(const FastNoiseGradientConfig& rhs) const
  51. {
  52. return (m_cellularDistanceFunction == rhs.m_cellularDistanceFunction)
  53. && (m_cellularJitter == rhs.m_cellularJitter)
  54. && (m_cellularReturnType == rhs.m_cellularReturnType)
  55. && (m_fractalType == rhs.m_fractalType)
  56. && (m_frequency == rhs.m_frequency)
  57. && (m_gain == rhs.m_gain)
  58. && (m_interp == rhs.m_interp)
  59. && (m_lacunarity == rhs.m_lacunarity)
  60. && (m_noiseType == rhs.m_noiseType)
  61. && (m_octaves == rhs.m_octaves)
  62. && (m_seed == rhs.m_seed);
  63. }
  64. void FastNoiseGradientConfig::Reflect(AZ::ReflectContext* context)
  65. {
  66. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  67. {
  68. serializeContext->Class<FastNoiseGradientConfig, AZ::ComponentConfig>()
  69. ->Version(0)
  70. ->Field("NoiseType", &FastNoiseGradientConfig::m_noiseType)
  71. ->Field("Seed", &FastNoiseGradientConfig::m_seed)
  72. ->Field("Frequency", &FastNoiseGradientConfig::m_frequency)
  73. ->Field("Octaves", &FastNoiseGradientConfig::m_octaves)
  74. ->Field("Lacunarity", &FastNoiseGradientConfig::m_lacunarity)
  75. ->Field("Gain", &FastNoiseGradientConfig::m_gain)
  76. ->Field("Interp", &FastNoiseGradientConfig::m_interp)
  77. ->Field("FractalType", &FastNoiseGradientConfig::m_fractalType)
  78. ->Field("CellularDistanceFunction", &FastNoiseGradientConfig::m_cellularDistanceFunction)
  79. ->Field("CellularReturnType", &FastNoiseGradientConfig::m_cellularReturnType)
  80. ->Field("CellularJitter", &FastNoiseGradientConfig::m_cellularJitter)
  81. ;
  82. if (auto editContext = serializeContext->GetEditContext())
  83. {
  84. editContext->Class<FastNoiseGradientConfig>(
  85. "FastNoise Gradient", "")
  86. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  87. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  88. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  89. ->DataElement(AZ::Edit::UIHandlers::Slider, &FastNoiseGradientConfig::m_seed, "Random Seed", "Using different seeds will cause the noise output to change")
  90. ->Attribute(AZ::Edit::Attributes::Min, 1)
  91. ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<int>::max())
  92. ->Attribute(AZ::Edit::Attributes::SoftMin, 1)
  93. ->Attribute(AZ::Edit::Attributes::SoftMax, 100)
  94. ->Attribute(AZ::Edit::Attributes::Step, 10)
  95. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &FastNoiseGradientConfig::m_noiseType, "Noise Type", "Sets the type of noise generator used")
  96. ->Attribute(AZ::Edit::Attributes::Min, std::numeric_limits<int>::min())
  97. ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<int>::max())
  98. ->EnumAttribute(FastNoise::NoiseType::Value, "Value")
  99. ->EnumAttribute(FastNoise::NoiseType::ValueFractal, "Value Fractal")
  100. ->EnumAttribute(FastNoise::NoiseType::Perlin, "Perlin")
  101. ->EnumAttribute(FastNoise::NoiseType::PerlinFractal, "Perlin Fractal")
  102. ->EnumAttribute(FastNoise::NoiseType::Simplex, "Simplex")
  103. ->EnumAttribute(FastNoise::NoiseType::SimplexFractal, "Simplex Fractal")
  104. ->EnumAttribute(FastNoise::NoiseType::Cellular, "Cellular")
  105. ->EnumAttribute(FastNoise::NoiseType::WhiteNoise, "White Noise")
  106. ->EnumAttribute(FastNoise::NoiseType::Cubic, "Cubic")
  107. ->EnumAttribute(FastNoise::NoiseType::CubicFractal, "Cubic Fractal")
  108. ->DataElement(AZ::Edit::UIHandlers::Slider, &FastNoiseGradientConfig::m_frequency, "Frequency", "Higher frequencies are more coarse")
  109. ->Attribute(AZ::Edit::Attributes::DisplayDecimals, 4)
  110. ->Attribute(AZ::Edit::Attributes::Min, 0.0001f)
  111. ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max())
  112. ->Attribute(AZ::Edit::Attributes::SoftMax, 8.0f)
  113. ->Attribute(AZ::Edit::Attributes::SliderCurveMidpoint, 0.25) // Give the frequency a non-linear scale slider with higher precision at the low end
  114. ->Attribute(AZ::Edit::Attributes::Visibility, &FastNoiseGradientConfig::GetFrequencyParameterVisbility)
  115. ->DataElement(AZ::Edit::UIHandlers::Slider, &FastNoiseGradientConfig::m_octaves, "Octaves", "Number of recursions in the pattern generation, higher octaves refine the pattern")
  116. ->Attribute(AZ::Edit::Attributes::Min, 0)
  117. ->Attribute(AZ::Edit::Attributes::Max, 20)
  118. ->Attribute(AZ::Edit::Attributes::SoftMax, 8)
  119. ->Attribute(AZ::Edit::Attributes::Visibility, &FastNoiseGradientConfig::GetFractalParameterVisbility)
  120. ->DataElement(AZ::Edit::UIHandlers::Slider, &FastNoiseGradientConfig::m_lacunarity, "Lacunarity", "The frequency multiplier between each octave")
  121. ->Attribute(AZ::Edit::Attributes::Min, 0.f)
  122. ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max())
  123. ->Attribute(AZ::Edit::Attributes::SoftMax, 5.f)
  124. ->Attribute(AZ::Edit::Attributes::Visibility, &FastNoiseGradientConfig::GetFractalParameterVisbility)
  125. ->DataElement(AZ::Edit::UIHandlers::Slider, &FastNoiseGradientConfig::m_gain, "Gain", "The relative strength of noise from each layer when compared to the last")
  126. ->Attribute(AZ::Edit::Attributes::Min, 0.f)
  127. ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max())
  128. ->Attribute(AZ::Edit::Attributes::SoftMax, 5.f)
  129. ->Attribute(AZ::Edit::Attributes::Visibility, &FastNoiseGradientConfig::GetFractalParameterVisbility)
  130. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &FastNoiseGradientConfig::m_cellularDistanceFunction, "Distance Function", "Sets the distance function used to calculate the cell for a given point")
  131. ->Attribute(AZ::Edit::Attributes::Visibility, &FastNoiseGradientConfig::GetCellularParameterVisibility)
  132. ->EnumAttribute(FastNoise::CellularDistanceFunction::Euclidean, "Euclidean")
  133. ->EnumAttribute(FastNoise::CellularDistanceFunction::Manhattan, "Manhattan")
  134. ->EnumAttribute(FastNoise::CellularDistanceFunction::Natural, "Natural")
  135. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &FastNoiseGradientConfig::m_cellularReturnType, "Return Type", "Alters the value type the cellular function returns from its calculation")
  136. ->Attribute(AZ::Edit::Attributes::Visibility, &FastNoiseGradientConfig::GetCellularParameterVisibility)
  137. ->EnumAttribute(FastNoise::CellularReturnType::CellValue, "CellValue")
  138. ->EnumAttribute(FastNoise::CellularReturnType::Distance, "Distance")
  139. ->EnumAttribute(FastNoise::CellularReturnType::Distance2, "Distance2")
  140. ->EnumAttribute(FastNoise::CellularReturnType::Distance2Add, "Distance2Add")
  141. ->EnumAttribute(FastNoise::CellularReturnType::Distance2Sub, "Distance2Sub")
  142. ->EnumAttribute(FastNoise::CellularReturnType::Distance2Mul, "Distance2Mul")
  143. ->EnumAttribute(FastNoise::CellularReturnType::Distance2Div, "Distance2Div")
  144. ->DataElement(AZ::Edit::UIHandlers::Slider, &FastNoiseGradientConfig::m_cellularJitter, "Jitter", "Sets the maximum distance a cellular point can move from its grid position")
  145. ->Attribute(AZ::Edit::Attributes::Min, 0.f)
  146. ->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max())
  147. ->Attribute(AZ::Edit::Attributes::SoftMax, 10.f)
  148. ->Attribute(AZ::Edit::Attributes::Visibility, &FastNoiseGradientConfig::GetCellularParameterVisibility)
  149. ->ClassElement(AZ::Edit::ClassElements::Group, "FastNoise Advanced Settings")
  150. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  151. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &FastNoiseGradientConfig::m_interp, "Interpolation", "Changes the interpolation method used to smooth between noise values")
  152. ->Attribute(AZ::Edit::Attributes::Visibility, &FastNoiseGradientConfig::GetInterpParameterVisibility)
  153. ->EnumAttribute(FastNoise::Interp::Linear, "Linear")
  154. ->EnumAttribute(FastNoise::Interp::Hermite, "Hermite")
  155. ->EnumAttribute(FastNoise::Interp::Quintic, "Quintic")
  156. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &FastNoiseGradientConfig::m_fractalType, "Fractal Type", "Sets how the fractal is combined")
  157. ->Attribute(AZ::Edit::Attributes::Visibility, &FastNoiseGradientConfig::GetFractalParameterVisbility)
  158. ->EnumAttribute(FastNoise::FractalType::FBM, "FBM")
  159. ->EnumAttribute(FastNoise::FractalType::Billow, "Billow")
  160. ->EnumAttribute(FastNoise::FractalType::RigidMulti, "Rigid Multi")
  161. ;
  162. }
  163. }
  164. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  165. {
  166. behaviorContext->Class<FastNoiseGradientConfig>()
  167. ->Constructor()
  168. ->Attribute(AZ::Script::Attributes::Category, "Vegetation")
  169. ->Property("randomSeed", BehaviorValueProperty(&FastNoiseGradientConfig::m_seed))
  170. ->Property("frequency", BehaviorValueProperty(&FastNoiseGradientConfig::m_frequency))
  171. ->Property("octaves", BehaviorValueProperty(&FastNoiseGradientConfig::m_octaves))
  172. ->Property("lacunarity", BehaviorValueProperty(&FastNoiseGradientConfig::m_lacunarity))
  173. ->Property("gain", BehaviorValueProperty(&FastNoiseGradientConfig::m_gain))
  174. ->Property("noiseType",
  175. [](FastNoiseGradientConfig* config) { return (int&)(config->m_noiseType); },
  176. [](FastNoiseGradientConfig* config, const int& i) { config->m_noiseType = (FastNoise::NoiseType)i; })
  177. ->Property("interpolation",
  178. [](FastNoiseGradientConfig* config) { return (int&)(config->m_interp); },
  179. [](FastNoiseGradientConfig* config, const int& i) { config->m_interp = (FastNoise::Interp)i; })
  180. ->Property("fractalType",
  181. [](FastNoiseGradientConfig* config) { return (int&)(config->m_fractalType); },
  182. [](FastNoiseGradientConfig* config, const int& i) { config->m_fractalType = (FastNoise::FractalType)i; })
  183. ;
  184. }
  185. }
  186. void FastNoiseGradientComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  187. {
  188. services.push_back(AZ_CRC_CE("GradientService"));
  189. }
  190. void FastNoiseGradientComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  191. {
  192. services.push_back(AZ_CRC_CE("GradientService"));
  193. }
  194. void FastNoiseGradientComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services)
  195. {
  196. services.push_back(AZ_CRC_CE("GradientTransformService"));
  197. }
  198. void FastNoiseGradientComponent::Reflect(AZ::ReflectContext* context)
  199. {
  200. FastNoiseGradientConfig::Reflect(context);
  201. AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
  202. if (serialize)
  203. {
  204. serialize->Class<FastNoiseGradientComponent, AZ::Component>()
  205. ->Version(0)
  206. ->Field("Configuration", &FastNoiseGradientComponent::m_configuration)
  207. ;
  208. }
  209. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  210. {
  211. behaviorContext->Constant("FastNoiseGradientComponentTypeId", BehaviorConstant(FastNoiseGradientComponentTypeId));
  212. behaviorContext->Class<FastNoiseGradientComponent>()->RequestBus("FastNoiseGradientRequestBus");
  213. behaviorContext->EBus<FastNoiseGradientRequestBus>("FastNoiseGradientRequestBus")
  214. ->Attribute(AZ::Script::Attributes::Category, "Vegetation")
  215. ->Event("GetRandomSeed", &FastNoiseGradientRequestBus::Events::GetRandomSeed)
  216. ->Event("SetRandomSeed", &FastNoiseGradientRequestBus::Events::SetRandomSeed)
  217. ->VirtualProperty("RandomSeed", "GetRandomSeed", "SetRandomSeed")
  218. ->Event("GetFrequency", &FastNoiseGradientRequestBus::Events::GetFrequency)
  219. ->Event("SetFrequency", &FastNoiseGradientRequestBus::Events::SetFrequency)
  220. ->VirtualProperty("Frequency", "GetFrequency", "SetFrequency")
  221. ->Event("GetInterpolation", &FastNoiseGradientRequestBus::Events::GetInterpolation)
  222. ->Event("SetInterpolation", &FastNoiseGradientRequestBus::Events::SetInterpolation)
  223. ->VirtualProperty("Interpolation", "GetInterpolation", "SetInterpolation")
  224. ->Event("GetNoiseType", &FastNoiseGradientRequestBus::Events::GetNoiseType)
  225. ->Event("SetNoiseType", &FastNoiseGradientRequestBus::Events::SetNoiseType)
  226. ->VirtualProperty("NoiseType", "GetNoiseType", "SetNoiseType")
  227. ->Event("GetOctaves", &FastNoiseGradientRequestBus::Events::GetOctaves)
  228. ->Event("SetOctaves", &FastNoiseGradientRequestBus::Events::SetOctaves)
  229. ->VirtualProperty("Octaves", "GetOctaves", "SetOctaves")
  230. ->Event("GetLacunarity", &FastNoiseGradientRequestBus::Events::GetLacunarity)
  231. ->Event("SetLacunarity", &FastNoiseGradientRequestBus::Events::SetLacunarity)
  232. ->VirtualProperty("Lacunarity", "GetLacunarity", "SetLacunarity")
  233. ->Event("GetGain", &FastNoiseGradientRequestBus::Events::GetGain)
  234. ->Event("SetGain", &FastNoiseGradientRequestBus::Events::SetGain)
  235. ->VirtualProperty("Gain", "GetGain", "SetGain")
  236. ->Event("GetFractalType", &FastNoiseGradientRequestBus::Events::GetFractalType)
  237. ->Event("SetFractalType", &FastNoiseGradientRequestBus::Events::SetFractalType)
  238. ->VirtualProperty("FractalType", "GetFractalType", "SetFractalType")
  239. ;
  240. }
  241. }
  242. FastNoiseGradientComponent::FastNoiseGradientComponent(const FastNoiseGradientConfig& configuration)
  243. : m_configuration(configuration)
  244. {
  245. }
  246. void FastNoiseGradientComponent::Activate()
  247. {
  248. // This will immediately call OnGradientTransformChanged and initialize m_gradientTransform.
  249. GradientSignal::GradientTransformNotificationBus::Handler::BusConnect(GetEntityId());
  250. // Some platforms require random seeds to be > 0. Clamp to a positive range to ensure we're always safe.
  251. m_generator.SetSeed(AZ::GetMax(m_configuration.m_seed, 1));
  252. m_generator.SetFrequency(m_configuration.m_frequency);
  253. m_generator.SetInterp(m_configuration.m_interp);
  254. m_generator.SetNoiseType(m_configuration.m_noiseType);
  255. m_generator.SetFractalOctaves(m_configuration.m_octaves);
  256. m_generator.SetFractalLacunarity(m_configuration.m_lacunarity);
  257. m_generator.SetFractalGain(m_configuration.m_gain);
  258. m_generator.SetFractalType(m_configuration.m_fractalType);
  259. m_generator.SetCellularDistanceFunction(m_configuration.m_cellularDistanceFunction);
  260. m_generator.SetCellularReturnType(m_configuration.m_cellularReturnType);
  261. m_generator.SetCellularJitter(m_configuration.m_cellularJitter);
  262. FastNoiseGradientRequestBus::Handler::BusConnect(GetEntityId());
  263. // Connect to GradientRequestBus last so that everything is initialized before listening for gradient queries.
  264. GradientSignal::GradientRequestBus::Handler::BusConnect(GetEntityId());
  265. }
  266. void FastNoiseGradientComponent::Deactivate()
  267. {
  268. // Disconnect from GradientRequestBus first to ensure no queries are in process when deactivating.
  269. GradientSignal::GradientRequestBus::Handler::BusDisconnect();
  270. FastNoiseGradientRequestBus::Handler::BusDisconnect();
  271. GradientSignal::GradientTransformNotificationBus::Handler::BusDisconnect();
  272. }
  273. bool FastNoiseGradientComponent::ReadInConfig(const AZ::ComponentConfig* baseConfig)
  274. {
  275. if (auto config = azrtti_cast<const FastNoiseGradientConfig*>(baseConfig))
  276. {
  277. m_configuration = *config;
  278. return true;
  279. }
  280. return false;
  281. }
  282. bool FastNoiseGradientComponent::WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const
  283. {
  284. if (auto config = azrtti_cast<FastNoiseGradientConfig*>(outBaseConfig))
  285. {
  286. *config = m_configuration;
  287. return true;
  288. }
  289. return false;
  290. }
  291. void FastNoiseGradientComponent::OnGradientTransformChanged(const GradientSignal::GradientTransform& newTransform)
  292. {
  293. AZStd::unique_lock lock(m_queryMutex);
  294. m_gradientTransform = newTransform;
  295. }
  296. float FastNoiseGradientComponent::GetValue(const GradientSignal::GradientSampleParams& sampleParams) const
  297. {
  298. AZ::Vector3 uvw;
  299. bool wasPointRejected = false;
  300. AZStd::shared_lock lock(m_queryMutex);
  301. m_gradientTransform.TransformPositionToUVW(sampleParams.m_position, uvw, wasPointRejected);
  302. // Generator returns a range between [-1, 1], map that to [0, 1]
  303. return wasPointRejected ?
  304. 0.0f :
  305. AZ::GetClamp((m_generator.GetNoise(uvw.GetX(), uvw.GetY(), uvw.GetZ()) + 1.0f) / 2.0f, 0.0f, 1.0f);
  306. }
  307. void FastNoiseGradientComponent::GetValues(AZStd::span<const AZ::Vector3> positions, AZStd::span<float> outValues) const
  308. {
  309. if (positions.size() != outValues.size())
  310. {
  311. AZ_Assert(false, "input and output lists are different sizes (%zu vs %zu).", positions.size(), outValues.size());
  312. return;
  313. }
  314. AZStd::shared_lock lock(m_queryMutex);
  315. AZ::Vector3 uvw;
  316. for (size_t index = 0; index < positions.size(); index++)
  317. {
  318. bool wasPointRejected = false;
  319. m_gradientTransform.TransformPositionToUVW(positions[index], uvw, wasPointRejected);
  320. // Generator returns a range between [-1, 1], map that to [0, 1]
  321. outValues[index] = wasPointRejected ?
  322. 0.0f :
  323. AZ::GetClamp((m_generator.GetNoise(uvw.GetX(), uvw.GetY(), uvw.GetZ()) + 1.0f) / 2.0f, 0.0f, 1.0f);
  324. }
  325. }
  326. template <typename TValueType, TValueType FastNoiseGradientConfig::*TConfigMember, void (FastNoise::*TMethod)(TValueType)>
  327. void FastNoiseGradientComponent::SetConfigValue(TValueType value)
  328. {
  329. // Only hold the lock while we're changing the data. Don't hold onto it during the OnCompositionChanged call, because that can
  330. // execute an arbitrary amount of logic, including calls back to this component.
  331. {
  332. AZStd::unique_lock lock(m_queryMutex);
  333. m_configuration.*TConfigMember = value;
  334. ((&m_generator)->*TMethod)(value);
  335. }
  336. LmbrCentral::DependencyNotificationBus::Event(GetEntityId(), &LmbrCentral::DependencyNotificationBus::Events::OnCompositionChanged);
  337. }
  338. int FastNoiseGradientComponent::GetRandomSeed() const
  339. {
  340. return m_configuration.m_seed;
  341. }
  342. void FastNoiseGradientComponent::SetRandomSeed(int seed)
  343. {
  344. // Some platforms require random seeds to be > 0. Clamp to a positive range to ensure we're always safe.
  345. SetConfigValue<int, &FastNoiseGradientConfig::m_seed, &FastNoise::SetSeed>(AZ::GetMax(seed, 1));
  346. }
  347. float FastNoiseGradientComponent::GetFrequency() const
  348. {
  349. return m_configuration.m_frequency;
  350. }
  351. void FastNoiseGradientComponent::SetFrequency(float freq)
  352. {
  353. SetConfigValue<float, &FastNoiseGradientConfig::m_frequency, &FastNoise::SetFrequency>(freq);
  354. }
  355. FastNoise::Interp FastNoiseGradientComponent::GetInterpolation() const
  356. {
  357. return m_configuration.m_interp;
  358. }
  359. void FastNoiseGradientComponent::SetInterpolation(FastNoise::Interp interp)
  360. {
  361. SetConfigValue<FastNoise::Interp, &FastNoiseGradientConfig::m_interp, &FastNoise::SetInterp>(interp);
  362. }
  363. FastNoise::NoiseType FastNoiseGradientComponent::GetNoiseType() const
  364. {
  365. return m_configuration.m_noiseType;
  366. }
  367. void FastNoiseGradientComponent::SetNoiseType(FastNoise::NoiseType type)
  368. {
  369. SetConfigValue<FastNoise::NoiseType, &FastNoiseGradientConfig::m_noiseType, &FastNoise::SetNoiseType>(type);
  370. }
  371. int FastNoiseGradientComponent::GetOctaves() const
  372. {
  373. return m_configuration.m_octaves;
  374. }
  375. void FastNoiseGradientComponent::SetOctaves(int octaves)
  376. {
  377. SetConfigValue<int, &FastNoiseGradientConfig::m_octaves, &FastNoise::SetFractalOctaves>(octaves);
  378. }
  379. float FastNoiseGradientComponent::GetLacunarity() const
  380. {
  381. return m_configuration.m_lacunarity;
  382. }
  383. void FastNoiseGradientComponent::SetLacunarity(float lacunarity)
  384. {
  385. SetConfigValue<float, &FastNoiseGradientConfig::m_lacunarity, &FastNoise::SetFractalLacunarity>(lacunarity);
  386. }
  387. float FastNoiseGradientComponent::GetGain() const
  388. {
  389. return m_configuration.m_gain;
  390. }
  391. void FastNoiseGradientComponent::SetGain(float gain)
  392. {
  393. SetConfigValue<float, &FastNoiseGradientConfig::m_gain, &FastNoise::SetFractalGain>(gain);
  394. }
  395. FastNoise::FractalType FastNoiseGradientComponent::GetFractalType() const
  396. {
  397. return m_configuration.m_fractalType;
  398. }
  399. void FastNoiseGradientComponent::SetFractalType(FastNoise::FractalType type)
  400. {
  401. SetConfigValue<FastNoise::FractalType, &FastNoiseGradientConfig::m_fractalType, &FastNoise::SetFractalType>(type);
  402. }
  403. } // namespace FastNoiseGem