public NoisePresetValues(string name, int Seed, double Frequency, double Lacunarity,
                          int OctaveCount, double Persistence,
                          PerlinModuleWrapper.NoiseQuality Quality)
 {
     this.Name = name;
     this.Seed = Seed;
     this.Frequency = Frequency;
     this.Lacunarity = Lacunarity;
     this.OctaveCount = OctaveCount;
     this.Persistence = Persistence;
     this.Quality = Quality;
 }
        public static VolumeTexture GenerateVolumeTexture(string path, string name, Device device, int width, int height, int depth, int levels,
                                                          NoisePresetValues settings, Usage usage, Pool pool)
        {
            PerlinModuleWrapper noiseModule = new PerlinModuleWrapper();

            // apply any presets
            if (settings != null)
            {
                if (settings.Seed != -1)
                {
                    noiseModule.Seed = settings.Seed;
                }
                if (!double.IsNaN(settings.Frequency))
                {
                    noiseModule.Frequency = settings.Frequency;
                }
                if (!double.IsNaN(settings.Lacunarity))
                {
                    noiseModule.Lacunarity = settings.Lacunarity;
                }
                if (!double.IsNaN(settings.OctaveCount))
                {
                    noiseModule.OctaveCount = settings.OctaveCount;
                }
                if (!double.IsNaN(settings.Persistence))
                {
                    noiseModule.Persistence = settings.Persistence;
                }
                if (settings.Quality != (PerlinModuleWrapper.NoiseQuality)(int) - 1)
                {
                    noiseModule.Quality = settings.Quality;
                }
            }

            // generate slices
            // vol needs to be 32-bit stride
            //VolumeTexture volumeTex = new VolumeTexture(device, 2, 2, 2, 1, usage, Format.A8B8G8R8, pool);

            float sliceStep = 0;

            if (levels > 1)
            {
                sliceStep = (float)depth / (levels - 1);
            }

            float z = depth;

            for (int level = 0; level < levels; level++)
            {
                // sample texels for slice
                //Volume vol = volumeTex.GetVolumeLevel(level);
                Texture tex = new Texture(device, width, height, 1, Usage.None, Format.X8R8G8B8, Pool.Managed);
                //GraphicsStream lvlStream = vol.LockBox(LockFlags.None);
                GraphicsStream lvlStream = tex.LockRectangle(0, LockFlags.None);
                for (float x = 0; x < width; x++)
                {
                    for (float y = 0; y < height; y++)
                    {
                        // sample texel value
                        double value = noiseModule.GetPerlinNoiseValue(x / 3f, y / 3f, z / 3f);
                        // convert to colour data
                        // just write in direct range of -1 -> 1 as 32-bit float
                        //float valueF = (float)value;
                        //lvlStream.Write(valueF);
                        value++;
                        if (value < 0)
                        {
                            value = 0;
                        }
                        if (value > 2)
                        {
                            value = 2;
                        }
                        byte R = (byte)(value * 127f);
                        lvlStream.Write((byte)255);
                        lvlStream.Write(R);
                        lvlStream.Write(R);
                        lvlStream.Write(R);
                    }
                }
                tex.UnlockRectangle(0);
                TextureLoader.Save(path + name + level.ToString() + ".dds", ImageFileFormat.Dds, tex);
                tex.Dispose();
                //vol.UnlockBox();
                z += sliceStep;
            }

            return(null);// volumeTex;
        }
        public static VolumeTexture GenerateVolumeTexture(string path, string name, Device device, int width, int height, int depth, int levels,
                                                 NoisePresetValues settings, Usage usage, Pool pool)
        {
            PerlinModuleWrapper noiseModule = new PerlinModuleWrapper();

            // apply any presets
            if (settings != null)
            {
                if (settings.Seed != -1)
                    noiseModule.Seed = settings.Seed;
                if (!double.IsNaN(settings.Frequency))
                    noiseModule.Frequency = settings.Frequency;
                if (!double.IsNaN(settings.Lacunarity))
                    noiseModule.Lacunarity = settings.Lacunarity;
                if (!double.IsNaN(settings.OctaveCount))
                    noiseModule.OctaveCount = settings.OctaveCount;
                if (!double.IsNaN(settings.Persistence))
                    noiseModule.Persistence = settings.Persistence;
                if (settings.Quality != (PerlinModuleWrapper.NoiseQuality)(int)-1)
                    noiseModule.Quality = settings.Quality;
            }

            // generate slices
            // vol needs to be 32-bit stride
            //VolumeTexture volumeTex = new VolumeTexture(device, 2, 2, 2, 1, usage, Format.A8B8G8R8, pool);
            
            float sliceStep = 0;
            if (levels > 1)
                sliceStep = (float)depth / (levels - 1);

            float z = depth;
            for (int level = 0; level < levels; level++)
            {
                // sample texels for slice
                //Volume vol = volumeTex.GetVolumeLevel(level);
                Texture tex = new Texture(device, width, height, 1, Usage.None, Format.X8R8G8B8, Pool.Managed);
                //GraphicsStream lvlStream = vol.LockBox(LockFlags.None);
                GraphicsStream lvlStream = tex.LockRectangle(0, LockFlags.None);
                for (float x = 0; x < width; x++)
                {
                    for (float y = 0; y < height; y++)
                    {
                        // sample texel value
                        double value = noiseModule.GetPerlinNoiseValue(x / 3f, y / 3f, z / 3f);
                        // convert to colour data
                        // just write in direct range of -1 -> 1 as 32-bit float
                        //float valueF = (float)value;
                        //lvlStream.Write(valueF);
                        value++;
                        if (value < 0)
                            value = 0;
                        if (value > 2)
                            value = 2;
                        byte R = (byte)(value * 127f);
                        lvlStream.Write((byte)255);
                        lvlStream.Write(R);
                        lvlStream.Write(R);
                        lvlStream.Write(R);
                    }
                }
                tex.UnlockRectangle(0);
                TextureLoader.Save(path + name + level.ToString() + ".dds", ImageFileFormat.Dds, tex);
                tex.Dispose();
                //vol.UnlockBox();
                z += sliceStep;
            }

            return null;// volumeTex;
        }