From 1dd7d845d945514524ab0abe5ffd887f2ebe3ac3 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Tue, 24 Jan 2023 06:44:20 +0100 Subject: [PATCH] Specific cloud noise --- common/noise/cloudnoise.cpp | 32 ++++++++++++++++++++++++++++++++ common/noise/cloudnoise.h | 14 ++++++++++++++ fancy1.cpp | 4 ++++ shader/cloudshader.cpp | 6 ++---- shader/cloudshader.h | 1 - 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 common/noise/cloudnoise.cpp create mode 100644 common/noise/cloudnoise.h diff --git a/common/noise/cloudnoise.cpp b/common/noise/cloudnoise.cpp new file mode 100644 index 0000000..ba5a395 --- /dev/null +++ b/common/noise/cloudnoise.cpp @@ -0,0 +1,32 @@ +#include "cloudnoise.h" +#include "worleynoise.h" +#include "perlinnoise.h" + +cloudnoise::cloudnoise(int size) : Noise(size) +{ + // Some worley noises + WorleyNoise worleyNoise1(size, 3); + WorleyNoise worleyNoise3(size, 12); + + // Some perlin noises + PerlinNoise perlinNoise1(size, 10); + + // 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 worley1 = worleyNoise1.getNoise(x, y, z); + float worley3 = worleyNoise3.getNoise(x, y, z); + + float perlin1 = perlinNoise1.getNoise(x, y, z); + + float noise = worley1 * 0.6f + worley3 * 0.2f + perlin1 * 0.2; + + setNoise(x, y, z, noise); + } + } + } +} diff --git a/common/noise/cloudnoise.h b/common/noise/cloudnoise.h new file mode 100644 index 0000000..b2a67c7 --- /dev/null +++ b/common/noise/cloudnoise.h @@ -0,0 +1,14 @@ +#ifndef CG1_TRACER_CLOUDNOISE_H +#define CG1_TRACER_CLOUDNOISE_H + + +#include "noise.h" + +class cloudnoise : public Noise +{ +public: + cloudnoise(int size); +}; + + +#endif //CG1_TRACER_CLOUDNOISE_H diff --git a/fancy1.cpp b/fancy1.cpp index e01cec2..87e5c42 100644 --- a/fancy1.cpp +++ b/fancy1.cpp @@ -20,6 +20,7 @@ #include "shader/cloudshader.h" #include "common/noise/perlinnoise.h" #include "shader/noiseshader.h" +#include "common/noise/cloudnoise.h" int main() { @@ -37,6 +38,9 @@ int main() busShader); // Add floor +// auto noise = std::make_shared(32); +// noise->invert = true; +// auto noiseShader = std::make_shared(noise, 0.2f); auto noiseShader = std::make_shared(std::make_shared(256, 10), 0.02f); // auto floorShader = std::make_shared(Color(0.9f, 0.9f, 0.9f)); scene.add(std::make_shared(Vector3d(0.0f, 0.0f, 0.0f), Vector3d(0.0f, 1.0f, 0.0f), diff --git a/shader/cloudshader.cpp b/shader/cloudshader.cpp index 063c6d4..da3aca0 100644 --- a/shader/cloudshader.cpp +++ b/shader/cloudshader.cpp @@ -1,4 +1,5 @@ #include "cloudshader.h" +#include "common/noise/cloudnoise.h" Color CloudShader::shade(const Scene &scene, const Ray &ray) const @@ -82,10 +83,7 @@ bool CloudShader::isTransparent() const } CloudShader::CloudShader(const CloudSettings &settings) : settings(settings), - cloudNoise(WorleyNoise( - NOISE_SIZE, - NOISE_POINTS) - ) + cloudNoise(cloudnoise(NOISE_SIZE)) { cloudNoise.invert = true; } diff --git a/shader/cloudshader.h b/shader/cloudshader.h index f4ec86b..e993d32 100644 --- a/shader/cloudshader.h +++ b/shader/cloudshader.h @@ -7,7 +7,6 @@ #include "common/noise/worleynoise.h" int const NOISE_SIZE = 32; -int const NOISE_POINTS = 5; struct CloudSettings {