mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-24 21:39:02 -05:00
Added a background exposure control for atm scenes.
This commit is contained in:
@@ -92,8 +92,8 @@ return {
|
||||
--"atmospheremars",
|
||||
--"moon",
|
||||
|
||||
--"lodglobes/earth",
|
||||
"lodglobes/mars",
|
||||
"lodglobes/earth",
|
||||
--"lodglobes/mars",
|
||||
--"lodglobes/moon",
|
||||
|
||||
--"toyvolume",
|
||||
|
||||
@@ -69,9 +69,9 @@ return {
|
||||
SegmentsPerPatch = 64,
|
||||
Atmosphere = {
|
||||
-- Atmosphere radius in Km
|
||||
--AtmoshereRadius = 6450,
|
||||
--AtmoshereRadius = 6420.0,
|
||||
AtmoshereRadius = 6447.0,
|
||||
--AtmosphereRadius = 6450,
|
||||
--AtmosphereRadius = 6420.0,
|
||||
AtmosphereRadius = 6447.0,
|
||||
--PlanetRadius = 6378.137,
|
||||
PlanetRadius = 6377.0,
|
||||
--PlanetRadius = 6360.0,
|
||||
@@ -131,6 +131,7 @@ return {
|
||||
Image = {
|
||||
ToneMapping = jToneMapping,
|
||||
Exposure = 0.4,
|
||||
Background = 1.8,
|
||||
Gamma = 1.85,
|
||||
},
|
||||
Debug = {
|
||||
|
||||
@@ -128,7 +128,7 @@ return {
|
||||
-- Allows camera to go down 10000 meters below the reference ellipsoid InteractionDepthBelowEllipsoid = 10000, -- Useful when having negative height map values
|
||||
Atmosphere = {
|
||||
-- Atmosphere radius in Km
|
||||
AtmoshereRadius = 3463.17495,
|
||||
AtmosphereRadius = 3463.17495,
|
||||
--PlanetRadius = 3396.19,
|
||||
--PlanetRadius = 3393.0,
|
||||
PlanetRadius = 3386.190,
|
||||
@@ -160,6 +160,7 @@ return {
|
||||
Image = {
|
||||
ToneMapping = jToneMapping,
|
||||
Exposure = 0.4,
|
||||
Background = 1.8,
|
||||
Gamma = 1.85,
|
||||
},
|
||||
Debug = {
|
||||
|
||||
@@ -109,6 +109,7 @@ AtmosphereDeferredcaster::AtmosphereDeferredcaster()
|
||||
, _ellipsoidRadii(glm::dvec3(0.0))
|
||||
, _sunRadianceIntensity(50.0f)
|
||||
, _exposureConstant(0.4f)
|
||||
, _exposureBackgroundConstant(1.8f)
|
||||
, _gammaConstant(1.8f)
|
||||
, _renderableClass(NoRenderableClass)
|
||||
, _calculationTextureScale(1.0)
|
||||
@@ -201,6 +202,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData & renderData, const D
|
||||
program.setUniform("betaOzoneExtinction", _ozoneExtinctionCoeff);
|
||||
|
||||
program.setUniform("exposure", _exposureConstant);
|
||||
program.setUniform("backgroundExposure", _exposureBackgroundConstant);
|
||||
program.setUniform("gamma", _gammaConstant);
|
||||
program.setUniform("RenderableClass", static_cast<int>(_renderableClass));
|
||||
|
||||
@@ -489,6 +491,10 @@ void AtmosphereDeferredcaster::setHDRConstant(const float hdrConstant) {
|
||||
_exposureConstant = hdrConstant;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setBackgroundConstant(const float backgroundConstant) {
|
||||
_exposureBackgroundConstant = backgroundConstant;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setGammaConstant(const float gammaConstant) {
|
||||
_gammaConstant = gammaConstant;
|
||||
}
|
||||
@@ -1578,6 +1584,7 @@ void AtmosphereDeferredcaster::loadAtmosphereDataIntoShaderProgram(std::unique_p
|
||||
shaderProg->setUniform("mieG", _miePhaseConstant);
|
||||
shaderProg->setUniform("sunRadiance", _sunRadianceIntensity);
|
||||
shaderProg->setUniform("exposure", _exposureConstant);
|
||||
shaderProg->setUniform("backgroundExposure", _exposureBackgroundConstant);
|
||||
shaderProg->setUniform("gamma", _gammaConstant);
|
||||
shaderProg->setUniform("RenderableClass", static_cast<int>(_renderableClass));
|
||||
shaderProg->setUniform("TRANSMITTANCE_W", (int)_transmittance_table_width);
|
||||
|
||||
@@ -102,6 +102,7 @@ public:
|
||||
void setMiePhaseConstant(const float miePhaseConstant);
|
||||
void setSunRadianceIntensity(const float sunRadiance);
|
||||
void setHDRConstant(const float hdrConstant);
|
||||
void setBackgroundConstant(const float backgroundConstant);
|
||||
void setGammaConstant(const float gammaConstant);
|
||||
void setRayleighScatteringCoefficients(const glm::vec3 & rayScattCoeff);
|
||||
void setOzoneExtinctionCoefficients(const glm::vec3 & ozoneExtCoeff);
|
||||
@@ -175,6 +176,7 @@ private:
|
||||
float _miePhaseConstant;
|
||||
float _sunRadianceIntensity;
|
||||
float _exposureConstant;
|
||||
float _exposureBackgroundConstant;
|
||||
float _gammaConstant;
|
||||
|
||||
glm::vec3 _rayleighScatteringCoeff;
|
||||
|
||||
@@ -36,6 +36,9 @@ const int RenderableGlobe = 2;
|
||||
// a RenderableGlobe
|
||||
uniform int RenderableClass;
|
||||
|
||||
// Background exposure hack
|
||||
uniform float backgroundExposure;
|
||||
|
||||
uniform sampler2D irradianceTexture;
|
||||
uniform sampler3D inscatterTexture;
|
||||
uniform sampler2DMS mainPositionTexture;
|
||||
@@ -448,7 +451,7 @@ vec3 inscatterRadiance(inout vec3 x, inout float t, inout float irradianceFactor
|
||||
if (groundHit) {
|
||||
return finalScatteringRadiance;
|
||||
} else {
|
||||
return ((r-Rg)/(Rt-Rg))*spaceColor.rgb * 1.8 + finalScatteringRadiance;
|
||||
return ((r-Rg)/(Rt-Rg))*spaceColor.rgb * backgroundExposure + finalScatteringRadiance;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -659,7 +662,7 @@ void main() {
|
||||
renderTarget = finalRadiance;
|
||||
}
|
||||
} else {
|
||||
renderTarget = vec4(HDR(meanColor.xyz * 1.8), meanColor.a);
|
||||
renderTarget = vec4(HDR(meanColor.xyz * backgroundExposure), meanColor.a);
|
||||
//renderTarget = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
} else if ( RenderableClass == RenderableGlobe) {
|
||||
@@ -789,7 +792,7 @@ void main() {
|
||||
renderTarget = finalRadiance;
|
||||
}
|
||||
} else {
|
||||
renderTarget = vec4(HDR(meanColor.xyz * 1.8), meanColor.a);
|
||||
renderTarget = vec4(HDR(meanColor.xyz * backgroundExposure), meanColor.a);
|
||||
//renderTarget = meanColor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace {
|
||||
const std::string keyTextureScale = "PreCalculatedTextureScale";
|
||||
const std::string keySaveTextures = "SaveCalculatedTextures";
|
||||
const std::string keyAtmosphere = "Atmosphere";
|
||||
const std::string keyAtmosphereRadius = "AtmoshereRadius";
|
||||
const std::string keyAtmosphereRadius = "AtmosphereRadius";
|
||||
const std::string keyPlanetRadius = "PlanetRadius";
|
||||
const std::string keyAverageGroundReflectance = "PlanetAverageGroundReflectance";
|
||||
const std::string keyRayleigh = "Rayleigh";
|
||||
@@ -61,6 +61,7 @@ namespace {
|
||||
const std::string keyImage = "Image";
|
||||
const std::string keyToneMappingOp = "ToneMapping";
|
||||
const std::string keyExposure = "Exposure";
|
||||
const std::string keyBackground = "Background";
|
||||
const std::string keyGamma = "Gamma";
|
||||
#endif
|
||||
}
|
||||
@@ -117,7 +118,8 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
"Mie Scattering/Extinction Proportion Coefficient (%)", 0.9f, 0.01f, 1.0f),
|
||||
FloatProperty("mieAsymmetricFactorG", "Mie Asymmetric Factor G", 0.85f, -1.0f, 1.0f),
|
||||
FloatProperty("sunIntensity", "Sun Intensity", 50.0f, 0.1f, 1000.0f),
|
||||
FloatProperty("hdrExposition", "HDR", 0.4f, 0.01f, 5.0f),
|
||||
FloatProperty("hdrExposition", "HDR Exposition", 0.4f, 0.01f, 5.0f),
|
||||
FloatProperty("backgroundExposition", "Background Exposition", 1.8f, 0.01f, 10.0f),
|
||||
FloatProperty("gamma", "Gamma Correction", 1.8f, 0.1f, 3.0f ),
|
||||
BoolProperty("ozone", "Ozone Layer Enabled", true)
|
||||
})
|
||||
@@ -135,6 +137,7 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
, _mieExtinctionCoeff(glm::vec3(0.f))
|
||||
, _sunRadianceIntensity(50.0f)
|
||||
, _exposureConstant(0.4f)
|
||||
, _exposureBackgroundConstant(1.8f)
|
||||
, _gammaConstant(1.8f)
|
||||
, _atmosphereEnabled(false)
|
||||
, _saveCalculationsToTexture(false)
|
||||
@@ -333,6 +336,10 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
//LDEBUG("Saving Precalculated Atmosphere Textures.");
|
||||
}
|
||||
|
||||
if (ImageDictionary.getValue(keyBackground, _exposureBackgroundConstant)) {
|
||||
//LDEBUG("Saving Precalculated Atmosphere Textures.");
|
||||
}
|
||||
|
||||
if (ImageDictionary.getValue(keyGamma, _gammaConstant)) {
|
||||
//LDEBUG("Saving Precalculated Atmosphere Textures.");
|
||||
}
|
||||
@@ -435,6 +442,10 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
_atmosphereProperties.hdrExpositionP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
||||
_atmospherePropertyOwner.addProperty(_atmosphereProperties.hdrExpositionP);
|
||||
|
||||
_atmosphereProperties.backgroundExpositionP.set(_exposureBackgroundConstant);
|
||||
_atmosphereProperties.backgroundExpositionP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
||||
_atmospherePropertyOwner.addProperty(_atmosphereProperties.backgroundExpositionP);
|
||||
|
||||
_atmosphereProperties.gammaConstantP.set(_gammaConstant);
|
||||
_atmosphereProperties.gammaConstantP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
||||
_atmospherePropertyOwner.addProperty(_atmosphereProperties.gammaConstantP);
|
||||
@@ -460,6 +471,7 @@ bool RenderableGlobe::initialize() {
|
||||
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
|
||||
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
|
||||
_deferredcaster->setHDRConstant(_exposureConstant);
|
||||
_deferredcaster->setBackgroundConstant(_exposureBackgroundConstant);
|
||||
_deferredcaster->setGammaConstant(_gammaConstant);
|
||||
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
|
||||
_deferredcaster->setOzoneExtinctionCoefficients(_ozoneLayerExtinctionCoeff);
|
||||
@@ -627,6 +639,7 @@ void RenderableGlobe::updateAtmosphereParameters() {
|
||||
bool executeComputation = true;
|
||||
if (_sunRadianceIntensity != _atmosphereProperties.sunIntensityP.value() ||
|
||||
_exposureConstant != _atmosphereProperties.hdrExpositionP.value() ||
|
||||
_exposureBackgroundConstant != _atmosphereProperties.backgroundExpositionP.value() ||
|
||||
_gammaConstant != _atmosphereProperties.gammaConstantP.value())
|
||||
executeComputation = false;
|
||||
_atmosphereRadius = _atmospherePlanetRadius + _atmosphereProperties.atmosphereHeightP.value();
|
||||
@@ -648,6 +661,7 @@ void RenderableGlobe::updateAtmosphereParameters() {
|
||||
_miePhaseConstant = _atmosphereProperties.mieAsymmetricFactorGP.value();
|
||||
_sunRadianceIntensity = _atmosphereProperties.sunIntensityP.value();
|
||||
_exposureConstant = _atmosphereProperties.hdrExpositionP.value();
|
||||
_exposureBackgroundConstant = _atmosphereProperties.backgroundExpositionP.value();
|
||||
_gammaConstant = _atmosphereProperties.gammaConstantP.value();
|
||||
|
||||
if (_deferredcaster) {
|
||||
@@ -661,6 +675,10 @@ void RenderableGlobe::updateAtmosphereParameters() {
|
||||
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
|
||||
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
|
||||
_deferredcaster->setHDRConstant(_exposureConstant);
|
||||
_deferredcaster->setBackgroundConstant(_exposureBackgroundConstant);
|
||||
|
||||
std::cout << "==== set background constnat to: " << _exposureBackgroundConstant << " =====" << std::endl;
|
||||
|
||||
_deferredcaster->setGammaConstant(_gammaConstant);
|
||||
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
|
||||
_deferredcaster->setOzoneExtinctionCoefficients(_ozoneLayerExtinctionCoeff);
|
||||
|
||||
@@ -102,6 +102,7 @@ public:
|
||||
properties::FloatProperty mieAsymmetricFactorGP;
|
||||
properties::FloatProperty sunIntensityP;
|
||||
properties::FloatProperty hdrExpositionP;
|
||||
properties::FloatProperty backgroundExpositionP;
|
||||
properties::FloatProperty gammaConstantP;
|
||||
properties::BoolProperty ozoneLayerEnabledP;
|
||||
};
|
||||
@@ -171,6 +172,7 @@ private:
|
||||
float _miePhaseConstant;
|
||||
float _sunRadianceIntensity;
|
||||
float _exposureConstant;
|
||||
float _exposureBackgroundConstant;
|
||||
float _gammaConstant;
|
||||
|
||||
glm::vec3 _rayleighScatteringCoeff;
|
||||
|
||||
@@ -86,6 +86,7 @@ namespace {
|
||||
const std::string keyImage = "Image";
|
||||
const std::string keyToneMappingOp = "ToneMapping";
|
||||
const std::string keyExposure = "Exposure";
|
||||
const std::string keyBackground = "Background";
|
||||
const std::string keyGamma = "Gamma";
|
||||
const std::string keyATMDebug = "Debug";
|
||||
const std::string keyTextureScale = "PreCalculatedTextureScale";
|
||||
@@ -176,6 +177,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
, _mieAsymmetricFactorGP("mieAsymmetricFactorG", "Mie Asymmetric Factor G", 0.85f, -1.0f, 1.0f)
|
||||
, _sunIntensityP("sunIntensity", "Sun Intensity", 50.0f, 0.1f, 1000.0f)
|
||||
, _hdrExpositionP("hdrExposition", "HDR", 0.4f, 0.01f, 5.0f)
|
||||
, _backgroundExposureP("backgroundExposition", "Background Exposition", 1.8f, 0.01f, 10.0f)
|
||||
, _gammaConstantP("gamma", "Gamma Correction", 1.8f, 0.1f, 3.0f)
|
||||
, _atmosphereEnabled(false)
|
||||
, _ozoneLayerEnabled(false)
|
||||
@@ -188,6 +190,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
, _miePhaseConstant(0.f)
|
||||
, _sunRadianceIntensity(50.f)
|
||||
, _hdrConstant(0.f)
|
||||
, _exposureBackgroundConstant(1.8f)
|
||||
, _gammaConstant(1.8f)
|
||||
, _mieExtinctionCoeff(glm::vec3(0.f))
|
||||
, _rayleighScatteringCoeff(glm::vec3(0.f))
|
||||
@@ -553,6 +556,10 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
_hdrExpositionP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
|
||||
addProperty(_hdrExpositionP);
|
||||
|
||||
_backgroundExposureP.set(_exposureBackgroundConstant);
|
||||
_backgroundExposureP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
|
||||
addProperty(_backgroundExposureP);
|
||||
|
||||
_gammaConstantP.set(_gammaConstant);
|
||||
_gammaConstantP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
|
||||
addProperty(_gammaConstantP);
|
||||
@@ -641,6 +648,7 @@ bool RenderablePlanet::initialize() {
|
||||
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
|
||||
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
|
||||
_deferredcaster->setHDRConstant(_hdrConstant);
|
||||
_deferredcaster->setBackgroundConstant(_exposureBackgroundConstant);
|
||||
_deferredcaster->setGammaConstant(_gammaConstant);
|
||||
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
|
||||
_deferredcaster->setOzoneExtinctionCoefficients(_ozoneExtinctionCoeff);
|
||||
@@ -960,6 +968,7 @@ void RenderablePlanet::updateAtmosphereParameters() {
|
||||
|
||||
if (_sunRadianceIntensity != _sunIntensityP ||
|
||||
_hdrConstant != _hdrExpositionP ||
|
||||
_exposureBackgroundConstant != _backgroundExposureP ||
|
||||
_gammaConstant != _gammaConstantP)
|
||||
executeComputation = false;
|
||||
|
||||
@@ -979,6 +988,7 @@ void RenderablePlanet::updateAtmosphereParameters() {
|
||||
_miePhaseConstant = _mieAsymmetricFactorGP;
|
||||
_sunRadianceIntensity = _sunIntensityP;
|
||||
_hdrConstant = _hdrExpositionP;
|
||||
_exposureBackgroundConstant = _backgroundExposureP;
|
||||
_gammaConstant = _gammaConstantP.value();
|
||||
|
||||
if (_deferredcaster) {
|
||||
@@ -992,6 +1002,7 @@ void RenderablePlanet::updateAtmosphereParameters() {
|
||||
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
|
||||
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
|
||||
_deferredcaster->setHDRConstant(_hdrConstant);
|
||||
_deferredcaster->setBackgroundConstant(_exposureBackgroundConstant);
|
||||
_deferredcaster->setGammaConstant(_gammaConstant);
|
||||
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
|
||||
_deferredcaster->setOzoneExtinctionCoefficients(_ozoneExtinctionCoeff);
|
||||
|
||||
@@ -131,6 +131,7 @@ private:
|
||||
properties::FloatProperty _mieAsymmetricFactorGP;
|
||||
properties::FloatProperty _sunIntensityP;
|
||||
properties::FloatProperty _hdrExpositionP;
|
||||
properties::FloatProperty _backgroundExposureP;
|
||||
properties::FloatProperty _gammaConstantP;
|
||||
|
||||
bool _atmosphereEnabled;
|
||||
@@ -144,6 +145,7 @@ private:
|
||||
float _miePhaseConstant;
|
||||
float _sunRadianceIntensity;
|
||||
float _hdrConstant;
|
||||
float _exposureBackgroundConstant;
|
||||
float _gammaConstant;
|
||||
|
||||
glm::vec3 _mieExtinctionCoeff;
|
||||
|
||||
Reference in New Issue
Block a user