FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
CloudLayer.h
1#pragma once
2
3#include "SkyModel.h"
4
5#include <cstdint>
6#include <vector>
7
23namespace visual::sky
24{
25
28{
29 double baseX = 0.0, baseY = 0.0;
30 double detailX = 0.0, detailY = 0.0;
31};
32
35{
36 Rgb sun {0.0, 0.0, 0.0};
37 double sunUp = 0.0;
38 Rgb sky {0.0, 0.0, 0.0};
39};
40
42{
43public:
45 static constexpr int kSize = 256;
46
53 CloudLayer(std::uint32_t seed, double cover, double altitude = 1500.0, double thickness = 1.0, int size = kSize);
54
56 const std::vector<float>& Texels() const { return m_texels; }
57
59 int Size() const { return m_size; }
60
61 double Cover() const { return m_cover; }
62 double Altitude() const { return m_altitude; }
64 double BasePeriod() const { return 24000.0; }
66 double DetailPeriod() const { return 3000.0; }
68 double DetailWeight() const { return 0.35; }
70 double Threshold() const { return m_threshold; }
72 double Softness() const { return m_softness; }
74 double MaxOpticalDepth() const { return m_thickness * (2.0 + 30.0 * m_cover * m_cover); }
76 double DepthWidth() const { return 0.3 + 0.5 * m_cover * m_cover; }
77
83 double Noise(double x, double y, const CloudDrift& drift) const;
84
86 double OpticalDepth(double x, double y, const CloudDrift& drift) const;
87
89 double OpticalDepthOfNoise(double noise) const;
90
92 double MeanTransmittance() const { return m_meanTransmittance; }
93
95 double CoveredFraction() const { return m_covered; }
96
97private:
99 double Lookup(int c, double u, double v) const;
100
101 int m_size;
102 double m_softness = 0.12;
103 double m_cover;
104 double m_altitude;
105 double m_thickness;
106 double m_threshold = 0.0;
107 double m_meanTransmittance = 1.0;
108 double m_covered = 0.0;
109 std::vector<float> m_texels;
110};
111
120double DistanceToCloud(double eyeAltitude, double mu, double cloudAltitude, double groundRadius = 6360e3);
121
130Rgb CloudRadiance(double tau, double viewUp, double cosSunView, const CloudLight& light);
131
133double CloudViewTransmittance(double tau, double viewUp);
134
145Rgb CompositeCloud(const Rgb& clear, const Rgb& cloud, double tView, const Rgb& air, double haze = 1.0);
146
152double HazeLight(double meanTransmittance);
153
154} // namespace visual::sky
Definition CloudLayer.h:42
CloudLayer(std::uint32_t seed, double cover, double altitude=1500.0, double thickness=1.0, int size=kSize)
double OpticalDepth(double x, double y, const CloudDrift &drift) const
Vertical optical depth of the layer at a horizontal position (see Noise()).
double Softness() const
Width of the cloud edge in noise units (narrower for finer textures, whose detail then shows at the e...
Definition CloudLayer.h:72
double OpticalDepthOfNoise(double noise) const
Optical depth from a noise value.
int Size() const
Texels per side of the noise texture.
Definition CloudLayer.h:59
double Noise(double x, double y, const CloudDrift &drift) const
const std::vector< float > & Texels() const
The noise texture, RGBA float per texel (base, detail, 0, 0), row-major (row along y),...
Definition CloudLayer.h:56
double DetailWeight() const
Weight of the detail channel in the noise.
Definition CloudLayer.h:68
double BasePeriod() const
Tile size of the base channel [m].
Definition CloudLayer.h:64
double CoveredFraction() const
Share of the base tile covered by cloud (optical depth above 0.3).
Definition CloudLayer.h:95
double DetailPeriod() const
Tile size of the detail channel [m].
Definition CloudLayer.h:66
double Threshold() const
Noise value where the cloud starts (edge 0 of the density smoothstep).
Definition CloudLayer.h:70
double MeanTransmittance() const
Mean of exp(-optical depth) over the base tile: the share of the direct sun that gets through on aver...
Definition CloudLayer.h:92
double MaxOpticalDepth() const
Optical depth of the densest cloud (thicker layers for higher coverage, times the thickness).
Definition CloudLayer.h:74
double DepthWidth() const
Noise range over which the optical depth grows to its maximum (wider for overcast,...
Definition CloudLayer.h:76
static constexpr int kSize
Texels per side of the noise texture by default (Visual.CloudResolution = "Normal").
Definition CloudLayer.h:45
Definition CloudLayer.h:24
Rgb CompositeCloud(const Rgb &clear, const Rgb &cloud, double tView, const Rgb &air, double haze=1.0)
double HazeLight(double meanTransmittance)
Rgb CloudRadiance(double tau, double viewUp, double cosSunView, const CloudLight &light)
double CloudViewTransmittance(double tau, double viewUp)
Transmittance of the cloud along the view: exp(-tau / max(viewUp, 0.1)).
double DistanceToCloud(double eyeAltitude, double mu, double cloudAltitude, double groundRadius=6360e3)
std::array< double, 3 > Rgb
Red, green, blue.
Definition SkyModel.h:27
Horizontal offsets of the two noise channels [m], from the wind.
Definition CloudLayer.h:28
Light arriving at the cloud layer (any consistent radiometric unit).
Definition CloudLayer.h:35
double sunUp
Sine of the sun's elevation.
Definition CloudLayer.h:37
Rgb sun
Direct sun irradiance at the cloud altitude, normal to the beam.
Definition CloudLayer.h:36
Rgb sky
Clear-sky irradiance on a horizontal surface.
Definition CloudLayer.h:38