CalcMySky  v0.3.1
Public Member Functions | List of all members
AtmosphereRenderer Class Reference
Inheritance diagram for AtmosphereRenderer:
ShowMySky::AtmosphereRenderer

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
 

Constructor & Destructor Documentation

◆ AtmosphereRenderer()

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 dlopened the ShowMySky library, use ShowMySky_AtmosphereRenderer_create.

Parameters
glQtOpenGL-provided OpenGL 3.3 function resolver;
pathToDatapath to the data directory of the atmosphere model that contains params.atmo;
toolspointer to an implementation of the ShowMySky::Settings interface;
drawSurfacea callback function that will be called each time a surface is to be rendered.

Member Function Documentation

◆ canGrabRadiance()

bool AtmosphereRenderer::canGrabRadiance ( ) const
overridevirtual
Returns
Whether radiance of a pixel can be queried by a call to getPixelSpectralRadiance.

Implements ShowMySky::AtmosphereRenderer.

◆ canRenderPrecomputedEclipsedDoubleScattering()

bool AtmosphereRenderer::canRenderPrecomputedEclipsedDoubleScattering ( ) const
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.

Returns
Whether precomputed eclipsed double scattering can be rendered.

Implements ShowMySky::AtmosphereRenderer.

◆ canSetSolarSpectrum()

bool AtmosphereRenderer::canSetSolarSpectrum ( ) const
overridevirtual
Returns
Whether solar spectrum can be set by a call to setSolarSpectrum.

Implements ShowMySky::AtmosphereRenderer.

◆ currentActivity()

QString AtmosphereRenderer::currentActivity ( ) const
inlineoverridevirtual

This is a string intended for the user to see what's going on, e.g. "Loading textures and shaders...".

Implements ShowMySky::AtmosphereRenderer.

◆ draw()

void AtmosphereRenderer::draw ( double  brightness,
bool  clear 
)
overridevirtual

This is the method that performs all the drawing logic.

Parameters
brightnessrelative brightness of the scene. 0 effectively means draw nothing (or NaNs in case of broken textures or shaders), 1 means normal brightness.
clearwhether 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.

◆ getLuminanceTexture()

GLuint AtmosphereRenderer::getLuminanceTexture ( )
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.

Returns
OpenGL name of the luminance render target.

Implements ShowMySky::AtmosphereRenderer.

◆ getPixelLuminance()

QVector4D AtmosphereRenderer::getPixelLuminance ( QPoint const &  pixelPos)
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.

Parameters
pixelPospixel position in window coordinates: (0,0) corresponds to top-left point.
Returns
Luminance of the pixel specified.

Implements ShowMySky::AtmosphereRenderer.

◆ getPixelSpectralRadiance()

auto AtmosphereRenderer::getPixelSpectralRadiance ( QPoint const &  pixelPos)
overridevirtual

This method obtains spectral radiance of the pixel specified by pixelPos.

Parameters
pixelPospixel position in window coordinates: (0,0) corresponds to top-left point.
Returns
Spectral radiance of the pixel specified.

Implements ShowMySky::AtmosphereRenderer.

◆ getViewDirection()

auto AtmosphereRenderer::getViewDirection ( QPoint const &  pixelPos)
overridevirtual

This method obtains view direction corresponding to the pixel specified by pixelPos.

Parameters
pixelPospixel position in window coordinates: (0,0) corresponds to top-left point.
Returns
View direction of the pixel specified.

Implements ShowMySky::AtmosphereRenderer.

◆ getWavelengths()

std::vector< float > AtmosphereRenderer::getWavelengths ( )
overridevirtual
Returns
All the wavelengths used in computations, in nanometers.

Implements ShowMySky::AtmosphereRenderer.

◆ initDataLoading()

int AtmosphereRenderer::initDataLoading ( QByteArray  viewDirVertShaderSrc,
QByteArray  viewDirFragShaderSrc,
std::vector< std::pair< std::string, GLuint >>  viewDirBindAttribLocations 
)
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.

Parameters
viewDirVertShaderSrca vertex shader that will be used by all the shader programs that implement the atmosphere model;
viewDirFragShaderSrca fragment shader that implements calcViewDir function;
viewDirBindAttribLocationslocations of vertex attributes necessary to render the screen surface. Each pair consists of an attribute name and its location.
Returns
Total number of loading steps to complete the loading.

Implements ShowMySky::AtmosphereRenderer.

◆ initPreparationToDraw()

int AtmosphereRenderer::initPreparationToDraw ( )
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.

Returns
Total number of loading steps to complete the preparation.

Implements ShowMySky::AtmosphereRenderer.

◆ initShaderReloading()

int AtmosphereRenderer::initShaderReloading ( )
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.

◆ isLoading()

bool AtmosphereRenderer::isLoading ( ) const
inlineoverridevirtual
Returns
Whether the renderer is in process of loading data.

Implements ShowMySky::AtmosphereRenderer.

◆ isReadyToRender()

bool AtmosphereRenderer::isReadyToRender ( ) const
inlineoverridevirtual
Returns
Whether the renderer is ready to render via the draw method.

Implements ShowMySky::AtmosphereRenderer.

◆ resetSolarSpectrum()

void AtmosphereRenderer::resetSolarSpectrum ( )
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.

◆ resizeEvent()

void AtmosphereRenderer::resizeEvent ( int  width,
int  height 
)
overridevirtual

This method should be called whenever the render target changes its size.

Parameters
widthwidth of the render target;
heightheight of the rener target.

Implements ShowMySky::AtmosphereRenderer.

◆ setDrawSurfaceCallback()

void AtmosphereRenderer::setDrawSurfaceCallback ( std::function< void(QOpenGLShaderProgram &shprog)> const &  drawSurface)
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.

Parameters
drawSurfacethe callback that renders the surface.

Implements ShowMySky::AtmosphereRenderer.

◆ setScattererEnabled()

void AtmosphereRenderer::setScattererEnabled ( QString const &  name,
bool  enable 
)
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.

Parameters
namename of the species, as given in the Scatterer section of the model description file;
enablewhether first-order inscattered light from this species should be rendered.

Implements ShowMySky::AtmosphereRenderer.

◆ setSolarSpectrum()

void AtmosphereRenderer::setSolarSpectrum ( std::vector< float > const &  spectralIrradianceAtTOA)
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.

Parameters
spectralIrradianceAtTOASpectral 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.

◆ setViewDirShaders()

void AtmosphereRenderer::setViewDirShaders ( QByteArray  viewDirVertShaderSrc,
QByteArray  viewDirFragShaderSrc,
std::vector< std::pair< std::string, GLuint >>  viewDirBindAttribLocations 
)
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.

Parameters
viewDirVertShaderSrca vertex shader that will be used by all the shader programs that implement the atmosphere model;
viewDirFragShaderSrca fragment shader that implements calcViewDir function;
viewDirBindAttribLocationslocations of vertex attributes necessary to render the screen surface. Each pair consists of an attribute name and its location.

Implements ShowMySky::AtmosphereRenderer.

◆ stepDataLoading()

auto AtmosphereRenderer::stepDataLoading ( )
overridevirtual

This method performs a single step of data loading.

Returns
Status of data loading process: progress, error indication.

Implements ShowMySky::AtmosphereRenderer.

◆ stepPreparationToDraw()

auto AtmosphereRenderer::stepPreparationToDraw ( )
overridevirtual

This method performs a single step of preparation to draw started by initPreparationToDraw.

Returns
Status of preparation process: progress, error indication.

Implements ShowMySky::AtmosphereRenderer.

◆ stepShaderReloading()

auto AtmosphereRenderer::stepShaderReloading ( )
overridevirtual

This is a debug method. It performs a single step of the process of reloading of shaders initialized by initShaderReloading.

Implements ShowMySky::AtmosphereRenderer.


The documentation for this class was generated from the following files: