1

我一直在使用 Libnoise 的 dotnet 端口使用以下代码在 XNA 中生成一些高度图:

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);

这一切都很好,即使我在提供的不使用 XNA 的 libnoise 样本中得到不同的结果(出于某种原因,我需要降低频率才能在 XNA 中获得相同的结果)。

遗憾的是,没有 NoiseBuilder[3D] 可以生成噪声的 3D 变体,所以我必须使用 perlin 函数自己构建它。但是,即使尝试使用 perlin.getValue() 来生成 2D 噪声似乎也以错误告终;

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);

左 = perlin.getValue(),右 = 法师 2 = NoiseMapBuilderPlane

我也不知道如何合并 SumFractal,但我想这对以后来说是一个担心。

4

0 回答 0