How to add noise

Hi this is my voxel engine so far…

This is my chunk class - http://pastebin.com/W64LSh07
This is my main game class - http://pastebin.com/axULjzRt

Could someone please tell me how to add random noise to this engine, so my voxels have different heights thus making random generation, I have looked a simplex noise i just dont know how to add it to my engine

Thanks Toby




http://www.java-gaming.org/topics/generating-2d-perlin-noise/31637/view.html

Several threads on it. Simply use the result as a heightmap.

These help a bit but i need some help on how to add these to my code

Noise is a bunch of values related to each other. In your case, it seems like you want to add these values to your heights.

So just do that.

Create a noise map and add its values to your your blocks height value. How big should the noise map be? Preferably the same size as your game map. Makes sense right?

e.g. it could look like this for a 2d map:


for (int i = 0; i < map_width; i++) {
  for (int j = 0; j < map_height; j++) {
    gameMap[i][j].height = noiseMap[i][j];
  }
}

To add to Jonjova’s answer:

for each [i,j], you would execute the following call:


double noiseValue = SimplexNoise.noise(i * widthFactor, j * heightFactor);

This will return values that range from -1 to 1. How you convert those values to ones that are useful for your voxels is up to you. The two most common strategies are scaling (“smooth” noise) and applying an Abs function to the results prior to scaling (“turbulent” noise).

The values widthFactor and hightFactor above are used to control how quickly the values transition. With SimplexNoise, progressing integers tend to just generate unrelated, random values. I’d try using a factor such as 1/128 (give or take a power of two) as then you will get the transitions between the random peaks.

To get more interesting effects, you will have to make multiple calls to the function at differing width/height factors, and weight the various answers depending on the frequency content you desire. Also, the noise result can be used to permute another function such as a sin or radial gradient.

Ok have no idea but what the hell

Whats the game map array I havent got that

How do you create your map? The map array is what contains the data that will be rendered as your map. For example an array of floats with the values -1 to 1 as described below. You then tell the game to go trough every single post in the array and render all numbers between lets say -1 to -0.40 as a dirt block, -0.40 to -0 as grass, etc etc.