Public Member Functions | |
AtmosphereRenderer (QOpenGLFunctions_3_3_Core &gl, QString const &pathToData, ShowMySky::Settings *tools, std::function< void(QOpenGLShaderProgram &shprog)> const &drawSurface) | |
AtmosphereRenderer (AtmosphereRenderer const &)=delete | |
AtmosphereRenderer (AtmosphereRenderer &&)=delete | |
void | setDrawSurfaceCallback (std::function< void(QOpenGLShaderProgram &shprog)> const &drawSurface) override |
Set the callback that will draw the screen surface. More... | |
int | initDataLoading (QByteArray viewDirVertShaderSrc, QByteArray viewDirFragShaderSrc, std::vector< std::pair< std::string, GLuint >> viewDirBindAttribLocations) override |
Initialize step-by-step process of loading of data. More... | |
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. More... | |
LoadingStatus | stepDataLoading () override |
Perform a single step of data loading. More... | |
int | initPreparationToDraw () override |
Initialize step-by-step process of preparation to render. More... | |
LoadingStatus | stepPreparationToDraw () override |
Perform a single step of preparation to draw. More... | |
QString | currentActivity () const override |
Get a string describing current activity. More... | |
bool | isLoading () const override |
Tell whether the renderer is in process of loading data. More... | |
bool | isReadyToRender () const override |
Tell whether the renderer is ready for a draw call. More... | |
bool | canGrabRadiance () const override |
Tell whether radiance of a pixel can be queried. More... | |
bool | canSetSolarSpectrum () const override |
Tell whether solar spectrum can be changed. More... | |
bool | canRenderPrecomputedEclipsedDoubleScattering () const override |
Tell whether precomputed eclipsed double scattering can be rendered. More... | |
GLuint | getLuminanceTexture () override |
Get OpenGL name of the luminance render target. More... | |
void | draw (double brightness, bool clear) override |
Do the drawing. More... | |
void | resizeEvent (int width, int height) override |
Update render target size. More... | |
QVector4D | getPixelLuminance (QPoint const &pixelPos) override |
Get luminance of a pixel. More... | |
SpectralRadiance | getPixelSpectralRadiance (QPoint const &pixelPos) override |
Get spectral radiance of a pixel. More... | |
std::vector< float > | getWavelengths () override |
Get the wavelengths used in computations. More... | |
void | setSolarSpectrum (std::vector< float > const &solarIrradianceAtTOA) override |
Set a custom solar spectrum. More... | |
void | resetSolarSpectrum () override |
Reset solar spectrum to the default. More... | |
Direction | getViewDirection (QPoint const &pixelPos) override |
Get view direction of a pixel. More... | |
void | setScattererEnabled (QString const &name, bool enable) override |
Enable or disable a single-scattering layer. More... | |
int | initShaderReloading () override |
Initialize step-by-step process of reloading of shaders. More... | |
LoadingStatus | stepShaderReloading () override |
Perform a single step of reloading of shaders. More... | |
AtmosphereParameters const & | atmosphereParameters () const |
AtmosphereRenderer::AtmosphereRenderer | ( | QOpenGLFunctions_3_3_Core & | gl, |
QString const & | pathToData, | ||
ShowMySky::Settings * | tools, | ||
std::function< void(QOpenGLShaderProgram &shprog)> const & | drawSurface | ||
) |
This is the constructor of the renderer. It saves the reference to gl
, tools
for later use (so these objects must outlive AtmosphereRenderer), also saves the drawSurface
callback. Then the model description file params.atmo
inside the directory pointed to pathToData
is parsed.
If an error occurs while parsing the model description file, ShowMySky::Error is thrown.
The callback function drawSurface
has one parameter: a shader program shprog
that includes, aside from the core atmosphere model GLSL code, the shaders viewDirVertShaderSrc
and viewDirFragShaderSrc
that have been passed to initDataLoading method (this should be done by the application before any other calls). By the point when this callback is called, shprog
has already been bound to current OpenGL context (via glUseProgram
).
The purpose of shprog
is to enable setting of the necessary uniform values via the glUniform*
family of functions to make the drawing work. It also includes the calcViewDir
function implemented in viewDirVertShaderSrc
shader, so the necessary uniform values (if any) for the operation of calcViewDir
should also to be set in this callback before issuing any draw calls.
To create an instance of AtmosphereRenderer indirectly having dlopen
ed the ShowMySky
library, use ShowMySky_AtmosphereRenderer_create.
gl | QtOpenGL-provided OpenGL 3.3 function resolver; |
pathToData | path to the data directory of the atmosphere model that contains params.atmo ; |
tools | pointer to an implementation of the ShowMySky::Settings interface; |
drawSurface | a callback function that will be called each time a surface is to be rendered. |
|
overridevirtual |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
The calcmysky
utility has an option to disable generation of the texture for second-order scattering during solar eclipse. If this option was used for generation of the current atmosphere model, this function will return false
. In this case, it is only valid for ShowMySky::Settings::multipleScatteringEnabled to return true
either with ShowMySky::Settings::onTheFlyPrecompDoubleScatteringEnabled returning true
, or ShowMySky::Settings::usingEclipseShader returning false
.
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
Implements ShowMySky::AtmosphereRenderer.
|
inlineoverridevirtual |
This is a string intended for the user to see what's going on, e.g. "Loading textures and shaders...".
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This is the method that performs all the drawing logic.
brightness | relative brightness of the scene. 0 effectively means draw nothing (or NaNs in case of broken textures or shaders), 1 means normal brightness. |
clear | whether to clear the screen surface to zeros prior to drawing. This can be set to false to accumulate subsequent draws, and to true to draw the first render. |
Implements ShowMySky::AtmosphereRenderer.
|
inlineoverridevirtual |
This method returns the OpenGL name suitable for use with glBindTexture
for the render target containing photopic and scotopic luminance values packed into vec4
pixels (see getPixelLuminance for details). This is the main output of draw that can be used to finally render the data to screen in the desired color space.
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method obtains luminance of the pixel specified by pixelPos
. First three components of the 4D vector are the CIE 1931 tristimulus values in lumens, while the fourth one is the scotopic luminance in lumens (CIE 1951).
Maximum luminous efficacy is 683.002 lm/W for photopic values and 1700.13 lm/W for scotopic ones. Reference: Rapport BIPM-2019/05. Principles Governing Photometry, 2nd edition. Sections 6.2, 6.3.
pixelPos | pixel position in window coordinates: (0,0) corresponds to top-left point. |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method obtains spectral radiance of the pixel specified by pixelPos
.
pixelPos | pixel position in window coordinates: (0,0) corresponds to top-left point. |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method obtains view direction corresponding to the pixel specified by pixelPos
.
pixelPos | pixel position in window coordinates: (0,0) corresponds to top-left point. |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method initializes the process of loading of shaders and textures for the current atmosphere model. The actual loading is done step-by-step by calling stepDataLoading.
The fragment shader viewDirFragShaderSrc
passed here implements vec3 calcViewDir(void)
function that is used as an application-agnostic way of determining view direction of the ray associated with a given fragment of the surface being rendered.
viewDirVertShaderSrc | a vertex shader that will be used by all the shader programs that implement the atmosphere model; |
viewDirFragShaderSrc | a fragment shader that implements calcViewDir function; |
viewDirBindAttribLocations | locations of vertex attributes necessary to render the screen surface. Each pair consists of an attribute name and its location. |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
The renderer loads different slices of textures depending on current scene parameters (e.g. altitude). Whenever such parameters change, it may become necessary to reload another slice.
The application might want to show a progress indicator for this reloading process. In this case, calling this method will initialize the process if it's needed and tell whether there's anything to do (return value is positive). If the return value is positive, stepPreparationToDraw should be called repeatedly until its return value indicates completion (or failure).
If there's no need for progress indication, this function (and stepPreparationToDraw) can be ignored. Otherwise, use this method to initialize the process of reloading data.
This method can also be called during the preparation to render to find out the number of steps to do.
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This is a debug method. It initializes the process of reloading of shaders for the current atmosphere model. The actual reloading is done step-by-step by calling stepShaderReloading.
The reloading can be used to quickly update the current model when a shader has been edited or regenerated with another parameters.
Implements ShowMySky::AtmosphereRenderer.
|
inlineoverridevirtual |
Implements ShowMySky::AtmosphereRenderer.
|
inlineoverridevirtual |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method undoes what setSolarSpectrum did, returning the current spectrum to the one used by calcmysky
utility when generating the textures.
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method should be called whenever the render target changes its size.
width | width of the render target; |
height | height of the rener target. |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method sets a callback function that will be called each time a surface is to be rendered.
The callback has one parameter: a shader program shprog
that includes, aside from the core atmosphere model GLSL code, the shaders viewDirVertShaderSrc
and viewDirFragShaderSrc
that were passed to initDataLoading method (or to the constructor of AtmosphereRenderer). By the point when this callback is called, shprog
has already been bound to current OpenGL context (via glUseProgram
).
The purpose of shprog
is to enable setting of the necessary uniform values via the glUniform*
family of functions to make the drawing work. It also includes the calcViewDir
function implemented in viewDirVertShaderSrc
shader, so the necessary uniform values (if any) for the operation of calcViewDir
should also to be set in this callback before issuing any draw calls.
drawSurface | the callback that renders the surface. |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This is a debug option that lets one toggle a single-scattering layer associated with a particular scattering species.
This option doesn't affect transmittance of air, it only controls whether first-order inscattered light from the species specified is included in the render.
name | name of the species, as given in the Scatterer section of the model description file; |
enable | whether first-order inscattered light from this species should be rendered. |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method lets one change the solar spectrum that was used in computations by calcmysky
utility, to aid easy switching between types of the illuminating star.
This method can only be called if canSetSolarSpectrum returns true
.
spectralIrradianceAtTOA | Spectral irradiance at the top of atmosphere (i.e. at the highest altitude for which the model has data), in \(\mathrm{\frac{W}{m^2\,sr\,nm}}\). |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method lets the user change the way view direction is computed (e.g. to switch projections). The new vertex and fragment shaders replace the old ones that initially are passed to initDataLoading. This action may take some time because it causes relinking of all the shader programs in use.
viewDirVertShaderSrc | a vertex shader that will be used by all the shader programs that implement the atmosphere model; |
viewDirFragShaderSrc | a fragment shader that implements calcViewDir function; |
viewDirBindAttribLocations | locations of vertex attributes necessary to render the screen surface. Each pair consists of an attribute name and its location. |
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method performs a single step of data loading.
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This method performs a single step of preparation to draw started by initPreparationToDraw.
Implements ShowMySky::AtmosphereRenderer.
|
overridevirtual |
This is a debug method. It performs a single step of the process of reloading of shaders initialized by initShaderReloading.
Implements ShowMySky::AtmosphereRenderer.