Ejemplo n.º 1
0
        /// <summary>
        /// Returns settings value at given point.
        /// </summary>
        /// <param name="x">X coordinate</param>
        /// <param name="y">Y coordinate</param>
        /// <param name="z">Z coordinate</param>
        /// <returns>Noise value</returns>
        public override float GetValue(float x, float y, float z)
        {
            int ix = Mathf.FloorToInt(x);
            int iy = Mathf.FloorToInt(y);

            // interpolate the coordinates instead of values - it's way faster
            float xs = SCurve.Interpolate(x - ix);
            float ys = SCurve.Interpolate(y - iy);

            // THEN we can use linear interp to find our value - biliear actually

            float n0  = m_Source.GetValue(ix, iy, 0);
            float n1  = m_Source.GetValue(ix + 1, iy, 0);
            float ix0 = Mathf.Lerp(n0, n1, xs);

            n0 = m_Source.GetValue(ix, iy + 1, 0);
            n1 = m_Source.GetValue(ix + 1, iy + 1, 0);
            float ix1 = Mathf.Lerp(n0, n1, xs);

            return(Mathf.Lerp(ix0, ix1, ys));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create new generator with specified seed and interpolation algorithm. Different interpolation algorithms can make noise smoother at the expense of speed.
 /// </summary>
 /// <param name="seed">noise seed</param>
 /// <param name="sCurve">Interpolator to use. Can be null, in which case default will be used</param>
 public GradientNoise(int seed, SCurve sCurve)
 {
     m_seed   = seed;
     m_SCurve = sCurve;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create new generator with specified seed and interpolation algorithm. Different interpolation algorithms can make noise smoother at the expense of speed.
 /// </summary>
 /// <param name="seed">noise seed</param>
 /// <param name="sCurve">Interpolator to use. Can be null, in which case default will be used</param>
 public ValueNoise(int seed, SCurve sCurve)
 {
     m_source = new LatticeNoise(seed);
     m_SCurve = sCurve;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Create new generator with specified seed and interpolation algorithm. Different interpolation algorithms can make noise smoother at the expense of speed.
 /// </summary>
 /// <param name="seed">noise seed</param>
 /// <param name="sCurve">Interpolator to use. Can be null, in which case default will be used</param>
 public ValueNoise(int seed, SCurve sCurve)
 {
     m_Source = new CoherentNoise.LatticeNoise(seed);
     m_SCurve = sCurve;
 }