cloudy-raytracer/common/noise/cloudnoise.cpp

41 lines
1.1 KiB
C++
Raw Normal View History

2023-01-24 06:44:20 +01:00
#include "cloudnoise.h"
#include "worleynoise.h"
#include "perlinnoise.h"
CloudNoise::CloudNoise(int size) : Noise(size)
2023-01-24 06:44:20 +01:00
{
2023-01-26 20:32:40 +01:00
int minSize = std::min(32, size);
2023-01-24 06:44:20 +01:00
// Some worley noises
2023-01-26 20:32:40 +01:00
WorleyNoise worleyNoise1(minSize, 3);
2023-01-24 11:18:03 +01:00
WorleyNoise worleyNoise3(size, 15);
2023-01-24 06:44:20 +01:00
// Some perlin noises
2023-01-26 20:32:40 +01:00
PerlinNoise perlinNoise1(minSize, 3);
2023-01-24 08:35:10 +01:00
PerlinNoise perlinNoise2(size, 15);
2023-01-24 06:44:20 +01:00
// Generate the noise
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
for (int z = 0; z < size; z++)
{
float sx = x / (float) size;
float sy = y / (float) size;
float sz = z / (float) size;
2023-01-24 06:44:20 +01:00
float worley1 = worleyNoise1.getNoise(sx, sy, sz);
float worley3 = worleyNoise3.getNoise(sx, sy, sz);
float perlin1 = perlinNoise1.getNoise(sx, sy, sz);
2023-01-24 08:35:10 +01:00
float perlin2 = perlinNoise2.getNoise(sx, sy, sz);
2023-01-24 06:44:20 +01:00
2023-01-24 08:35:10 +01:00
float noise = worley1 * 0.4f + worley3 * 0.12f + perlin1 * 0.36f + perlin2 * 0.12;
2023-01-24 06:44:20 +01:00
setNoise(x, y, z, noise);
}
}
}
}