2023-01-24 05:22:40 +01:00
|
|
|
#ifndef CG1_TRACER_CLOUDSHADER_H
|
|
|
|
#define CG1_TRACER_CLOUDSHADER_H
|
|
|
|
|
|
|
|
#include "scene/scene.h"
|
|
|
|
#include "shader.h"
|
2023-01-24 19:38:12 +01:00
|
|
|
#include "light/light.h"
|
2023-01-24 05:22:40 +01:00
|
|
|
#include "primitive/primitive.h"
|
|
|
|
#include "common/noise/worleynoise.h"
|
|
|
|
|
2023-01-24 07:52:55 +01:00
|
|
|
int const NOISE_SIZE = 128;
|
2023-01-26 05:04:30 +01:00
|
|
|
float const TRANSMITTANCE_BREAK = 0.005f; // If transmittance goes below this limit, the cloud is considered opaque
|
2023-01-24 05:22:40 +01:00
|
|
|
|
|
|
|
struct CloudSettings
|
|
|
|
{
|
|
|
|
int densitySamples = 100;
|
2023-01-26 05:04:30 +01:00
|
|
|
int lightSamples = 100;
|
2023-01-24 08:35:10 +01:00
|
|
|
float scale = 10;
|
2023-01-26 20:14:45 +01:00
|
|
|
float densityOffset = -0.57f;
|
2023-01-26 05:04:30 +01:00
|
|
|
float densityIntensity = 7.0f;
|
|
|
|
float darknessThreshold = 0.07f;
|
2023-01-24 22:55:48 +01:00
|
|
|
float shadowIntensity = 0.8f;
|
2023-01-26 20:14:45 +01:00
|
|
|
float shadowLightAbsorption = 1;
|
2023-01-26 05:04:30 +01:00
|
|
|
float lightAbsorptionTowardsLight = 0.94f;
|
|
|
|
float lightAbsorptionThroughCloud = 0.85f;
|
2023-01-24 05:22:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class CloudShader : public Shader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CloudShader(CloudSettings const &settings = CloudSettings());
|
|
|
|
|
|
|
|
// Shader functions
|
|
|
|
Color shade(Scene const &scene, Ray const &ray) const;
|
2023-01-24 22:55:48 +01:00
|
|
|
Color transparency(const Scene &scene, const Ray &ray, float maxLength) const override;
|
2023-01-24 05:22:40 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
CloudSettings settings;
|
|
|
|
|
|
|
|
|
|
|
|
bool isTransparent() const;
|
|
|
|
|
2023-01-24 06:26:24 +01:00
|
|
|
Noise cloudNoise;
|
2023-01-24 05:22:40 +01:00
|
|
|
|
|
|
|
float getCloudDensity(Vector3d point) const;
|
2023-01-24 19:38:12 +01:00
|
|
|
|
2023-01-26 05:04:30 +01:00
|
|
|
Color lightMarch(const Scene &scene, Vector3d currentInCloudPosition, Vector3d lengthDistance) const;
|
|
|
|
|
|
|
|
float rayDensity(const Ray &ray, float maxLength) const;
|
|
|
|
|
|
|
|
float scatterFactor(Vector3d visualRay, Vector3d illuminationRay) const;
|
|
|
|
|
|
|
|
float HenyeyGreenstein(float cosTheta, float g) const;
|
2023-01-24 05:22:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //CG1_TRACER_CLOUDSHADER_H
|