An atmosphere effect. More...
Static Public Member Functions | |
static nkMemory::UniquePtr< AtmosphereEffect > | create (System *system=nullptr) |
An atmosphere effect.
This effect imitates the atmosphere and the way it interacts with light. This allows to create a plausible, dynamic sky. The effect also packs a light scattering logic, allowing to simulate the atmosphere impact on distant objects. While it defaults to a reality-like rendering, the numerous parameters also ensure it is possible to be creative with the effect.
This effect is heavily based on various papers, that can help getting a good understanding of how the effect works :
Note that this effect focuses (for now) on painting the atmosphere as seen from inside of it, not outside. As such, it is not possible to simulate the atmosphere as seen from a planet far away.
|
noexcept |
Default constructor. Alternatively, see AtmosphereEffect::create(), or EffectManager::createOrRetrieve().
|
virtual |
Destructor. See EffectManager::erase().
nkGraphics::Texture* nkAstraeus::AtmosphereEffect::getSunTransmittanceLut | ( | ) | const |
nkGraphics::Texture* nkAstraeus::AtmosphereEffect::getMultiScatteringLut | ( | ) | const |
nkGraphics::Texture* nkAstraeus::AtmosphereEffect::getSourceColorTexture | ( | ) | const |
nkGraphics::Texture* nkAstraeus::AtmosphereEffect::getSourceDepthTexture | ( | ) | const |
nkGraphics::Shader* nkAstraeus::AtmosphereEffect::getLutShader | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getSunPosition | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getPlanetAlbedo | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getRayleighScattering | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getRayleighExtinction | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getRayleighAbsorb | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getMieScattering | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getMieExtinction | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getMieAbsorb | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getOzoneScattering | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getOzoneExtinction | ( | ) | const |
nkMaths::Vector nkAstraeus::AtmosphereEffect::getOzoneAbsorb | ( | ) | const |
float nkAstraeus::AtmosphereEffect::getMieG | ( | ) | const |
float nkAstraeus::AtmosphereEffect::getRayleighHeightDensityFactor | ( | ) | const |
float nkAstraeus::AtmosphereEffect::getMieHeightDensityFactor | ( | ) | const |
float nkAstraeus::AtmosphereEffect::getOzoneHeighthDensityFactor | ( | ) | const |
float nkAstraeus::AtmosphereEffect::getDistanceFactor | ( | ) | const |
float nkAstraeus::AtmosphereEffect::getSunIlluminanceFactor | ( | ) | const |
float nkAstraeus::AtmosphereEffect::getSunAngularRadius | ( | ) | const |
unsigned int nkAstraeus::AtmosphereEffect::getSunLutSampleCount | ( | ) | const |
unsigned int nkAstraeus::AtmosphereEffect::getMultiScatteringLutSphereSampleCount | ( | ) | const |
unsigned int nkAstraeus::AtmosphereEffect::getMultiScatteringLutMarchSampleCount | ( | ) | const |
unsigned int nkAstraeus::AtmosphereEffect::getRaymarchSampleCount | ( | ) | const |
unsigned int nkAstraeus::AtmosphereEffect::getSunTransmittanceLutWidth | ( | ) | const |
unsigned int nkAstraeus::AtmosphereEffect::getSunTransmittanceLutHeight | ( | ) | const |
unsigned int nkAstraeus::AtmosphereEffect::getMultiScatteringLutWidth | ( | ) | const |
unsigned int nkAstraeus::AtmosphereEffect::getMultiScatteringLutHeight | ( | ) | const |
SHADOW_MAP_PCF nkAstraeus::AtmosphereEffect::getShadowSamplingMethod | ( | ) | const |
float nkAstraeus::AtmosphereEffect::getShadowDepthBias | ( | ) | const |
bool nkAstraeus::AtmosphereEffect::getShadowDebug | ( | ) | const |
bool nkAstraeus::AtmosphereEffect::getUseHalfFloatForLuts | ( | ) | const |
bool nkAstraeus::AtmosphereEffect::getOnlyScatterOnObjects | ( | ) | const |
void nkAstraeus::AtmosphereEffect::setSourceColorTexture | ( | nkGraphics::Texture * | value | ) |
Sets the source color texture to use to render the effect. The source color corresponds to the active color buffer, and will be interpreted as the incoming light from surrounding objects. Typically, the effect expects a black background to paint the sky. Any non black pixel will be taken as input and the light scattering along the way will be applied on it. To ensure the best rendering, it is expected to get a light buffer (float texture) to physically simulate the scattering on.
value | The source color (light) texture to use. |
void nkAstraeus::AtmosphereEffect::setSourceDepthTexture | ( | nkGraphics::Texture * | value | ) |
Sets the source depth texture to use to render the effect. The depth information is expected as non linear, as rendered normally. This information is used to casts the rays to march, to scatter the light along. The typical texture to provide is the depth buffer of the active scene rendering, for which the atmosphere effect should be applied.
value | The texture to use for depth sampling. |
void nkAstraeus::AtmosphereEffect::setSunPosition | ( | nkMaths::Vector | value | ) |
Sets the sun position to use for rendering. The sun position is normalized to ultimately be used as a direction from which the sun light is coming from. As such, the position can be thought as a position on the unit circle around the camera, in the world coordinates.
Defaults to the full zenith (0, 1, 0).
value | The wanted sun position, in world coordinates. |
void nkAstraeus::AtmosphereEffect::setPlanetAlbedo | ( | nkMaths::Vector | value | ) |
Sets the planet general albedo, which can be interpreted as the ambient light.
Defaults to a low, dark (0.1, 0.1, 0.1).
value | The planet albedo to use. |
void nkAstraeus::AtmosphereEffect::setRayleighScattering | ( | nkMaths::Vector | value | ) |
Sets the Rayleigh scattering value to use. The value is expected to be per meters. The Rayleigh component corresponds to the light interaction with the atmosphere molecules, in this context how they scatter the light over the distance.
Defaults to a realistic looking (5.802, 13.558, 33.1).
value | The scattering to use (R, G, B). |
void nkAstraeus::AtmosphereEffect::setRayleighExtinction | ( | nkMaths::Vector | value | ) |
Sets the Rayleigh extinction value to use. The value is expected to be per meters. The Rayleigh component corresponds to the light interaction with the atmosphere molecules, in this context how they extinct the light over the distance.
Defaults to a realistic looking (5.802, 13.558, 33.1).
value | The extinction to use (R, G, B). |
void nkAstraeus::AtmosphereEffect::setRayleighAbsorb | ( | nkMaths::Vector | value | ) |
Sets the Rayleigh absorb value to use. The value is expected to be per meters. The Rayleigh component corresponds to the light interaction with the atmosphere molecules, in this context how they absorb the light over the distance.
Defaults to a realistic looking (0, 0, 0).
value | The absorption to use (R, G, B). |
void nkAstraeus::AtmosphereEffect::setMieScattering | ( | nkMaths::Vector | value | ) |
Sets the Mie scattering value to use. The value is expected to be per meters. The Mie component corresponds to the light interaction with the atmosphere particles, in this context how they scatter the light over the distance.
Defaults to a realistic looking (3.996, 3.996, 3.996).
value | The scattering to use (R, G, B). |
void nkAstraeus::AtmosphereEffect::setMieExtinction | ( | nkMaths::Vector | value | ) |
Sets the Mie extinction value to use. The value is expected to be per meters. The Mie component corresponds to the light interaction with the atmosphere particles, in this context how they extinct the light over the distance.
Defaults to a realistic looking (8.396, 8.396, 8.396).
value | The extinction to use (R, G, B). |
void nkAstraeus::AtmosphereEffect::setMieAbsorb | ( | nkMaths::Vector | value | ) |
Sets the Mie absorption value to use. The value is expected to be per meters. The Mie component corresponds to the light interaction with the atmosphere particles, in this context how they absorb the light over the distance.
Defaults to a realistic looking (4.4, 4.4, 4.4).
value | The absorption to use (R, G, B). |
void nkAstraeus::AtmosphereEffect::setOzoneScattering | ( | nkMaths::Vector | value | ) |
Sets the ozone scattering value to use. The value is expected to be per meters. The ozone component corresponds to the light interaction with the gas, in this context how it scatters the light over the distance.
Defaults to a realistic looking (0, 0, 0).
value | The scattering to use (R, G, B). |
void nkAstraeus::AtmosphereEffect::setOzoneExtinction | ( | nkMaths::Vector | value | ) |
Sets the ozone extinction value to use. The value is expected to be per meters. The ozone component corresponds to the light interaction with the gas, in this context how it extincts the light over the distance.
Defaults to a realistic looking (0.65, 1.881, 0.085).
value | The extinction to use (R, G, B). |
void nkAstraeus::AtmosphereEffect::setOzoneAbsorb | ( | nkMaths::Vector | value | ) |
Sets the ozone absorption value to use. The value is expected to be per meters. The ozone component corresponds to the light interaction with the gas, in this context how it absorbs the light over the distance.
Defaults to a realistic looking (0.65, 1.881, 0.085).
value | The absorption to use (R, G, B). |
void nkAstraeus::AtmosphereEffect::setMieG | ( | float | value | ) |
Sets the Mie g parameter's value. The parameter is part of its phase equation, and can be interpreted as the amount of influence the particle have. Realistic values range between ]0, 1[, with a higher value cranking up the effect.
Defaults to a realistic looking value of 0.8.
value | The value to set for the parameter. |
void nkAstraeus::AtmosphereEffect::setRayleighHeightDensityFactor | ( | float | value | ) |
Sets the height density factor for the Rayleigh influence. The atmosphere having a different composition as altitude changes, it impacts differently the light traveling through it depending on its height. This parameter allows to make it more or less dense at lower altitude. The lower the value, the higher the density.
Defaults to 1.
value | The factor to use. |
void nkAstraeus::AtmosphereEffect::setMieHeightDensityFactor | ( | float | value | ) |
Sets the height density factor for the Mie influence. The atmosphere having a different composition as altitude changes, it impacts differently the light traveling through it depending on its height. This parameter allows to make it more or less dense at lower altitude. The lower the value, the higher the density.
Defaults to 1.
value | The factor to use. |
void nkAstraeus::AtmosphereEffect::setOzoneHeightDensityFactor | ( | float | value | ) |
Sets the height density factor for the ozone influence. The atmosphere having a different composition as altitude changes, it impacts differently the light traveling through it depending on its height. This parameter allows to make it more or less dense at lower altitude. The lower the value, the higher the density.
Defaults to 1.
value | The factor to use. |
void nkAstraeus::AtmosphereEffect::setDistanceFactor | ( | float | value | ) |
Sets the distance factor, to apply to computed distances found. This parameter is a direct factor applied to the raymarching distance, impacting how deep a ray will travel in the atmosphre. It is applied to the distance found from the source depth texture, and the intersection with the planet's surface.
Defaults to 1.
value | The factor to use. |
void nkAstraeus::AtmosphereEffect::setSunIlluminanceFactor | ( | float | value | ) |
Sets the sun illuminance factor, impacting how bright the sun should be considered. This will make the whole atmosphere brighter or darker depending on the setting.
Defaults to 5.
value | The factor to use. |
void nkAstraeus::AtmosphereEffect::setSunAngularRadius | ( | float | value | ) |
Sets the sun angular radius, in degrees. This drives how big the sun will be as seen in the sky.
Defaults to a realistic looking 0.545.
value | The angular radius, in degrees. |
void nkAstraeus::AtmosphereEffect::setSunTransmittanceLutSampleCount | ( | unsigned int | value | ) |
Sets the sample count when computing the sun transmittance LUT. The higher the sample count, the higher the quality, but also higher the impact on performances.
Defaults to 40.
value | The number of samples that should be taken during LUT creation. |
void nkAstraeus::AtmosphereEffect::setMultiScatteringLutSphereSampleCount | ( | unsigned int | value | ) |
Sets the sample count taken during sphere sampling (around a given point) when computing the multi scattering LUT. The sampling is done along 2 directions, giving a total sample count of the value given squared. The higher the sample count, the higher the quality, but also higher the impact on performances.
Defaults to 8.
value | The number of samples that should be taken during LUT creation. |
void nkAstraeus::AtmosphereEffect::setMultiScatteringLutMarchSampleCount | ( | unsigned int | value | ) |
Sets the sample count taken during marching when computing the multi scattering LUT. The higher the sample count, the higher the quality, but also higher the impact on performances.
Defaults to 20.
value | The number of samples that should be taken during LUT creation. |
void nkAstraeus::AtmosphereEffect::setRaymarchSampleCount | ( | unsigned int | value | ) |
Sets the sample count taken during marching when rendering the effect The higher the sample count, the higher the quality, but also higher the impact on performances.
Defaults to 32.
value | The number of samples that should be taken during LUT creation. |
void nkAstraeus::AtmosphereEffect::setShadowSource | ( | nkGraphics::Texture * | shadowMap, |
nkGraphics::Camera * | lightCamera | ||
) |
Sets the shadow mapping resources to use for the visibility method during sampling of the light scattering. This directly links it to the ShadowMappingLib::nkShadowMap() sources.
If left unset, the visibility method always returns 1.
shadowMap | The texture to use as the shadow map. |
lightCamera | The camera from which the shadow map has been generated. |
void nkAstraeus::AtmosphereEffect::setShadowSamplingMethod | ( | SHADOW_MAP_PCF | value | ) |
Sets the shadow map sampling method for the visibility method. This directly links to the dedicated flag within the ShadowMappingLib::nkShadowMap() sources.
The default value is the one used by default by ShadowMappingLib::nkShadowMap().
value | The sampling method to use. |
void nkAstraeus::AtmosphereEffect::setShadowDepthBias | ( | float | value | ) |
Sets the shadow mapping depth bias, for the visibility method. This directly links to the dedicated flag within the ShadowMappingLib::nkShadowMap() sources.
value | The bias to use. |
void nkAstraeus::AtmosphereEffect::setShadowDebug | ( | bool | value | ) |
Sets whether the shadow mapping out of bounds debugging capabilities should be enabled or not. This directly links to the dedicated flag within the ShadowMappingLib::nkShadowMap() sources.
value | Whether the enable the flag (true) or not (false). |
void nkAstraeus::AtmosphereEffect::setSunTransmittanceLutWidth | ( | unsigned int | value | ) |
Sets the target width for the sun transmittance LUT.
Defaults to 256.
value | The dimension wanted, in pixels. |
void nkAstraeus::AtmosphereEffect::setSunTransmittanceLutHeight | ( | unsigned int | value | ) |
Sets the target height for the sun transmittance LUT.
Defaults to 64.
value | The dimension wanted, in pixels. |
void nkAstraeus::AtmosphereEffect::setMultiScatteringLutWidth | ( | unsigned int | value | ) |
Sets the target width for the multi scattering LUT.
Defaults to 64.
value | The dimension wanted, in pixels. |
void nkAstraeus::AtmosphereEffect::setMultiScatteringLutHeight | ( | unsigned int | value | ) |
Sets the target height for the multi scattering LUT.
Defaults to 64.
value | The dimension wanted, in pixels. |
void nkAstraeus::AtmosphereEffect::setUseHalfFloatForLuts | ( | bool | value | ) |
Sets whether the LUTs generated should use half floats instead of pure floats. This can save memory and bandwith, potentially helping with performances at the price of less accurate LUTs. Default is false (off, pure floats).
value | Whether the LUTs should be hald floats (true) or not (false). |
void nkAstraeus::AtmosphereEffect::setOnlyScatterOnObjects | ( | bool | value | ) |
Sets whether the effect will only scatter on visible object, or not. When this option is activated, the depth value will be filtered and all values equal to 1 won't be rendered. This prevents the effect from rendering the far sky.
value | Whether the effect should only scatter on visible object (true), or not (false). |
bool nkAstraeus::AtmosphereEffect::refreshLuts | ( | ) |
Manually refreshes the Look-Up-Table textures. Calling this method might be necessary depending on which parameter has been changed while the effect was loaded. Else, the LUTs are generated during the effect loading, for given parameters at the time.
|
overridevirtual |
Loads the effect and make it ready for rendering.
Implements nkAstraeus::Effect.
|
overridevirtual |
Unloads the effect and its internal memory. After that, the effect is unusable for rendering.
Implements nkAstraeus::Effect.
|
static |
Creates an instance of the class, and returns ownership over it.
system | The system the resource should live in. If left to nullptr, will seek the singleton instance of the system. |