internal override void GenerateColorMap(int height) { var width = 2 * height; if (HasAtmosphere && TemperatureNoiseMap == null) { GenerateTemperatureMap(height); } else if (HeightNoiseMap == null) { GenerateHeightMap(height); } var builder = new SphereNoiseMapBuilder(); builder.SetDestSize(width, height); builder.SetBounds(-90, 90, -180, 180); ColorNoiseMap = new NoiseMap(); builder.SourceModule = ColorNoiseModule; builder.DestNoiseMap = ColorNoiseMap; builder.Build(); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var value = ColorNoiseMap.GetValue(x, y); value = (value - MinHeight) / (MaxHeight - MinHeight); ColorNoiseMap.SetValue(x, y, value); } } }
public void SphericalRenderTest() { var sphere = new SphereNoiseMapBuilder(); sphere.SetBounds(-90, 90, -180, 180); sphere.SetDestSize(512, 256); sphere.SourceModule = module; sphere.DestNoiseMap = noiseMap; sphere.Build(); renderer.SourceNoiseMap = noiseMap; renderer.DestinationImage = textureImage; renderer.Render(); }
public void WoodTexture_SphericalRender() { var noiseMap = new NoiseMap(); var sphere = new SphereNoiseMapBuilder(); sphere.SetBounds(-90, 90, -180, 180); sphere.SetDestSize(512, 256); sphere.SourceModule = testModule; sphere.DestNoiseMap = noiseMap; sphere.Build(); testRenderer.SourceNoiseMap = noiseMap; testRenderer.DestinationImage = testTextureImage; testRenderer.Render(); }
private void GenerateTemperatureMap(int height) { var width = 2 * height; if (HeightNoiseMap == null) { GenerateHeightMap(height); } var builder = new SphereNoiseMapBuilder(); builder.SetDestSize(width, height); builder.SetBounds(-90, 90, -180, 180); TemperatureNoiseMap = new NoiseMap(); builder.SourceModule = TemperatureNoiseModule; builder.DestNoiseMap = TemperatureNoiseMap; builder.Build(); MinTemperature = 1000000.0f; MaxTemperature = 0.0f; var solarHeat = Pow(SurfaceTemperature, 4); var extraHeat = Pow(GeothermalTemperature, 4) + Pow(GreenhouseTemp, 4); var coldness = 1 - (float)Random.Uniform("coldness", Pow(extraHeat / (solarHeat + extraHeat), 0.25), 1); if (HasAtmosphere) { for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var heat = extraHeat + solarHeat * 2 * Sin(PI * y / height); var temperature = (float)Pow(heat, 0.25); temperature *= 1 - coldness * HeightNoiseMap.GetValue(x, y); if (temperature < MinTemperature) { MinTemperature = temperature; } else if (temperature > MaxTemperature) { MaxTemperature = temperature; } temperature *= 1 + 0.05f * (TemperatureNoiseMap.GetValue(x, y) - 1); TemperatureNoiseMap.SetValue(x, y, temperature); } } } }
private void GenerateTemperatureMap(int height) { var width = 2 * height; var builder = new SphereNoiseMapBuilder(); builder.SetDestSize(width, height); builder.SetBounds(-90, 90, -180, 180); TemperatureNoiseMap = new NoiseMap(); builder.SourceModule = TemperatureNoiseModule; builder.DestNoiseMap = TemperatureNoiseMap; builder.Build(); var min = 10.0f; var max = -10.0f; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var value = TemperatureNoiseMap.GetValue(x, y); if (value < min) { min = value; } else if (value > max) { max = value; } } } for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var value = TemperatureNoiseMap.GetValue(x, y); value = (value - min) / (max - min); value = 0.75f + 0.25f * value; value *= (float)EffectiveTemperature; TemperatureNoiseMap.SetValue(x, y, value); } } }
private void GenerateHeightMap(int height) { var width = 2 * height; var builder = new SphereNoiseMapBuilder(); builder.SetDestSize(width, height); builder.SetBounds(-90, 90, -180, 180); HeightNoiseMap = new NoiseMap(); builder.SourceModule = HeightNoiseModule; builder.DestNoiseMap = HeightNoiseMap; builder.Build(); MinHeight = 10.0f; MaxHeight = -10.0f; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var value = HeightNoiseMap.GetValue(x, y); if (value < MinHeight) { MinHeight = value; } else if (value > MaxHeight) { MaxHeight = value; } } } for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var value = HeightNoiseMap.GetValue(x, y); value = (value - MinHeight) / (MaxHeight - MinHeight); HeightNoiseMap.SetValue(x, y, value); } } }
private void GenerateRingMap(int width) { var height = 32; RingNoiseModule = Random.Perlin("ring noise", 0.25, 2, 1.8, 2.2, 10, 16, 0.65, 0.75); RingNoiseModule = new Add { Source0 = RingNoiseModule, Source1 = new Constant { ConstantValue = Random.Uniform("ring offset", -0.5, 0.5) } }; var builder = new SphereNoiseMapBuilder(); RingNoiseMap = new NoiseMap(); builder.SourceModule = RingNoiseModule; builder.SetDestSize(width, height); builder.DestNoiseMap = RingNoiseMap; builder.SetBounds(0, 0.00000001, -180, 180); builder.Build(); }
private void GenerateNoiseMaps() { tbLogView.Text = "Started\r\n"; int SizeX; int SizeY; try { SizeX = Int32.Parse(tbWidth.Text); SizeY = Int32.Parse(tbHeight.Text); NoiseBitmapTerrain = new Bitmap(SizeX, SizeY); NoiseBitmapHeight = new Bitmap(SizeX, SizeY); tbLogView.AppendText("Size OK \r\n"); } catch (Exception) { SizeX = 250; SizeY = 250; MessageBox.Show("Nonparsable size values! Running at 250x250\r\n"); NoiseBitmapTerrain = new Bitmap(250, 250); NoiseBitmapTerrain = new Bitmap(250, 250); tbLogView.AppendText("Size was incorrect, going default\r\n"); } tbLogView.AppendText("Loading Perlin from Noiser(legacy)\r\n"); SharpNoise.Modules.Perlin perlin = new SharpNoise.Modules.Perlin(); tbLogView.AppendText("Loading OK\r\n"); try { perlin.OctaveCount = Int32.Parse(tbOctaves.Text); perlin.Seed = Int32.Parse(tbSeed.Text); perlin.Frequency = Double.Parse(tbFreq.Text); tbLogView.AppendText("Settings OK\r\n"); } catch (Exception) { MessageBox.Show("Wrong octaves count or seed! Running at 1 octave and seed 000000 @ Frequency = 10."); perlin.OctaveCount = 1; perlin.Seed = 000000; perlin.Frequency = 10.0; tbLogView.AppendText("Setting incorrect, going default\r\n"); } double down, up, right, left; try { down = Double.Parse(tbTileDown.Text); up = Double.Parse(tbTileUp.Text); left = Double.Parse(tbTileLeft.Text); right = Double.Parse(tbTileRight.Text); tbLogView.AppendText("Tiles OK\r\n"); } catch (Exception) { up = 3; left = -3; right = 3; down = -3; tbLogView.AppendText("Tiles incorrect, going default\r\n"); } var NoiseMap = new NoiseMap(SizeX, SizeY); if (comboModuleSelector.SelectedIndex == 0) { var NoiseMapBuilder = new PlaneNoiseMapBuilder() { DestNoiseMap = NoiseMap, SourceModule = perlin }; tbLogView.AppendText("Module OK, Destination OK\r\n"); NoiseMapBuilder.SetDestSize(SizeX, SizeY); NoiseMapBuilder.SetBounds(left, right, down, up); tbLogView.AppendText("Building maps.....\r\n"); NoiseMapBuilder.Build(); } if (comboModuleSelector.SelectedIndex == 1) { var GlobeMapBuilder = new SphereNoiseMapBuilder() { DestNoiseMap = NoiseMap, SourceModule = perlin }; tbLogView.AppendText("Module OK, Destination OK\r\n"); GlobeMapBuilder.SetDestSize(SizeX, SizeY); GlobeMapBuilder.SetBounds(down, up, left, right); GlobeMapBuilder.Build(); tbLogView.AppendText("Building maps.....\r\n"); } tbLogView.AppendText("Building OK\r\n"); var ImageTerrain = new SharpNoise.Utilities.Imaging.Image(); var RendererTerrain = new ImageRenderer() { SourceNoiseMap = NoiseMap, DestinationImage = ImageTerrain }; tbLogView.AppendText("Renderer starting\r\n"); if (chboxLightMap.IsChecked == true) { RendererTerrain.EnableLight = true; RendererTerrain.LightAzimuth = Double.Parse(tbLightAzimuth.Text); RendererTerrain.LightBrightness = Double.Parse(tbLightBrightness.Text); RendererTerrain.LightContrast = Double.Parse(tbLightContrast.Text); RendererTerrain.LightElevation = Double.Parse(tbLightElevation.Text); RendererTerrain.LightIntensity = Double.Parse(tbLightIntensity.Text); } Thread ColorBuilder = new Thread(() => { RendererTerrain.BuildTerrainGradient(); RendererTerrain.Render(); NoiseBitmapTerrain = ImageTerrain.ToGdiBitmap(); ImageNoiseHolder.Dispatcher.Invoke(new Action(() => { ImageNoiseHolder.Source = BitmapToImageSource(NoiseBitmapTerrain); tbLogView.AppendText("Done! Noise map OK, renderer OK\r\n"); })); }); ColorBuilder.Start(); var ImageTerrainHeight = new SharpNoise.Utilities.Imaging.Image(); var RendererTerrainHeight = new ImageRenderer() { SourceNoiseMap = NoiseMap, DestinationImage = ImageTerrainHeight }; Thread heightBuilder = new Thread(() => { RendererTerrainHeight.BuildGrayscaleGradient(); RendererTerrainHeight.Render(); NoiseBitmapHeight = ImageTerrainHeight.ToGdiBitmap(); ImageNoiseHeightHolder.Dispatcher.Invoke(new Action(() => { ImageNoiseHeightHolder.Source = BitmapToImageSource(NoiseBitmapHeight); tbLogView.AppendText("Done! Noise map OK, renderer OK\r\n"); })); }); heightBuilder.Start(); tbLogView.AppendText("Process status: OK\r\n"); }
internal override void GenerateColorMap(int height) { var width = 2 * height; var builder = new SphereNoiseMapBuilder(); ColorNoiseMap = new NoiseMap(); builder.SourceModule = ColorNoiseModule; builder.SetDestSize(width, height); builder.DestNoiseMap = ColorNoiseMap; builder.SetBounds(-90, 90, -180, 180); builder.Build(); HeightNoiseMap = new NoiseMap(); builder.SourceModule = HeightNoiseModule; builder.SetDestSize(1, height); builder.DestNoiseMap = HeightNoiseMap; builder.SetBounds(-90, 90, 0, 0.000001); builder.Build(); var min = 1000.0f; var max = -1000.0f; var factor = 0.3f; var values = new float[height]; for (var y = 0; y < height; y++) { var value = (1 - factor) * HeightNoiseMap.GetValue(0, y) + factor * HeightNoiseMap.GetValue(0, height - y); values[y] = value; if (value < min) { min = value; } else if (value > max) { max = value; } } for (var y = 0; y < height; y++) { var value = values[y]; value = (value - min) / (max - min); values[y] = value; } min = 1000.0f; max = -1000.0f; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var value = ColorNoiseMap.GetValue(x, y); if (value < min) { min = value; } else if (value > max) { max = value; } } } var turbulence = (float)Sqrt(0.003 * Mass / EarthMass); var d = turbulence * 0.03f; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var value = ColorNoiseMap.GetValue(x, y); value = (value - min) / (max - min); value = (1 - 2 * d) * y / height + d + d * value; var i = (int)(value * height); if (i < 0) { i = 0; } if (i > height - 1) { i = height - 1; } value = values[i]; var a = (float)Sin(PI * y / height); a *= a * a; value *= a; value *= turbulence; ColorNoiseMap.SetValue(x, y, value); } } }