static void Tutorial4() { Console.WriteLine("Begin Tutorial 4"); RiggedMultifractal mountainTerrain = new RiggedMultifractal(); Billow baseFlatTerrain = new Billow(); baseFlatTerrain.Frequency = 2.0; ScaleBias flatTerrain = new ScaleBias(); flatTerrain[0] = baseFlatTerrain; flatTerrain.Scale = 0.125; flatTerrain.Bias = -0.75; Perlin terrainType = new Perlin(); terrainType.Frequency = 0.5; terrainType.Persistence = 0.25; Select finalTerrain = new Select(); finalTerrain[0] = flatTerrain; finalTerrain[1] = mountainTerrain; finalTerrain.Controller = terrainType; finalTerrain.SetBounds(0.0, 1000.0); finalTerrain.FallOff = 0.125; NoiseMap heightMap = new NoiseMap(); NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane();; heightMapBuilder.SetSourceModule(finalTerrain); heightMapBuilder.SetDestNoiseMap(heightMap); heightMapBuilder.SetDestSize(256, 256); heightMapBuilder.SetBounds(6.0, 10.0, 1.0, 5.0); heightMapBuilder.Build(); RendererImage renderer = new RendererImage(); NoiseImage image = new NoiseImage(); renderer.SetSourceNoiseMap(heightMap); renderer.SetDestImage(image); renderer.ClearGradient(); renderer.AddGradientPoint(-1.00, new Color(32, 160, 0, 255)); // grass renderer.AddGradientPoint(-0.25, new Color(224, 224, 0, 255)); // dirt renderer.AddGradientPoint(0.25, new Color(128, 128, 128, 255)); // rock renderer.AddGradientPoint(1.00, new Color(255, 255, 255, 255)); // snow renderer.EnableLight(); renderer.SetLightContrast(3.0); renderer.SetLightBrightness(2.0); renderer.Render(); WriterBMP writer = new WriterBMP(); writer.SetSourceImage(image); writer.SetDestFilename("tutorial4.bmp"); writer.WriteDestFile(); Console.WriteLine("End Tutorial 4"); }
// Use this for initialization void Start() { IModule mountainTerrain = new RidgedMulti(); IModule baseFlatTerrain = new Billow(); ((Billow)baseFlatTerrain).Frequency = 2.0; IModule flatTerrain = new ScaleBias(baseFlatTerrain, 0.125, -0.75); IModule terrainType = new Perlin(); ((Perlin)terrainType).Frequency = 0.5; ((Perlin)terrainType).Persistence = 0.25; IModule finalTerrain = new Select(flatTerrain, mountainTerrain, terrainType); ((Select)finalTerrain).SetBounds(0.0, 1000.0); ((Select)finalTerrain).SetEdgeFallOff(0.125); NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane(256, 256); heightMapBuilder.SetBounds(6.0, 10.0, 1.0, 5.0); heightMapBuilder.Build(finalTerrain); RendererImage render = new RendererImage(); render.SourceNoiseMap = heightMapBuilder.Map; render.ClearGradient(); render.AddGradientPoint(-1.0000, new Color32(32, 160, 0, 255)); render.AddGradientPoint(-0.2500, new Color32(224, 224, 0, 255)); render.AddGradientPoint(0.2500, new Color32(128, 128, 128, 255)); render.AddGradientPoint(1.0000, new Color32(255, 255, 255, 255)); render.IsLightEnabled = true; render.LightContrast = 3.0; render.LightBrightness = 2.0; render.Render(); tex = render.GetTexture(); }
private Texture2D RenderNorm(IModule module) { RendererNormal render = new RendererNormal(); switch ((MAPTYPE)popMapTypes) { case MAPTYPE.Cylindirical: NoiseMapBuilderCylinder buildCylindirical = new NoiseMapBuilderCylinder(textureWidth, textureHeight); buildCylindirical.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound); buildCylindirical.Build(module); render.SourceNoiseMap = buildCylindirical.Map; break; case MAPTYPE.Spherical: NoiseMapBuilderSphere buildSpherical = new NoiseMapBuilderSphere(textureWidth, textureHeight); buildSpherical.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound); buildSpherical.Build(module); render.SourceNoiseMap = buildSpherical.Map; break; case MAPTYPE.Planar: NoiseMapBuilderPlane buildPlanar = new NoiseMapBuilderPlane(textureWidth, textureHeight); buildPlanar.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound); buildPlanar.Build(module); render.SourceNoiseMap = buildPlanar.Map; break; default: break; } render.BumpHeight = bumpHeight; render.Render(); return(render.GetTexture()); }
private Texture2D RenderTex(IModule module) { switch ((MAPTYPE)popMapTypes) { case MAPTYPE.Cylindirical: NoiseMapBuilderCylinder buildCylindirical = new NoiseMapBuilderCylinder(textureWidth, textureHeight); buildCylindirical.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound); buildCylindirical.Build(module); render.SourceNoiseMap = buildCylindirical.Map; break; case MAPTYPE.Spherical: NoiseMapBuilderSphere buildSpherical = new NoiseMapBuilderSphere(textureWidth, textureHeight); buildSpherical.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound); buildSpherical.Build(module); render.SourceNoiseMap = buildSpherical.Map; break; case MAPTYPE.Planar: NoiseMapBuilderPlane buildPlanar = new NoiseMapBuilderPlane(textureWidth, textureHeight); buildPlanar.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound); buildPlanar.IsSeamless = seamlessEnabled; buildPlanar.Build(module); render.SourceNoiseMap = buildPlanar.Map; break; default: break; } ImageMap backMap = null; if (backgroundTexture != null) { backMap = new ImageMap(backgroundTexture, Color.gray); } if (backMap != null) { render.BackgroundImage = backMap; } render.IsWrapEnabled = wrapEnabled; render.IsLightEnabled = lightEnabled; render.LightContrast = lightContrast; render.LightAzimuth = lightAzimuth; render.LightBrightness = lightBrightness; render.LightColor = lightColor; render.LightContrast = lightContrast; render.LightElev = lightElevation; render.LightIntensity = lightIntensity; render.Render(); return(render.GetTexture()); }
static void Tutorial3() { Console.WriteLine("Begin Tutorial 3"); Perlin myModule = new Perlin(); NoiseMap heightMap = new NoiseMap(); NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane(); heightMapBuilder.SetSourceModule(myModule); heightMapBuilder.SetDestNoiseMap(heightMap); heightMapBuilder.SetDestSize(256, 256); heightMapBuilder.SetBounds(6.0, 10.0, 1.0, 5.0); RendererImage renderer = new RendererImage(); NoiseImage image = new NoiseImage(); renderer.SetSourceNoiseMap(heightMap); renderer.SetDestImage(image); WriterBMP writer = new WriterBMP(); writer.SetSourceImage(image); renderer.ClearGradient(); renderer.AddGradientPoint(-1.0000, new Color(0, 0, 128, 255)); // deeps renderer.AddGradientPoint(-0.2500, new Color(0, 0, 255, 255)); // shallow renderer.AddGradientPoint(0.0000, new Color(0, 128, 255, 255)); // shore renderer.AddGradientPoint(0.0625, new Color(240, 240, 64, 255)); // sand renderer.AddGradientPoint(0.1250, new Color(32, 160, 0, 255)); // grass renderer.AddGradientPoint(0.3750, new Color(224, 224, 0, 255)); // dirt renderer.AddGradientPoint(0.7500, new Color(128, 128, 128, 255)); // rock renderer.AddGradientPoint(1.0000, new Color(255, 255, 255, 255)); // snow renderer.EnableLight(); renderer.SetLightContrast(3.0); // Triple the contrast renderer.SetLightBrightness(2.0); // Double the brightness for (int octave = 1; octave <= 6; octave++) { for (int frecuency = 1; frecuency <= 8; frecuency = frecuency * 2) { for (int persistence = 1; persistence <= 3; persistence++) { myModule.OctaveCount = octave; myModule.Frequency = frecuency; myModule.Persistence = persistence / 4.0f; heightMapBuilder.Build(); renderer.Render(); writer.SetDestFilename("tutorial3-" + octave + "-" + frecuency + "-" + persistence + ".bmp"); writer.WriteDestFile(); } } } Console.WriteLine("End Tutorial 3"); }
// Use this for initialization void Start() { IModule primaryGranite = new Billow(); ((Billow)primaryGranite).Seed = 0; ((Billow)primaryGranite).Frequency = 8.0; ((Billow)primaryGranite).Persistence = 0.625; ((Billow)primaryGranite).Lacunarity = 2.18359375; ((Billow)primaryGranite).OctaveCount = 6; ((Billow)primaryGranite).NoiseQuality = NoiseQuality.Standard; IModule baseGrains = new Voronoi(); ((Voronoi)baseGrains).Seed = 1; ((Voronoi)baseGrains).Frequency = 16.0; ((Voronoi)baseGrains).EnableDistance = true; IModule scaledGrains = new ScaleBias(baseGrains); ((ScaleBias)scaledGrains).Scale = -0.5; ((ScaleBias)scaledGrains).Bias = 0.0; IModule combinedGranite = new Add(primaryGranite, scaledGrains); IModule finalGranite = new Turbulence(combinedGranite); ((Turbulence)finalGranite).Seed = 2; ((Turbulence)finalGranite).Frequency = 4.0; ((Turbulence)finalGranite).Power = 1.0 / 8.0; ((Turbulence)finalGranite).Roughness = 6; NoiseMapBuilderPlane plane = new NoiseMapBuilderPlane(256, 256); plane.SetBounds(-1.0, 1.0, -1.0, 1.0); plane.Build(finalGranite); RendererImage render = new RendererImage(); render.SourceNoiseMap = plane.Map; render.ClearGradient(); render.AddGradientPoint(-1.0000, new Color32(0, 0, 0, 255)); render.AddGradientPoint(-0.9375, new Color32(0, 0, 0, 255)); render.AddGradientPoint(-0.8750, new Color32(216, 216, 242, 255)); render.AddGradientPoint(0.0000, new Color32(191, 191, 191, 255)); render.AddGradientPoint(0.5000, new Color32(210, 116, 125, 255)); render.AddGradientPoint(0.7500, new Color32(210, 113, 98, 255)); render.AddGradientPoint(1.0000, new Color32(255, 176, 192, 255)); render.IsLightEnabled = true; render.LightAzimuth = 135.0; render.LightElev = 60.0; render.LightContrast = 2.0; render.LightColor = new Color32(255, 255, 255, 0); render.Render(); tex = render.GetTexture(); }
private NoiseMap GenerateNoiseMap(int width, int height) { //module::Perlin myModule; var module = new LibNoise.Primitive.SimplexPerlin(); //var module = new LibNoise.Primitive.BevinsGradient(); //var module = new LibNoise.Primitive.ImprovedPerlin(); module.Quality = NoiseQuality.Best; //module.Seed = PrimitiveModule.DefaultSeed; var random = new Random(); module.Seed = random.Next(); //ScaleBias scale = null; FilterModule fModule = new Pipe(); fModule.Primitive3D = (IModule3D)module; fModule.OctaveCount = random.Next(1, 6); // 1; // FilterModule.DEFAULT_OCTAVE_COUNT; //fModule.Frequency = FilterModule.DEFAULT_FREQUENCY; //fModule.Gain = FilterModule.DEFAULT_GAIN; //fModule.Lacunarity = FilterModule.DEFAULT_LACUNARITY; //fModule.Offset = FilterModule.DEFAULT_OFFSET; //fModule.SpectralExponent = FilterModule.DEFAULT_SPECTRAL_EXPONENT; fModule.Frequency = random.Next(1, 5); fModule.Gain = 10; fModule.Lacunarity = 10; fModule.Offset = 10; fModule.SpectralExponent = 1; NoiseMap heightMap = new NoiseMap(); heightMap.SetSize(width, height); float bound = 2f; //NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane(bound, bound * 2, 0.0f, 100.0f, true); bool seemless = random.Next(0, 1) == 1; NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane(bound, bound * 2, bound, bound * 2, seemless); heightMapBuilder.SourceModule = (IModule3D)fModule; heightMapBuilder.NoiseMap = heightMap; heightMapBuilder.SetSize(width, height); heightMapBuilder.Build(); return(heightMap); }
private void SetTerrainHeights(IModule module) { TerrainData terData = terrain.terrainData; NoiseMapBuilderPlane buildPlanar = new NoiseMapBuilderPlane(terData.heightmapResolution, terData.heightmapResolution); buildPlanar.SetBounds(lowerXBound, upperXBound, lowerZBound, upperZBound); buildPlanar.Build(module); float[,] heights = new float[terData.heightmapResolution, terData.heightmapResolution]; for (int z = 0; z < terData.heightmapResolution; z++) { for (int x = 0; x < terData.heightmapResolution; x++) { heights[x, z] = ConvertRange01(buildPlanar.Map.GetValue(x, z)); //heights[x,z] *= terData.size.y; } } terData.SetHeights(0, 0, heights); //terData.splatPrototypes[0].texture = finalTexture; Debug.Log("Water Level is: " + terData.size.y / 2.0f); }
/// <summary> /// /// </summary> protected void GenerateNoise() { EnabledInterface(false); // Parse input ------------------------------------------------------------------------------------ int seed = ParseInt(_tbxSeed.Text, PrimitiveModule.DefaultSeed); double frequency = ParseDouble(_tbxFrequency.Text, FilterModule.DEFAULT_FREQUENCY); double lacunarity = ParseDouble(_tbxLacunarity.Text, FilterModule.DEFAULT_LACUNARITY); double gain = ParseDouble(_tbxGain.Text, FilterModule.DEFAULT_GAIN); double offset = ParseDouble(_tbxOffset.Text, FilterModule.DEFAULT_OFFSET); double exponent = ParseDouble(_tbxExponent.Text, FilterModule.DEFAULT_SPECTRAL_EXPONENT); var octaveCount = (int)_nstpOctave.Value; bool seamless = _chkbx.Checked; GradientColor gradient = GradientColors.Grayscale; NoiseQuality quality = PrimitiveModule.DefaultQuality; var primitive = NoisePrimitive.ImprovedPerlin; var filter = NoiseFilter.SumFractal; try { quality = (NoiseQuality)Enum.Parse(typeof(NoiseQuality), _cbxQuality.Text); } catch { MessageBox.Show( String.Format("Unknown quality '{0}'", _cbxQuality.Text), "Libnoise Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); EnabledInterface(true); return; } try { primitive = (NoisePrimitive)Enum.Parse(typeof(NoisePrimitive), _cbxPrimitive.Text); } catch { MessageBox.Show( String.Format("Unknown primitive '{0}'", _cbxPrimitive.Text), "Libnoise Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); EnabledInterface(true); return; } try { filter = (NoiseFilter)Enum.Parse(typeof(NoiseFilter), _cbxFilter.Text); } catch { MessageBox.Show( String.Format("Unknown filter '{0}'", _cbxFilter.Text), "Libnoise Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); EnabledInterface(true); return; } switch (_cbxGradient.Text) { case "Grayscale": gradient = GradientColors.Grayscale; break; case "Terrain": gradient = GradientColors.Terrain; break; } // Create module tree ------------------------------------------------------------------------------------ PrimitiveModule pModule = null; switch (primitive) { case NoisePrimitive.Constant: pModule = new Constant(offset); break; case NoisePrimitive.Cylinders: pModule = new Cylinders(offset); seamless = false; break; case NoisePrimitive.Spheres: pModule = new Spheres(offset); seamless = false; break; case NoisePrimitive.BevinsGradient: pModule = new BevinsGradient(); break; case NoisePrimitive.BevinsValue: pModule = new BevinsValue(); break; case NoisePrimitive.ImprovedPerlin: pModule = new ImprovedPerlin(); break; case NoisePrimitive.SimplexPerlin: pModule = new SimplexPerlin(); break; } pModule.Quality = quality; pModule.Seed = seed; FilterModule fModule = null; ScaleBias scale = null; switch (filter) { case NoiseFilter.Pipe: fModule = new Pipe(); break; case NoiseFilter.SumFractal: fModule = new SumFractal(); break; case NoiseFilter.SinFractal: fModule = new SinFractal(); break; case NoiseFilter.MultiFractal: fModule = new MultiFractal(); // Used to show the difference with our gradient color (-1 + 1) scale = new ScaleBias(fModule, 1, -0.8); break; case NoiseFilter.Billow: fModule = new Billow(); ((Billow)fModule).Bias = -0.2; ((Billow)fModule).Scale = 2; break; case NoiseFilter.HeterogeneousMultiFractal: fModule = new HeterogeneousMultiFractal(); // Used to show the difference with our gradient color (-1 + 1) scale = new ScaleBias(fModule, -1, 2); break; case NoiseFilter.HybridMultiFractal: fModule = new HybridMultiFractal(); // Used to show the difference with our gradient color (-1 + 1) scale = new ScaleBias(fModule, 0.7, -2); break; case NoiseFilter.RidgedMultiFractal: fModule = new RidgedMultiFractal(); // Used to show the difference with our gradient color (-1 + 1) scale = new ScaleBias(fModule, 0.9, -1.25); break; case NoiseFilter.Voronoi: fModule = new Voronoi(); break; } fModule.Frequency = frequency; fModule.Lacunarity = lacunarity; fModule.OctaveCount = octaveCount; fModule.Offset = offset; fModule.Offset = offset; fModule.Gain = gain; fModule.Primitive3D = (IModule3D)pModule; IModule3D finalModule; if (scale == null) { finalModule = (IModule3D)fModule; } else { finalModule = scale; } NoiseMapBuilder projection; switch (_cbxProjection.Text) { case "Spherical": projection = new NoiseMapBuilderSphere(); ((NoiseMapBuilderSphere)projection).SetBounds(-90, 90, -180, 180); // degrees break; case "Cylindrical": projection = new NoiseMapBuilderCylinder(); ((NoiseMapBuilderCylinder)projection).SetBounds(-180, 180, -10, 10); break; case "Planar": default: double bound = 2; projection = new NoiseMapBuilderPlane(bound, bound * 2, bound, bound * 2, seamless); //projection = new NoiseMapBuilderPlane(-bound, bound, -bound, bound, seamless); //projection = new NoiseMapBuilderPlane(0, bound, 0, bound, seamless); break; } int width = 0; int height = 0; switch (_cbxSize.Text) { case "256 x 256": width = 256; height = 256; break; case "512 x 512": width = 512; height = 512; break; case "1024 x 1024": width = 1024; height = 1024; break; case "256 x 128": width = 256; height = 128; break; case "512 x 256": width = 512; height = 256; break; case "1024 x 512": width = 1024; height = 512; break; case "2048 x 1024": width = 2048; height = 1024; break; default: case "128 x 128": width = 128; height = 128; break; } // ------------------------------------------------------------------------------------------------ // 0 - Initializing _prbarRenderProgression.Visible = true; _lblProgressPercent.Visible = true; _prbarRenderProgression.Value = 0; ; _lblProgressPercent.Text = ""; _lblLog.Text = String.Format("Create a {0} image with a {1} projection\n", _cbxSize.Text, _cbxProjection.Text); var watchDog = new Stopwatch(); TimeSpan ts; double elaspedTime = 0; // // ------------------------------------------------------------------------------------------------ // 1 - Build the noise map watchDog.Reset(); _prbarRenderProgression.Value = 0; _lblLog.Text += "Building noise map ... "; var noiseMap = new NoiseMap(); /* * // ShapeFilter test * Bitmap bmpShape = new Bitmap("smileyShape.bmp"); * BitmapAdaptater bmShapeAdaptater = new BitmapAdaptater(bmpShape); * * ShapeFilter shapeFilter = new ShapeFilter(); * shapeFilter.Shape = bmShapeAdaptater; * * projection.Filter = shapeFilter; */ projection.SetSize(width, height); projection.SourceModule = finalModule; projection.NoiseMap = noiseMap; projection.CallBack = delegate(int line) { line++; watchDog.Stop(); //Process message Application.DoEvents(); _prbarRenderProgression.Value = (line * 100 / height); _lblProgressPercent.Text = String.Format("{0} % - {1} line(s)", _prbarRenderProgression.Value, line); watchDog.Start(); }; watchDog.Start(); projection.Build(); watchDog.Stop(); ts = watchDog.Elapsed; elaspedTime += ts.TotalMilliseconds; _lblLog.Text += String.Format("{0:00}:{1:00} {2:00},{3:0000}\n", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds * 10 ); // ------------------------------------------------------------------------------------------------ // 2 - Render image // Create a renderer, BitmapAdaptater create a System.Drawing.Bitmap on the fly watchDog.Reset(); _prbarRenderProgression.Value = 0; _lblLog.Text += "Rendering image ... "; var renderer = new ImageRenderer(); renderer.NoiseMap = noiseMap; renderer.Gradient = gradient; renderer.LightBrightness = 2; renderer.LightContrast = 8; //renderer.LightEnabled = true; // Libnoise image struct strategy //Graphics.Tools.Noise.Renderer.Image image = new Graphics.Tools.Noise.Renderer.Image(); //renderer.Image = image; // Dotnet Bitmap Strategy var bmpAdaptater = new BitmapAdaptater(width, height); renderer.Image = bmpAdaptater; renderer.CallBack = delegate(int line) { line++; watchDog.Stop(); //Process message Application.DoEvents(); _prbarRenderProgression.Value = (line * 100 / height); _lblProgressPercent.Text = String.Format("{0} % - {1} line(s)", _prbarRenderProgression.Value, line); watchDog.Start(); }; // Render the texture. watchDog.Start(); renderer.Render(); watchDog.Stop(); ts = watchDog.Elapsed; elaspedTime += ts.TotalMilliseconds; _lblLog.Text += String.Format("{0:00}:{1:00} {2:00},{3:0000}\n", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds * 10 ); //---------------------------------------- // Normalmap rendering test // /* * BitmapAdaptater nmapAdaptater = new BitmapAdaptater(width, height); * NormalMapRenderer nmap = new NormalMapRenderer(); * nmap.Image = nmapAdaptater; * nmap.BumpHeight = 30.0; * nmap.NoiseMap = noiseMap; * nmap.Render(); * nmapAdaptater.Bitmap.Save("normalMap.png", ImageFormat.Png); */ //---------------------------------------- /* * Heightmap8 heightmap8 = new Heightmap8(); * Heightmap8Renderer heightmapRenderer = new Heightmap8Renderer(); * heightmapRenderer.Heightmap = heightmap8; */ /* * Heightmap16 heightmap16 = new Heightmap16(); * Heightmap16Renderer heightmapRenderer = new Heightmap16Renderer(); * heightmapRenderer.Heightmap = heightmap16; */ /* * Heightmap32 heightmap32 = new Heightmap32(); * Heightmap32Renderer heightmapRenderer = new Heightmap32Renderer(); * heightmapRenderer.Heightmap = heightmap32; */ /* * heightmapRenderer.NoiseMap = noiseMap; * heightmapRenderer.ExactFit(); * heightmapRenderer.Render(); */ /* * Heightmap16RawWriter rawWriter = new Heightmap16RawWriter(); * rawWriter.Heightmap = heightmap16; * rawWriter.Filename = "heightmap16.raw"; * rawWriter.WriteFile(); */ // ------------------------------------------------------------------------------------------------ // 3 - Painting // Save the file //bmpAdaptater.Bitmap.Save("rendered.png",ImageFormat.Png); _imageRendered.Width = width; _imageRendered.Height = height; //_imageRendered.Image = _bitmap; _imageRendered.Image = bmpAdaptater.Bitmap; if (_imageRendered.Width > _panImageViewport.Width) { _imageRendered.Left = 0; } else { _imageRendered.Left = (_panImageViewport.Width - _imageRendered.Width) / 2; } if (_imageRendered.Height > _panImageViewport.Height) { _imageRendered.Top = 0; } else { _imageRendered.Top = (_panImageViewport.Height - _imageRendered.Height) / 2; } if (_imageRendered.Width > _panImageViewport.Width || _imageRendered.Height > _panImageViewport.Height) { _imageRendered.Anchor = (AnchorStyles.Left | AnchorStyles.Top); _panImageViewport.AutoScroll = true; } else { _panImageViewport.AutoScroll = false; } // ---------------------------------------------------------------- ts = TimeSpan.FromMilliseconds(elaspedTime); // Format and display the TimeSpan value. _lblLog.Text += String.Format("Duration : {0:00}:{1:00} {2:00},{3:0000}\n", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds * 10 ); EnabledInterface(true); _prbarRenderProgression.Value = 0; _lblProgressPercent.Text = ""; _prbarRenderProgression.Visible = false; _lblProgressPercent.Visible = false; }
public NoiseMap Render() { PrimitiveModule primitive = null; switch (this.Primitive) { case NoisePrimitive.Constant: primitive = new Constant(this.Offset); break; case NoisePrimitive.Cylinders: primitive = new Cylinders(this.Offset); this.Seamless = false; break; case NoisePrimitive.Spheres: primitive = new Spheres(this.Offset); this.Seamless = false; break; case NoisePrimitive.BevinsGradient: primitive = new BevinsGradient(); break; case NoisePrimitive.BevinsValue: primitive = new BevinsValue(); break; case NoisePrimitive.ImprovedPerlin: primitive = new ImprovedPerlin(); break; case NoisePrimitive.SimplexPerlin: primitive = new SimplexPerlin(); break; } primitive.Seed = this.Seed; primitive.Quality = this.NoiseQuality; FilterModule filter = null; ScaleBias scale = null; switch (this.Filter) { case NoiseFilter.Pipe: filter = new Pipe(); break; case NoiseFilter.SumFractal: filter = new SumFractal(); break; case NoiseFilter.SinFractal: filter = new SinFractal(); break; case NoiseFilter.MultiFractal: filter = new MultiFractal(); // Used to show the difference with our gradient color (-1 + 1) scale = new ScaleBias(filter, 1f, -0.8f); break; case NoiseFilter.Billow: filter = new Billow(); ((Billow)filter).Bias = -0.2f; ((Billow)filter).Scale = 2f; break; case NoiseFilter.HeterogeneousMultiFractal: filter = new HeterogeneousMultiFractal(); // Used to show the difference with our gradient color (-1 + 1) scale = new ScaleBias(filter, -1f, 2f); break; case NoiseFilter.HybridMultiFractal: filter = new HybridMultiFractal(); // Used to show the difference with our gradient color (-1 + 1) scale = new ScaleBias(filter, 0.7f, -2f); break; case NoiseFilter.RidgedMultiFractal: filter = new RidgedMultiFractal(); // Used to show the difference with our gradient color (-1 + 1) scale = new ScaleBias(filter, 0.9f, -1.25f); break; case NoiseFilter.Voronoi: filter = new Voronoi(); break; } filter.Frequency = this.Frequency; filter.Lacunarity = this.Lacunarity; filter.OctaveCount = this.OctaveCount; filter.Offset = this.Offset; filter.Gain = this.Gain; filter.Primitive3D = (IModule3D)primitive; IModule3D final = scale ?? (IModule3D)filter; NoiseMapBuilder projection; switch (this.Projection) { case NoiseMapProjection.Spherical: projection = new NoiseMapBuilderSphere(); ((NoiseMapBuilderSphere)projection).SetBounds(-90f, 90f, -180f, 180f); // degrees break; case NoiseMapProjection.Cylindrical: projection = new NoiseMapBuilderCylinder(); ((NoiseMapBuilderCylinder)projection).SetBounds(-180f, 180f, -10f, 10f); break; case NoiseMapProjection.Planar: default: float bound = 2f; projection = new NoiseMapBuilderPlane(bound, bound * 2, bound, bound * 2, this.Seamless); break; } NoiseMap noise = new NoiseMap(); projection.SetSize(this.Width, this.Height); projection.SourceModule = final; projection.NoiseMap = noise; projection.Build(); float min, max; noise.MinMax(out min, out max); this.Map = noise; return(noise); }
static void Tutorial2() { Console.WriteLine("Begin Tutorial 2"); Perlin myModule = new Perlin(); NoiseMap heightMap = new NoiseMap(); NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane(); heightMapBuilder.SetSourceModule(myModule); heightMapBuilder.SetDestNoiseMap(heightMap); heightMapBuilder.SetDestSize(256, 256); heightMapBuilder.SetBounds(2.0, 6.0, 1.0, 5.0); heightMapBuilder.Build(); RendererImage renderer = new RendererImage(); NoiseImage image = new NoiseImage(); renderer.SetSourceNoiseMap(heightMap); renderer.SetDestImage(image); renderer.Render(); WriterBMP writer = new WriterBMP(); writer.SetSourceImage(image); writer.SetDestFilename("tutorial2-1.bmp"); writer.WriteDestFile(); renderer.ClearGradient(); renderer.AddGradientPoint(-1.0000, new Color(0, 0, 128, 255)); // deeps renderer.AddGradientPoint(-0.2500, new Color(0, 0, 255, 255)); // shallow renderer.AddGradientPoint(0.0000, new Color(0, 128, 255, 255)); // shore renderer.AddGradientPoint(0.0625, new Color(240, 240, 64, 255)); // sand renderer.AddGradientPoint(0.1250, new Color(32, 160, 0, 255)); // grass renderer.AddGradientPoint(0.3750, new Color(224, 224, 0, 255)); // dirt renderer.AddGradientPoint(0.7500, new Color(128, 128, 128, 255)); // rock renderer.AddGradientPoint(1.0000, new Color(255, 255, 255, 255)); // snow renderer.Render(); writer.SetDestFilename("tutorial2-2.bmp"); writer.WriteDestFile(); renderer.EnableLight(); renderer.Render(); writer.SetDestFilename("tutorial2-3.bmp"); writer.WriteDestFile(); renderer.SetLightContrast(3.0); // Triple the contrast renderer.Render(); writer.SetDestFilename("tutorial2-4.bmp"); writer.WriteDestFile(); renderer.SetLightBrightness(2.0); // Double the brightness renderer.Render(); writer.SetDestFilename("tutorial2-5.bmp"); writer.WriteDestFile(); heightMapBuilder.SetDestSize(256 * 2, 256); heightMapBuilder.SetBounds(2.0, 10.0, 1.0, 5.0); heightMapBuilder.Build(); renderer.Render(); writer.SetDestFilename("tutorial2-6.bmp"); writer.WriteDestFile(); Console.WriteLine("End Tutorial 2"); }