Add the ability to fade the atmosphere (closes #2700)

This commit is contained in:
Alexander Bock
2023-05-17 11:00:39 +02:00
parent d0d82b79fa
commit 5abbe9dcd9
4 changed files with 27 additions and 16 deletions

View File

@@ -70,14 +70,14 @@
namespace {
constexpr std::string_view _loggerCat = "AtmosphereDeferredcaster";
constexpr std::array<const char*, 27> UniformNames = {
"cullAtmosphere", "Rg", "Rt", "groundRadianceEmission", "HR", "betaRayleigh",
"HM", "betaMieExtinction", "mieG", "sunRadiance", "ozoneLayerEnabled", "HO",
"betaOzoneExtinction", "SAMPLES_R", "SAMPLES_MU", "SAMPLES_MU_S", "SAMPLES_NU",
"inverseModelTransformMatrix", "modelTransformMatrix",
"projectionToModelTransformMatrix", "viewToWorldMatrix", "camPosObj",
"sunDirectionObj", "hardShadows", "transmittanceTexture", "irradianceTexture",
"inscatterTexture"
constexpr std::array<const char*, 28> UniformNames = {
"cullAtmosphere", "opacity", "Rg", "Rt", "groundRadianceEmission", "HR",
"betaRayleigh", "HM", "betaMieExtinction", "mieG", "sunRadiance",
"ozoneLayerEnabled", "HO", "betaOzoneExtinction", "SAMPLES_R", "SAMPLES_MU",
"SAMPLES_MU_S", "SAMPLES_NU", "inverseModelTransformMatrix",
"modelTransformMatrix", "projectionToModelTransformMatrix", "viewToWorldMatrix",
"camPosObj", "sunDirectionObj", "hardShadows", "transmittanceTexture",
"irradianceTexture", "inscatterTexture"
};
constexpr float ATM_EPS = 2000.f;
@@ -294,6 +294,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& data, const Deferred
isAtmosphereInFrustum(MV, tPlanetPos, scaledRadius + ATM_EPS))
{
prg.setUniform(_uniformCache.cullAtmosphere, 0);
prg.setUniform(_uniformCache.opacity, _opacity);
prg.setUniform(_uniformCache.Rg, _atmospherePlanetRadius);
prg.setUniform(_uniformCache.Rt, _atmosphereRadius);
prg.setUniform(_uniformCache.groundRadianceEmission, _groundRadianceEmission);
@@ -503,6 +504,10 @@ void AtmosphereDeferredcaster::setModelTransform(glm::dmat4 transform) {
_modelTransform = std::move(transform);
}
void AtmosphereDeferredcaster::setOpacity(float opacity) {
_opacity = opacity;
}
void AtmosphereDeferredcaster::setParameters(float atmosphereRadius, float planetRadius,
float averageGroundReflectance,
float groundRadianceEmission,

View File

@@ -79,6 +79,7 @@ public:
void calculateAtmosphereParameters();
void setModelTransform(glm::dmat4 transform);
void setOpacity(float opacity);
void setParameters(float atmosphereRadius, float planetRadius,
float averageGroundReflectance, float groundRadianceEmission,
@@ -112,12 +113,12 @@ private:
ghoul::opengl::ProgramObject& program, GLuint deltaSRayleigh);
UniformCache(cullAtmosphere, Rg, Rt, groundRadianceEmission, HR, betaRayleigh, HM,
betaMieExtinction, mieG, sunRadiance, ozoneLayerEnabled, HO, betaOzoneExtinction,
SAMPLES_R, SAMPLES_MU, SAMPLES_MU_S, SAMPLES_NU, inverseModelTransformMatrix,
modelTransformMatrix, projectionToModelTransform, viewToWorldMatrix,
camPosObj, sunDirectionObj, hardShadows, transmittanceTexture, irradianceTexture,
inscatterTexture) _uniformCache;
UniformCache(cullAtmosphere, opacity, Rg, Rt, groundRadianceEmission, HR,
betaRayleigh, HM, betaMieExtinction, mieG, sunRadiance, ozoneLayerEnabled, HO,
betaOzoneExtinction, SAMPLES_R, SAMPLES_MU, SAMPLES_MU_S, SAMPLES_NU,
inverseModelTransformMatrix, modelTransformMatrix, projectionToModelTransform,
viewToWorldMatrix, camPosObj, sunDirectionObj, hardShadows, transmittanceTexture,
irradianceTexture, inscatterTexture) _uniformCache;
ghoul::opengl::TextureUnit _transmittanceTableTextureUnit;
ghoul::opengl::TextureUnit _irradianceTableTextureUnit;
@@ -156,6 +157,7 @@ private:
const glm::ivec3 _textureSize;
glm::dmat4 _modelTransform;
float _opacity = 1.f;
// Eclipse Shadows
std::vector<ShadowConfiguration> _shadowConfArray;

View File

@@ -469,6 +469,7 @@ void RenderableAtmosphere::update(const UpdateData& data) {
glm::dmat4 modelTransform = computeModelTransformMatrix(data.modelTransform);
_deferredcaster->setModelTransform(modelTransform);
_deferredcaster->setOpacity(opacity());
_deferredcaster->update(data);
// Calculate atmosphere dimming coefficient

View File

@@ -64,6 +64,7 @@ in vec2 texCoord;
out vec4 renderTarget;
uniform int cullAtmosphere;
uniform float opacity;
uniform float Rg;
uniform float Rt;
uniform float groundRadianceEmission;
@@ -641,6 +642,8 @@ void main() {
atmColor = sunColor(v, s, r, mu, irradianceFactor);
}
// Final Color of ATM plus terrain:
renderTarget = vec4(inscatterColor + atmColor, 1.0);;
// Final Color of ATM plus terrain. We want to support opacity so we blend between the
// planet color and the full atmosphere color using the opacity value
vec3 c = mix(color, inscatterColor + atmColor, opacity);
renderTarget = vec4(c, 1.0);
}