/// <summary> /// Generates a gradient-coherent-noise value from the coordinates of a /// three-dimensional input value. /// </summary> /// <remarks> /// <para> /// The return value ranges from -1.0 to +1.0. /// </para> /// <para> /// For an explanation of the difference between gradient noise and /// value noise, see the comments for the <see cref="GradientNoise3D" /> function. /// </para> /// </remarks> /// <param name="x">The x coordinate of the input value.</param> /// <param name="y">The y coordinate of the input value.</param> /// <param name="z">The z coordinate of the input value.</param> /// <param name="seed">The random number seed.</param> /// <param name="noiseQuality">The quality of the coherent-noise.</param> /// <returns>The generated gradient-coherent-noise value.</returns> public static double GradientCoherentNoise1D(double x, int seed = 0, NoiseQuality noiseQuality = NoiseQuality.Standard) { // Create a unit-length cube aligned along an integer boundary. This cube // surrounds the input point. int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; // Map the difference between the coordinates of the input value and the // coordinates of the cube's outer-lower-left vertex onto an S-curve. double xs = 0, ys = 0; switch (noiseQuality) { case NoiseQuality.Fast: xs = (x - x0); break; case NoiseQuality.Standard: xs = Interp.SCurve3(x - x0); break; case NoiseQuality.Best: xs = Interp.SCurve5(x - x0); break; } // Now calculate the noise values at each vertex of the cube. To generate // the coherent-noise value at the input point, interpolate these eight // noise values using the S-curve value as the interpolant (trilinear // interpolation.) double n0 = GradientNoise1D(x, x0, seed); double n1 = GradientNoise1D(x, x1, seed); return(Interp.LinearInterp(n0, n1, xs)); }
} //end GetValue #endregion #region ValueNoise1D /// <summary> /// Generates a value-coherent-noise value from the coordinates of a /// one-dimensional input value. /// /// The return value ranges from -1.0 to +1.0. /// /// </summary> /// <param name="x">The x coordinate of the input value</param> /// <param name="seed">The random number seed</param> /// <param name="quality">The quality of the coherent-noise</param> /// <returns>The generated value-coherent-noise value</returns> public static float ValueCoherentNoise1D(float x, long seed, NoiseQuality quality) { // Create a unit-length line aligned along an integer boundary. // This line surrounds the input point. int x0 = (x > 0.0 ? (int)x: (int)x - 1); int x1 = x0 + 1; float xs = 0; switch (quality) { case NoiseQuality.Fast: xs = (x - (float)x0); break; case NoiseQuality.Standard: xs = Libnoise.SCurve3(x - (float)x0); break; case NoiseQuality.Best: xs = Libnoise.SCurve5(x - (float)x0); break; } //end switch // Now calculate the noise values at each point of the line. To generate // the coherent-noise value at the input point, interpolate these two // noise values using the S-curve value as the interpolant (trilinear // interpolation.) float n0, n1; n0 = ValueNoise1D(x0, seed); n1 = ValueNoise1D(x1, seed); return(Libnoise.Lerp(n0, n1, xs)); } //end ValueCoherentNoise1D
public double Noise1D(double x, NoiseQuality quality) { //returns a noise value between -0.5 and 0.5 int ix0, ix1; double fx0, fx1; double s, n0, n1; ix0 = NoiseHelper.FastFloor(x); // Fractional part of x & y if (quality == NoiseQuality.Low) { fx0 = x - ix0; } else if (quality == NoiseQuality.Standard) { fx0 = MathEx.SCurve3(x - ix0); } else { fx0 = MathEx.SCurve5(x - ix0); } fx1 = fx0 - 1.0f; ix1 = (ix0 + 1) & 0xff; ix0 = ix0 & 0xff; // Wrap to 0..255 s = FADE(fx0); n0 = GRAD1(m_perm[ix0], fx0); n1 = GRAD1(m_perm[ix1], fx1); return(0.188f * LERP(s, n0, n1)); }
protected bool GetNoiseQualityInput(IGH_DataAccess DA, ref NoiseQuality noiseQuality) { int q = 0; if (!DA.GetData(1, ref q)) { return(false); } switch (q) { case 0: noiseQuality = NoiseQuality.Standard; break; case 1: noiseQuality = NoiseQuality.Fast; break; case 2: noiseQuality = NoiseQuality.Best; break; default: noiseQuality = NoiseQuality.Standard; AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Quality must be between 0 and 2."); break; } return(true); }
public float getValue(Vector3 cubeWorldPosition) { this.frequency = 0.5f; this.lacunarity = 2; this.offset = 1; this.gain = 2; this.exponent = 1f; this.octaveCount = 4f; this.gradient = GradientColors.Grayscale; this.quality = PrimitiveModule.DefaultQuality; this.primitive = NoisePrimitive.ImprovedPerlin; this.filter = NoiseFilter.MultiFractal; this.pModule = new ImprovedPerlin(); this.pModule.Quality = quality; this.pModule.Seed = seed; this.fModule = new MultiFractal(); this.scale = new ScaleBias(fModule, 1f, -0.8f); this.fModule.Frequency = frequency; this.fModule.Lacunarity = lacunarity; this.fModule.OctaveCount = octaveCount; this.fModule.Offset = offset; this.fModule.Gain = gain; this.fModule.Primitive3D = (IModule3D)pModule; this.finalModule = scale; return(this.finalModule.GetValue(cubeWorldPosition.X, cubeWorldPosition.Y, cubeWorldPosition.Z)); }
/// <summary> /// Create a new ImprovedPerlin with given values /// </summary> /// <param name="seed"></param> /// <param name="quality"></param> public SimplexPerlin(int seed, NoiseQuality quality) : base(seed, quality) { this._perm = new int[1024]; this._perm2D = new int[1024]; this._perm2DSph2 = new int[1024]; this._perm3D = new int[1024]; int[] source = new int[1024]; for (int i = 0; i < 1024; i++) { source[i] = i; } for (int i = 1023; i >= 0; i--) { seed = (int)((seed * 6364136223846793005L + 1442695040888963407L) % int.MaxValue); int r = (int)((seed + 31) % (i + 1)); if (r < 0) { r += (i + 1); } _perm[i] = source[r]; _perm2D[i] = _perm[i] % 12 * 2; _perm2DSph2[i] = _perm[i] / 12 % 12 * 2; _perm3D[i] = _perm[i] % 48 * 3; source[r] = source[i]; } }
public static float ValueCoherentNoise1D(float x, long seed, NoiseQuality quality) { int num = (!((double)x > 0.0)) ? ((int)x - 1) : ((int)x); int x2 = num + 1; float a = 0f; switch (quality) { case NoiseQuality.Fast: a = x - (float)num; break; case NoiseQuality.Standard: a = Libnoise.SCurve3(x - (float)num); break; case NoiseQuality.Best: a = Libnoise.SCurve5(x - (float)num); break; } float n = ValueNoise1D(num, seed); float n2 = ValueNoise1D(x2, seed); return(Libnoise.Lerp(n, n2, a)); }
} //end ImprovedPerlin /// <summary> /// Create a new ImprovedPerlin with given values /// </summary> /// <param name="seed"></param> /// <param name="quality"></param> public ImprovedPerlin(int seed, NoiseQuality quality) { _seed = seed; _quality = quality; Randomize(_seed); } //end ImprovedPerlin
/// Generates a gradient-coherent-noise value from the coordinates of a /// three-dimensional input value. /// /// @param x The @a x coordinate of the input value. /// @param y The @a y coordinate of the input value. /// @param z The @a z coordinate of the input value. /// @param seed The random number seed. /// @param noiseQuality The quality of the coherent-noise. /// /// @returns The generated gradient-coherent-noise value. /// /// The return value ranges from -1.0 to +1.0. /// /// For an explanation of the difference between <i>gradient</i> noise and /// <i>value</i> noise, see the comments for the GradientNoise3D() function. public static double GradientCoherentNoise3D(double x, double y, double z, int seed = 0, NoiseQuality noiseQuality = NoiseQuality.QUALITY_STD) { // Create a unit-length cube aligned along an integer boundary. This cube // surrounds the input point. int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int)y : (int)y - 1); int y1 = y0 + 1; int z0 = (z > 0.0 ? (int)z : (int)z - 1); int z1 = z0 + 1; // Map the difference between the coordinates of the input value and the // coordinates of the cube's outer-lower-left vertex onto an S-curve. double xs = 0, ys = 0, zs = 0; switch (noiseQuality) { case NoiseQuality.QUALITY_FAST: xs = (x - (double)x0); ys = (y - (double)y0); zs = (z - (double)z0); break; case NoiseQuality.QUALITY_STD: xs = Interp.SCurve3(x - (double)x0); ys = Interp.SCurve3(y - (double)y0); zs = Interp.SCurve3(z - (double)z0); break; case NoiseQuality.QUALITY_BEST: xs = Interp.SCurve5(x - (double)x0); ys = Interp.SCurve5(y - (double)y0); zs = Interp.SCurve5(z - (double)z0); break; } // Now calculate the noise values at each vertex of the cube. To generate // the coherent-noise value at the input point, interpolate these eight // noise values using the S-curve value as the interpolant (trilinear // interpolation.) double n0, n1, ix0, ix1, iy0, iy1; n0 = GradientNoise3D(x, y, z, x0, y0, z0, seed); n1 = GradientNoise3D(x, y, z, x1, y0, z0, seed); ix0 = Interp.LinearInterp(n0, n1, xs); n0 = GradientNoise3D(x, y, z, x0, y1, z0, seed); n1 = GradientNoise3D(x, y, z, x1, y1, z0, seed); ix1 = Interp.LinearInterp(n0, n1, xs); iy0 = Interp.LinearInterp(ix0, ix1, ys); n0 = GradientNoise3D(x, y, z, x0, y0, z1, seed); n1 = GradientNoise3D(x, y, z, x1, y0, z1, seed); ix0 = Interp.LinearInterp(n0, n1, xs); n0 = GradientNoise3D(x, y, z, x0, y1, z1, seed); n1 = GradientNoise3D(x, y, z, x1, y1, z1, seed); ix1 = Interp.LinearInterp(n0, n1, xs); iy1 = Interp.LinearInterp(ix0, ix1, ys); return(Interp.LinearInterp(iy0, iy1, zs)); }
public FastRidgedMultifractal(int seed) : base(seed) { Frequency = 1.0; Lacunarity = 2.0; OctaveCount = 6; NoiseQuality = NoiseQuality.Standard; }
public HybridMultiFractal3DPrimitive(double frequency, double scale, int seed, NoiseQuality quality) { this.frequency = frequency; this.scale = scale; noise = new HybridMultiFractal { Primitive3D = new SimplexPerlin(seed, quality) }; }
public RidgedMultifractal() { Frequency = 1.0f; Lacunarity = 2.0f; OctaveCount = 6; NoiseQuality = NoiseQuality.Standard; Seed = 0; }
public RidgedMulti(double frequency, double lacunaruity, int octaves, NoiseQuality quality, int seed) { Frequency = frequency; OctaveCount = octaves; Quality = quality; Seed = seed; Lacunaruty = lacunaruity; }
public Perlin() { Frequency = DefaultPerlinFrequency; OctaveCount = DefaultPerlinOctaveCount; Persistence = DefaultPerlinPersistence; Lacunarity = DefaultPerlinLacunarity; Quality = DefaultPerlinQuality; Seed = DefaultPerlinSeed; }
public Billow() : base(4) { // Frequency = 1.0; // Lacunarity = 2.0; // mOctaveCount = 6; // Persistence = 0.5; NoiseQuality = NoiseQuality.Standard; Seed = 0; }
public override void OnEditorGUI(UltimateTerrain uTerrain, IReadOnlyFlowGraph graph) { #if UNITY_EDITOR frequency = EditorGUILayout.FloatField("Frequency:", frequency); scale = EditorGUILayout.FloatField("Scale:", scale); seed = EditorGUILayout.IntField("Seed:", seed); quality = (NoiseQuality)EditorGUILayout.EnumPopup("Quality:", quality); #endif }
public RidgedMultifractal() : base(5) { //Frequency = 1.0; //Lacunarity = 2.0; // OctaveCount = 6; // Gain = 2; NoiseQuality = NoiseQuality.Standard; Seed = 0; }
public Perlin(double frequency, double lacunarity, NoiseQuality quality, uint octaveCount, double persistence, int seed) { Frequency = frequency; Lacunarity = lacunarity; Quality = quality; OctaveCount = octaveCount; Persistence = persistence; Seed = seed; }
public static double GradientCoherentNoise(double x, double y, double z, int seed, NoiseQuality noiseQuality) { int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int)y : (int)y - 1); int y1 = y0 + 1; int z0 = (z > 0.0 ? (int)z : (int)z - 1); int z1 = z0 + 1; double xs = 0, ys = 0, zs = 0; switch (noiseQuality) { case NoiseQuality.Low: xs = (x - x0); ys = (y - y0); zs = (z - z0); break; case NoiseQuality.Standard: xs = Loonim.Math.SCurve3(x - x0); ys = Loonim.Math.SCurve3(y - y0); zs = Loonim.Math.SCurve3(z - z0); break; case NoiseQuality.High: xs = Loonim.Math.SCurve5(x - x0); ys = Loonim.Math.SCurve5(y - y0); zs = Loonim.Math.SCurve5(z - z0); break; } // Now calculate the noise values at each vertex of the cube. To generate // the coherent-noise value at the input point, interpolate these eight // noise values using the S-curve value as the interpolant (trilinear // interpolation.) double n0, n1, ix0, ix1, iy0, iy1; n0 = Gradient(x, y, z, x0, y0, z0, seed); n1 = Gradient(x, y, z, x1, y0, z0, seed); ix0 = Loonim.Math.LinearInterpolate(n0, n1, xs); n0 = Gradient(x, y, z, x0, y1, z0, seed); n1 = Gradient(x, y, z, x1, y1, z0, seed); ix1 = Loonim.Math.LinearInterpolate(n0, n1, xs); iy0 = Loonim.Math.LinearInterpolate(ix0, ix1, ys); n0 = Gradient(x, y, z, x0, y0, z1, seed); n1 = Gradient(x, y, z, x1, y0, z1, seed); ix0 = Loonim.Math.LinearInterpolate(n0, n1, xs); n0 = Gradient(x, y, z, x0, y1, z1, seed); n1 = Gradient(x, y, z, x1, y1, z1, seed); ix1 = Loonim.Math.LinearInterpolate(n0, n1, xs); iy1 = Loonim.Math.LinearInterpolate(ix0, ix1, ys); return(Loonim.Math.LinearInterpolate(iy0, iy1, zs)); }
public ExDistPerlin(Double frequency, Double lacunarity, Double persistence, Double mu, Int32 octaves, Int32 seed, NoiseQuality quality) { Frequency = frequency; Lacunarity = lacunarity; Persistence = persistence; Mu = mu; OctaveCount = octaves; Seed = seed; Quality = quality; }
public override void OnEditorGUI(UltimateTerrain uTerrain, IReadOnlyFlowGraph graph) { #if UNITY_EDITOR Frequency = EditorGUILayout.FloatField("Frequency:", Frequency); Scale = EditorGUILayout.FloatField("Scale:", Scale); offset = EditorGUILayout.Vector3Field("Offset:", offset); Seed = EditorGUILayout.IntField("Seed:", Seed); Quality = (NoiseQuality)EditorGUILayout.EnumPopup("Quality:", Quality); #endif }
public static double GradientCoherentNoise3D(double x, double y, double z, int seed, NoiseQuality noiseQuality) { // Create a unit-length cube aligned along an integer boundary. This cube // surrounds the input point. int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int)y : (int)y - 1); int y1 = y0 + 1; int z0 = (z > 0.0 ? (int)z : (int)z - 1); int z1 = z0 + 1; // Map the difference between the coordinates of the input value and the // coordinates of the cube's outer-lower-left vertex onto an S-curve. double xs = 0, ys = 0, zs = 0; switch (noiseQuality) { case NoiseQuality.Fast: xs = (x - (double)x0); ys = (y - (double)y0); zs = (z - (double)z0); break; case NoiseQuality.Standard: xs = Interpolation.SCurve3(x - (double)x0); ys = Interpolation.SCurve3(y - (double)y0); zs = Interpolation.SCurve3(z - (double)z0); break; case NoiseQuality.Best: xs = Interpolation.SCurve5(x - (double)x0); ys = Interpolation.SCurve5(y - (double)y0); zs = Interpolation.SCurve5(z - (double)z0); break; } // Now calculate the noise values at each vertex of the cube. To generate // the coherent-noise value at the input point, interpolate these eight // noise values using the S-curve value as the interpolant (trilinear // interpolation.) double n0, n1, ix0, ix1, iy0, iy1; n0 = GradientNoise3D(x, y, z, x0, y0, z0, seed); n1 = GradientNoise3D(x, y, z, x1, y0, z0, seed); ix0 = Interpolation.LinearInterpolate(n0, n1, xs); n0 = GradientNoise3D(x, y, z, x0, y1, z0, seed); n1 = GradientNoise3D(x, y, z, x1, y1, z0, seed); ix1 = Interpolation.LinearInterpolate(n0, n1, xs); iy0 = Interpolation.LinearInterpolate(ix0, ix1, ys); n0 = GradientNoise3D(x, y, z, x0, y0, z1, seed); n1 = GradientNoise3D(x, y, z, x1, y0, z1, seed); ix0 = Interpolation.LinearInterpolate(n0, n1, xs); n0 = GradientNoise3D(x, y, z, x0, y1, z1, seed); n1 = GradientNoise3D(x, y, z, x1, y1, z1, seed); ix1 = Interpolation.LinearInterpolate(n0, n1, xs); iy1 = Interpolation.LinearInterpolate(ix0, ix1, ys); return Interpolation.LinearInterpolate(iy0, iy1, zs); }
/// <summary> /// Code original : libnoise. /// Portage vers C# par l'équipe du projet. /// </summary> public float ValueCoherentNoise3D(float x, float y, float z, int seed, NoiseQuality noiseQuality) { // Create a unit-length cube aligned along an integer boundary. This cube // surrounds the input point. int x0 = (x > (float)0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; int y0 = (y > (float)0.0 ? (int)y : (int)y - 1); int y1 = y0 + 1; int z0 = (z > (float)0.0 ? (int)z : (int)z - 1); int z1 = z0 + 1; // Map the difference between the coordinates of the input value and the // coordinates of the cube's outer-lower-left vertex onto an S-curve. float xs = 0, ys = 0, zs = 0; switch (noiseQuality) { case NoiseQuality.QUALITY_FAST: xs = (x - (float)x0); ys = (y - (float)y0); zs = (z - (float)z0); break; case NoiseQuality.QUALITY_STD: xs = SCurve3(x - (float)x0); ys = SCurve3(y - (float)y0); zs = SCurve3(z - (float)z0); break; case NoiseQuality.QUALITY_BEST: xs = SCurve5(x - (float)x0); ys = SCurve5(y - (float)y0); zs = SCurve5(z - (float)z0); break; } // Now calculate the noise values at each vertex of the cube. To generate // the coherent-noise value at the input point, interpolate these eight // noise values using the S-curve value as the interpolant (trilinear // interpolation.) float n0, n1, ix0, ix1, iy0, iy1; n0 = ValueNoise3D(x0, y0, z0, seed); n1 = ValueNoise3D(x1, y0, z0, seed); ix0 = LinearInterp(n0, n1, xs); n0 = ValueNoise3D(x0, y1, z0, seed); n1 = ValueNoise3D(x1, y1, z0, seed); ix1 = LinearInterp(n0, n1, xs); iy0 = LinearInterp(ix0, ix1, ys); n0 = ValueNoise3D(x0, y0, z1, seed); n1 = ValueNoise3D(x1, y0, z1, seed); ix0 = LinearInterp(n0, n1, xs); n0 = ValueNoise3D(x0, y1, z1, seed); n1 = ValueNoise3D(x1, y1, z1, seed); ix1 = LinearInterp(n0, n1, xs); iy1 = LinearInterp(ix0, ix1, ys); return LinearInterp(iy0, iy1, zs); }
public PerlinConfig(float lacunarity, float frequency, float persistance, int octaves, NoiseQuality quality, NoiseConfig cfg ) : base(cfg) { Lacunarity = lacunarity; Frequency = frequency; Persistance = persistance; Octaves = octaves; Quality = quality; }
public double ValueCoherentNoise3D(double x, double y, double z, int seed, NoiseQuality noiseQuality) { //Create unit-length cube aligned along an integer boundary int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int)y : (int)y - 1); int y1 = y0 + 1; int z0 = (z > 0.0 ? (int)z : (int)z - 1); int z1 = z0 + 1; //Map the difference between the coordinates of input value double xs = 0, ys = 0, zs = 0; switch (noiseQuality) { case NoiseQuality.Fast: xs = (x - (double)x0); ys = (y - (double)y0); zs = (z - (double)z0); break; case NoiseQuality.Standard: xs = MathUtils.SCurve3(x - (double)x0); ys = MathUtils.SCurve3(y - (double)y0); zs = MathUtils.SCurve3(z - (double)z0); break; case NoiseQuality.Best: xs = MathUtils.SCurve5(x - (double)x0); ys = MathUtils.SCurve5(y - (double)y0); zs = MathUtils.SCurve5(z - (double)z0); break; } //Now calculate noise values at each vertex of the cube. double n0, n1, ix0, ix1, iy0, iy1; n0 = ValueNoise3D(x0, y0, z0, seed); n1 = ValueNoise3D(x1, y0, z0, seed); ix0 = MathUtils.LinearInterp(n0, n1, xs); n0 = ValueNoise3D(x0, y1, z0, seed); n1 = ValueNoise3D(x1, y1, z0, seed); ix1 = MathUtils.LinearInterp(n0, n1, xs); iy0 = MathUtils.LinearInterp(ix0, ix1, ys); n0 = ValueNoise3D(x0, y0, z1, seed); n1 = ValueNoise3D(x1, y0, z1, seed); ix0 = MathUtils.LinearInterp(n0, n1, xs); n0 = ValueNoise3D(x0, y1, z1, seed); n1 = ValueNoise3D(x1, y1, z1, seed); ix1 = MathUtils.LinearInterp(n0, n1, xs); iy1 = MathUtils.LinearInterp(ix0, ix1, ys); return(MathUtils.LinearInterp(iy0, iy1, zs)); }
public double GradientCoherentNoise(double x, double y, double z, int seed, NoiseQuality noiseQuality) { int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int)y : (int)y - 1); int y1 = y0 + 1; int z0 = (z > 0.0 ? (int)z : (int)z - 1); int z1 = z0 + 1; double xs = 0, ys = 0, zs = 0; switch (noiseQuality) { case NoiseQuality.Low: xs = (x - x0); ys = (y - y0); zs = (z - z0); break; case NoiseQuality.Standard: xs = SCurve3(x - x0); ys = SCurve3(y - y0); zs = SCurve3(z - z0); break; case NoiseQuality.High: xs = SCurve5(x - x0); ys = SCurve5(y - y0); zs = SCurve5(z - z0); break; } double n0, n1, ix0, ix1, iy0, iy1; n0 = GradientNoise(x, y, z, x0, y0, z0, seed); n1 = GradientNoise(x, y, z, x1, y0, z0, seed); ix0 = LinearInterpolate(n0, n1, xs); n0 = GradientNoise(x, y, z, x0, y1, z0, seed); n1 = GradientNoise(x, y, z, x1, y1, z0, seed); ix1 = LinearInterpolate(n0, n1, xs); iy0 = LinearInterpolate(ix0, ix1, ys); n0 = GradientNoise(x, y, z, x0, y0, z1, seed); n1 = GradientNoise(x, y, z, x1, y0, z1, seed); ix0 = LinearInterpolate(n0, n1, xs); n0 = GradientNoise(x, y, z, x0, y1, z1, seed); n1 = GradientNoise(x, y, z, x1, y1, z1, seed); ix1 = LinearInterpolate(n0, n1, xs); iy1 = LinearInterpolate(ix0, ix1, ys); return(LinearInterpolate(iy0, iy1, zs)); }
public Perlin(double frequency, double lacunarity, NoiseQuality noiseQuality, int octaveCount, double persistence, int seed) { if(octaveCount < 1 || octaveCount > PerlinMaxOctave) { throw new ArgumentException("Count was too high, above " + PerlinMaxOctave, "octaveCount"); } Seed = seed; Persistence = persistence; OctaveCount = octaveCount; NoiseQuality = noiseQuality; Lacunarity = lacunarity; Frequency = frequency; }
public Perlin(double frequency, double lacunarity, NoiseQuality noiseQuality, int octaveCount, double persistence, int seed) { if (octaveCount < 1 || octaveCount > PerlinMaxOctave) { throw new ArgumentException("Count was too high, above " + PerlinMaxOctave, "octaveCount"); } Seed = seed; Persistence = persistence; OctaveCount = octaveCount; NoiseQuality = noiseQuality; Lacunarity = lacunarity; Frequency = frequency; }
public float GradientCoherentNoise3D(float x, float y, float z, long seed, NoiseQuality quality) { int num = (!((double)x > 0.0)) ? ((int)x - 1) : ((int)x); int ix = num + 1; int num2 = (!((double)y > 0.0)) ? ((int)y - 1) : ((int)y); int iy = num2 + 1; int num3 = (!((double)z > 0.0)) ? ((int)z - 1) : ((int)z); int iz = num3 + 1; float a = 0f; float a2 = 0f; float a3 = 0f; switch (quality) { case NoiseQuality.Fast: a = x - (float)num; a2 = y - (float)num2; a3 = z - (float)num3; break; case NoiseQuality.Standard: a = Libnoise.SCurve3(x - (float)num); a2 = Libnoise.SCurve3(y - (float)num2); a3 = Libnoise.SCurve3(z - (float)num3); break; case NoiseQuality.Best: a = Libnoise.SCurve5(x - (float)num); a2 = Libnoise.SCurve5(y - (float)num2); a3 = Libnoise.SCurve5(z - (float)num3); break; } float n = GradientNoise3D(x, y, z, num, num2, num3, seed); float n2 = GradientNoise3D(x, y, z, ix, num2, num3, seed); float n3 = Libnoise.Lerp(n, n2, a); n = GradientNoise3D(x, y, z, num, iy, num3, seed); n2 = GradientNoise3D(x, y, z, ix, iy, num3, seed); float n4 = Libnoise.Lerp(n, n2, a); float n5 = Libnoise.Lerp(n3, n4, a2); n = GradientNoise3D(x, y, z, num, num2, iz, seed); n2 = GradientNoise3D(x, y, z, ix, num2, iz, seed); n3 = Libnoise.Lerp(n, n2, a); n = GradientNoise3D(x, y, z, num, iy, iz, seed); n2 = GradientNoise3D(x, y, z, ix, iy, iz, seed); n4 = Libnoise.Lerp(n, n2, a); float n6 = Libnoise.Lerp(n3, n4, a2); return(Libnoise.Lerp(n5, n6, a3)); }
public RidgedMulti(double lacunarity, double frequency, NoiseQuality noiseQuality, int octaveCount, int seed) { if(octaveCount < 1 || octaveCount > RidgedMaxOctave) { throw new ArgumentException("Count was too high, above " + RidgedMaxOctave, "octaveCount"); } Seed = seed; OctaveCount = octaveCount; spectralWeights = new double[RidgedMaxOctave]; NoiseQuality = noiseQuality; Frequency = frequency; Lacunarity = lacunarity; }
public RidgedMulti(double lacunarity, double frequency, NoiseQuality noiseQuality, int octaveCount, int seed) { if (octaveCount < 1 || octaveCount > RidgedMaxOctave) { throw new ArgumentException("Count was too high, above " + RidgedMaxOctave, "octaveCount"); } Seed = seed; OctaveCount = octaveCount; spectralWeights = new double[RidgedMaxOctave]; NoiseQuality = noiseQuality; Frequency = frequency; Lacunarity = lacunarity; }
} //end GetValue #endregion #region ValueCoherentNoise2D /// <summary> /// Generates a value-coherent-noise value from the coordinates of a /// two-dimensional input value. /// /// The return value ranges from -1.0 to +1.0. /// /// </summary> /// <param name="x">The x coordinate of the input value</param> /// <param name="y">The y coordinate of the input value</param> /// <param name="seed">The random number seed</param> /// <param name="quality">The quality of the coherent-noise</param> /// <returns>The generated value-coherent-noise value</returns> public float ValueCoherentNoise2D(float x, float y, long seed, NoiseQuality quality) { // Create a unit-length square aligned along an integer boundary. // This square surrounds the input point. int x0 = (x > 0.0 ? (int)x: (int)x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int)y: (int)y - 1); int y1 = y0 + 1; // Map the difference between the coordinates of the input value and the // coordinates of the cube's outer-lower-left vertex onto an S-curve. float xs = 0, ys = 0; switch (quality) { case NoiseQuality.Fast: xs = (x - (float)x0); ys = (y - (float)y0); break; case NoiseQuality.Standard: xs = Libnoise.SCurve3(x - (float)x0); ys = Libnoise.SCurve3(y - (float)y0); break; case NoiseQuality.Best: xs = Libnoise.SCurve5(x - (float)x0); ys = Libnoise.SCurve5(y - (float)y0); break; } //end switch // Now calculate the noise values at each point of the square. To generate // the coherent-noise value at the input point, interpolate these four // noise values using the S-curve value as the interpolant (trilinear // interpolation.) float n0, n1, ix0, ix1; n0 = ValueNoise2D(x0, y0, seed); n1 = ValueNoise2D(x1, y0, seed); ix0 = Libnoise.Lerp(n0, n1, xs); n0 = ValueNoise2D(x0, y1, seed); n1 = ValueNoise2D(x1, y1, seed); ix1 = Libnoise.Lerp(n0, n1, xs); return(Libnoise.Lerp(ix0, ix1, ys)); } //end ValueCoherentNoise2D
public double GradientCoherentNoise(double x, double y, double z, int seed, NoiseQuality noiseQuality) { int x0 = (x > 0.0 ? (int)x : (int)x - 1); int y0 = (y > 0.0 ? (int)y : (int)y - 1); int z0 = (z > 0.0 ? (int)z : (int)z - 1); int X = x0 & 255; int Y = y0 & 255; int Z = z0 & 255; double x1 = 0, y1 = 0, z1 = 0; switch (noiseQuality) { case NoiseQuality.Low: x1 = (x - x0); y1 = (y - y0); z1 = (z - z0); break; case NoiseQuality.Standard: x1 = Loonim.Math.SCurve3(x - x0); y1 = Loonim.Math.SCurve3(y - y0); z1 = Loonim.Math.SCurve3(z - z0); break; case NoiseQuality.High: x1 = Loonim.Math.SCurve5(x - x0); y1 = Loonim.Math.SCurve5(y - y0); z1 = Loonim.Math.SCurve5(z - z0); break; } int A = SelectedPermutations[X] + Y; int AA = SelectedPermutations[A] + Z; int AB = SelectedPermutations[A + 1] + Z; int B = SelectedPermutations[X + 1] + Y; int BA = SelectedPermutations[B] + Z; int BB = SelectedPermutations[B + 1] + Z; double a = Loonim.Math.LinearInterpolate(GradientTable[AA], GradientTable[BA], x1); double b = Loonim.Math.LinearInterpolate(GradientTable[AB], GradientTable[BB], x1); double c = Loonim.Math.LinearInterpolate(a, b, y1); double d = Loonim.Math.LinearInterpolate(GradientTable[AA + 1], GradientTable[BA + 1], x1); double e = Loonim.Math.LinearInterpolate(GradientTable[AB + 1], GradientTable[BB + 1], x1); double f = Loonim.Math.LinearInterpolate(d, e, y1); return(Loonim.Math.LinearInterpolate(c, f, z1)); }
public double GradientCoherentNoise(double x, double y, double z, int seed, NoiseQuality noiseQuality) { var x0 = (x > 0.0 ? (int)x : (int)x - 1); var y0 = (y > 0.0 ? (int)y : (int)y - 1); var z0 = (z > 0.0 ? (int)z : (int)z - 1); var xbit = x0 & 255; var ybit = y0 & 255; var zbit = z0 & 255; double u, v, w; switch (noiseQuality) { case NoiseQuality.Low: { u = (x - x0); v = (y - y0); w = (z - z0); break; } case NoiseQuality.Standard: { u = SCurve3(x - x0); v = SCurve3(y - y0); w = SCurve3(z - z0); break; } case NoiseQuality.High: { u = SCurve5(x - x0); v = SCurve5(y - y0); w = SCurve5(z - z0); break; } default: { throw new Exception("Invalid noise quality!"); } } int abit = SelectedPermutations[xbit] + ybit, abitabit = SelectedPermutations[abit] + zbit, abitbbit = SelectedPermutations[abit + 1] + zbit; int bbit = SelectedPermutations[xbit + 1] + ybit, bbitabit = SelectedPermutations[bbit] + zbit, bbitbbit = SelectedPermutations[bbit + 1] + zbit; var a = LinearInterpolate(GradientTable[abitabit], GradientTable[bbitabit], u); var b = LinearInterpolate(GradientTable[abitbbit], GradientTable[bbitbbit], u); var c = LinearInterpolate(a, b, v); var d = LinearInterpolate(GradientTable[abitabit + 1], GradientTable[bbitabit + 1], u); var e = LinearInterpolate(GradientTable[abitbbit + 1], GradientTable[bbitbbit + 1], u); var f = LinearInterpolate(d, e, v); return LinearInterpolate(c, f, w); }
public double Noise2D(double x, double y, NoiseQuality quality) { //returns a noise value between -0.75 and 0.75 int ix0, iy0, ix1, iy1; double fx0, fy0, fx1, fy1, s, t, nx0, nx1, n0, n1; ix0 = NoiseHelper.FastFloor(x); // Integer part of x iy0 = NoiseHelper.FastFloor(y); // Integer part of y // Fractional part of x & y if (quality == NoiseQuality.Low) { fx0 = x - ix0; fy0 = y - iy0; } else if (quality == NoiseQuality.Standard) { fx0 = MathEx.SCurve3(x - ix0); fy0 = MathEx.SCurve3(y - iy0); } else { fx0 = MathEx.SCurve5(x - ix0); fy0 = MathEx.SCurve5(y - iy0); } fx1 = fx0 - 1.0f; fy1 = fy0 - 1.0f; ix1 = (ix0 + 1) & 0xff; // Wrap to 0..255 iy1 = (iy0 + 1) & 0xff; ix0 = ix0 & 0xff; iy0 = iy0 & 0xff; t = FADE(fy0); s = FADE(fx0); nx0 = GRAD2(m_perm[ix0 + m_perm[iy0]], fx0, fy0); nx1 = GRAD2(m_perm[ix0 + m_perm[iy1]], fx0, fy1); n0 = LERP(t, nx0, nx1); nx0 = GRAD2(m_perm[ix1 + m_perm[iy0]], fx1, fy0); nx1 = GRAD2(m_perm[ix1 + m_perm[iy1]], fx1, fy1); n1 = LERP(t, nx0, nx1); return(0.507f * LERP(s, n0, n1)); }
public double GradientCoherentNoise(double x, double y, double z, int seed, NoiseQuality noiseQuality) { int x0 = (x > 0.0 ? (int)x : (int)x - 1); int y0 = (y > 0.0 ? (int)y : (int)y - 1); int z0 = (z > 0.0 ? (int)z : (int)z - 1); int X = x0 & 255; int Y = y0 & 255; int Z = z0 & 255; double u = 0, v = 0, w = 0; switch (noiseQuality) { case NoiseQuality.Low: u = (x - x0); v = (y - y0); w = (z - z0); break; case NoiseQuality.Standard: u = SCurve3(x - x0); v = SCurve3(y - y0); w = SCurve3(z - z0); break; case NoiseQuality.High: u = SCurve5(x - x0); v = SCurve5(y - y0); w = SCurve5(z - z0); break; } int A = SelectedPermutations[X] + Y, AA = SelectedPermutations[A] + Z, AB = SelectedPermutations[A + 1] + Z, B = SelectedPermutations[X + 1] + Y, BA = SelectedPermutations[B] + Z, BB = SelectedPermutations[B + 1] + Z; double a = LinearInterpolate(GradientTable[AA], GradientTable[BA], u); double b = LinearInterpolate(GradientTable[AB], GradientTable[BB], u); double c = LinearInterpolate(a, b, v); double d = LinearInterpolate(GradientTable[AA + 1], GradientTable[BA + 1], u); double e = LinearInterpolate(GradientTable[AB + 1], GradientTable[BB + 1], u); double f = LinearInterpolate(d, e, v); return(LinearInterpolate(c, f, w)); }
public double GradientCoherentNoise(double x, double y, double z, int seed, NoiseQuality noiseQuality) { int x0 = (x > 0.0 ? (int)x : (int)x - 1); int y0 = (y > 0.0 ? (int)y : (int)y - 1); int z0 = (z > 0.0 ? (int)z : (int)z - 1); int X = x0 & 255; int Y = y0 & 255; int Z = z0 & 255; double u = 0, v = 0, w = 0; switch (noiseQuality) { case NoiseQuality.Low: u = (x - x0); v = (y - y0); w = (z - z0); break; case NoiseQuality.Standard: u = SCurve3(x - x0); v = SCurve3(y - y0); w = SCurve3(z - z0); break; case NoiseQuality.High: u = SCurve5(x - x0); v = SCurve5(y - y0); w = SCurve5(z - z0); break; } int A = SelectedPermutations[X] + Y, AA = SelectedPermutations[A] + Z, AB = SelectedPermutations[A + 1] + Z, B = SelectedPermutations[X + 1] + Y, BA = SelectedPermutations[B] + Z, BB = SelectedPermutations[B + 1] + Z; double a = LinearInterpolate(GradientTable[AA], GradientTable[BA], u); double b = LinearInterpolate(GradientTable[AB], GradientTable[BB], u); double c = LinearInterpolate(a, b, v); double d = LinearInterpolate(GradientTable[AA + 1], GradientTable[BA + 1], u); double e = LinearInterpolate(GradientTable[AB + 1], GradientTable[BB + 1], u); double f = LinearInterpolate(d, e, v); return LinearInterpolate(c, f, w); }
public HeightmapGenerator(int size) { this.size = size; seed = 0; octaves = 2; frequency = 0.01f; lacunarity = 2.0f; quality = NoiseQuality.Standard; primitive = new ImprovedPerlin(); primitive.Quality = quality; primitive.Seed = seed; filter = new RidgedMultiFractal(); filter.Frequency = frequency; filter.Lacunarity = lacunarity; filter.OctaveCount = octaves; filter.Primitive3D = (IModule3D)primitive; scale = new ScaleBias(filter, 1f, 0); }
/// <summary> /// A basic connstrucutor /// </summary> /// <param name="seed"></param> /// <param name="quality"></param> public PrimitiveModule(int seed, NoiseQuality quality) { _seed = seed; _quality = quality; }
/// <summary> /// Create a new BevinsValueNoise with given values. /// </summary> /// <param name="seed">Seed.</param> /// <param name="quality">Quality.</param> public BevinsValue(int seed, NoiseQuality quality) { Seed = seed; Quality = quality; }
/// <summary> /// Generates a value-coherent-noise value from the coordinates of a /// one-dimensional input value. /// /// The return value ranges from -1.0 to +1.0. /// /// </summary> /// <param name="x">The x coordinate of the input value</param> /// <param name="seed">The random number seed</param> /// <param name="quality">The quality of the coherent-noise</param> /// <returns>The generated value-coherent-noise value</returns> public static float ValueCoherentNoise1D(float x, long seed, NoiseQuality quality) { // Create a unit-length line aligned along an integer boundary. // This line surrounds the input point. int x0 = (x > 0.0 ? (int) x : (int) x - 1); int x1 = x0 + 1; float xs = 0; switch (quality) { case NoiseQuality.Fast: xs = (x - x0); break; case NoiseQuality.Standard: xs = Libnoise.SCurve3(x - x0); break; case NoiseQuality.Best: xs = Libnoise.SCurve5(x - x0); break; } // Now calculate the noise values at each point of the line. To generate // the coherent-noise value at the input point, interpolate these two // noise values using the S-curve value as the interpolant (trilinear // interpolation.) float n0, n1; n0 = ValueNoise1D(x0, seed); n1 = ValueNoise1D(x1, seed); return Libnoise.Lerp(n0, n1, xs); }
/// <summary> /// Generates a value-coherent-noise value from the coordinates of a /// two-dimensional input value. /// /// The return value ranges from -1.0 to +1.0. /// /// </summary> /// <param name="x">The x coordinate of the input value</param> /// <param name="y">The y coordinate of the input value</param> /// <param name="seed">The random number seed</param> /// <param name="quality">The quality of the coherent-noise</param> /// <returns>The generated value-coherent-noise value</returns> public float ValueCoherentNoise2D(float x, float y, long seed, NoiseQuality quality) { // Create a unit-length square aligned along an integer boundary. // This square surrounds the input point. int x0 = (x > 0.0 ? (int) x : (int) x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int) y : (int) y - 1); int y1 = y0 + 1; // Map the difference between the coordinates of the input value and the // coordinates of the cube's outer-lower-left vertex onto an S-curve. float xs = 0, ys = 0; switch (quality) { case NoiseQuality.Fast: xs = (x - x0); ys = (y - y0); break; case NoiseQuality.Standard: xs = Libnoise.SCurve3(x - x0); ys = Libnoise.SCurve3(y - y0); break; case NoiseQuality.Best: xs = Libnoise.SCurve5(x - x0); ys = Libnoise.SCurve5(y - y0); break; } // Now calculate the noise values at each point of the square. To generate // the coherent-noise value at the input point, interpolate these four // noise values using the S-curve value as the interpolant (trilinear // interpolation.) float n0, n1, ix0, ix1; n0 = ValueNoise2D(x0, y0, seed); n1 = ValueNoise2D(x1, y0, seed); ix0 = Libnoise.Lerp(n0, n1, xs); n0 = ValueNoise2D(x0, y1, seed); n1 = ValueNoise2D(x1, y1, seed); ix1 = Libnoise.Lerp(n0, n1, xs); return Libnoise.Lerp(ix0, ix1, ys); }
/// <summary> /// Create a new ImprovedPerlin with given values /// </summary> /// <param name="seed"></param> /// <param name="quality"></param> public ImprovedPerlin(int seed, NoiseQuality quality) { _seed = seed; _quality = quality; Randomize(_seed); }
/// <summary> /// Create a new BevinsGradientNoise with given values /// </summary> /// <param name="seed"></param> /// <param name="quality"></param> public BevinsGradient(int seed, NoiseQuality quality) { Seed = seed; Quality = quality; }
/// <summary> /// Create a new ImprovedPerlin with given values /// </summary> /// <param name="seed"></param> /// <param name="quality"></param> public SimplexPerlin(int seed, NoiseQuality quality) : base(seed, quality) { }
}//end BevinsGradient /// <summary> /// Create a new BevinsGradientNoise with given values /// </summary> /// <param name="seed"></param> /// <param name="quality"></param> public BevinsGradient(int seed, NoiseQuality quality) { _seed = seed; _quality = quality; }//end BevinsGradient
/// <summary> /// Generates a gradient-coherent-noise value from the coordinates of a /// three-dimensional input value. /// </summary> /// <remarks> /// <para> /// The return value ranges from -1.0 to +1.0. /// </para> /// <para> /// For an explanation of the difference between gradient noise and /// value noise, see the comments for the <see cref="GradientNoise3D" /> function. /// </para> /// </remarks> /// <param name="x">The x coordinate of the input value.</param> /// <param name="y">The y coordinate of the input value.</param> /// <param name="z">The z coordinate of the input value.</param> /// <param name="seed">The random number seed.</param> /// <param name="noiseQuality">The quality of the coherent-noise.</param> /// <returns>The generated gradient-coherent-noise value.</returns> public static double GradientCoherentNoise1D(double x, int seed = 0, NoiseQuality noiseQuality = NoiseQuality.Standard) { // Create a unit-length cube aligned along an integer boundary. This cube // surrounds the input point. int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; // Map the difference between the coordinates of the input value and the // coordinates of the cube's outer-lower-left vertex onto an S-curve. double xs = 0, ys = 0; switch(noiseQuality) { case NoiseQuality.Fast: xs = (x - x0); break; case NoiseQuality.Standard: xs = Interp.SCurve3(x - x0); break; case NoiseQuality.Best: xs = Interp.SCurve5(x - x0); break; } // Now calculate the noise values at each vertex of the cube. To generate // the coherent-noise value at the input point, interpolate these eight // noise values using the S-curve value as the interpolant (trilinear // interpolation.) double n0 = GradientNoise1D(x, x0, seed); double n1 = GradientNoise1D(x, x1, seed); return Interp.LinearInterp(n0, n1, xs); }
public double GradientCoherentNoise(double x, double y, double z, int seed, NoiseQuality noiseQuality) { int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int)y : (int)y - 1); int y1 = y0 + 1; int z0 = (z > 0.0 ? (int)z : (int)z - 1); int z1 = z0 + 1; double xs = 0, ys = 0, zs = 0; switch (noiseQuality) { case NoiseQuality.Low: xs = (x - x0); ys = (y - y0); zs = (z - z0); break; case NoiseQuality.Standard: xs = SCurve3(x - x0); ys = SCurve3(y - y0); zs = SCurve3(z - z0); break; case NoiseQuality.High: xs = SCurve5(x - x0); ys = SCurve5(y - y0); zs = SCurve5(z - z0); break; } double n0, n1, ix0, ix1, iy0, iy1; n0 = GradientNoise(x, y, z, x0, y0, z0, seed); n1 = GradientNoise(x, y, z, x1, y0, z0, seed); ix0 = LinearInterpolate(n0, n1, xs); n0 = GradientNoise(x, y, z, x0, y1, z0, seed); n1 = GradientNoise(x, y, z, x1, y1, z0, seed); ix1 = LinearInterpolate(n0, n1, xs); iy0 = LinearInterpolate(ix0, ix1, ys); n0 = GradientNoise(x, y, z, x0, y0, z1, seed); n1 = GradientNoise(x, y, z, x1, y0, z1, seed); ix0 = LinearInterpolate(n0, n1, xs); n0 = GradientNoise(x, y, z, x0, y1, z1, seed); n1 = GradientNoise(x, y, z, x1, y1, z1, seed); ix1 = LinearInterpolate(n0, n1, xs); iy1 = LinearInterpolate(ix0, ix1, ys); return LinearInterpolate(iy0, iy1, zs); }
/// <summary> /// Create a new ImprovedPerlin with given values /// </summary> /// <param name="seed"></param> /// <param name="quality"></param> public ImprovedPerlin(int seed, NoiseQuality quality) : base(seed, quality) { Randomize(Seed); }
public double ValueCoherentNoise3D(double x, double y, double z, int seed, NoiseQuality noiseQuality) { //Create unit-length cube aligned along an integer boundary int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int)y : (int)y - 1); int y1 = y0 + 1; int z0 = (z > 0.0 ? (int)z : (int)z - 1); int z1 = z0 + 1; //Map the difference between the coordinates of input value double xs = 0, ys = 0, zs = 0; switch (noiseQuality) { case NoiseQuality.Fast: xs = (x - (double)x0); ys = (y - (double)y0); zs = (z - (double)z0); break; case NoiseQuality.Standard: xs = MathUtils.SCurve3(x - (double)x0); ys = MathUtils.SCurve3(y - (double)y0); zs = MathUtils.SCurve3(z - (double)z0); break; case NoiseQuality.Best: xs = MathUtils.SCurve5(x - (double)x0); ys = MathUtils.SCurve5(y - (double)y0); zs = MathUtils.SCurve5(z - (double)z0); break; } //Now calculate noise values at each vertex of the cube. double n0, n1, ix0, ix1, iy0, iy1; n0 = ValueNoise3D(x0, y0, z0, seed); n1 = ValueNoise3D(x1, y0, z0, seed); ix0 = MathUtils.LinearInterp(n0, n1, xs); n0 = ValueNoise3D(x0, y1, z0, seed); n1 = ValueNoise3D(x1, y1, z0, seed); ix1 = MathUtils.LinearInterp(n0, n1, xs); iy0 = MathUtils.LinearInterp(ix0, ix1, ys); n0 = ValueNoise3D(x0, y0, z1, seed); n1 = ValueNoise3D(x1, y0, z1, seed); ix0 = MathUtils.LinearInterp(n0, n1, xs); n0 = ValueNoise3D(x0, y1, z1, seed); n1 = ValueNoise3D(x1, y1, z1, seed); ix1 = MathUtils.LinearInterp(n0, n1, xs); iy1 = MathUtils.LinearInterp(ix0, ix1, ys); return MathUtils.LinearInterp(iy0, iy1, zs); }
/// <summary> /// Generates a gradient-coherent-noise value from the coordinates of a /// three-dimensional input value. /// /// The return value ranges from -1.0 to +1.0. /// /// For an explanation of the difference between <i>gradient</i> noise and /// <i>value</i> noise, see the comments for the GradientNoise3D() function. /// </summary> /// <param name="x">The x coordinate of the input value</param> /// <param name="y">The y coordinate of the input value</param> /// <param name="z">The z coordinate of the input value</param> /// <param name="seed">seed The random number seed</param> /// <param name="quality">The quality of the coherent-noise</param> /// <returns>The generated gradient-coherent-noise value</returns> public float GradientCoherentNoise3D(float x, float y, float z, long seed, NoiseQuality quality) { // Create a unit-length cube aligned along an integer boundary. // This cube surrounds the input point. int x0 = (x > 0.0 ? (int) x : (int) x - 1); // FastFloor() int x1 = x0 + 1; int y0 = (y > 0.0 ? (int) y : (int) y - 1); int y1 = y0 + 1; int z0 = (z > 0.0 ? (int) z : (int) z - 1); int z1 = z0 + 1; // Map the difference between the coordinates of the input value and the // coordinates of the cube's outer-lower-left vertex onto an S-curve. float xs = 0, ys = 0, zs = 0; switch (quality) { case NoiseQuality.Fast: xs = (x - x0); ys = (y - y0); zs = (z - z0); break; case NoiseQuality.Standard: xs = Libnoise.SCurve3(x - x0); ys = Libnoise.SCurve3(y - y0); zs = Libnoise.SCurve3(z - z0); break; case NoiseQuality.Best: xs = Libnoise.SCurve5(x - x0); ys = Libnoise.SCurve5(y - y0); zs = Libnoise.SCurve5(z - z0); break; } // Now calculate the noise values at each vertex of the cube. To generate // the coherent-noise value at the input point, interpolate these eight // noise values using the S-curve value as the interpolant (trilinear // interpolation.) float n0, n1, ix0, ix1, iy0, iy1; n0 = GradientNoise3D(x, y, z, x0, y0, z0, seed); n1 = GradientNoise3D(x, y, z, x1, y0, z0, seed); ix0 = Libnoise.Lerp(n0, n1, xs); n0 = GradientNoise3D(x, y, z, x0, y1, z0, seed); n1 = GradientNoise3D(x, y, z, x1, y1, z0, seed); ix1 = Libnoise.Lerp(n0, n1, xs); iy0 = Libnoise.Lerp(ix0, ix1, ys); n0 = GradientNoise3D(x, y, z, x0, y0, z1, seed); n1 = GradientNoise3D(x, y, z, x1, y0, z1, seed); ix0 = Libnoise.Lerp(n0, n1, xs); n0 = GradientNoise3D(x, y, z, x0, y1, z1, seed); n1 = GradientNoise3D(x, y, z, x1, y1, z1, seed); ix1 = Libnoise.Lerp(n0, n1, xs); iy1 = Libnoise.Lerp(ix0, ix1, ys); return Libnoise.Lerp(iy0, iy1, zs); }
/// <summary> /// A basic connstrucutor /// </summary> /// <param name="seed"></param> /// <param name="quality"></param> protected PrimitiveModule(int seed, NoiseQuality quality) { _seed = seed; _quality = quality; }
public double GradientCoherentNoise(double x, double y, double z, int seed, NoiseQuality noiseQuality) { var x0 = (x > 0.0 ? (int)x : (int)x - 1); var x1 = x0 + 1; var y0 = (y > 0.0 ? (int)y : (int)y - 1); var y1 = y0 + 1; var z0 = (z > 0.0 ? (int)z : (int)z - 1); var z1 = z0 + 1; double xs, ys, zs; switch (noiseQuality) { case NoiseQuality.Low: { xs = (x - x0); ys = (y - y0); zs = (z - z0); break; } case NoiseQuality.Standard: { xs = SCurve3(x - x0); ys = SCurve3(y - y0); zs = SCurve3(z - z0); break; } case NoiseQuality.High: { xs = SCurve5(x - x0); ys = SCurve5(y - y0); zs = SCurve5(z - z0); break; } default: { throw new ArgumentOutOfRangeException(nameof(noiseQuality), noiseQuality, null); } } var n0 = GradientNoise(x, y, z, x0, y0, z0, seed); var n1 = GradientNoise(x, y, z, x1, y0, z0, seed); var ix0 = LinearInterpolate(n0, n1, xs); n0 = GradientNoise(x, y, z, x0, y1, z0, seed); n1 = GradientNoise(x, y, z, x1, y1, z0, seed); var ix1 = LinearInterpolate(n0, n1, xs); var iy0 = LinearInterpolate(ix0, ix1, ys); n0 = GradientNoise(x, y, z, x0, y0, z1, seed); n1 = GradientNoise(x, y, z, x1, y0, z1, seed); ix0 = LinearInterpolate(n0, n1, xs); n0 = GradientNoise(x, y, z, x0, y1, z1, seed); n1 = GradientNoise(x, y, z, x1, y1, z1, seed); ix1 = LinearInterpolate(n0, n1, xs); var iy1 = LinearInterpolate(ix0, ix1, ys); return LinearInterpolate(iy0, iy1, zs); }