CalcMySky  v0.3.1
AtmosphereParameters.hpp
1 #ifndef INCLUDE_ONCE_D1C5F1EB_B6E7_4260_8AC3_57C35BB9B0DF
2 #define INCLUDE_ONCE_D1C5F1EB_B6E7_4260_8AC3_57C35BB9B0DF
3 
4 #include <cmath>
5 #include <glm/glm.hpp>
6 #include <QtGui>
7 #include "types.hpp"
8 #include "util.hpp"
9 
11 {
12  DEFINE_EXPLICIT_BOOL(ForceNoEDSTextures);
13  // We don't copy external spectra into output directory, so the renderer needs to skip loading them
14  DEFINE_EXPLICIT_BOOL(SkipSpectra);
15 
16  struct Scatterer
17  {
18  QString name;
19  AtmosphereParameters const& atmo;
20 
21  GLfloat scatteringCrossSectionAt1um = NAN;
22  GLfloat angstromExponent = NAN;
23  std::vector<glm::vec4> singleScatteringAlbedo;
24  std::vector<glm::vec4> extinctionCrossSection_;
25  std::vector<glm::vec4> scatteringCrossSection_;
26  QString numberDensity;
27  QString phaseFunction;
28  PhaseFunctionType phaseFunctionType=PhaseFunctionType::General;
29  bool needsInterpolationGuides = false;
30 
31  explicit Scatterer(QString const& name, AtmosphereParameters const& atmo)
32  : name(name)
33  , atmo(atmo)
34  {}
35  bool valid(const SkipSpectra spectrumSkipped) const
36  {
37  return (spectrumSkipped || scatteringCrossSection_.size()==atmo.allWavelengths.size()) &&
38  (spectrumSkipped || extinctionCrossSection_.size()==atmo.allWavelengths.size()) &&
39  (spectrumSkipped || singleScatteringAlbedo .size()==atmo.allWavelengths.size()) &&
40  !numberDensity.isEmpty() &&
41  !phaseFunction.isEmpty() &&
42  !name.isEmpty();
43  }
44  void finalizeLoading();
45  glm::vec4 scatteringCrossSection(glm::vec4 const wavelengths) const
46  {
47  const auto i=atmo.wavelengthsIndex(wavelengths);
48  return scatteringCrossSection_[i];
49  }
50  glm::vec4 extinctionCrossSection(glm::vec4 const wavelengths) const
51  {
52  const auto i=atmo.wavelengthsIndex(wavelengths);
53  return extinctionCrossSection_[i];
54  }
55  };
56  struct Absorber
57  {
58  QString numberDensity;
59  QString name;
60  std::vector<glm::vec4> absorptionCrossSection;
61 
62  AtmosphereParameters const& atmo;
63 
64  Absorber(QString const& name, AtmosphereParameters const& atmo)
65  : name(name)
66  , atmo(atmo)
67  {}
68  bool valid(const SkipSpectra spectrumSkipped) const
69  {
70  return !numberDensity.isEmpty() &&
71  (spectrumSkipped || absorptionCrossSection.size()==atmo.allWavelengths.size()) &&
72  !name.isEmpty();
73  }
74  glm::vec4 crossSection(glm::vec4 const wavelengths) const
75  {
76  const auto i=atmo.wavelengthsIndex(wavelengths);
77  return absorptionCrossSection[i];
78  }
79  };
80 
81  QString descriptionFileText;
82  std::vector<glm::vec4> allWavelengths;
83  std::vector<glm::vec4> solarIrradianceAtTOA;
84  std::vector<glm::vec4> lightPollutionRelativeRadiance;
85  std::string textureOutputDir=".";
86  GLint transmittanceTexW, transmittanceTexH;
87  GLint irradianceTexW, irradianceTexH;
88  glm::ivec4 scatteringTextureSize;
89  glm::ivec2 eclipsedSingleScatteringTextureSize;
90  glm::ivec4 eclipsedDoubleScatteringTextureSize;
91  glm::ivec2 lightPollutionTextureSize;
92  unsigned eclipsedDoubleScatteringNumberOfAzimuthPairsToSample;
93  unsigned eclipsedDoubleScatteringNumberOfElevationPairsToSample;
94  unsigned scatteringOrdersToCompute;
95  GLint numTransmittanceIntegrationPoints;
96  GLint radialIntegrationPoints;
97  GLint angularIntegrationPoints;
98  GLint eclipseAngularIntegrationPoints;
99  GLint lightPollutionAngularIntegrationPoints;
100  GLfloat earthRadius;
101  GLfloat atmosphereHeight;
102  double earthSunDistance;
103  double earthMoonDistance;
104  GLfloat sunAngularRadius; // calculated from earthSunDistance
105  float lengthOfHorizRayFromGroundToBorderOfAtmo; // calculated from atmosphereHeight and earthRadius
106  // moonAngularRadius is calculated from earthMoonDistance and other parameters on the fly, so isn't kept here
107  std::vector<glm::vec4> groundAlbedo;
108  std::vector<Scatterer> scatterers;
109  std::vector<Absorber> absorbers;
110  bool allTexturesAreRadiance=false;
111  bool noEclipsedDoubleScatteringTextures=false;
112  static constexpr unsigned pointsPerWavelengthItem=4;
113  static constexpr unsigned FORMAT_VERSION = 6;
114  static constexpr char ALL_TEXTURES_ARE_RADIANCES_DIRECTIVE[]="all textures are radiances";
115  static constexpr char NO_ECLIPSED_DOUBLE_SCATTERING_TEXTURES_DIRECTIVE[]="no eclipsed double scattering textures";
116  static constexpr char SOLAR_IRRADIANCE_AT_TOA_KEY[]="solar irradiance at toa";
117  static constexpr char WAVELENGTHS_KEY[]="wavelengths";
118 
119  void parse(QString const& atmoDescrFileName,
120  ForceNoEDSTextures forceNoEDSTextures=ForceNoEDSTextures{false},
121  SkipSpectra skipSpectra=SkipSpectra{false});
122  // XXX: keep in sync with those in previewer and renderer
123  auto scatTexWidth() const { return GLsizei(scatteringTextureSize[0]); }
124  auto scatTexHeight() const { return GLsizei(scatteringTextureSize[1]*scatteringTextureSize[2]); }
125  auto scatTexDepth() const { return GLsizei(scatteringTextureSize[3]); }
126  unsigned wavelengthsIndex(glm::vec4 const& wavelengths) const
127  {
128  const auto it=std::find(allWavelengths.begin(), allWavelengths.end(), wavelengths);
129  assert(it!=allWavelengths.end());
130  return it-allWavelengths.begin();
131  }
132  static QString spectrumToString(std::vector<glm::vec4> const& spectrum);
133 };
134 
135 #endif
Definition: AtmosphereParameters.hpp:10
Definition: AtmosphereParameters.hpp:16
Definition: AtmosphereParameters.hpp:56