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 "worleynoise.h"
#include "perlinnoise.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); int minSize = std::min(32, size);
// Some worley noises // Some worley noises
WorleyNoise worleyNoise1(minSize, 3); WorleyNoise worleyNoise1(minSize, 3, seed);
WorleyNoise worleyNoise3(size, 15); WorleyNoise worleyNoise3(size, 15, seed);
// Some perlin noises // Some perlin noises
PerlinNoise perlinNoise1(minSize, 3); PerlinNoise perlinNoise1(minSize, 3, seed);
PerlinNoise perlinNoise2(size, 15); PerlinNoise perlinNoise2(size, 15, seed);
// Generate the noise // Generate the noise
for (int x = 0; x < size; x++) for (int x = 0; x < size; x++)

View file

@ -7,7 +7,12 @@
class CloudNoise : public Noise class CloudNoise : public Noise
{ {
public: 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; 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 // Init random
std::random_device rd; if (seed == 0)
this->generator = std::mt19937(rd()); {
std::random_device rd;
seed = rd();
}
this->generator = std::mt19937(seed);
this->distribution = std::normal_distribution<float>(0.0f, 1.0f); this->distribution = std::normal_distribution<float>(0.0f, 1.0f);
generateNoise(); generateNoise();

View file

@ -8,7 +8,13 @@
class PerlinNoise : public Noise class PerlinNoise : public Noise
{ {
public: 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: private:
void generateNoise(); void generateNoise();

View file

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

View file

@ -10,7 +10,13 @@
class WorleyNoise : public Noise class WorleyNoise : public Noise
{ {
public: 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: protected:
int numberOfPoints; int numberOfPoints;

View file

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

View file

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

View file

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