Class PerlueNoise
java.lang.Object
com.github.yellowstonegames.grid.PerlueNoise
- All Implemented Interfaces:
INoise, Externalizable, Serializable
A mix of "Classic"
This tends to look fairly different from vanilla PerlinNoise or ValueNoise; it is capable of more chaotic arrangements of high and low values than either of those, but it still tends to have clusters of values of a specific size more often than clusters with very different sizes. In higher dimensions (4 and up, mainly), the value noise artifacts are more readily apparent. Using more octaves tends to improve the appearance of both this and PerlinNoise. In the highest dimensions this supports, PerlinNoise may have less-noticeable artifacts when compared to PerlueNoise.
PerlinNoise, written by Ken Perlin before he created Simplex Noise, with
ValueNoise calculated at the same time. This uses quintic interpolation throughout (which was an improvement
found in Simplex Noise), and has a single int seed. Perlue Noise can have significant grid-aligned and
45-degree-diagonal artifacts when too few octaves are used, but sometimes this is irrelevant, such as when sampling
3D noise on the surface of a sphere. These artifacts sometimes manifest as "waves" of quickly-changing and then
slowly-changing noise, when 3D noise uses time as the z axis.
This tends to look fairly different from vanilla PerlinNoise or ValueNoise; it is capable of more chaotic arrangements of high and low values than either of those, but it still tends to have clusters of values of a specific size more often than clusters with very different sizes. In higher dimensions (4 and up, mainly), the value noise artifacts are more readily apparent. Using more octaves tends to improve the appearance of both this and PerlinNoise. In the highest dimensions this supports, PerlinNoise may have less-noticeable artifacts when compared to PerlueNoise.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface INoise
INoise.Serializer -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatstatic final PerlueNoisestatic final floatstatic final floatstatic final floatstatic final floatstatic final floatint -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a copy of this PerlueNoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions.static floatequalize(float x, float add, float mul) Given inputs asxin the range -1.0 to 1.0 that are too biased towards 0.0, this "squashes" the range softly to widen it and spread it away from 0.0 without increasing bias anywhere else.booleanintGets the maximum dimension supported by this generator, which is 6.intGets the minimum dimension supported by this generator, which is 2.floatgetNoise(float x, float y) Gets 2D noise with a default or pre-set seed.floatgetNoise(float x, float y, float z) Gets 3D noise with a default or pre-set seed.floatgetNoise(float x, float y, float z, float w) Gets 4D noise with a default or pre-set seed.floatgetNoise(float x, float y, float z, float w, float u) Gets 5D noise with a default or pre-set seed.floatgetNoise(float x, float y, float z, float w, float u, float v) Gets 6D noise with a default or pre-set seed.floatgetNoiseWithSeed(float x, float y, float z, float w, float u, float v, long s) Gets 6D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, float z, float w, float u, long s) Gets 5D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, float z, float w, long s) Gets 4D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, float z, long s) Gets 3D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, long s) Gets 2D noise with a specific seed.longgetSeed()Gets the current seed of the generator, as a long (it is really an int).getTag()Returns the constant String"PluN"that identifies this in serialized Strings.protected static floatgradCoord2D(int seed, int x, int y, float xd, float yd) protected static floatgradCoord3D(int seed, int x, int y, int z, float xd, float yd, float zd) protected static floatgradCoord4D(int seed, int x, int y, int z, int w, float xd, float yd, float zd, float wd) protected static floatgradCoord5D(int seed, int x, int y, int z, int w, int u, float xd, float yd, float zd, float wd, float ud) protected static floatgradCoord6D(int seed, int x, int y, int z, int w, int u, int v, float xd, float yd, float zd, float wd, float ud, float vd) booleanReturns true because this generator can be seeded withsetSeed(long)and retrieved withgetSeed().inthashCode()static PerlueNoiserecreateFromString(String data) voidsetSeed(long seed) Sets the seed to the given int, or really the int portion of the given long.stringDeserialize(String data) Given a serialized String produced bystringSerialize(), reassigns this PerlueNoise to have the described state from the given String.Produces a String that describes everything needed to recreate this RawNoise in full.toString()Methods inherited from interface INoise
getNoise, getNoiseWithSeed, readExternal, writeExternal
-
Field Details
-
instance
-
SCALE2
public static final float SCALE2- See Also:
-
SCALE3
public static final float SCALE3- See Also:
-
SCALE4
public static final float SCALE4- See Also:
-
SCALE5
public static final float SCALE5- See Also:
-
SCALE6
public static final float SCALE6- See Also:
-
EQ_ADD_2
public static final float EQ_ADD_2- See Also:
-
EQ_ADD_3
public static final float EQ_ADD_3- See Also:
-
EQ_ADD_4
public static final float EQ_ADD_4- See Also:
-
EQ_ADD_5
public static final float EQ_ADD_5- See Also:
-
EQ_ADD_6
public static final float EQ_ADD_6- See Also:
-
EQ_MUL_2
public static final float EQ_MUL_2- See Also:
-
EQ_MUL_3
public static final float EQ_MUL_3- See Also:
-
EQ_MUL_4
public static final float EQ_MUL_4- See Also:
-
EQ_MUL_5
public static final float EQ_MUL_5- See Also:
-
EQ_MUL_6
public static final float EQ_MUL_6- See Also:
-
seed
public int seed
-
-
Constructor Details
-
PerlueNoise
public PerlueNoise() -
PerlueNoise
public PerlueNoise(int seed) -
PerlueNoise
public PerlueNoise(long seed) -
PerlueNoise
-
-
Method Details
-
getMinDimension
public int getMinDimension()Gets the minimum dimension supported by this generator, which is 2.- Specified by:
getMinDimensionin interfaceINoise- Returns:
- the minimum supported dimension, 2
-
getMaxDimension
public int getMaxDimension()Gets the maximum dimension supported by this generator, which is 6.- Specified by:
getMaxDimensionin interfaceINoise- Returns:
- the maximum supported dimension, 6
-
hasEfficientSetSeed
public boolean hasEfficientSetSeed()Returns true because this generator can be seeded withsetSeed(long)and retrieved withgetSeed().- Specified by:
hasEfficientSetSeedin interfaceINoise- Returns:
- true
-
setSeed
-
getSeed
-
getTag
-
copy
Creates a copy of this PerlueNoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions. This almost always just calls a copy constructor. -
gradCoord2D
protected static float gradCoord2D(int seed, int x, int y, float xd, float yd) -
gradCoord3D
protected static float gradCoord3D(int seed, int x, int y, int z, float xd, float yd, float zd) -
gradCoord4D
protected static float gradCoord4D(int seed, int x, int y, int z, int w, float xd, float yd, float zd, float wd) -
gradCoord5D
protected static float gradCoord5D(int seed, int x, int y, int z, int w, int u, float xd, float yd, float zd, float wd, float ud) -
gradCoord6D
protected static float gradCoord6D(int seed, int x, int y, int z, int w, int u, int v, float xd, float yd, float zd, float wd, float ud, float vd) -
equalize
public static float equalize(float x, float add, float mul) Given inputs asxin the range -1.0 to 1.0 that are too biased towards 0.0, this "squashes" the range softly to widen it and spread it away from 0.0 without increasing bias anywhere else.
This starts with a common sigmoid function,x / sqrt(x * x + add), but instead of approaching -1 and 1 but never reaching them, this multiplies the result so the line crosses -1 when x is -1, and crosses 1 when x is 1. It has a smooth derivative, if that matters to you.- Parameters:
x- a float between -1 and 1add- if greater than 1, this will have nearly no effect; the lower this goes below 1, the more this will separate results near the center of the range. This must be greater than or equal to 0.0mul- typically the result of calling(float) Math.sqrt(add + 1f)- Returns:
- a float with a slightly different distribution from
x, but still between -1 and 1
-
getNoise
public float getNoise(float x, float y) Description copied from interface:INoiseGets 2D noise with a default or pre-set seed. -
getNoiseWithSeed
public float getNoiseWithSeed(float x, float y, long s) Description copied from interface:INoiseGets 2D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floats- can be any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
getNoise
public float getNoise(float x, float y, float z) Description copied from interface:INoiseGets 3D noise with a default or pre-set seed. -
getNoiseWithSeed
public float getNoiseWithSeed(float x, float y, float z, long s) Description copied from interface:INoiseGets 3D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floats- can be any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
getNoise
public float getNoise(float x, float y, float z, float w) Description copied from interface:INoiseGets 4D noise with a default or pre-set seed. -
getNoiseWithSeed
public float getNoiseWithSeed(float x, float y, float z, float w, long s) Description copied from interface:INoiseGets 4D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floats- can be any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
getNoise
public float getNoise(float x, float y, float z, float w, float u) Description copied from interface:INoiseGets 5D noise with a default or pre-set seed.- Specified by:
getNoisein interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floatu- u position; can be any finite float- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
getNoiseWithSeed
public float getNoiseWithSeed(float x, float y, float z, float w, float u, long s) Description copied from interface:INoiseGets 5D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floatu- u position; can be any finite floats- can be any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
getNoise
public float getNoise(float x, float y, float z, float w, float u, float v) Description copied from interface:INoiseGets 6D noise with a default or pre-set seed.- Specified by:
getNoisein interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floatu- u position; can be any finite floatv- v position; can be any finite float- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
getNoiseWithSeed
public float getNoiseWithSeed(float x, float y, float z, float w, float u, float v, long s) Description copied from interface:INoiseGets 6D noise with a specific seed. If the seed cannot be retrieved or changed per-call, then this falls back to changing the position instead of the seed; you can check if this will happen withINoise.hasEfficientSetSeed().- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatz- z position; can be any finite floatw- w position; can be any finite floatu- u position; can be any finite floatv- v position; can be any finite floats- can be any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
stringSerialize
Produces a String that describes everything needed to recreate this RawNoise in full. This String can be read back in bystringDeserialize(String)to reassign the described state to another RawNoise.- Specified by:
stringSerializein interfaceINoise- Returns:
- a String that describes this PerlueNoise for serialization
-
stringDeserialize
Given a serialized String produced bystringSerialize(), reassigns this PerlueNoise to have the described state from the given String. The serialized String must have been produced by a PerlueNoise.- Specified by:
stringDeserializein interfaceINoise- Parameters:
data- a serialized String, typically produced bystringSerialize()- Returns:
- this PerlueNoise, after being modified (if possible)
-
recreateFromString
-
equals
-
hashCode
-
toString
-