CalcMySky  v0.3.1
EclipsedDoubleScatteringPrecomputer.hpp
1 #ifndef INCLUDE_ONCE_9100E17F_B7DD_4CC0_8D2F_9DBB66C7D23D
2 #define INCLUDE_ONCE_9100E17F_B7DD_4CC0_8D2F_9DBB66C7D23D
3 
4 #include <vector>
5 #include <utility>
6 #include <complex>
7 #include <glm/glm.hpp>
8 #include <QtOpenGL>
9 #include "AtmosphereParameters.hpp"
10 
12 {
13  QOpenGLFunctions_3_3_Core& gl;
14  AtmosphereParameters const& atmo;
15  const unsigned texSizeByViewAzimuth;
16  const unsigned texSizeByViewElevation;
17  const unsigned texSizeBySZA;
18 
19  const double texW, texH; // size of the intermediate texture we are rendering to
20  std::vector<glm::vec4> texture_; // output 4D texture data
21  std::vector<std::complex<float>> fourierIntermediate;
22  std::vector<float> elevationsAboveHorizon, elevationsBelowHorizon;
23 
24  static constexpr unsigned VEC_ELEM_COUNT=4; // number of components in the partial radiance vector
25  // The samples of radiance, one container per vec4 component. These containers are re-used for different altitudes and Sun elevations.
26  // The separation into above-horizon and below-horizon parts is because at some altitudes there's a jump (or simply rapid change) in
27  // radiance at the horizon, so spline interpolation would misbehave near this point if done without separation.
28  std::vector<glm::vec2> samplesAboveHorizon[VEC_ELEM_COUNT];
29  std::vector<glm::vec2> samplesBelowHorizon[VEC_ELEM_COUNT];
30  // The samples of radiance interpolated over view elevations but not yet over view azimuths, one container per vec4 component.
31  // These containers are re-used for different altitudes and Sun elevations.
32  std::vector<float> radianceInterpolatedOverElevations[VEC_ELEM_COUNT];
33 
34  GLint origViewportWidth, origViewportHeight;
35 
36  float cosZenithAngleOfHorizon(const float altitude) const;
37  std::pair<float,bool> eclipseTexCoordsToTexVars_cosVZA_VRIG(float vzaTexCoordInUnitRange, float altitude) const;
38  void generateElevationsForEclipsedDoubleScattering(float cameraAltitude);
39 public:
40  /* Preconditions:
41  * * Rendering FBO is bound, and the target texture is attached to it
42  * * program is bound
43  * * Transmittance texture uniform is set for program
44  * * VAO for a quad is bound
45  */
46  EclipsedDoubleScatteringPrecomputer(QOpenGLFunctions_3_3_Core& gl,
47  AtmosphereParameters const& atmo,
48  unsigned texSizeByViewAzimuth, unsigned texSizeByViewElevation,
49  unsigned texSizeBySZA, unsigned texSizeByAltitude);
51 
52  void computeRadianceOnCoarseGrid(QOpenGLShaderProgram& program,
53  GLuint intermediateTextureName, GLuint intermediateTextureTexUnitNum,
54  double cameraAltitude, double sunZenithAngle, double moonZenithAngle,
55  double moonAzimuthRelativeToSun, double earthMoonDistance);
56  void convertRadianceToLuminance(glm::mat4 const& radianceToLuminance);
57  void accumulateLuminance(EclipsedDoubleScatteringPrecomputer const& source, glm::mat4 const& sourceRadianceToLuminance);
58  void generateTextureFromCoarseGridData(unsigned altIndex, unsigned szaIndex, double cameraAltitude);
59 
60  size_t appendCoarseGridSamplesTo(std::vector<glm::vec4>& data) const;
61  void loadCoarseGridSamples(double cameraAltitude, glm::vec4 const* data, size_t numElements);
62 
63  std::vector<glm::vec4> const& texture() const { return texture_; }
64 };
65 
66 #endif
Definition: EclipsedDoubleScatteringPrecomputer.hpp:11
Definition: AtmosphereParameters.hpp:10