/// <summary> /// Calculate a billow fractal /// </summary> /// <param name="x">x location</param> /// <param name="z">z location</param> /// <returns></returns> public float GetValue_Billow(float x, float z) { float value = 0f; float signal = 0f; float persistence = 1f; float nx, nz; x += m_seed; z += m_seed; x += m_XOffset; z += m_ZOffset; x *= m_frequency; z *= m_frequency; for (int octave = 0; octave < m_octaves; octave++) { nx = x; nz = z; signal = SimplexNoiseGenerator.Generate(nx, nz); signal = 2f * Mathf.Abs(signal) - 1f; value += signal * persistence; x *= m_lacunarity; z *= m_lacunarity; persistence *= m_persistence; } value += m_YOffset * 2.4f; return(value); }
/// <summary> /// Calculate a ridged multi fractal /// </summary> /// <param name="x">x location</param> /// <param name="z">z location</param> /// <returns></returns> public float GetValue_RidgedMulti(float x, float z) { float signal = 0.0f; float value = 0.0f; float weight = 1.0f; float offset = 1f; float gain = m_persistence; float nx, nz; x += m_seed; z += m_seed; x += m_XOffset; z += m_ZOffset; x *= m_frequency; z *= m_frequency; for (int octave = 0; octave < m_octaves; octave++) { nx = x; nz = z; //Get the coherent-noise value from input value and add it to final result signal = SimplexNoiseGenerator.Generate(nx, nz); //Make the ridges signal = Mathf.Abs(signal); signal = offset - signal; //Square signal to increase sharpness of ridges. signal *= signal; //The weighting from previous octave is applied to the signal. signal *= weight; //Weight successive contributions by previous signal. weight = signal * gain; if (weight > 1.0) { weight = 1.0f; } if (weight < 0.0f) { weight = 0.0f; } //Add the signal to output value. value += signal * m_spectralWeights[octave]; //Next Octave x *= m_lacunarity; z *= m_lacunarity; } value = (value * 1.25f) - 1.0f; value += m_YOffset; return(value); }