diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp index 7fc66f32b7..26f1dac64c 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp @@ -70,14 +70,14 @@ namespace { constexpr std::string_view _loggerCat = "AtmosphereDeferredcaster"; - constexpr std::array 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 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, diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.h b/modules/atmosphere/rendering/atmospheredeferredcaster.h index d6f58ed5df..49f29a6395 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.h +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.h @@ -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 _shadowConfArray; diff --git a/modules/atmosphere/rendering/renderableatmosphere.cpp b/modules/atmosphere/rendering/renderableatmosphere.cpp index e46c6e2956..7894d814de 100644 --- a/modules/atmosphere/rendering/renderableatmosphere.cpp +++ b/modules/atmosphere/rendering/renderableatmosphere.cpp @@ -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 diff --git a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl index 4789e2ba2d..c0bfdcdc30 100644 --- a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl +++ b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl @@ -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); }