Hello,
I want to use Perlin Noise in my game for some smooth randoms, but it doesn’t seem to exist in FMath or other Unreal libraries.
Is there somewhere/how I can get Perlin Noise working in Unreal c++?
Any help would be appreciated, thanks!
Hello,
I want to use Perlin Noise in my game for some smooth randoms, but it doesn’t seem to exist in FMath or other Unreal libraries.
Is there somewhere/how I can get Perlin Noise working in Unreal c++?
Any help would be appreciated, thanks!
You could make a Blueprints Function Library in C++.
https://docs.unrealengine.com/latest/INT/Programming/BlueprintFunctionLibraries/
From the Editor create a C++ class and choose BlueprintFunctionLibrary as the parent. It will make it for you. Then put your function in that class.
I think you may have misunderstood the topic… (I just edited it a bit for clarification)
I was asking about getting a perlin noise c++ function working in Unreal, similar to Unity or other game engines:
Check out this thread, DevDad made a nice plugin…it’s Ken Perlin’s simplex version which is superior in every way to his original algorithm.
Yup, I’m the 4th post on that page :).
It works slightly (although very broken in 4.10) however I’m wondering if a C++ version exists anywhere.
I’m doing some complex things through C++ so having my code constantly jumping from C++ to blueprint, back to C++ just for noise is kind of outrageous.
Ah, didn’t see your post there…
You shouldn’t need to jump between BP and Cpp, just because the functions are blueprint callable doesn’t mean you have to call them from blueprints, he even shows an example of this on that thread…
However if it is actually broken in 4.10 you could simply roll your own, Cpp noise libraries are plentiful and there’s many Cpp examples of Perlin noise floating around the web, I believe the material editor has a noise node, you could probably re-use the source code to that even …I can’t imagine it taking more than 10 minutes to port some code to a UE4 class though.
Yep I managed to do just that, though it took closer to 3 hours lol (I couldn’t figure out how to use static 2D arrays in Unreal).
Though I got it working through C++, they should consider adding it to FMath in future releases, it’s invaluable.
Submit a pull request
For people Googling:
float FMath::PerlinNoise1D(const float Value)
Just to tack on a little more context for those of you coming in from Google…
FMath provides the following Perlin functions:
float FMath::PerlinNoise1D(float X)
float FMath::PerlinNoise2D(const FVector2D& Location)
float FMath::PerlinNoise3D(const FVector& Location)
Bear in mind the perlin “tiles” or repeats itself for each 0-1 range. For instance, so the value at location 0 is the same as the value at location 1, is the same as the value at location 10.
Take the example of generating random height values over a landscape with PerlinNoise2D - you’ll want to scale the value by the range over which you want the noise to tile. You may also find it useful to normalize (or bias / scale) the output -1 to 1 values to a 0 to 1 range. For instance:
constexpr float Scale = 1000.f; // Repeat every 1000 Unreal units.
const auto PerlinPosition = FVector2d(WorldPosition.X, WorldPosition.Y) / Scale;
const auto RawHeight = FMath::PerlinNoise2D(PerlinPosition);
const auto NormalizedHeight = (RawHeight + 1.f) / 2.f;
You may also want to play around with adding multiple perlin noises together at different scales / offsets to make the tiling effect less obvious.
Have fun and experiment!
There is and very simple to setup.
Just call on the lib with ::
LibraryClass::FunctionFromTheLibClass()
For example.
FMath::PerlinNoise2D(FVector2D (( x,y));
You can divide multiply by factors and so on , the simple x,y,z is just an example
store it to some value and use the value to insert it where ever you like.