Beispiel #1
0
            /// <summary>
            /// Returns the noise value at the given coordinates.
            /// </summary>
            /// <param name="x"></param>
            /// <param name="y"></param>
            /// <returns></returns>
            public static double ValueAt(double x, double y)
            {
                // separate whole and fractional components
                x = SlurMath.Fract(x, out int i);
                y = SlurMath.Fract(y, out int j);

                // wrap to perm table
                i &= 255;
                j &= 255;

                // calculate noise contributions from each corner
                double n00 = GradDot(ToIndex(i, j), x, y);
                double n10 = GradDot(ToIndex(i + 1, j), x - 1.0, y);
                double n01 = GradDot(ToIndex(i, j + 1), x, y - 1.0);
                double n11 = GradDot(ToIndex(i + 1, j + 1), x - 1.0, y - 1.0);

                // eased values for x and y
                x = SlurMath.HermiteC2(x);
                y = SlurMath.HermiteC2(y);

                // bilinear interpolation
                return(SlurMath.Lerp(
                           SlurMath.Lerp(n00, n10, x),
                           SlurMath.Lerp(n01, n11, x),
                           y));
            }
Beispiel #2
0
        /// <summary>
        /// Returns the noise value at the given coordinates
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public static double ValueAt(double x, double y, double z)
        {
            // separate whole and fractional components
            x = SlurMath.Fract(x, out int i);
            y = SlurMath.Fract(y, out int j);
            z = SlurMath.Fract(z, out int k);

            // calculate noise contributions from each corner
            double n000 = GradDot(ToIndex(i, j, k), x, y, z);
            double n100 = GradDot(ToIndex(i + 1, j, k), x - 1.0, y, z);
            double n010 = GradDot(ToIndex(i, j + 1, k), x, y - 1.0, z);
            double n110 = GradDot(ToIndex(i + 1, j + 1, k), x - 1.0, y - 1.0, z);

            double n001 = GradDot(ToIndex(i, j, k + 1), x, y, z - 1.0);
            double n101 = GradDot(ToIndex(i + 1, j, k + 1), x - 1.0, y, z - 1.0);
            double n011 = GradDot(ToIndex(i, j + 1, k + 1), x, y - 1.0, z - 1.0);
            double n111 = GradDot(ToIndex(i + 1, j + 1, k + 1), x - 1.0, y - 1.0, z - 1.0);

            // eased values for each dimension
            x = SlurMath.HermiteC2(x);
            y = SlurMath.HermiteC2(y);
            z = SlurMath.HermiteC2(z);

            // trilinear interpolation
            return(SlurMath.Lerp(
                       SlurMath.Lerp(
                           SlurMath.Lerp(n000, n100, x),
                           SlurMath.Lerp(n010, n110, x),
                           y),
                       SlurMath.Lerp(
                           SlurMath.Lerp(n001, n101, x),
                           SlurMath.Lerp(n011, n111, x),
                           y),
                       z));
        }