Class ShapedFoamNoise
java.lang.Object
com.github.yellowstonegames.grid.ShapedFoamNoise
- All Implemented Interfaces:
INoise, Externalizable, Serializable
Foam noise code as an
This is normally a smooth type of noise that can work well using fewer octaves than simplex noise or value noise. It also tends to look similar in lower dimensions and higher dimensions, where some other kinds of noise (such as
INoise implementation, additionally taking a shape parameter for its interpolations
(to allow using something shaped differently from a cubic Hermite spline, which is otherwise the default).
This is normally a smooth type of noise that can work well using fewer octaves than simplex noise or value noise. It also tends to look similar in lower dimensions and higher dimensions, where some other kinds of noise (such as
SimplexNoise change their appearance quite a bit in 2D vs. 6D. Changing the shape with
setShape(float) can make this try to be smoother (with shape values greater than 1) or spiky (less than 1).- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface INoise
INoise.Serializer -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ShapedFoamNoiseprotected longUse the same seed for any noise that should be continuous (smooth) across calls to nearby points.protected floatThe shape parameter of the spline this uses to smooth value noise results. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a copy of this INoise, which should be a deep copy for any mutable state but can be shallow for immutable types such as functions.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 usinggetSeed().floatgetNoise(float x, float y, float z) Gets 3D noise usinggetSeed().floatgetNoise(float x, float y, float z, float w) Gets 4D foam noise usinggetSeed().floatgetNoise(float x, float y, float z, float w, float u) Gets 5D noise withgetSeed().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 seed) Gets 6D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, float z, float w, float u, long seed) Gets 5D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, float z, float w, long seed) Gets 4D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, float z, long seed) Gets 3D noise with a specific seed.floatgetNoiseWithSeed(float x, float y, long seed) Gets 2D noise with a specific seed.longgetSeed()Gets the current seed of the generator, as a long even if the seed is stored internally as an int.floatgetShape()getTag()Returns the String "SFoN", to be used as a unique tag for this generator.booleanReturns true because this generator can be seeded withsetSeed(long)and retrieved withgetSeed().inthashCode()static ShapedFoamNoiserecreateFromString(String data) voidsetSeed(long seed) Sets the seed to the given long, if long seeds are supported, or(int)seedif only int seeds are supported.voidsetShape(float shape) protected floatspline(float x) The smoothing function applied to an x-value between 0 and 1, both inclusive.stringDeserialize(String data) Given a serialized String produced byINoise.stringSerialize(), reassigns this INoise to have the described state from the given String.Produces a String that describes everything needed to recreate this INoise in full.toString()floatvalueNoise(float x, float y, float z, float w, float u, float v, long seed) floatvalueNoise(float x, float y, float z, float w, float u, long seed) Gets 5D value noise with the lowest, fastest level of detail.floatvalueNoise(float x, float y, float z, float w, long seed) Gets 4D value noise with the lowest, fastest level of detail.floatvalueNoise(float x, float y, float z, long seed) Gets value noise with the lowest, fastest level of detail.floatvalueNoise(float x, float y, long seed) Gets 2D value noise with the lowest, fastest level of detail.Methods inherited from interface INoise
getNoise, getNoiseWithSeed, readExternal, writeExternal
-
Field Details
-
seed
protected long seedUse the same seed for any noise that should be continuous (smooth) across calls to nearby points. -
shape
protected float shapeThe shape parameter of the spline this uses to smooth value noise results. This defaults to 2, which makes the shape similar to a cubic Hermite spline function, but can be 1 to linear-interpolate, or between 0 and 1 to make noise the opposite of smooth. -
instance
-
-
Constructor Details
-
ShapedFoamNoise
public ShapedFoamNoise() -
ShapedFoamNoise
public ShapedFoamNoise(long seed) -
ShapedFoamNoise
public ShapedFoamNoise(long seed, float shape)
-
-
Method Details
-
spline
protected float spline(float x) The smoothing function applied to an x-value between 0 and 1, both inclusive. This can use theshapevalue to determine how it works, but doesn't have to in subclasses. This defaults to usingMathTools.barronSpline(float, float, float)with 0.5f for turning, and the shape of this object for shape.- Parameters:
x- between 0 and 1, both inclusive- Returns:
- a float between 0 and 1, both inclusive
-
getNoise
-
getNoiseWithSeed
public float getNoiseWithSeed(float x, float y, long seed) Gets 2D noise with a specific seed.- Specified by:
getNoiseWithSeedin interfaceINoise- Parameters:
x- x position; can be any finite floaty- y position; can be any finite floatseed- can be any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
valueNoise
public float valueNoise(float x, float y, long seed) Gets 2D value noise with the lowest, fastest level of detail. Uses the given seed and does not change x or y. This has a different output range (0 to 1) than foam noise.- Parameters:
x- x coordinatey- y coordinateseed- the seed to use for the noise (used in place ofgetSeed())- Returns:
- noise between 0 and 1
-
getNoise
-
getNoiseWithSeed
public float getNoiseWithSeed(float x, float y, float z, long seed) Gets 3D noise with a specific seed.- 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 floatseed- can be any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
valueNoise
public float valueNoise(float x, float y, float z, long seed) Gets value noise with the lowest, fastest level of detail. Uses the given seed and does not change x, y, or z. This has a different output range (0 to 1) than foam noise.- Parameters:
x- x coordinatey- y coordinatez- z coordinateseed- the seed to use for the noise (used in place ofgetSeed())- Returns:
- noise between 0 and 1
-
getNoise
-
getNoiseWithSeed
public float getNoiseWithSeed(float x, float y, float z, float w, long seed) Gets 4D noise with a specific seed.- 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 floatseed- can be any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
valueNoise
public float valueNoise(float x, float y, float z, float w, long seed) Gets 4D value noise with the lowest, fastest level of detail. Uses the given seed and does not change x, y, z, or w. This has a different output range (0 to 1) than foam noise.- Parameters:
x- x coordinatey- y coordinatez- z coordinatew- w coordinateseed- the seed to use for the noise (used in place ofgetSeed())- Returns:
- noise between 0 and 1
-
getNoise
public float getNoise(float x, float y, float z, float w, float u) Gets 5D noise withgetSeed().- 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 seed) Gets 5D noise with a specific seed.- 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 floatseed- any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
valueNoise
public float valueNoise(float x, float y, float z, float w, float u, long seed) Gets 5D value noise with the lowest, fastest level of detail. Uses the given seed and does not change x, y, z, w, or u. This has a different output range (0 to 1) than foam noise.- Parameters:
x- x coordinatey- y coordinatez- z coordinatew- w coordinateu- u coordinateseed- the seed to use for the noise (used in place ofgetSeed())- Returns:
- noise between 0 and 1
-
getNoise
public float getNoise(float x, float y, float z, float w, float u, float v) Gets 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 seed) Gets 6D noise with a specific seed.- 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 floatseed- any long- Returns:
- a noise value between -1.0f and 1.0f, both inclusive
-
valueNoise
public float valueNoise(float x, float y, float z, float w, float u, float v, long seed) -
getTag
-
getMinDimension
public int getMinDimension()Gets the minimum dimension supported by this generator, which is 2.- Specified by:
getMinDimensionin interfaceINoise- Returns:
- the minimum supported dimension, which is 2 inclusive
-
getMaxDimension
public int getMaxDimension()Gets the maximum dimension supported by this generator, which is 6.- Specified by:
getMaxDimensionin interfaceINoise- Returns:
- the maximum supported dimension, which is 6 inclusive
-
hasEfficientSetSeed
public boolean hasEfficientSetSeed()Returns true because this generator can be seeded withsetSeed(long)and retrieved withgetSeed().- Specified by:
hasEfficientSetSeedin interfaceINoise- Returns:
- true
-
setSeed
public void setSeed(long seed) Description copied from interface:INoiseSets the seed to the given long, if long seeds are supported, or(int)seedif only int seeds are supported. If this generator cannot be seeded, this should do nothing, and should not throw an exception. If this operation allocates or is time-intensive, thenINoise.hasEfficientSetSeed()should return false. That method is checked inINoise.getNoiseWithSeed(float, float, long), and if it returns false, the noise call will avoid calling setSeed(). You can always at least try to set the seed, even if it does nothing or is heavy on performance, and doing it a few times each frame should typically be fine for any generator. In the case this is called thousands of times each frame, checkINoise.hasEfficientSetSeed(). -
getSeed
public long getSeed()Description copied from interface:INoiseGets the current seed of the generator, as a long even if the seed is stored internally as an int. This must be implemented, but if the generator doesn't have a seed that can be expressed as a long (potentially usingBitConversion.floatToIntBits(float)), this can just return0. -
getShape
public float getShape() -
setShape
public void setShape(float shape) -
stringSerialize
Description copied from interface:INoiseProduces a String that describes everything needed to recreate this INoise in full. This String can be read back in byINoise.stringDeserialize(String)to reassign the described state to another INoise. The syntax here should always start and end with the`character, which is used byINoise.stringDeserialize(String)to identify the portion of a String that can be read back. The`character should not be otherwise used unless to serialize another INoise that this uses.
If you useBaseto produce String representations for numeric fields in an INoise,Base.BASE10is strongly recommended; in most cases, you can just use string concatenation with the fields separated by the tilde character,"~". For printing a floatfieldwith Base to a StringBuildersb, useBase.BASE10.appendGeneral(sb, field).
The default implementation throws anUnsupportedOperationExceptiononly. INoise classes do not have to implement any serialization methods, but they aren't serializable by the methods in this class or inINoise.Serializerunless they do implement this,INoise.getTag(),INoise.stringDeserialize(String), andINoise.copy().- Specified by:
stringSerializein interfaceINoise- Returns:
- a String that describes this INoise for serialization
-
stringDeserialize
Description copied from interface:INoiseGiven a serialized String produced byINoise.stringSerialize(), reassigns this INoise to have the described state from the given String. The serialized String must have been produced by the same class as this object is.
Any class that implementsINoise.stringSerialize()should also implement this method in a compatible way. Using base-10 is expected for most uses. UsingBase.BASE10.readFloat(data, start, end)may be useful to parse only the part of data between start and end.
The default implementation throws anUnsupportedOperationExceptiononly. INoise classes do not have to implement any serialization methods, but they aren't serializable by the methods in this class or inINoise.Serializerunless they do implement this,INoise.getTag(),INoise.stringSerialize(), andINoise.copy().- Specified by:
stringDeserializein interfaceINoise- Parameters:
data- a serialized String, typically produced byINoise.stringSerialize()- Returns:
- this INoise, after being modified (if possible)
-
recreateFromString
-
copy
Description copied from interface:INoiseCreates a copy of this INoise, 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.
The default implementation throws anUnsupportedOperationExceptiononly. Implementors are strongly encouraged to implement this in general, and that is required to use an INoise class withINoise.Serializer. -
toString
-
equals
-
hashCode
-