Added two if statements to clap the value returned by stb_perlin_fbm_noise3 to between -1.0f and 1.0f. Not sure why this was required but it fixed the issue with random spikes.
This commit is contained in:
parent
f31df7521a
commit
36bf4372b8
|
|
@ -846,10 +846,14 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
|
||||||
// octaves = 6 -- number of "octaves" of noise3() to sum
|
// octaves = 6 -- number of "octaves" of noise3() to sum
|
||||||
float p = stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6);
|
float p = stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6);
|
||||||
|
|
||||||
|
// Clamp between -1.0f and 1.0f
|
||||||
|
if(p < -1.0f) p = -1.0f;
|
||||||
|
if(p > 1.0f) p = 1.0f;
|
||||||
|
|
||||||
// We need to normalize the data from [-1..1] to [0..1]
|
// We need to normalize the data from [-1..1] to [0..1]
|
||||||
float np = (p + 1.0f)/2.0f;
|
float np = (p + 1.0f)/2.0f;
|
||||||
|
|
||||||
int intensity = (int)(np*255.0f);
|
int intensity = (int)(np*255.0);
|
||||||
pixels[y*width + x] = (Color){ intensity, intensity, intensity, 255 };
|
pixels[y*width + x] = (Color){ intensity, intensity, intensity, 255 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user