I am trying to display noise in B&W, im using library and got weird results, so i changed the library however this still keeps happening so i feel that the issue is with how i am displaying it, does anyone have any idea why it is doing this: 
This is my code:
namespace BiomeGen
{
class Terrain
{
Texture2D map;
Color[] mapData;
FastNoiseLite noise;
public Terrain(GraphicsDevice grpDev, int width, int height)
{
map = new Texture2D(grpDev, width, height);
mapData = new Color[width * height];
noise = new FastNoiseLite();
noise.SetNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
}
public Texture2D getTexture()
{
int counter = 0;
for(int i = 0;i < map.Width;i++)
{
for(int j = 0;j < map.Height;j++)
{
int temp = (int)Math.Round((noise.GetNoise(i, j) + 1) * 127);
//Debug.WriteLine(temp);
mapData[counter] = new Color(temp, temp, temp);
counter++;
}
}
map.SetData(mapData);
return map;
}
}
}
and this:
_spriteBatch.Begin();
_spriteBatch.Draw(gener.getTexture(), new Vector2(0, 0), Color.White);
_spriteBatch.End();
and this:
Terrain gener;
Thanks in advance
From a rough glance, it appears you are not conveying the correct dimensions of your texture to the FastNoiseLite object. Documentation for your library is hard to find, it seems like it should be set next to
noise = new FastNoiseLite();
I do not know because I have never used the library, but having dealt with this kind of thing before that would be my suggestion on what to look at.
If you can’t do that, it may be that .GetNoise(x, y) could take a float value? This is a guess. If that’s the case, try
noise.GetNoise((float)i / (float)width, (float)j / (float)height)
One other note, when iterating through x and y values, names like i and j can be confusing. 
None of your suggestions seemed to work, do you have any suggestions for a noise lib that has worked for you in the past, like i said i tried one or two and they all had this problem which led me to believe the issue is with the way i display it.Thanks very much! and yes i should have used x, y they are much better than letters my bad.
I tried your code. It seems like it works just fine as long as you keep Terrain’s width * height a square value.

gener = new Terrain(GraphicsDevice, 500,500);
works,
gener = new Terrain(GraphicsDevice, 500,200);
will cause broken graphics.
The problem was in your getTexture() method. I replaced your counter with this. I usually do it this way when iterating through an array, it leaves less room for error imo.
public Texture2D getTexture()
{
int counter = 0;
for (int x = 0; x < map.Width; x++)
{
for (int y = 0; y < map.Height; y++)
{
int temp = (int)Math.Round((noise.GetNoise(x, y) + 1) * 127);
//Debug.WriteLine(temp);
mapData[x + y * map.Width] = new Color(temp, temp, temp);
}
}
map.SetData(mapData);
return map;
}
Also, note that calling this method every draw frame will be very slow. Is that what you’re wanting to do? Using multithreading here will be much faster and not that hard to do. If it’s just a one off thing and you don’t care how long it takes it doesn’t really matter.
Thanks, this is very helpful however i still have a problem, the noise that i need is for a non-square space, do you know how i can do it for this(the issue with it being square suggest the issue is with my code for drawing to the texture as the size does in no way affect the perlin so maybe my drawing code is broke?)? As for the efficiency, this perlin noise will never be displayed only used in a 2d array of floats, i only displayed it to see what it looked like. Are you able to suggest a fix for the square issue?
I fixed your code by rewriting your getTexture() method. Sorry if I didn’t make that clear. It’s in my above post.
I got rid of your counter
and did this instead.
mapData[x + y * map.Width] = new Color(temp, temp, temp);
That fixed the bug for me.
This happened because your for loop was iterating from top to bottom while writing from left to right. Using x and y in this way ensures there’s no hidden mistake like that.
1 Like