cloudy-raytracer/common/noise/worleynoise.h

43 lines
1,000 B
C
Raw Normal View History

#ifndef CG1_TRACER_WORLEYNOISE_H
#define CG1_TRACER_WORLEYNOISE_H
#include <random>
#include "common/vector3d.h"
#include "noise.h"
// Based on: https://www.youtube.com/watch?v=4QOcCGI6xOU
class WorleyNoise : public Noise
{
public:
2023-01-29 12:19:19 +01:00
/**
*
* @param size
* @param numberOfPoints
* @param seed 0 for random seed
*/
WorleyNoise(int size, int numberOfPoints, unsigned int seed = 0);
2023-01-29 15:48:17 +01:00
void renderNoiseThread(int xOffset, int xSize);
protected:
int numberOfPoints;
2023-01-24 07:04:58 +01:00
std::vector<Vector3d> points; // 3D-Array, each cell represents a subcell. There are numberOfPoints^3 subcells.
std::uniform_real_distribution<float> distribution;
std::mt19937 generator;
Vector3d getRandomPoint();
float distanceToClosestPoint(Vector3d point);
void generateNoise();
2023-01-24 07:04:58 +01:00
std::vector<Vector3d> getSubcellPoints(Vector3d point);
2023-01-29 15:48:17 +01:00
static void runWorleyNoiseInThread(int xOffset, int xSize, WorleyNoise *noise);
};
#endif //CG1_TRACER_WORLEYNOISE_H