Skip to content

Commit

Permalink
Auto stash before rebase of "main" onto "origin/main"
Browse files Browse the repository at this point in the history
  • Loading branch information
tolstenko committed Oct 21, 2024
1 parent efd4939 commit a39a595
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion docs/artificialintelligence/01-pcg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,39 @@ As you might notice, the function is not stateless, so you have to initialize th

Another one is the Mersenne Twister. It is a high quality PRNG, but it is a bit slower.


## Noise Generation

Noise functions are a type of function that generates random values that are spatially coherent. This means that nearby points in space will have similar values, creating a smooth and continuous pattern. You can use a combination of noise functions to generate complex patterns, such as terrain or textures.

You can implement a random noise function using the PRNG we just covered. The most naive way is to sample a range of RNG values and interpolate them, and use linear interpolation between the samples.

```cpp
// naive noise function
class Noise
{
private:
// samples
float p[512];

// initialize the samples with random values
Noise() {
// fill p with random values between 0 and 1
for (int i = 0; i < 256; i++)
p[i] = xorshift32()/(float)UINT32_MAX;
}

float noise(float x)
{
// find the cell that x is in
int X = (int)floor(x) & 255;
// find the relative position of x in the cell
x -= floor(x);
// return the interpolated value
return P[X] + x * (P[X+1] - P[X]);
}
}
```
### Noise based Procedural Terrain Generation
## Wave function collapse
Expand Down

0 comments on commit a39a595

Please sign in to comment.