mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-30 07:49:31 -05:00
Added Gamma Correction Control.
This commit is contained in:
@@ -106,6 +106,7 @@ AtmosphereDeferredcaster::AtmosphereDeferredcaster()
|
||||
, _ellipsoidRadii(glm::dvec3(0.0))
|
||||
, _sunRadianceIntensity(50.0f)
|
||||
, _hdrConstant(0.4f)
|
||||
, _gammaConstant(1.8f)
|
||||
, _renderableClass(NoRenderableClass)
|
||||
, _calculationTextureScale(1.0)
|
||||
, _saveCalculationTextures(false)
|
||||
@@ -194,6 +195,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData & renderData, const D
|
||||
program.setUniform("sunRadiance", _sunRadianceIntensity);
|
||||
|
||||
program.setUniform("exposure", _hdrConstant);
|
||||
program.setUniform("gamma", _gammaConstant);
|
||||
program.setUniform("RenderableClass", static_cast<int>(_renderableClass));
|
||||
|
||||
program.setUniform("TRANSMITTANCE_W", (int)_transmittance_table_width);
|
||||
@@ -464,6 +466,10 @@ void AtmosphereDeferredcaster::setHDRConstant(const float hdrConstant) {
|
||||
_hdrConstant = hdrConstant;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setGammaConstant(const float gammaConstant) {
|
||||
_gammaConstant = gammaConstant;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setRayleighScatteringCoefficients(const glm::vec3 & rayScattCoeff) {
|
||||
_rayleighScatteringCoeff = rayScattCoeff;
|
||||
}
|
||||
@@ -1544,6 +1550,9 @@ void AtmosphereDeferredcaster::loadAtmosphereDataIntoShaderProgram(std::unique_p
|
||||
shaderProg->setUniform("betaMieExtinction", _mieExtinctionCoeff);
|
||||
shaderProg->setUniform("mieG", _miePhaseConstant);
|
||||
shaderProg->setUniform("sunRadiance", _sunRadianceIntensity);
|
||||
shaderProg->setUniform("exposure", _hdrConstant);
|
||||
shaderProg->setUniform("gamma", _gammaConstant);
|
||||
shaderProg->setUniform("RenderableClass", static_cast<int>(_renderableClass));
|
||||
shaderProg->setUniform("TRANSMITTANCE_W", (int)_transmittance_table_width);
|
||||
shaderProg->setUniform("TRANSMITTANCE_H", (int)_transmittance_table_height);
|
||||
shaderProg->setUniform("SKY_W", (int)_irradiance_table_width);
|
||||
|
||||
@@ -100,6 +100,7 @@ public:
|
||||
void setMiePhaseConstant(const float miePhaseConstant);
|
||||
void setSunRadianceIntensity(const float sunRadiance);
|
||||
void setHDRConstant(const float hdrConstant);
|
||||
void setGammaConstant(const float gammaConstant);
|
||||
void setRayleighScatteringCoefficients(const glm::vec3 & rayScattCoeff);
|
||||
void setMieScatteringCoefficients(const glm::vec3 & mieScattCoeff);
|
||||
void setMieExtinctionCoefficients(const glm::vec3 & mieExtCoeff);
|
||||
@@ -169,6 +170,8 @@ private:
|
||||
float _miePhaseConstant;
|
||||
float _sunRadianceIntensity;
|
||||
float _hdrConstant;
|
||||
float _gammaConstant;
|
||||
|
||||
glm::vec3 _mieExtinctionCoeff;
|
||||
glm::vec3 _rayleighScatteringCoeff;
|
||||
glm::vec3 _mieScatteringCoeff;
|
||||
|
||||
@@ -489,7 +489,7 @@ vec3 groundColor(const vec3 x, const float t, const vec3 v, const vec3 s, const
|
||||
float r0 = length(x0);
|
||||
// Normal of intersection point.
|
||||
vec3 n = normalReflectance.xyz;
|
||||
vec4 groundReflectance = groundColor * vec4(.65);
|
||||
vec4 groundReflectance = groundColor * vec4(.35);
|
||||
//reflectance.w = 1.0;
|
||||
|
||||
// L0 is not included in the irradiance texture.
|
||||
@@ -789,8 +789,8 @@ void main() {
|
||||
renderTarget = finalRadiance;
|
||||
}
|
||||
} else {
|
||||
//renderTarget = vec4(HDR(meanColor.xyz), meanColor.a);
|
||||
renderTarget = meanColor;
|
||||
renderTarget = vec4(HDR(meanColor.xyz), meanColor.a);
|
||||
//renderTarget = meanColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
****************************************************************************************/
|
||||
|
||||
uniform float exposure;
|
||||
const float gamma = 2.0f;
|
||||
uniform float gamma;
|
||||
|
||||
vec3 exponentialToneMapping(vec3 color) {
|
||||
color *= exposure;
|
||||
|
||||
color.r = color.r < 1.413 ? pow(color.r * 0.38317, 1.0 / 2.2) : 1.0 - exp(-color.r);
|
||||
color.g = color.g < 1.413 ? pow(color.g * 0.38317, 1.0 / 2.2) : 1.0 - exp(-color.g);
|
||||
color.b = color.b < 1.413 ? pow(color.b * 0.38317, 1.0 / 2.2) : 1.0 - exp(-color.b);
|
||||
color.r = color.r < 1.413 ? pow(color.r * 0.38317, 1.0 / gamma) : 1.0 - exp(-color.r);
|
||||
color.g = color.g < 1.413 ? pow(color.g * 0.38317, 1.0 / gamma) : 1.0 - exp(-color.g);
|
||||
color.b = color.b < 1.413 ? pow(color.b * 0.38317, 1.0 / gamma) : 1.0 - exp(-color.b);
|
||||
|
||||
return color;
|
||||
|
||||
@@ -64,7 +64,8 @@ vec3 lumaBasedReinhardToneMapping(vec3 color)
|
||||
vec3 whitePreservingLumaBasedReinhardToneMapping(vec3 color)
|
||||
{
|
||||
float white = 4.0f;
|
||||
float luma = dot(color, vec3(0.2126f, 0.7152f, 0.0722f));
|
||||
//float luma = dot(color, vec3(0.2126f, 0.7152f, 0.0722f));
|
||||
float luma = dot(color, vec3(0.4126f, 0.9152f, 0.2722f));
|
||||
float toneMappedLuma = luma * (1.0f + luma / (white * white)) / (1.0f + luma);
|
||||
color *= toneMappedLuma / luma;
|
||||
color = pow(color, vec3(1.0f / gamma));
|
||||
@@ -74,7 +75,7 @@ vec3 whitePreservingLumaBasedReinhardToneMapping(vec3 color)
|
||||
vec3 RomBinDaHouseToneMapping(vec3 color)
|
||||
{
|
||||
color = exp( -1.0f / ( 2.72f * color + 0.15f ) );
|
||||
color = pow(color, vec3(1. / gamma));
|
||||
color = pow(color, vec3(1.7 / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -94,7 +95,7 @@ vec3 Uncharted2ToneMapping(vec3 color)
|
||||
float E = 0.02f;
|
||||
float F = 0.30f;
|
||||
float W = 11.2f;
|
||||
float tExposure = 0.3f;
|
||||
float tExposure = 0.4f;
|
||||
color *= tExposure;
|
||||
color = ((color * (A * color + C * B) + D * E) / (color * (A * color + B) + D * F)) - E / F;
|
||||
float white = ((W * (A * W + C * B) + D * E) / (W * (A * W + B) + D * F)) - E / F;
|
||||
@@ -104,13 +105,13 @@ vec3 Uncharted2ToneMapping(vec3 color)
|
||||
}
|
||||
|
||||
vec3 HDR(vec3 color) {
|
||||
//return exponentialToneMapping(color);
|
||||
return exponentialToneMapping(color);
|
||||
//return linearToneMapping(color);
|
||||
//return simpleReinhardToneMapping(color);
|
||||
//return lumaBasedReinhardToneMapping(color);
|
||||
//return whitePreservingLumaBasedReinhardToneMapping(color);
|
||||
//return RomBinDaHouseToneMapping(color);
|
||||
return filmicToneMapping(color);
|
||||
//return filmicToneMapping(color);
|
||||
//return Uncharted2ToneMapping(color);
|
||||
|
||||
}
|
||||
|
||||
@@ -105,7 +105,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", 0.4f, 0.01f, 5.0f),
|
||||
FloatProperty("gamma", "Gamma Correction", 1.8f, 0.1f, 3.0f )
|
||||
})
|
||||
, _atmospherePropertyOwner("Atmosphere")
|
||||
, _atmosphereRadius(0.f)
|
||||
@@ -119,6 +120,7 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
, _mieScatteringCoeff(glm::vec3(0.f))
|
||||
, _sunRadianceIntensity(50.0f)
|
||||
, _hdrConstant(0.4f)
|
||||
, _gammaConstant(1.8f)
|
||||
, _atmosphereEnabled(false)
|
||||
, _saveCalculationsToTexture(false)
|
||||
, _preCalculatedTexturesScale(1.0)
|
||||
@@ -346,6 +348,10 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
_atmosphereProperties.hdrExpositionP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
||||
_atmospherePropertyOwner.addProperty(_atmosphereProperties.hdrExpositionP);
|
||||
|
||||
_atmosphereProperties.gammaConstantP.set(_gammaConstant);
|
||||
_atmosphereProperties.gammaConstantP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
||||
_atmospherePropertyOwner.addProperty(_atmosphereProperties.gammaConstantP);
|
||||
|
||||
addPropertySubOwner(_atmospherePropertyOwner);
|
||||
}
|
||||
}
|
||||
@@ -365,6 +371,7 @@ bool RenderableGlobe::initialize() {
|
||||
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
|
||||
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
|
||||
_deferredcaster->setHDRConstant(_hdrConstant);
|
||||
_deferredcaster->setGammaConstant(_gammaConstant);
|
||||
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
|
||||
_deferredcaster->setMieScatteringCoefficients(_mieScatteringCoeff);
|
||||
_deferredcaster->setMieExtinctionCoefficients(_mieExtinctionCoeff);
|
||||
@@ -529,7 +536,8 @@ void RenderableGlobe::setSaveCamera(std::shared_ptr<Camera> camera) {
|
||||
void RenderableGlobe::updateAtmosphereParameters() {
|
||||
bool executeComputation = true;
|
||||
if (_sunRadianceIntensity != _atmosphereProperties.sunIntensityP.value() ||
|
||||
_hdrConstant != _atmosphereProperties.hdrExpositionP.value())
|
||||
_hdrConstant != _atmosphereProperties.hdrExpositionP.value() ||
|
||||
_gammaConstant != _atmosphereProperties.gammaConstantP.value())
|
||||
executeComputation = false;
|
||||
_atmosphereRadius = _atmospherePlanetRadius + _atmosphereProperties.atmosphereHeightP.value();
|
||||
_planetAverageGroundReflectance = _atmosphereProperties.groundAverageReflectanceP.value();
|
||||
@@ -543,6 +551,7 @@ void RenderableGlobe::updateAtmosphereParameters() {
|
||||
_miePhaseConstant = _atmosphereProperties.mieAsymmetricFactorGP.value();
|
||||
_sunRadianceIntensity = _atmosphereProperties.sunIntensityP.value();
|
||||
_hdrConstant = _atmosphereProperties.hdrExpositionP.value();
|
||||
_gammaConstant = _atmosphereProperties.gammaConstantP.value();
|
||||
|
||||
if (_deferredcaster) {
|
||||
_deferredcaster->setAtmosphereRadius(_atmosphereRadius);
|
||||
@@ -553,6 +562,7 @@ void RenderableGlobe::updateAtmosphereParameters() {
|
||||
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
|
||||
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
|
||||
_deferredcaster->setHDRConstant(_hdrConstant);
|
||||
_deferredcaster->setGammaConstant(_gammaConstant);
|
||||
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
|
||||
_deferredcaster->setMieScatteringCoefficients(_mieScatteringCoeff);
|
||||
_deferredcaster->setMieExtinctionCoefficients(_mieExtinctionCoeff);
|
||||
|
||||
@@ -96,6 +96,7 @@ public:
|
||||
properties::FloatProperty mieAsymmetricFactorGP;
|
||||
properties::FloatProperty sunIntensityP;
|
||||
properties::FloatProperty hdrExpositionP;
|
||||
properties::FloatProperty gammaConstantP;
|
||||
};
|
||||
|
||||
const AtmosphereProperties& atmosphereProperties() const;
|
||||
@@ -161,6 +162,7 @@ private:
|
||||
float _miePhaseConstant;
|
||||
float _sunRadianceIntensity;
|
||||
float _hdrConstant;
|
||||
float _gammaConstant;
|
||||
glm::vec3 _mieExtinctionCoeff;
|
||||
glm::vec3 _rayleighScatteringCoeff;
|
||||
glm::vec3 _mieScatteringCoeff;
|
||||
|
||||
Reference in New Issue
Block a user