1

I have been using the dotnet port of Libnoise to generate some heighmaps in XNA using the following code:

ImprovedPerlin perlin = new ImprovedPerlin(seed, NoiseQuality.Standard);
FilterModule module = new SumFractal();
module.Frequency = 0.2f;
module.OctaveCount = 6;
module.Lacunarity = 2;
module.Gain = 2;
module.Offset = 1;
module.SpectralExponent = 0.9f;
module.Primitive3D = perlin;
float bound = 10f;
NoiseMapBuilderPlane builder = new NoiseMapBuilderPlane(
  6.0f + mapX, 10.0f + mapX, 1.0f + mapZ, 5.0f + mapZ, true);
    //bound + mapx,  (bound + mapX) * 2, bound, bound * 2, true);
NoiseMap noiseMap = new NoiseMap(128, 128);

builder.SetSize(128, 128);
builder.SourceModule = module;
builder.NoiseMap = noiseMap;
builder.Build();

Graphics.Tools.Noise.Renderer.GradientColor gradient = 
Graphics.Tools.Noise.Renderer.GradientColor.GRAYSCALE;
Color[] colorData = new Color[128 * 128];
texture =
  new Texture2D(AssetManager.graphicsDeviceManager.GraphicsDevice, 128, 128);

for (int y = 0; y < 128; ++y)
{
    for (int x = 0; x < 128; ++x)
    {
        byte color = gradient.GetColor(noiseMap.GetValue(x, y)).Green;
    }
}
texture.SetData<Color>(colorData);

This all works fine, even if I get different results in the provided libnoise sample that doesn't use XNA (I neeed to lower the frequancy to get the same result in XNA for some reason).

Sadly there is no NoiseBuilder[3D] to generate a 3D variant of noise, so I have to build it myself using the perlin function. But even trying to generate 2D noise using perlin.getValue() seems to end up wrong;

float px = 0;
float py = 0;
for (int y = 0; y < 128; ++y)
{
    py += 0.1f;
    for (int x = 0; x < 128; ++x)
    {
        px += 0.1f;
        int color = (int)((perlin.GetValue(px, py, 0) + 1) * 177.5f);
    }
}

texture.SetData < Color > (colorData);

left = perlin.getValue(), right = mage 2 = NoiseMapBuilderPlane

I have no idea how to incorporate the SumFractal aswell, but that's a worry for later I guess.

user1306322
  • 8,561
  • 18
  • 61
  • 122
omgnoseat
  • 361
  • 2
  • 19
  • Check out this other question: http://stackoverflow.com/questions/6963388/fastest-perlin-like-3d-noise-algorithm – user1306322 Jan 15 '13 at 00:49
  • I actually understand how perlin noise works behind the screens, I'm just not sure how to actually generate a proper heightmap use individual "getValue()" calls – omgnoseat Jan 15 '13 at 15:45

0 Answers0