#include "CoreMinimal.h" #include "UnrealPerlinHelpers.inl" float FMath::PerlinNoise2D(const FVector2D& Location) { using namespace FMathPerlinHelpers; const float Xfl = FMath::FloorToFloat(static_cast(Location.X)); const float Yfl = FMath::FloorToFloat(static_cast(Location.Y)); const int32 Xi = static_cast(Xfl) & 255; const int32 Yi = static_cast(Yfl) & 255; const float X = static_cast(Location.X) - Xfl; const float Y = static_cast(Location.Y) - Yfl; const float Xm1 = X - 1.0f; const float Ym1 = Y - 1.0f; const int32* P = Permutation; const int32 AA = P[Xi] + Yi; const int32 AB = AA + 1; const int32 BA = P[Xi + 1] + Yi; const int32 BB = BA + 1; const float U = SmoothCurve(X); const float V = SmoothCurve(Y); return FMath::Lerp( FMath::Lerp(Grad2(P[AA], X, Y), Grad2(P[BA], Xm1, Y), U), FMath::Lerp(Grad2(P[AB], X, Ym1), Grad2(P[BB], Xm1, Ym1), U), V); } float FMath::PerlinNoise3D(const FVector& Location) { using namespace FMathPerlinHelpers; const float Xfl = FMath::FloorToFloat(static_cast(Location.X)); const float Yfl = FMath::FloorToFloat(static_cast(Location.Y)); const float Zfl = FMath::FloorToFloat(static_cast(Location.Z)); const int32 Xi = static_cast(Xfl) & 255; const int32 Yi = static_cast(Yfl) & 255; const int32 Zi = static_cast(Zfl) & 255; const float X = static_cast(Location.X) - Xfl; const float Y = static_cast(Location.Y) - Yfl; const float Z = static_cast(Location.Z) - Zfl; const float Xm1 = X - 1.0f; const float Ym1 = Y - 1.0f; const float Zm1 = Z - 1.0f; const int32* P = Permutation; const int32 A = P[Xi] + Yi; const int32 AA = P[A] + Zi; const int32 AB = P[A + 1] + Zi; const int32 B = P[Xi + 1] + Yi; const int32 BA = P[B] + Zi; const int32 BB = P[B + 1] + Zi; const float U = SmoothCurve(X); const float V = SmoothCurve(Y); const float W = SmoothCurve(Z); const float Value = 0.97f * FMath::Lerp( FMath::Lerp( FMath::Lerp(Grad3(P[AA], X, Y, Z), Grad3(P[BA], Xm1, Y, Z), U), FMath::Lerp(Grad3(P[AB], X, Ym1, Z), Grad3(P[BB], Xm1, Ym1, Z), U), V), FMath::Lerp( FMath::Lerp(Grad3(P[AA + 1], X, Y, Zm1), Grad3(P[BA + 1], Xm1, Y, Zm1), U), FMath::Lerp(Grad3(P[AB + 1], X, Ym1, Zm1), Grad3(P[BB + 1], Xm1, Ym1, Zm1), U), V), W); return FMath::Clamp(Value, -1.0f, 1.0f); }