Allows retrieving interpolated values from a three-dimensional noise table.
示例#1
0
        /// <summary>
        /// Generates sky textures.
        /// </summary>
        public void GenerateSky()
        {
            if (noiseTextures != null)
                for (int i = 0; i < noiseTextures.Length; i++)
                    if (noiseTextures[i] != null)
                        noiseTextures[i].Dispose();

            noiseTextures = new ShaderResourceView[4];
            for (int i = 0; i < 4; i++)
                noiseTextures[i] = new NoiseCube(16, 16, 16).ToTexture3D(graphicsDevice);
        }
示例#2
0
        /// <summary>
        /// Generates mesh using some random values interpolated with trilinear interpolation.
        /// Uses coordinates transformed with warp values.
        /// </summary>
        /// <param name="width">Mesh widht.</param>
        /// <param name="height">Mesh height.</param>
        /// <param name="depth">Mesh depth.</param>
        public void GenerateFromNoiseCubeWithWarp(int width, int height, int depth)
        {
            Voxel[, ,] voxels = new Voxel[width, height, depth];

            Vector3 center = new Vector3(width / 2, height / 2, depth / 2);

            NoiseCube n0 = new NoiseCube(16, 16, 16);
            NoiseCube n1 = new NoiseCube(16, 16, 16);
            NoiseCube n2 = new NoiseCube(16, 16, 16);
            NoiseCube n3 = new NoiseCube(16, 16, 16);
            NoiseCube n4 = new NoiseCube(16, 16, 16);

            Parallel.For(0, width, (x) =>
            {
                for (int y = 0; y < height; y++)
                {
                    for (int z = 0; z < depth; z++)
                    {
                        Vector3 position = new Vector3(x, y, z);
                        float weight     = center.Y - y;

                        float warp = n0.GetInterpolatedValue(x * 0.004, y * 0.004, z * 0.004);
                        float cx   = x + warp * 8;
                        float cy   = y + warp * 8;
                        float cz   = z + warp * 8;

                        weight += n1.GetInterpolatedValue(cx / 32.04, cy / 32.01, cz / 31.97) * 64.0f;
                        weight += n2.GetInterpolatedValue(cx / 8.01, cy / 7.96, cz / 7.98) * 4.0f;
                        weight += n3.GetInterpolatedValue(cx / 4.01, cy / 4.04, cz / 3.96) * 2.0f;
                        weight += n4.GetInterpolatedValue(cx / 2.02, cy / 1.98, cz / 1.97) * 1.0f;

                        voxels[x, y, z] = new Voxel()
                        {
                            Position = position,
                            Weight   = weight
                        };
                    }
                }
            });

            ComputeNormal(voxels);
            ComputeAmbient(voxels);
            CreateGeometryBuffer(ComputeTriangles(voxels, container.Settings.LevelOfDetail));
        }
示例#3
0
        /// <summary>
        /// Generates sky textures.
        /// </summary>
        public void GenerateSky()
        {
            if (noiseTextures != null)
            {
                for (int i = 0; i < noiseTextures.Length; i++)
                {
                    if (noiseTextures[i] != null)
                    {
                        noiseTextures[i].Dispose();
                    }
                }
            }

            noiseTextures = new ShaderResourceView[4];
            for (int i = 0; i < 4; i++)
            {
                noiseTextures[i] = new NoiseCube(16, 16, 16).ToTexture3D(graphicsDevice);
            }
        }
示例#4
0
        /// <summary>
        /// Generates mesh using mathematical functions.
        /// </summary>
        /// <param name="width">Mesh width.</param>
        /// <param name="height">Mesh height.</param>
        /// <param name="depth">Mesh depth.</param>
        public void GenerateFromFormula(int width, int height, int depth)
        {
            Voxel[, ,] voxels = new Voxel[width, height, depth];

            float area = (float)Math.Sqrt(width * depth);

            Vector3 center = new Vector3(width / 2.0f, height / 2.0f, depth / 2.0f);

            Vector3[] pillars = new Vector3[]
            {
                new Vector3(width / 4.0f, 0, depth / 4.0f),
                new Vector3(width * 3.0f / 4.0f, 0, depth * 3.0f / 4.0f),
                new Vector3(width * 2.0f / 4.0f, 0, depth / 4.0f)
            };

            NoiseCube n1 = new NoiseCube(16, 16, 16);
            NoiseCube n2 = new NoiseCube(16, 16, 16);
            NoiseCube n3 = new NoiseCube(16, 16, 16);
            NoiseCube n4 = new NoiseCube(16, 16, 16);

            Parallel.For(0, width, (x) =>
            {
                for (int y = 0; y < height; y++)
                {
                    for (int z = 0; z < depth; z++)
                    {
                        Vector3 position = new Vector3(x, y, z);
                        float weight     = 0;

                        float distanceFromCenter = new Vector2(x - center.X, z - center.Z).Length();
                        distanceFromCenter       = distanceFromCenter < 0.1f ? 0.1f : distanceFromCenter;

                        // Create pillars.
                        for (int i = 0; i < pillars.Length; i++)
                        {
                            float distance = new Vector2(x - pillars[i].X, z - pillars[i].Z).Length();
                            distance       = distance < 0.1f ? 0.1f : distance;
                            weight        += area / distance;
                        }

                        // Subtract values near center.
                        weight -= area / distanceFromCenter;

                        // Subtract big values at outer edge.
                        weight -= (float)Math.Pow(distanceFromCenter, 3) / (float)Math.Pow(area, 1.5f);

                        // Create helix.
                        double coordinate = 3 * Math.PI * y / height;
                        Vector2 helix     = new Vector2((float)Math.Cos(coordinate), (float)Math.Sin(coordinate));
                        weight           += Vector2.Dot(helix, new Vector2(x - center.X, z - center.Z));

                        // Create shelves.
                        weight += 10 * (float)Math.Cos(coordinate * 4 / 3);

                        // Add a little randomness.
                        weight += n1.GetInterpolatedValue(x / 32.04, y / 32.01, z / 31.97) * 8.0f;
                        weight += n2.GetInterpolatedValue(x / 8.01, y / 7.96, z / 7.98) * 4.0f;
                        weight += n3.GetInterpolatedValue(x / 4.01, y / 4.04, z / 3.96) * 2.0f;
                        weight += n4.GetInterpolatedValue(x / 2.02, y / 1.98, z / 1.97) * 1.0f;

                        voxels[x, y, z] = new Voxel()
                        {
                            Position = position,
                            Weight   = weight
                        };
                    }
                }
            });

            ComputeNormal(voxels);
            ComputeAmbient(voxels);
            CreateGeometryBuffer(ComputeTriangles(voxels, container.Settings.LevelOfDetail));
        }
示例#5
0
        /// <summary>
        /// Generates mesh using mathematical functions.
        /// </summary>
        /// <param name="width">Mesh width.</param>
        /// <param name="height">Mesh height.</param>
        /// <param name="depth">Mesh depth.</param>
        public void GenerateFromFormula(int width, int height, int depth)
        {
            Voxel[, ,] voxels = new Voxel[width, height, depth];

            float area = (float)Math.Sqrt(width * depth);

            Vector3 center = new Vector3(width / 2.0f, height / 2.0f, depth / 2.0f);

            Vector3[] pillars = new Vector3[]
			{
				new Vector3(width / 4.0f, 0, depth / 4.0f),
				new Vector3(width * 3.0f / 4.0f, 0, depth * 3.0f / 4.0f),
				new Vector3(width * 2.0f / 4.0f, 0, depth / 4.0f)
			};

            NoiseCube n1 = new NoiseCube(16, 16, 16);
            NoiseCube n2 = new NoiseCube(16, 16, 16);
            NoiseCube n3 = new NoiseCube(16, 16, 16);
            NoiseCube n4 = new NoiseCube(16, 16, 16);

            Parallel.For(0, width, (x) =>
            {
                for (int y = 0; y < height; y++)
                {
                    for (int z = 0; z < depth; z++)
                    {
                        Vector3 position = new Vector3(x, y, z);
                        float weight = 0;

                        float distanceFromCenter = new Vector2(x - center.X, z - center.Z).Length();
                        distanceFromCenter = distanceFromCenter < 0.1f ? 0.1f : distanceFromCenter;

                        // Create pillars.
                        for (int i = 0; i < pillars.Length; i++)
                        {
                            float distance = new Vector2(x - pillars[i].X, z - pillars[i].Z).Length();
                            distance = distance < 0.1f ? 0.1f : distance;
                            weight += area / distance;
                        }

                        // Subtract values near center.
                        weight -= area / distanceFromCenter;

                        // Subtract big values at outer edge.
                        weight -= (float)Math.Pow(distanceFromCenter, 3) / (float)Math.Pow(area, 1.5f);

                        // Create helix.
                        double coordinate = 3 * Math.PI * y / height;
                        Vector2 helix = new Vector2((float)Math.Cos(coordinate), (float)Math.Sin(coordinate));
                        weight += Vector2.Dot(helix, new Vector2(x - center.X, z - center.Z));

                        // Create shelves.
                        weight += 10 * (float)Math.Cos(coordinate * 4 / 3);

                        // Add a little randomness.
                        weight += n1.GetInterpolatedValue(x / 32.04, y / 32.01, z / 31.97) * 8.0f;
                        weight += n2.GetInterpolatedValue(x / 8.01, y / 7.96, z / 7.98) * 4.0f;
                        weight += n3.GetInterpolatedValue(x / 4.01, y / 4.04, z / 3.96) * 2.0f;
                        weight += n4.GetInterpolatedValue(x / 2.02, y / 1.98, z / 1.97) * 1.0f;

                        voxels[x, y, z] = new Voxel()
                        {
                            Position = position,
                            Weight = weight
                        };
                    }
                }
            });

            ComputeNormal(voxels);
            ComputeAmbient(voxels);
            CreateGeometryBuffer(ComputeTriangles(voxels, container.Settings.LevelOfDetail));
        }
示例#6
0
        /// <summary>
        /// Generates mesh using some random values interpolated with trilinear interpolation.
        /// Uses coordinates transformed with warp values.
        /// </summary>
        /// <param name="width">Mesh widht.</param>
        /// <param name="height">Mesh height.</param>
        /// <param name="depth">Mesh depth.</param>
        public void GenerateFromNoiseCubeWithWarp(int width, int height, int depth)
        {
            Voxel[, ,] voxels = new Voxel[width, height, depth];

            Vector3 center = new Vector3(width / 2, height / 2, depth / 2);

            NoiseCube n0 = new NoiseCube(16, 16, 16);
            NoiseCube n1 = new NoiseCube(16, 16, 16);
            NoiseCube n2 = new NoiseCube(16, 16, 16);
            NoiseCube n3 = new NoiseCube(16, 16, 16);
            NoiseCube n4 = new NoiseCube(16, 16, 16);

            Parallel.For(0, width, (x) =>
            {
                for (int y = 0; y < height; y++)
                {
                    for (int z = 0; z < depth; z++)
                    {
                        Vector3 position = new Vector3(x, y, z);
                        float weight = center.Y - y;

                        float warp = n0.GetInterpolatedValue(x * 0.004, y * 0.004, z * 0.004);
                        float cx = x + warp * 8;
                        float cy = y + warp * 8;
                        float cz = z + warp * 8;

                        weight += n1.GetInterpolatedValue(cx / 32.04, cy / 32.01, cz / 31.97) * 64.0f;
                        weight += n2.GetInterpolatedValue(cx / 8.01, cy / 7.96, cz / 7.98) * 4.0f;
                        weight += n3.GetInterpolatedValue(cx / 4.01, cy / 4.04, cz / 3.96) * 2.0f;
                        weight += n4.GetInterpolatedValue(cx / 2.02, cy / 1.98, cz / 1.97) * 1.0f;

                        voxels[x, y, z] = new Voxel()
                        {
                            Position = position,
                            Weight = weight
                        };
                    }
                }
            });

            ComputeNormal(voxels);
            ComputeAmbient(voxels);
            CreateGeometryBuffer(ComputeTriangles(voxels, container.Settings.LevelOfDetail));
        }