cloudy-raytracer/shader/cloudshader.h

68 lines
2.1 KiB
C
Raw Normal View History

#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"
#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
struct CloudSettings
{
int noiseSize = 512; // 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
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
float phaseA = .8f; // .5f
float phaseB = .4f; // .3f
2023-01-29 04:25:14 +01:00
float phaseOffset = .8f; // .8f
float phaseIntensity = .1f; // 1.0f
2023-01-29 04:25:14 +01:00
float edgeFadeOffDistance = .5f; // .5f
};
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
Color transparency(const Scene &scene, const Ray &ray, float maxLength) const override;
private:
CloudSettings settings;
bool isTransparent() const;
2023-01-24 06:26:24 +01:00
Noise cloudNoise;
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;
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-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;
};
#endif //CG1_TRACER_CLOUDSHADER_H