Reviewed function GenImagePerlinNoise()
Added support for noise image offset
This commit is contained in:
parent
dd3b3dbadb
commit
c8e97df233
3 changed files with 18 additions and 9 deletions
|
@ -24,10 +24,10 @@ int main()
|
|||
|
||||
Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE);
|
||||
Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE);
|
||||
Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.f, WHITE, BLACK);
|
||||
Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK);
|
||||
Image checked = GenImageChecked(screenWidth, screenHeight, 32, 32, RED, BLUE);
|
||||
Image whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f);
|
||||
Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 8.f);
|
||||
Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f);
|
||||
Image cellular = GenImageCellular(screenWidth, screenHeight, 32);
|
||||
|
||||
Texture2D textures[NUM_TEXTURES];
|
||||
|
|
|
@ -908,7 +908,7 @@ RLAPI Image GenImageGradientH(int width, int height, Color left, Color right);
|
|||
RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient
|
||||
RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2); // Generate image: checked
|
||||
RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise
|
||||
RLAPI Image GenImagePerlinNoise(int width, int height, float scale); // Generate image: perlin noise
|
||||
RLAPI Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale); // Generate image: perlin noise
|
||||
RLAPI Image GenImageCellular(int width, int height, int tileSize); // Generate image: cellular algorithm. Bigger tileSize means bigger cells
|
||||
|
||||
// Texture2D configuration functions
|
||||
|
|
|
@ -611,6 +611,8 @@ Image ImageCopy(Image image)
|
|||
newImage.height = image.height;
|
||||
newImage.mipmaps = image.mipmaps;
|
||||
newImage.format = image.format;
|
||||
|
||||
//if (image.mipmaps > 1) ImageMipmaps(&newImage);
|
||||
}
|
||||
|
||||
return newImage;
|
||||
|
@ -823,6 +825,8 @@ void ImageFormat(Image *image, int newFormat)
|
|||
}
|
||||
|
||||
free(pixels);
|
||||
|
||||
//if (image->mipmaps > 1) ImageMipmaps(image);
|
||||
}
|
||||
else TraceLog(LOG_WARNING, "Image data format is compressed, can not be converted");
|
||||
}
|
||||
|
@ -1688,7 +1692,7 @@ Image GenImageWhiteNoise(int width, int height, float factor)
|
|||
}
|
||||
|
||||
// Generate image: perlin noise
|
||||
Image GenImagePerlinNoise(int width, int height, float scale)
|
||||
Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale)
|
||||
{
|
||||
Color *pixels = (Color *)malloc(width*height*sizeof(Color));
|
||||
|
||||
|
@ -1696,10 +1700,15 @@ Image GenImagePerlinNoise(int width, int height, float scale)
|
|||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
float nx = (float)x*scale/(float)width;
|
||||
float ny = (float)y*scale/(float)height;
|
||||
float nx = (float)(x + offsetX)*scale/(float)width;
|
||||
float ny = (float)(y + offsetY)*scale/(float)height;
|
||||
|
||||
// we need to translate the data from [-1; 1] to [0; 1]
|
||||
// Typical values to start playing with:
|
||||
// lacunarity = ~2.0 -- spacing between successive octaves (use exactly 2.0 for wrapping output)
|
||||
// gain = 0.5 -- relative weighting applied to each successive octave
|
||||
// octaves = 6 -- number of "octaves" of noise3() to sum
|
||||
|
||||
// NOTE: We need to translate the data from [-1..1] to [0..1]
|
||||
float p = (stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6, 0, 0, 0) + 1.0f)/2.0f;
|
||||
|
||||
int intensity = (int)(p*255.0f);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue