FastNoise GetValues() specialization (#7009)
* Add comparison operator for use from unit tests. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * First version of FastNoise benchmarks. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Simplified unit tests and added initial benchmarks. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Add GetValue vs GetValues unit test. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Moved Gradient test code into helper files for use from FastNoise. Also added benchmarks for each type of FastNoise so that we can have some comparative values handy. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Specialization for GetValues(). Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
This commit is contained in:
@@ -54,6 +54,21 @@ namespace FastNoiseGem
|
||||
return AZ::Edit::PropertyVisibility::Hide;
|
||||
}
|
||||
|
||||
bool FastNoiseGradientConfig::operator==(const FastNoiseGradientConfig& rhs) const
|
||||
{
|
||||
return (m_cellularDistanceFunction == rhs.m_cellularDistanceFunction)
|
||||
&& (m_cellularJitter == rhs.m_cellularJitter)
|
||||
&& (m_cellularReturnType == rhs.m_cellularReturnType)
|
||||
&& (m_fractalType == rhs.m_fractalType)
|
||||
&& (m_frequency == rhs.m_frequency)
|
||||
&& (m_gain == rhs.m_gain)
|
||||
&& (m_interp == rhs.m_interp)
|
||||
&& (m_lacunarity == rhs.m_lacunarity)
|
||||
&& (m_noiseType == rhs.m_noiseType)
|
||||
&& (m_octaves == rhs.m_octaves)
|
||||
&& (m_seed == rhs.m_seed);
|
||||
}
|
||||
|
||||
void FastNoiseGradientConfig::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
@@ -306,7 +321,7 @@ namespace FastNoiseGem
|
||||
|
||||
float FastNoiseGradientComponent::GetValue(const GradientSignal::GradientSampleParams& sampleParams) const
|
||||
{
|
||||
AZ::Vector3 uvw = sampleParams.m_position;
|
||||
AZ::Vector3 uvw;
|
||||
bool wasPointRejected = false;
|
||||
|
||||
{
|
||||
@@ -314,13 +329,34 @@ namespace FastNoiseGem
|
||||
m_gradientTransform.TransformPositionToUVW(sampleParams.m_position, uvw, wasPointRejected);
|
||||
}
|
||||
|
||||
if (!wasPointRejected)
|
||||
// Generator returns a range between [-1, 1], map that to [0, 1]
|
||||
return wasPointRejected ?
|
||||
0.0f :
|
||||
AZ::GetClamp((m_generator.GetNoise(uvw.GetX(), uvw.GetY(), uvw.GetZ()) + 1.0f) / 2.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void FastNoiseGradientComponent::GetValues(AZStd::span<const AZ::Vector3> positions, AZStd::span<float> outValues) const
|
||||
{
|
||||
if (positions.size() != outValues.size())
|
||||
{
|
||||
// Generator returns a range between [-1, 1], map that to [0, 1]
|
||||
return AZ::GetClamp((m_generator.GetNoise(uvw.GetX(), uvw.GetY(), uvw.GetZ()) + 1.0f) / 2.0f, 0.0f, 1.0f);
|
||||
AZ_Assert(false, "input and output lists are different sizes (%zu vs %zu).", positions.size(), outValues.size());
|
||||
return;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
AZStd::shared_lock<decltype(m_transformMutex)> lock(m_transformMutex);
|
||||
AZ::Vector3 uvw;
|
||||
|
||||
for (size_t index = 0; index < positions.size(); index++)
|
||||
{
|
||||
bool wasPointRejected = false;
|
||||
|
||||
m_gradientTransform.TransformPositionToUVW(positions[index], uvw, wasPointRejected);
|
||||
|
||||
// Generator returns a range between [-1, 1], map that to [0, 1]
|
||||
outValues[index] = wasPointRejected ?
|
||||
0.0f :
|
||||
AZ::GetClamp((m_generator.GetNoise(uvw.GetX(), uvw.GetY(), uvw.GetZ()) + 1.0f) / 2.0f, 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TValueType, TValueType FastNoiseGradientConfig::*TConfigMember, void (FastNoise::*TMethod)(TValueType)>
|
||||
|
||||
Reference in New Issue
Block a user