1 #ifndef INCLUDE_ONCE_5DB905D2_61C0_44DB_8F35_67B31BD78315 2 #define INCLUDE_ONCE_5DB905D2_61C0_44DB_8F35_67B31BD78315 10 #include <QOpenGLTexture> 11 #include <QOpenGLShaderProgram> 12 #include <QOpenGLFunctions_3_3_Core> 13 #include "../common/types.hpp" 14 #include "../common/AtmosphereParameters.hpp" 19 using ShaderProgPtr=std::unique_ptr<QOpenGLShaderProgram>;
20 using TexturePtr=std::unique_ptr<QOpenGLTexture>;
21 using ScattererName=QString;
22 QOpenGLFunctions_3_3_Core& gl;
42 QString
const& pathToData,
44 std::function<
void(QOpenGLShaderProgram& shprog)>
const& drawSurface);
48 void setDrawSurfaceCallback(std::function<
void(QOpenGLShaderProgram& shprog)>
const& drawSurface)
override;
49 int initDataLoading(QByteArray viewDirVertShaderSrc, QByteArray viewDirFragShaderSrc,
50 std::vector<std::pair<std::string,GLuint>> viewDirBindAttribLocations)
override;
51 void setViewDirShaders(QByteArray viewDirVertShaderSrc, QByteArray viewDirFragShaderSrc,
52 std::vector<std::pair<std::string,GLuint>> viewDirBindAttribLocations)
override;
57 bool isLoading()
const override {
return totalLoadingStepsToDo_ > 0; }
64 void draw(
double brightness,
bool clear)
override;
69 void setSolarSpectrum(std::vector<float>
const& solarIrradianceAtTOA)
override;
80 std::function<void(QOpenGLShaderProgram&)> drawSurfaceCallback;
83 int totalLoadingStepsToDo_=-1, loadingStepsDone_=0, currentLoadingIterationStepCounter_=0;
84 QString currentActivity_;
86 QByteArray viewDirVertShaderSrc_, viewDirFragShaderSrc_;
87 std::vector<std::pair<std::string,GLuint>> viewDirBindAttribLocations_;
89 GLuint vao_=0, vbo_=0, luminanceRadianceFBO_=0, viewDirectionFBO_=0;
90 GLuint eclipseSingleScatteringPrecomputationFBO_=0;
91 GLuint eclipseDoubleScatteringPrecomputationFBO_=0;
93 std::vector<TexturePtr> eclipsedDoubleScatteringTextures_;
94 std::vector<TexturePtr> multipleScatteringTextures_;
95 std::vector<TexturePtr> transmittanceTextures_;
96 std::vector<TexturePtr> irradianceTextures_;
97 std::vector<TexturePtr> lightPollutionTextures_;
98 std::vector<GLuint> radianceRenderBuffers_;
99 std::map<ScattererName,std::vector<TexturePtr>> singleScatteringInterpolationGuidesTextures01_;
100 std::map<ScattererName,std::vector<TexturePtr>> singleScatteringInterpolationGuidesTextures02_;
101 GLuint viewDirectionRenderBuffer_=0;
103 std::map<ScattererName,std::vector<TexturePtr>> singleScatteringTextures_;
104 std::map<ScattererName,std::vector<TexturePtr>> eclipsedSingleScatteringPrecomputationTextures_;
105 TexturePtr eclipsedDoubleScatteringPrecomputationScratchTexture_;
106 std::vector<TexturePtr> eclipsedDoubleScatteringPrecomputationTargetTextures_;
107 QOpenGLTexture luminanceRenderTargetTexture_;
109 double altCoordToLoad_=0;
111 std::vector<ShaderProgPtr> lightPollutionPrograms_;
112 std::vector<ShaderProgPtr> zeroOrderScatteringPrograms_;
113 std::vector<ShaderProgPtr> eclipsedZeroOrderScatteringPrograms_;
114 std::vector<ShaderProgPtr> multipleScatteringPrograms_;
116 using ScatteringProgramsMap=std::map<ScattererName,std::vector<ShaderProgPtr>>;
117 std::vector<std::unique_ptr<ScatteringProgramsMap>> singleScatteringPrograms_;
118 std::vector<std::unique_ptr<ScatteringProgramsMap>> eclipsedSingleScatteringPrograms_;
119 std::vector<ShaderProgPtr> eclipsedDoubleScatteringPrecomputedPrograms_;
120 std::vector<ShaderProgPtr> eclipsedDoubleScatteringPrecomputationPrograms_;
122 std::unique_ptr<ScatteringProgramsMap> eclipsedSingleScatteringPrecomputationPrograms_;
123 std::unique_ptr<QOpenGLShader> precomputationProgramsVertShader_;
124 std::unique_ptr<QOpenGLShader> viewDirVertShader_, viewDirFragShader_;
125 ShaderProgPtr viewDirectionGetterProgram_;
126 std::map<ScattererName,bool> scatterersEnabledStates_;
128 std::vector<QVector4D> solarIrradianceFixup_;
130 int numAltIntervalsIn4DTexture_;
139 } state_ = State::NotReady;
142 DEFINE_EXPLICIT_BOOL(CountStepsOnly);
143 void loadTextures(CountStepsOnly countStepsOnly);
144 void reloadScatteringTextures(CountStepsOnly countStepsOnly);
145 void setupRenderTarget();
146 void loadShaders(CountStepsOnly countStepsOnly);
148 void clearResources();
149 void finalizeLoading();
150 void drawSurface(QOpenGLShaderProgram& prog);
152 double altitudeUnitRangeTexCoord()
const;
153 double cameraMoonDistance()
const;
154 glm::dvec3 sunDirection()
const;
155 glm::dvec3 moonPosition()
const;
156 glm::dvec3 moonPositionRelativeToSunAzimuth()
const;
157 glm::dvec3 cameraPosition()
const;
158 glm::ivec2 loadTexture2D(QString
const& path);
159 enum class Texture4DType
164 void loadTexture4D(QString
const& path,
float altitudeCoord, Texture4DType texType = Texture4DType::ScatteringTexture);
165 void loadEclipsedDoubleScatteringTexture(QString
const& path,
float altitudeCoord);
167 void precomputeEclipsedSingleScattering();
168 void precomputeEclipsedDoubleScattering();
169 void renderZeroOrderScattering();
170 void renderSingleScattering();
171 void renderMultipleScattering();
172 void renderLightPollution();
173 void prepareRadianceFrames(
bool clear);
AtmosphereRenderer(QOpenGLFunctions_3_3_Core &gl, QString const &pathToData, ShowMySky::Settings *tools, std::function< void(QOpenGLShaderProgram &shprog)> const &drawSurface)
Definition: AtmosphereRenderer.cpp:2105
GLuint getLuminanceTexture() override
Get OpenGL name of the luminance render target.
Definition: AtmosphereRenderer.hpp:62
Scene settings for AtmosphereRenderer.
Definition: Settings.hpp:9
Definition: AtmosphereRenderer.hpp:34
Definition: AtmosphereParameters.hpp:10
void setDrawSurfaceCallback(std::function< void(QOpenGLShaderProgram &shprog)> const &drawSurface) override
Set the callback that will draw the screen surface.
Definition: AtmosphereRenderer.cpp:2116
int initDataLoading(QByteArray viewDirVertShaderSrc, QByteArray viewDirFragShaderSrc, std::vector< std::pair< std::string, GLuint >> viewDirBindAttribLocations) override
Initialize step-by-step process of loading of data.
Definition: AtmosphereRenderer.cpp:2121
bool isLoading() const override
Tell whether the renderer is in process of loading data.
Definition: AtmosphereRenderer.hpp:57
bool isReadyToRender() const override
Tell whether the renderer is ready for a draw call.
Definition: AtmosphereRenderer.hpp:58
Status of data loading process.
Definition: AtmosphereRenderer.hpp:66
LoadingStatus stepShaderReloading() override
Perform a single step of reloading of shaders.
Definition: AtmosphereRenderer.cpp:2350
LoadingStatus stepPreparationToDraw() override
Perform a single step of preparation to draw.
Definition: AtmosphereRenderer.cpp:1960
SpectralRadiance getPixelSpectralRadiance(QPoint const &pixelPos) override
Get spectral radiance of a pixel.
Definition: AtmosphereRenderer.cpp:1386
int initPreparationToDraw() override
Initialize step-by-step process of preparation to render.
Definition: AtmosphereRenderer.cpp:1936
Definition: AtmosphereRenderer.hpp:17
int initShaderReloading() override
Initialize step-by-step process of reloading of shaders.
Definition: AtmosphereRenderer.cpp:2334
LoadingStatus stepDataLoading() override
Perform a single step of data loading.
Definition: AtmosphereRenderer.cpp:2205
QVector4D getPixelLuminance(QPoint const &pixelPos) override
Get luminance of a pixel.
Definition: AtmosphereRenderer.cpp:1371
bool canRenderPrecomputedEclipsedDoubleScattering() const override
Tell whether precomputed eclipsed double scattering can be rendered.
Definition: AtmosphereRenderer.cpp:1484
void draw(double brightness, bool clear) override
Do the drawing.
Definition: AtmosphereRenderer.cpp:1986
void resizeEvent(int width, int height) override
Update render target size.
Definition: AtmosphereRenderer.cpp:2288
void setScattererEnabled(QString const &name, bool enable) override
Enable or disable a single-scattering layer.
Definition: AtmosphereRenderer.cpp:2329
Direction getViewDirection(QPoint const &pixelPos) override
Get view direction of a pixel.
Definition: AtmosphereRenderer.cpp:1444
QString currentActivity() const override
Get a string describing current activity.
Definition: AtmosphereRenderer.hpp:56
bool canSetSolarSpectrum() const override
Tell whether solar spectrum can be changed.
Definition: AtmosphereRenderer.cpp:1479
void resetSolarSpectrum() override
Reset solar spectrum to the default.
Definition: AtmosphereRenderer.cpp:1438
void setSolarSpectrum(std::vector< float > const &solarIrradianceAtTOA) override
Set a custom solar spectrum.
Definition: AtmosphereRenderer.cpp:1426
std::vector< float > getWavelengths() override
Get the wavelengths used in computations.
Definition: AtmosphereRenderer.cpp:1416
bool canGrabRadiance() const override
Tell whether radiance of a pixel can be queried.
Definition: AtmosphereRenderer.cpp:1471
void setViewDirShaders(QByteArray viewDirVertShaderSrc, QByteArray viewDirFragShaderSrc, std::vector< std::pair< std::string, GLuint >> viewDirBindAttribLocations) override
Replace the current view direction shaders with a new set.
Definition: AtmosphereRenderer.cpp:2150