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-29 04:25:14 +01:00
|
|
|
float const TRANSMITTANCE_BREAK = 0.0001f; // If transmittance goes below this limit, the cloud is considered opaque
|
2023-01-24 05:22:40 +01:00
|
|
|
|
|
|
|
struct CloudSettings
|
|
|
|
{
|
2023-01-29 15:48:17 +01:00
|
|
|
int noiseSize = 256; // 64
|
2023-01-29 12:19:19 +01:00
|
|
|
unsigned int seed = 0; // 0 for random seed
|
2023-01-29 04:25:14 +01:00
|
|
|
float densitySteps = .2f; // .2f
|
|
|
|
float scale = 30; // 30
|
|
|
|
float densityOffset = -.55f; // -.55f
|
|
|
|
float densityIntensity = 5.0f; // 5.0f
|
|
|
|
float darknessThreshold = .1f; // .1f
|
|
|
|
float shadowIntensity = .6f; // .6f
|
|
|
|
float shadowLightAbsorption = 1; // 1
|
2023-01-29 04:44:49 +01:00
|
|
|
float lightAbsorptionTowardsLight = 0.1f; // .3f // How Bright should the clouds be? Lower is brighter
|
2023-01-29 04:25:14 +01:00
|
|
|
float lightAbsorptionThroughCloud = .8f; // .8f // How dark should the background be where the cloud is? Higher values mean darker background
|
2023-01-29 04:44:49 +01:00
|
|
|
float phaseA = .8f; // .5f
|
|
|
|
float phaseB = .4f; // .3f
|
2023-01-29 04:25:14 +01:00
|
|
|
float phaseOffset = .8f; // .8f
|
2023-01-29 04:44:49 +01:00
|
|
|
float phaseIntensity = .1f; // 1.0f
|
2023-01-29 04:25:14 +01:00
|
|
|
float edgeFadeOffDistance = .5f; // .5f
|
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-29 04:25:14 +01:00
|
|
|
|
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
|
|
|
|
2023-01-29 04:25:14 +01:00
|
|
|
float getCloudDensity(Vector3d point, const Primitive *primitive = nullptr) const;
|
2023-01-24 19:38:12 +01:00
|
|
|
|
2023-01-29 04:25:14 +01:00
|
|
|
Color lightMarch(const Scene &scene, Vector3d currentInCloudPosition, Vector3d lengthDistance,
|
|
|
|
const Primitive *cloudObject) const;
|
2023-01-26 05:04:30 +01:00
|
|
|
|
|
|
|
float rayDensity(const Ray &ray, float maxLength) const;
|
|
|
|
|
2023-01-29 04:25:14 +01:00
|
|
|
float phase(Vector3d visualRay, Vector3d illuminationRay) const;
|
|
|
|
|
|
|
|
static float calcDualHenyeyGreenstein(float cosTheta, float g) ;
|
2023-01-26 05:04:30 +01:00
|
|
|
|
2023-01-29 04:25:14 +01:00
|
|
|
static float calcBeer(float d) ;
|
2023-01-27 05:22:54 +01:00
|
|
|
|
2023-01-29 04:25:14 +01:00
|
|
|
float getEdgeDensity(const Vector3d &point, const Primitive *primitive) const;
|
2023-01-24 05:22:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //CG1_TRACER_CLOUDSHADER_H
|