Changes ParallaxGenerator to use FastNoiseLite (#36214)
Instead of the NoiseGenerator we use FastNoiseLite If I'm correct, after this we'll be able to remove NoiseGenerator and FastNoise from the codebase entirely!
This commit is contained in:
@@ -131,7 +131,7 @@ namespace Content.Client.Parallax
|
|||||||
{
|
{
|
||||||
private readonly Color InnerColor = Color.White;
|
private readonly Color InnerColor = Color.White;
|
||||||
private readonly Color OuterColor = Color.Black;
|
private readonly Color OuterColor = Color.Black;
|
||||||
private readonly NoiseGenerator.NoiseType NoiseType = NoiseGenerator.NoiseType.Fbm;
|
private readonly FastNoiseLite.FractalType NoiseType = FastNoiseLite.FractalType.FBm;
|
||||||
private readonly uint Seed = 1234;
|
private readonly uint Seed = 1234;
|
||||||
private readonly float Persistence = 0.5f;
|
private readonly float Persistence = 0.5f;
|
||||||
private readonly float Lacunarity = (float) (Math.PI / 3);
|
private readonly float Lacunarity = (float) (Math.PI / 3);
|
||||||
@@ -204,10 +204,10 @@ namespace Content.Client.Parallax
|
|||||||
switch (((TomlValue<string>) tomlObject).Value)
|
switch (((TomlValue<string>) tomlObject).Value)
|
||||||
{
|
{
|
||||||
case "fbm":
|
case "fbm":
|
||||||
NoiseType = NoiseGenerator.NoiseType.Fbm;
|
NoiseType = FastNoiseLite.FractalType.FBm;
|
||||||
break;
|
break;
|
||||||
case "ridged":
|
case "ridged":
|
||||||
NoiseType = NoiseGenerator.NoiseType.Ridged;
|
NoiseType = FastNoiseLite.FractalType.Ridged;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
@@ -217,14 +217,11 @@ namespace Content.Client.Parallax
|
|||||||
|
|
||||||
public override void Apply(Image<Rgba32> bitmap)
|
public override void Apply(Image<Rgba32> bitmap)
|
||||||
{
|
{
|
||||||
var noise = new NoiseGenerator(NoiseType);
|
var noise = new FastNoiseLite((int)Seed);
|
||||||
noise.SetSeed(Seed);
|
noise.SetFractalType(NoiseType);
|
||||||
noise.SetFrequency(Frequency);
|
noise.SetFrequency(Frequency);
|
||||||
noise.SetPersistence(Persistence);
|
noise.SetFractalLacunarity(Lacunarity);
|
||||||
noise.SetLacunarity(Lacunarity);
|
noise.SetFractalOctaves((int)Octaves);
|
||||||
noise.SetOctaves(Octaves);
|
|
||||||
noise.SetPeriodX(bitmap.Width);
|
|
||||||
noise.SetPeriodY(bitmap.Height);
|
|
||||||
var threshVal = 1 / (1 - Threshold);
|
var threshVal = 1 / (1 - Threshold);
|
||||||
var powFactor = 1 / Power;
|
var powFactor = 1 / Power;
|
||||||
|
|
||||||
@@ -268,7 +265,7 @@ namespace Content.Client.Parallax
|
|||||||
|
|
||||||
// Noise mask stuff.
|
// Noise mask stuff.
|
||||||
private readonly bool Masked;
|
private readonly bool Masked;
|
||||||
private readonly NoiseGenerator.NoiseType MaskNoiseType = NoiseGenerator.NoiseType.Fbm;
|
private readonly FastNoiseLite.FractalType MaskNoiseType = FastNoiseLite.FractalType.FBm;
|
||||||
private readonly uint MaskSeed = 1234;
|
private readonly uint MaskSeed = 1234;
|
||||||
private readonly float MaskPersistence = 0.5f;
|
private readonly float MaskPersistence = 0.5f;
|
||||||
private readonly float MaskLacunarity = (float) (Math.PI * 2 / 3);
|
private readonly float MaskLacunarity = (float) (Math.PI * 2 / 3);
|
||||||
@@ -357,10 +354,10 @@ namespace Content.Client.Parallax
|
|||||||
switch (((TomlValue<string>) tomlObject).Value)
|
switch (((TomlValue<string>) tomlObject).Value)
|
||||||
{
|
{
|
||||||
case "fbm":
|
case "fbm":
|
||||||
MaskNoiseType = NoiseGenerator.NoiseType.Fbm;
|
MaskNoiseType = FastNoiseLite.FractalType.FBm;
|
||||||
break;
|
break;
|
||||||
case "ridged":
|
case "ridged":
|
||||||
MaskNoiseType = NoiseGenerator.NoiseType.Ridged;
|
MaskNoiseType = FastNoiseLite.FractalType.Ridged;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
@@ -439,14 +436,10 @@ namespace Content.Client.Parallax
|
|||||||
{
|
{
|
||||||
var o = PointSize - 1;
|
var o = PointSize - 1;
|
||||||
var random = new Random(Seed);
|
var random = new Random(Seed);
|
||||||
var noise = new NoiseGenerator(MaskNoiseType);
|
var noise = new FastNoiseLite((int)MaskSeed);
|
||||||
noise.SetSeed(MaskSeed);
|
noise.SetFractalType(MaskNoiseType);
|
||||||
noise.SetFrequency(MaskFrequency);
|
noise.SetFractalLacunarity(MaskLacunarity);
|
||||||
noise.SetPersistence(MaskPersistence);
|
noise.SetFractalOctaves((int)MaskOctaves);
|
||||||
noise.SetLacunarity(MaskLacunarity);
|
|
||||||
noise.SetOctaves(MaskOctaves);
|
|
||||||
noise.SetPeriodX(buffer.Width);
|
|
||||||
noise.SetPeriodY(buffer.Height);
|
|
||||||
|
|
||||||
var threshVal = 1 / (1 - MaskThreshold);
|
var threshVal = 1 / (1 - MaskThreshold);
|
||||||
var powFactor = 1 / MaskPower;
|
var powFactor = 1 / MaskPower;
|
||||||
|
|||||||
Reference in New Issue
Block a user