Created
February 24, 2024 19:24
-
-
Save AlexiyOrlov/5ccde8f0063974ab0b52d2818c4bd64f to your computer and use it in GitHub Desktop.
Noise generation at an arbitrary position for terrain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void GenerateNoise(int width, int height, float scale, int octaves, int positionX, int positionY) | |
{ | |
for (int y = positionY; y < positionY + height; y++) | |
{ | |
for (int x = positionX; x < positionX + width; x++) | |
{ | |
float sampleX = (float)x / width * scale; | |
float sampleY = (float)y / height * scale; | |
float noise = 0.0f; | |
float frequency = 0.0f; | |
for (int oct = 1; oct < octaves; oct *= 2) | |
{ | |
frequency += 1.0f / oct; | |
noise += (1.0f / oct) * perlin.noise2D_01(oct * sampleX /*+ randomInt*/, oct * sampleY /*+ randomInt*/); | |
} | |
noise = noise / frequency; | |
//do something based on noise | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment