Adds seed to noise and CloudSettings

This commit is contained in:
Maximilian Giller 2023-01-29 12:19:19 +01:00
parent ffaaa7e814
commit 9608281164
9 changed files with 46 additions and 20 deletions

View file

@ -2,17 +2,17 @@
#include "worleynoise.h"
#include "perlinnoise.h"
CloudNoise::CloudNoise(int size) : Noise(size)
CloudNoise::CloudNoise(int size, unsigned int seed) : Noise(size)
{
int minSize = std::min(32, size);
// Some worley noises
WorleyNoise worleyNoise1(minSize, 3);
WorleyNoise worleyNoise3(size, 15);
WorleyNoise worleyNoise1(minSize, 3, seed);
WorleyNoise worleyNoise3(size, 15, seed);
// Some perlin noises
PerlinNoise perlinNoise1(minSize, 3);
PerlinNoise perlinNoise2(size, 15);
PerlinNoise perlinNoise1(minSize, 3, seed);
PerlinNoise perlinNoise2(size, 15, seed);
// Generate the noise
for (int x = 0; x < size; x++)

View file

@ -7,7 +7,12 @@
class CloudNoise : public Noise
{
public:
CloudNoise(int size);
/**
*
* @param size
* @param seed 0 for random seed
*/
CloudNoise(int size, unsigned int seed = 0);
};

View file

@ -56,11 +56,15 @@ float PerlinNoise::getGradientValue(int x, int y, int z)
return noise;
}
PerlinNoise::PerlinNoise(int size, int gridSize) : Noise(size), gridSize(gridSize)
PerlinNoise::PerlinNoise(int size, int gridSize, unsigned int seed) : Noise(size), gridSize(gridSize)
{
// Init random
std::random_device rd;
this->generator = std::mt19937(rd());
if (seed == 0)
{
std::random_device rd;
seed = rd();
}
this->generator = std::mt19937(seed);
this->distribution = std::normal_distribution<float>(0.0f, 1.0f);
generateNoise();

View file

@ -8,7 +8,13 @@
class PerlinNoise : public Noise
{
public:
PerlinNoise(int size, int gridSize);
/**
*
* @param size
* @param gridSize
* @param seed 0 for random seed
*/
PerlinNoise(int size, int gridSize, unsigned int seed = 0);
private:
void generateNoise();

View file

@ -66,11 +66,15 @@ void WorleyNoise::generateNoise()
<< duration.count() << " seconds" << std::endl;
}
WorleyNoise::WorleyNoise(int size, int numberOfPoints) : numberOfPoints(numberOfPoints), Noise(size)
WorleyNoise::WorleyNoise(int size, int numberOfPoints, unsigned int seed) : numberOfPoints(numberOfPoints), Noise(size)
{
// Init random
std::random_device rd;
this->generator = std::mt19937(rd());
if (seed == 0)
{
std::random_device rd;
seed = rd();
}
this->generator = std::mt19937(seed);
this->distribution = std::uniform_real_distribution<float>(0.0f, 1.0f);
generateNoise();

View file

@ -10,7 +10,13 @@
class WorleyNoise : public Noise
{
public:
WorleyNoise(int size, int numberOfPoints);
/**
*
* @param size
* @param numberOfPoints
* @param seed 0 for random seed
*/
WorleyNoise(int size, int numberOfPoints, unsigned int seed = 0);
protected:
int numberOfPoints;

View file

@ -28,7 +28,7 @@
int main()
{
FastScene scene;
scene.setBackgroundColor(Color(0.529f, 0.808f, 0.922f) * 1.0f);
scene.setBackgroundColor(Color(0.2588f, 0.5098f, 0.9568f) * 1.0f);
// scene.setBackgroundColor(Color(1, 0.79f, 0.62f) * 0.8f);
// Add lights
@ -50,9 +50,9 @@ int main()
// scene.add(std::make_shared<Box>(Vector3d(9.0f, 3.0f, 12.0f), Vector3d(3.0f, 3.0f, 3.0f), boxShader1));
// Add floor
auto floorShader = std::make_shared<SimpleShadowShader>(Color(0.9f, 0.9f, 0.9f));
scene.add(std::make_shared<InfinitePlane>(Vector3d(0.0f, 0.0f, 0.0f), Vector3d(0.0f, 1.0f, 0.0f),
floorShader));
// auto floorShader = std::make_shared<SimpleShadowShader>(Color(0.9f, 0.9f, 0.9f));
// scene.add(std::make_shared<InfinitePlane>(Vector3d(0.0f, 0.0f, 0.0f), Vector3d(0.0f, 1.0f, 0.0f),
// floorShader));
// Add box for volume shader
auto cloudSettings = CloudSettings();
@ -72,7 +72,7 @@ int main()
// Render the scene
SuperRenderer sr;
sr.setSuperSamplingFactor(1);
sr.renderImage(scene, camera, 256, 256).save("result.png");
sr.renderImage(scene, camera, 512, 512).save("result.png");
return 0;
}

View file

@ -69,7 +69,7 @@ bool CloudShader::isTransparent() const
}
CloudShader::CloudShader(const CloudSettings &settings) : settings(settings),
cloudNoise(CloudNoise(NOISE_SIZE))
cloudNoise(CloudNoise(NOISE_SIZE, settings.seed))
{
cloudNoise.invert = true;
}

View file

@ -12,6 +12,7 @@ float const TRANSMITTANCE_BREAK = 0.0001f; // If transmittance goes below this
struct CloudSettings
{
unsigned int seed = 0; // 0 for random seed
float densitySteps = .2f; // .2f
float scale = 30; // 30
float densityOffset = -.55f; // -.55f