Added plugin FastNoiseGenerator. Added noise to landscape approach2 in map02. WIP

This commit is contained in:
krt 2023-12-15 16:20:18 +02:00
parent d370195393
commit 71b77f0f00
19 changed files with 3206 additions and 7 deletions

BIN
Content/Main/BP_landscape2.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -0,0 +1,3 @@
[FilterPlugin]
/Config/*
/Documentation/*

BIN
Plugins/FastNoiseGenerator/Documentation/Blueprint_nodes.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,34 @@
{
"FileVersion": 3,
"Version": 2,
"VersionName": "1.01",
"FriendlyName": "FastNoiseGenerator",
"Description": "Blueprint-friendly noise generator wrapper for Auburns's Fast Noise library.",
"Category": "Code Plugins",
"CreatedBy": "Víctor Hernández Molpeceres (Rockam)",
"CreatedByURL": "https://www.unrealengine.com/marketplace/en-US/profile/Rockam",
"DocsURL": "https://drive.google.com/file/d/1Md0e-c89Id7Kq6-5aWvGdSomEIb6fRgH/view?usp=sharing",
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/527737f42da544e9abf8607a40495fbd",
"SupportURL": "norlun5@gmail.com",
"EngineVersion": "5.3.0",
"CanContainContent": false,
"Installed": true,
"Modules": [
{
"Name": "FastNoise",
"Type": "Runtime",
"LoadingPhase": "Default",
"PlatformDenyList": [
"IOS"
]
},
{
"Name": "FastNoiseGenerator",
"Type": "Runtime",
"LoadingPhase": "Default",
"PlatformDenyList": [
"IOS"
]
}
]
}

BIN
Plugins/FastNoiseGenerator/Resources/Icon128.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,53 @@
// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class FastNoiseGenerator : ModuleRules
{
public FastNoiseGenerator(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
PublicIncludePaths.AddRange(
new string[] {
// ... add public include paths required here ...
}
);
PrivateIncludePaths.AddRange(
new string[] {
// ... add other private include paths required here ...
}
);
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
// ... add other public dependencies that you statically link with here ...
}
);
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
"FastNoise"
}
);
DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
}
}

View File

@ -0,0 +1,20 @@
// Copyright 2021 VICTOR HERNANDEZ MOLPECERES (Rockam). All rights reserved.
#include "FastNoiseGenerator.h"
#define LOCTEXT_NAMESPACE "FFastNoiseGeneratorModule"
void FFastNoiseGeneratorModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
}
void FFastNoiseGeneratorModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FFastNoiseGeneratorModule, FastNoiseGenerator)

View File

@ -0,0 +1,5 @@
// Copyright 2021 VICTOR HERNANDEZ MOLPECERES (Rockam). All rights reserved.
#include "FastNoiseWrapper.h"
// Nothing to do here

View File

@ -0,0 +1,15 @@
// Copyright 2021 VICTOR HERNANDEZ MOLPECERES (Rockam). All rights reserved.
#pragma once
#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"
class FFastNoiseGeneratorModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
};

View File

@ -0,0 +1,409 @@
// Copyright 2021 VICTOR HERNANDEZ MOLPECERES (Rockam). All rights reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "ThirdParty/FastNoise/Public/FastNoise.h"
#include "FastNoiseWrapper.generated.h"
// Fast Noise UE4 enum wrappers
UENUM(BlueprintType) enum class EFastNoise_NoiseType : uint8 { Value, ValueFractal, Perlin, PerlinFractal, Simplex, SimplexFractal, Cellular, WhiteNoise, Cubic, CubicFractal };
UENUM(BlueprintType) enum class EFastNoise_Interp : uint8 { Linear, Hermite, Quintic };
UENUM(BlueprintType) enum class EFastNoise_FractalType : uint8 { FBM, Billow, RigidMulti };
UENUM(BlueprintType) enum class EFastNoise_CellularDistanceFunction : uint8 { Euclidean, Manhattan, Natural };
UENUM(BlueprintType) enum class EFastNoise_CellularReturnType : uint8 { CellValue, /*NoiseLookup,*/ Distance, Distance2, Distance2Add, Distance2Sub, Distance2Mul, Distance2Div };
/**
* UE4 Wrapper for Auburns's FastNoise library, also available for blueprints usage.
*/
UCLASS(BlueprintType)
class FASTNOISEGENERATOR_API UFastNoiseWrapper : public UObject
{
GENERATED_BODY()
public:
/**
* Set all the properties needed to generate the noise
*
* @param noiseType - Noise return type of GetNoise(...). Default value: Simplex
* @param seed - Seed used for all noise types. Using different seeds will cause the noise output to change. Default value: 1337
* @param frequency - Frequency for all noise types, except White Noise. Affects how coarse the noise output is. Default value: 0.01
* @param interp - Interpolation method used to smooth between noise values in Value and Perlin Noise. Possible interpolation methods (lowest to highest quality): Linear; Hermite; Quintic. Default value: Quintic
* @param fractaltype - Method for combining octaves in all fractal noise types. Default value: FBM
* @param octaves - Octave count for all fractal noise types. The amount of noise layers used to create the fractal. Default value: 3
* @param lacunarity - Octave lacunarity for all fractal noise types. The frequency multiplier between each octave. Default value: 2.0
* @param gain - Octave gain for all fractal noise types. The relative strength of noise from each layer when compared to the last. Default value: 0.5
* @param cellularJitter - Maximum distance a cellular point can move from its grid position. Setting this high will make artifacts more common. Default value: 0.45
* @param cellularDistanceFunction - Distance function used in cellular noise calculations. The distance function used to calculate the cell for a given point. Natural is a blend of Euclidean and Manhattan to give curved cell boundaries. Default value: Euclidean
* @param cellularReturnType - Return type from cellular noise calculations. Default value: CellValue
*/
UFUNCTION(BlueprintCallable, Category = "Fast Noise")
void SetupFastNoise
(
const EFastNoise_NoiseType noiseType = EFastNoise_NoiseType::Simplex,
const int32 seed = 1337,
const float frequency = 0.01f,
const EFastNoise_Interp interp = EFastNoise_Interp::Quintic,
const EFastNoise_FractalType fractaltype = EFastNoise_FractalType::FBM,
const int32 octaves = 3,
const float lacunarity = 2.0f,
const float gain = 0.5f,
const float cellularJitter = 0.45f,
const EFastNoise_CellularDistanceFunction cellularDistanceFunction = EFastNoise_CellularDistanceFunction::Euclidean,
const EFastNoise_CellularReturnType cellularReturnType = EFastNoise_CellularReturnType::CellValue
)
{
SetNoiseType(noiseType);
SetSeed(seed);
SetFrequency(frequency);
SetInterpolation(interp);
SetFractalType(fractaltype);
SetOctaves(octaves);
SetLacunarity(lacunarity);
SetGain(gain);
SetCellularJitter(cellularJitter);
SetDistanceFunction(cellularDistanceFunction);
SetReturnType(cellularReturnType);
bInitialized = true;
}
/** Returns if Fast Noise properties are initialized or not */
UFUNCTION(BlueprintPure, Category = "Fast Noise")
bool IsInitialized() const { return bInitialized; }
/**
* Returns the noise calculation given x and y values
*
* @param x - The x axis value
* @param y - The y axis value
*/
UFUNCTION(BlueprintCallable, Category = "Fast Noise")
float GetNoise2D(const float x, const float y) const { return IsInitialized() ? fastNoise.GetNoise(x, y) : 0.0f; }
/**
* Returns the noise calculation given x, y and z values
*
* @param x - The x axis value
* @param y - The y axis value
* @param z - The z axis value
*/
UFUNCTION(BlueprintCallable, Category = "Fast Noise")
float GetNoise3D(const float x, const float y, const float z = 0.0f) const { return IsInitialized() ? fastNoise.GetNoise(x, y, z) : 0.0f; }
//***********************************************************
//********************* GETTERS *********************
//***********************************************************
/** Gets noise type */
UFUNCTION(BlueprintPure, Category = "Fast Noise|General settings")
EFastNoise_NoiseType GetNoiseType()
{
switch (fastNoise.GetNoiseType())
{
case FastNoise::NoiseType::Value:
return EFastNoise_NoiseType::Value;
case FastNoise::NoiseType::ValueFractal:
return EFastNoise_NoiseType::ValueFractal;
case FastNoise::NoiseType::Perlin:
return EFastNoise_NoiseType::Perlin;
case FastNoise::NoiseType::PerlinFractal:
return EFastNoise_NoiseType::PerlinFractal;
case FastNoise::NoiseType::SimplexFractal:
return EFastNoise_NoiseType::SimplexFractal;
case FastNoise::NoiseType::Cellular:
return EFastNoise_NoiseType::Cellular;
case FastNoise::NoiseType::WhiteNoise:
return EFastNoise_NoiseType::WhiteNoise;
case FastNoise::NoiseType::Cubic:
return EFastNoise_NoiseType::Cubic;
case FastNoise::NoiseType::CubicFractal:
return EFastNoise_NoiseType::CubicFractal;
case FastNoise::NoiseType::Simplex:
default:
return EFastNoise_NoiseType::Simplex;
}
}
/** Gets seed. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|General settings")
int32 GetSeed() const { return fastNoise.GetSeed(); }
/** Gets frequency. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|General settings")
float GetFrequency() const { return fastNoise.GetFrequency(); }
/** Gets interpolation type. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|General settings")
EFastNoise_Interp GetInterpolation() const
{
switch (fastNoise.GetInterp())
{
case FastNoise::Interp::Linear:
return EFastNoise_Interp::Linear;
case FastNoise::Interp::Hermite:
return EFastNoise_Interp::Hermite;
case FastNoise::Interp::Quintic:
default:
return EFastNoise_Interp::Quintic;
}
}
/** Gets fractal type. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|Fractal settings")
EFastNoise_FractalType GetFractalType() const
{
switch (fastNoise.GetFractalType())
{
case FastNoise::FractalType::Billow:
return EFastNoise_FractalType::Billow;
case FastNoise::FractalType::RigidMulti:
return EFastNoise_FractalType::RigidMulti;
case FastNoise::FractalType::FBM:
default:
return EFastNoise_FractalType::FBM;
}
}
/** Gets fractal octaves. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|Fractal settings")
int32 GetOctaves() const { return fastNoise.GetFractalOctaves(); }
/** Gets fractal lacunarity. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|Fractal settings")
float GetLacunarity() const { return fastNoise.GetFractalLacunarity(); }
/** Gets fractal gain. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|Fractal settings")
float GetGain() const { return fastNoise.GetFractalGain(); }
/** Gets cellular jitter. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|Cellular settings")
float GetCellularJitter() const { return fastNoise.GetCellularJitter(); }
/** Gets cellular distance function. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|Cellular settings")
EFastNoise_CellularDistanceFunction GetDistanceFunction() const
{
switch (fastNoise.GetCellularDistanceFunction())
{
case FastNoise::CellularDistanceFunction::Manhattan:
return EFastNoise_CellularDistanceFunction::Manhattan;
case FastNoise::CellularDistanceFunction::Natural:
return EFastNoise_CellularDistanceFunction::Natural;
case FastNoise::CellularDistanceFunction::Euclidean:
default:
return EFastNoise_CellularDistanceFunction::Euclidean;
}
}
/** Gets cellular return type. */
UFUNCTION(BlueprintPure, Category = "Fast Noise|Cellular settings")
EFastNoise_CellularReturnType GetReturnType() const
{
switch (fastNoise.GetCellularReturnType())
{
/*case FastNoise::CellularReturnType::NoiseLookup:
return EFastNoise_CellularReturnType::NoiseLookup;*/
case FastNoise::CellularReturnType::Distance:
return EFastNoise_CellularReturnType::Distance;
case FastNoise::CellularReturnType::Distance2:
return EFastNoise_CellularReturnType::Distance2;
case FastNoise::CellularReturnType::Distance2Add:
return EFastNoise_CellularReturnType::Distance2Add;
case FastNoise::CellularReturnType::Distance2Sub:
return EFastNoise_CellularReturnType::Distance2Sub;
case FastNoise::CellularReturnType::Distance2Mul:
return EFastNoise_CellularReturnType::Distance2Mul;
case FastNoise::CellularReturnType::Distance2Div:
return EFastNoise_CellularReturnType::Distance2Div;
case FastNoise::CellularReturnType::CellValue:
default:
return EFastNoise_CellularReturnType::CellValue;
}
}
//***********************************************************
//********************* SETTERS *********************
//***********************************************************
/** Set noise type. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|General settings")
void SetNoiseType(const EFastNoise_NoiseType noiseType)
{
switch (noiseType)
{
case EFastNoise_NoiseType::Value:
fastNoise.SetNoiseType(FastNoise::NoiseType::Value);
break;
case EFastNoise_NoiseType::ValueFractal:
fastNoise.SetNoiseType(FastNoise::NoiseType::ValueFractal);
break;
case EFastNoise_NoiseType::Perlin:
fastNoise.SetNoiseType(FastNoise::NoiseType::Perlin);
break;
case EFastNoise_NoiseType::PerlinFractal:
fastNoise.SetNoiseType(FastNoise::NoiseType::PerlinFractal);
break;
case EFastNoise_NoiseType::SimplexFractal:
fastNoise.SetNoiseType(FastNoise::NoiseType::SimplexFractal);
break;
case EFastNoise_NoiseType::Cellular:
fastNoise.SetNoiseType(FastNoise::NoiseType::Cellular);
break;
case EFastNoise_NoiseType::WhiteNoise:
fastNoise.SetNoiseType(FastNoise::NoiseType::WhiteNoise);
break;
case EFastNoise_NoiseType::Cubic:
fastNoise.SetNoiseType(FastNoise::NoiseType::Cubic);
break;
case EFastNoise_NoiseType::CubicFractal:
fastNoise.SetNoiseType(FastNoise::NoiseType::CubicFractal);
break;
case EFastNoise_NoiseType::Simplex:
default:
fastNoise.SetNoiseType(FastNoise::NoiseType::Simplex);
}
}
/** Set seed. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|General settings")
void SetSeed(const int32 seed) { fastNoise.SetSeed(seed); }
/** Set frequency. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|General settings")
void SetFrequency(const float frequency) { fastNoise.SetFrequency(frequency); }
/** Set interpolation type. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|General settings")
void SetInterpolation(const EFastNoise_Interp interp)
{
switch (interp)
{
case EFastNoise_Interp::Linear:
fastNoise.SetInterp(FastNoise::Interp::Linear);
break;
case EFastNoise_Interp::Hermite:
fastNoise.SetInterp(FastNoise::Interp::Hermite);
break;
case EFastNoise_Interp::Quintic:
default:
fastNoise.SetInterp(FastNoise::Interp::Quintic);
}
}
/** Set fractal type. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|Fractal settings")
void SetFractalType(const EFastNoise_FractalType fractalType)
{
switch (fractalType)
{
case EFastNoise_FractalType::Billow:
fastNoise.SetFractalType(FastNoise::FractalType::Billow);
break;
case EFastNoise_FractalType::RigidMulti:
fastNoise.SetFractalType(FastNoise::FractalType::RigidMulti);
break;
case EFastNoise_FractalType::FBM:
default:
fastNoise.SetFractalType(FastNoise::FractalType::FBM);
}
}
/** Set fractal octaves. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|Fractal settings")
void SetOctaves(const int32 octaves) { fastNoise.SetFractalOctaves(octaves); }
/** Set fractal lacunarity. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|Fractal settings")
void SetLacunarity(const float lacunarity) { fastNoise.SetFractalLacunarity(lacunarity); }
/** Set fractal gain. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|Fractal settings")
void SetGain(const float gain) { fastNoise.SetFractalGain(gain); }
/** Set cellular jitter. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|Cellular settings")
void SetCellularJitter(const float cellularJitter) { fastNoise.SetCellularJitter(cellularJitter); }
/** Set cellular distance function. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|Cellular settings")
void SetDistanceFunction(const EFastNoise_CellularDistanceFunction distanceFunction)
{
switch (distanceFunction)
{
case EFastNoise_CellularDistanceFunction::Manhattan:
fastNoise.SetCellularDistanceFunction(FastNoise::CellularDistanceFunction::Manhattan);
break;
case EFastNoise_CellularDistanceFunction::Natural:
fastNoise.SetCellularDistanceFunction(FastNoise::CellularDistanceFunction::Natural);
break;
case EFastNoise_CellularDistanceFunction::Euclidean:
default:
fastNoise.SetCellularDistanceFunction(FastNoise::CellularDistanceFunction::Euclidean);
}
}
/** Set cellular return type. */
UFUNCTION(BlueprintCallable, Category = "Fast Noise|Cellular settings")
void SetReturnType(const EFastNoise_CellularReturnType cellularReturnType)
{
switch (cellularReturnType)
{
/*case EFastNoise_CellularReturnType::NoiseLookup:
fastNoise.SetCellularReturnType(FastNoise::CellularReturnType::NoiseLookup);
break;*/
case EFastNoise_CellularReturnType::Distance:
fastNoise.SetCellularReturnType(FastNoise::CellularReturnType::Distance);
break;
case EFastNoise_CellularReturnType::Distance2:
fastNoise.SetCellularReturnType(FastNoise::CellularReturnType::Distance2);
break;
case EFastNoise_CellularReturnType::Distance2Add:
fastNoise.SetCellularReturnType(FastNoise::CellularReturnType::Distance2Add);
break;
case EFastNoise_CellularReturnType::Distance2Sub:
fastNoise.SetCellularReturnType(FastNoise::CellularReturnType::Distance2Sub);
break;
case EFastNoise_CellularReturnType::Distance2Mul:
fastNoise.SetCellularReturnType(FastNoise::CellularReturnType::Distance2Mul);
break;
case EFastNoise_CellularReturnType::Distance2Div:
fastNoise.SetCellularReturnType(FastNoise::CellularReturnType::Distance2Div);
break;
case EFastNoise_CellularReturnType::CellValue:
default:
fastNoise.SetCellularReturnType(FastNoise::CellularReturnType::CellValue);
}
}
private:
FastNoise fastNoise;
bool bInitialized = false;
};

View File

@ -0,0 +1,36 @@
// Copyright 2021 Víctor Hernández (Rockam). All Rights Reserved.
using System.IO;
using UnrealBuildTool;
public class FastNoise : ModuleRules
{
public FastNoise(ReadOnlyTargetRules rules) : base(rules)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
}
);
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine"
}
);
DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
}
}

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Jordan Peck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,20 @@
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "FastNoiseModule.h"
#define LOCTEXT_NAMESPACE "FFastNoiseModule"
void FFastNoiseModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
}
void FFastNoiseModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FFastNoiseModule, FastNoise)

View File

@ -0,0 +1,315 @@
#pragma once
#include "CoreMinimal.h"
// FastNoise.h
//
// MIT License
//
// Copyright(c) 2017 Jordan Peck
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// The developer's email is jorzixdan.me2@gzixmail.com (for great email, take
// off every 'zix'.)
//
// VERSION: 0.4.1
#ifndef FASTNOISE_H
#define FASTNOISE_H
// Uncomment the line below to use doubles throughout FastNoise instead of floats
//#define FN_USE_DOUBLES
#define FN_CELLULAR_INDEX_MAX 3
#ifdef FN_USE_DOUBLES
typedef double FN_DECIMAL;
#else
typedef float FN_DECIMAL;
#endif
class FASTNOISE_API FastNoise
{
public:
explicit FastNoise(int seed = 1337) { SetSeed(seed); CalculateFractalBounding(); }
enum NoiseType { Value, ValueFractal, Perlin, PerlinFractal, Simplex, SimplexFractal, Cellular, WhiteNoise, Cubic, CubicFractal };
enum Interp { Linear, Hermite, Quintic };
enum FractalType { FBM, Billow, RigidMulti };
enum CellularDistanceFunction { Euclidean, Manhattan, Natural };
enum CellularReturnType { CellValue, NoiseLookup, Distance, Distance2, Distance2Add, Distance2Sub, Distance2Mul, Distance2Div };
// Sets seed used for all noise types
// Default: 1337
void SetSeed(int seed);
// Returns seed used for all noise types
int GetSeed() const { return m_seed; }
// Sets frequency for all noise types
// Default: 0.01
void SetFrequency(FN_DECIMAL frequency) { m_frequency = frequency; }
// Returns frequency used for all noise types
FN_DECIMAL GetFrequency() const { return m_frequency; }
// Changes the interpolation method used to smooth between noise values
// Possible interpolation methods (lowest to highest quality) :
// - Linear
// - Hermite
// - Quintic
// Used in Value, Perlin Noise and Position Warping
// Default: Quintic
void SetInterp(Interp interp) { m_interp = interp; }
// Returns interpolation method used for supported noise types
Interp GetInterp() const { return m_interp; }
// Sets noise return type of GetNoise(...)
// Default: Simplex
void SetNoiseType(NoiseType noiseType) { m_noiseType = noiseType; }
// Returns the noise type used by GetNoise
NoiseType GetNoiseType() const { return m_noiseType; }
// Sets octave count for all fractal noise types
// Default: 3
void SetFractalOctaves(int octaves) { m_octaves = octaves; CalculateFractalBounding(); }
// Returns octave count for all fractal noise types
int GetFractalOctaves() const { return m_octaves; }
// Sets octave lacunarity for all fractal noise types
// Default: 2.0
void SetFractalLacunarity(FN_DECIMAL lacunarity) { m_lacunarity = lacunarity; }
// Returns octave lacunarity for all fractal noise types
FN_DECIMAL GetFractalLacunarity() const { return m_lacunarity; }
// Sets octave gain for all fractal noise types
// Default: 0.5
void SetFractalGain(FN_DECIMAL gain) { m_gain = gain; CalculateFractalBounding(); }
// Returns octave gain for all fractal noise types
FN_DECIMAL GetFractalGain() const { return m_gain; }
// Sets method for combining octaves in all fractal noise types
// Default: FBM
void SetFractalType(FractalType fractalType) { m_fractalType = fractalType; }
// Returns method for combining octaves in all fractal noise types
FractalType GetFractalType() const { return m_fractalType; }
// Sets distance function used in cellular noise calculations
// Default: Euclidean
void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { m_cellularDistanceFunction = cellularDistanceFunction; }
// Returns the distance function used in cellular noise calculations
CellularDistanceFunction GetCellularDistanceFunction() const { return m_cellularDistanceFunction; }
// Sets return type from cellular noise calculations
// Note: NoiseLookup requires another FastNoise object be set with SetCellularNoiseLookup() to function
// Default: CellValue
void SetCellularReturnType(CellularReturnType cellularReturnType) { m_cellularReturnType = cellularReturnType; }
// Returns the return type from cellular noise calculations
CellularReturnType GetCellularReturnType() const { return m_cellularReturnType; }
// Noise used to calculate a cell value if cellular return type is NoiseLookup
// The lookup value is acquired through GetNoise() so ensure you SetNoiseType() on the noise lookup, value, Perlin or simplex is recommended
void SetCellularNoiseLookup(FastNoise* noise) { m_cellularNoiseLookup = noise; }
// Returns the noise used to calculate a cell value if the cellular return type is NoiseLookup
FastNoise* GetCellularNoiseLookup() const { return m_cellularNoiseLookup; }
// Sets the 2 distance indices used for distance2 return types
// Default: 0, 1
// Note: index0 should be lower than index1
// Both indices must be >= 0, index1 must be < 4
void SetCellularDistance2Indices(int cellularDistanceIndex0, int cellularDistanceIndex1);
// Returns the 2 distance indices used for distance2 return types
void GetCellularDistance2Indices(int& cellularDistanceIndex0, int& cellularDistanceIndex1) const;
// Sets the maximum distance a cellular point can move from its grid position
// Setting this high will make artifacts more common
// Default: 0.45
void SetCellularJitter(FN_DECIMAL cellularJitter) { m_cellularJitter = cellularJitter; }
// Returns the maximum distance a cellular point can move from its grid position
FN_DECIMAL GetCellularJitter() const { return m_cellularJitter; }
// Sets the maximum warp distance from original location when using GradientPerturb{Fractal}(...)
// Default: 1.0
void SetGradientPerturbAmp(FN_DECIMAL gradientPerturbAmp) { m_gradientPerturbAmp = gradientPerturbAmp; }
// Returns the maximum warp distance from original location when using GradientPerturb{Fractal}(...)
FN_DECIMAL GetGradientPerturbAmp() const { return m_gradientPerturbAmp; }
//2D
FN_DECIMAL GetValue(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetValueFractal(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetPerlin(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetPerlinFractal(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetSimplex(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetSimplexFractal(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetCellular(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetWhiteNoise(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetWhiteNoiseInt(int x, int y) const;
FN_DECIMAL GetCubic(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetCubicFractal(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL GetNoise(FN_DECIMAL x, FN_DECIMAL y) const;
void GradientPerturb(FN_DECIMAL& x, FN_DECIMAL& y) const;
void GradientPerturbFractal(FN_DECIMAL& x, FN_DECIMAL& y) const;
//3D
FN_DECIMAL GetValue(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetValueFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetPerlin(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetPerlinFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetSimplex(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetSimplexFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetCellular(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetWhiteNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetWhiteNoiseInt(int x, int y, int z) const;
FN_DECIMAL GetCubic(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetCubicFractal(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL GetNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
void GradientPerturb(FN_DECIMAL& x, FN_DECIMAL& y, FN_DECIMAL& z) const;
void GradientPerturbFractal(FN_DECIMAL& x, FN_DECIMAL& y, FN_DECIMAL& z) const;
//4D
FN_DECIMAL GetSimplex(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w) const;
FN_DECIMAL GetWhiteNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w) const;
FN_DECIMAL GetWhiteNoiseInt(int x, int y, int z, int w) const;
private:
unsigned char m_perm[512];
unsigned char m_perm12[512];
int m_seed = 1337;
FN_DECIMAL m_frequency = FN_DECIMAL(0.01);
Interp m_interp = Quintic;
NoiseType m_noiseType = Simplex;
int m_octaves = 3;
FN_DECIMAL m_lacunarity = FN_DECIMAL(2);
FN_DECIMAL m_gain = FN_DECIMAL(0.5);
FractalType m_fractalType = FBM;
FN_DECIMAL m_fractalBounding;
CellularDistanceFunction m_cellularDistanceFunction = Euclidean;
CellularReturnType m_cellularReturnType = CellValue;
FastNoise* m_cellularNoiseLookup = nullptr;
int m_cellularDistanceIndex0 = 0;
int m_cellularDistanceIndex1 = 1;
FN_DECIMAL m_cellularJitter = FN_DECIMAL(0.45);
FN_DECIMAL m_gradientPerturbAmp = FN_DECIMAL(1);
void CalculateFractalBounding();
//2D
FN_DECIMAL SingleValueFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleValueFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleValueFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleValue(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SinglePerlinFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SinglePerlinFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SinglePerlinFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SinglePerlin(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleSimplexFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleSimplexFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleSimplexFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleSimplexFractalBlend(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleCubicFractalFBM(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleCubicFractalBillow(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleCubicFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleCubic(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleCellular(FN_DECIMAL x, FN_DECIMAL y) const;
FN_DECIMAL SingleCellular2Edge(FN_DECIMAL x, FN_DECIMAL y) const;
void SingleGradientPerturb(unsigned char offset, FN_DECIMAL warpAmp, FN_DECIMAL frequency, FN_DECIMAL& x, FN_DECIMAL& y) const;
//3D
FN_DECIMAL SingleValueFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleValueFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleValueFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleValue(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SinglePerlinFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SinglePerlinFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SinglePerlinFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SinglePerlin(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleSimplexFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleSimplexFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleSimplexFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCubicFractalFBM(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCubicFractalBillow(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCubicFractalRigidMulti(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCubic(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCellular(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
FN_DECIMAL SingleCellular2Edge(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z) const;
void SingleGradientPerturb(unsigned char offset, FN_DECIMAL warpAmp, FN_DECIMAL frequency, FN_DECIMAL& x, FN_DECIMAL& y, FN_DECIMAL& z) const;
//4D
FN_DECIMAL SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w) const;
inline unsigned char Index2D_12(unsigned char offset, int x, int y) const;
inline unsigned char Index3D_12(unsigned char offset, int x, int y, int z) const;
inline unsigned char Index4D_32(unsigned char offset, int x, int y, int z, int w) const;
inline unsigned char Index2D_256(unsigned char offset, int x, int y) const;
inline unsigned char Index3D_256(unsigned char offset, int x, int y, int z) const;
inline unsigned char Index4D_256(unsigned char offset, int x, int y, int z, int w) const;
inline FN_DECIMAL ValCoord2DFast(unsigned char offset, int x, int y) const;
inline FN_DECIMAL ValCoord3DFast(unsigned char offset, int x, int y, int z) const;
inline FN_DECIMAL GradCoord2D(unsigned char offset, int x, int y, FN_DECIMAL xd, FN_DECIMAL yd) const;
inline FN_DECIMAL GradCoord3D(unsigned char offset, int x, int y, int z, FN_DECIMAL xd, FN_DECIMAL yd, FN_DECIMAL zd) const;
inline FN_DECIMAL GradCoord4D(unsigned char offset, int x, int y, int z, int w, FN_DECIMAL xd, FN_DECIMAL yd, FN_DECIMAL zd, FN_DECIMAL wd) const;
};
#endif

View File

@ -0,0 +1,15 @@
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"
class FFastNoiseModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
};