コード例 #1
0
        /// <summary>
        /// Returns noise 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);
            int iz = Mathf.FloorToInt(z);

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

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

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

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

            float iy0 = Mathf.Lerp(ix0, ix1, ys);

            n0  = m_Source.GetValue(ix, iy, iz + 1);
            n1  = m_Source.GetValue(ix + 1, iy, iz + 1);
            ix0 = Mathf.Lerp(n0, n1, xs);             // on y=0, z=1 edge

            n0  = m_Source.GetValue(ix, iy + 1, iz + 1);
            n1  = m_Source.GetValue(ix + 1, iy + 1, iz + 1);
            ix1 = Mathf.Lerp(n0, n1, xs);             // on y=z=1 edge

            float iy1 = Mathf.Lerp(ix0, ix1, ys);

            return(Mathf.Lerp(iy0, iy1, zs));            // inside cube
        }
コード例 #2
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));
        }