mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-09 05:00:42 -06:00
Fixed HDR controls for multiple atm's.
This commit is contained in:
@@ -71,6 +71,10 @@ public:
|
||||
void setResolution(glm::ivec2 res) override;
|
||||
void setNAaSamples(const int nAaSamples) override;
|
||||
void setHDRExposure(const float hdrExposure) override;
|
||||
void setHDRBackground(const float hdrBackground) override;
|
||||
void setGamma(const float gamma) override;
|
||||
|
||||
float hdrBackground() const override;
|
||||
|
||||
void preRaycast(const RaycasterTask& raycasterTask);
|
||||
void postRaycast(const RaycasterTask& raycasterTask);
|
||||
@@ -132,6 +136,8 @@ private:
|
||||
int _nAaSamples;
|
||||
|
||||
float _hdrExposure;
|
||||
float _hdrBackground;
|
||||
float _gamma;
|
||||
float _blackoutFactor;
|
||||
|
||||
ghoul::Dictionary _rendererData;
|
||||
|
||||
@@ -73,6 +73,10 @@ public:
|
||||
void setResolution(glm::ivec2 res) override;
|
||||
void setNAaSamples(const int nAaSamples) override;
|
||||
void setHDRExposure(const float hdrExposure) override;
|
||||
void setHDRBackground(const float hdrBackground) override;
|
||||
void setGamma(const float gamma) override;
|
||||
|
||||
float hdrBackground() const override;
|
||||
|
||||
void update() override;
|
||||
void render(float blackoutFactor, bool doPerformanceMeasurements) override;
|
||||
@@ -122,6 +126,8 @@ private:
|
||||
glm::vec2 _resolution;
|
||||
int _nAaSamples;
|
||||
float _hdrExposure;
|
||||
float _hdrBackground;
|
||||
float _gamma;
|
||||
|
||||
ghoul::Dictionary _rendererData;
|
||||
};
|
||||
|
||||
@@ -222,6 +222,9 @@ private:
|
||||
int _fadeDirection;
|
||||
properties::IntProperty _nAaSamples;
|
||||
properties::FloatProperty _hdrExposure;
|
||||
properties::FloatProperty _hdrBackground;
|
||||
properties::FloatProperty _gamma;
|
||||
|
||||
uint64_t _frameNumber;
|
||||
|
||||
std::vector<ghoul::opengl::ProgramObject*> _programs;
|
||||
|
||||
@@ -60,7 +60,10 @@ public:
|
||||
virtual void setResolution(glm::ivec2 res) = 0;
|
||||
virtual void setNAaSamples(const int nAaSamples) = 0;
|
||||
virtual void setHDRExposure(const float hdrExposure) = 0;
|
||||
virtual void setHDRBackground(const float hdrBackground) = 0;
|
||||
virtual void setGamma(const float gamma) = 0;
|
||||
|
||||
virtual float hdrBackground() const = 0;
|
||||
|
||||
/**
|
||||
* Set raycasting uniforms on the program object, and setup raycasting.
|
||||
|
||||
@@ -34,8 +34,10 @@
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/renderer.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace {
|
||||
const char* keyFrame = "Frame";
|
||||
const char* keyRadii = "Radii";
|
||||
@@ -123,7 +125,6 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
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 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)
|
||||
})
|
||||
@@ -141,7 +142,7 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
, _mieExtinctionCoeff(glm::vec3(0.f))
|
||||
, _sunRadianceIntensity(50.0f)
|
||||
, _exposureConstant(0.4f)
|
||||
, _exposureBackgroundConstant(1.8f)
|
||||
, _exposureBackgroundConstant(2.8f)
|
||||
, _gammaConstant(1.8f)
|
||||
, _atmosphereEnabled(false)
|
||||
, _saveCalculationsToTexture(false)
|
||||
@@ -519,11 +520,7 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
_atmosphereProperties.hdrExpositionP.set(_exposureConstant);
|
||||
_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);
|
||||
@@ -657,6 +654,9 @@ void RenderableGlobe::update(const UpdateData& data) {
|
||||
if (_deferredcaster) {
|
||||
_deferredcaster->setTime(data.time.j2000Seconds());
|
||||
_deferredcaster->setModelTransform(_cachedModelTransform);
|
||||
|
||||
if (_exposureBackgroundConstant != OsEng.renderEngine().renderer()->hdrBackground())
|
||||
updateAtmosphereParameters();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -717,9 +717,10 @@ void RenderableGlobe::updateAtmosphereParameters() {
|
||||
bool executeComputation = true;
|
||||
if (_sunRadianceIntensity != _atmosphereProperties.sunIntensityP.value() ||
|
||||
_exposureConstant != _atmosphereProperties.hdrExpositionP.value() ||
|
||||
_exposureBackgroundConstant != _atmosphereProperties.backgroundExpositionP.value() ||
|
||||
_exposureBackgroundConstant != OsEng.renderEngine().renderer()->hdrBackground() ||
|
||||
_gammaConstant != _atmosphereProperties.gammaConstantP.value())
|
||||
executeComputation = false;
|
||||
|
||||
_atmosphereRadius = _atmospherePlanetRadius + _atmosphereProperties.atmosphereHeightP.value();
|
||||
_planetAverageGroundReflectance = _atmosphereProperties.groundAverageReflectanceP.value();
|
||||
_rayleighHeightScale = _atmosphereProperties.rayleighHeightScaleP.value();
|
||||
@@ -739,7 +740,7 @@ void RenderableGlobe::updateAtmosphereParameters() {
|
||||
_miePhaseConstant = _atmosphereProperties.mieAsymmetricFactorGP.value();
|
||||
_sunRadianceIntensity = _atmosphereProperties.sunIntensityP.value();
|
||||
_exposureConstant = _atmosphereProperties.hdrExpositionP.value();
|
||||
_exposureBackgroundConstant = _atmosphereProperties.backgroundExpositionP.value();
|
||||
_exposureBackgroundConstant = OsEng.renderEngine().renderer()->hdrBackground();
|
||||
_gammaConstant = _atmosphereProperties.gammaConstantP.value();
|
||||
|
||||
if (_deferredcaster) {
|
||||
|
||||
@@ -116,7 +116,6 @@ public:
|
||||
properties::FloatProperty mieAsymmetricFactorGP;
|
||||
properties::FloatProperty sunIntensityP;
|
||||
properties::FloatProperty hdrExpositionP;
|
||||
properties::FloatProperty backgroundExpositionP;
|
||||
properties::FloatProperty gammaConstantP;
|
||||
properties::BoolProperty ozoneLayerEnabledP;
|
||||
};
|
||||
|
||||
@@ -24,113 +24,18 @@
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
#include "hdr.glsl"
|
||||
|
||||
layout (location = 0) out vec4 finalColor;
|
||||
uniform int nAaSamples;
|
||||
|
||||
uniform sampler2DMS mainColorTexture;
|
||||
|
||||
//uniform float exposure;
|
||||
const float exposure = 0.4;
|
||||
//const float exposure = 0.4;
|
||||
uniform float backgroundExposure;
|
||||
//uniform float gamma;
|
||||
const float gamma = 2.2;
|
||||
|
||||
vec3 exponentialToneMapping(vec3 color) {
|
||||
color *= exposure;
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
vec3 linearToneMapping(vec3 color)
|
||||
{
|
||||
float tExposure = 1.0f;
|
||||
color = clamp(tExposure * color, 0.0f, 1.0f);
|
||||
color = pow(color, vec3(1.0f / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 simpleReinhardToneMapping(vec3 color)
|
||||
{
|
||||
float tExposure = 1.5f;
|
||||
color *= tExposure/(1.0f + color / tExposure);
|
||||
color = pow(color, vec3(1. / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 lumaBasedReinhardToneMapping(vec3 color)
|
||||
{
|
||||
float luma = dot(color, vec3(0.2126f, 0.7152f, 0.0722f));
|
||||
float toneMappedLuma = luma / (1.0f + luma);
|
||||
color *= toneMappedLuma / luma;
|
||||
color = pow(color, vec3(1.0f / gamma));
|
||||
return 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.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));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 RomBinDaHouseToneMapping(vec3 color)
|
||||
{
|
||||
color = exp( -1.0f / ( 2.72f * color + 0.15f ) );
|
||||
color = pow(color, vec3(1.7 / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 filmicToneMapping(vec3 color)
|
||||
{
|
||||
color = max(vec3(0.0f), color - vec3(0.04f));
|
||||
color = (color * (6.2f * color + 0.5f)) / (color * (6.2f * color + 20.0f) + 0.06f);
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 Uncharted2ToneMapping(vec3 color)
|
||||
{
|
||||
float A = 0.15f;
|
||||
float B = 0.50f;
|
||||
float C = 0.10f;
|
||||
float D = 0.20f;
|
||||
float E = 0.02f;
|
||||
float F = 0.30f;
|
||||
float W = 11.2f;
|
||||
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;
|
||||
color /= white;
|
||||
color = pow(color, vec3(1.0f / gamma));
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 jToneMapping(const vec3 color) {
|
||||
return 1.0 - exp(-exposure * color);
|
||||
}
|
||||
|
||||
vec3 HDR(vec3 color) {
|
||||
//return exponentialToneMapping(color);
|
||||
//return linearToneMapping(color);
|
||||
//return simpleReinhardToneMapping(color);
|
||||
//return lumaBasedReinhardToneMapping(color);
|
||||
//return whitePreservingLumaBasedReinhardToneMapping(color);
|
||||
//return RomBinDaHouseToneMapping(color);
|
||||
//return filmicToneMapping(color);
|
||||
//return Uncharted2ToneMapping(color);
|
||||
return jToneMapping(color);
|
||||
|
||||
}
|
||||
|
||||
//const float gamma = 2.2;
|
||||
|
||||
void main() {
|
||||
vec4 color = vec4(0.0);
|
||||
|
||||
@@ -65,6 +65,9 @@ ABufferRenderer::ABufferRenderer()
|
||||
, _dirtyRendererData(true)
|
||||
, _dirtyResolveDictionary(true)
|
||||
, _resolveProgram(nullptr)
|
||||
, _hdrExposure(0.4)
|
||||
, _hdrBackground(2.8)
|
||||
, _gamma(2.2)
|
||||
{}
|
||||
|
||||
ABufferRenderer::~ABufferRenderer() {}
|
||||
@@ -406,6 +409,27 @@ void ABufferRenderer::setHDRExposure(const float hdrExposure) {
|
||||
}
|
||||
}
|
||||
|
||||
void ABufferRenderer::setHDRBackground(const float hdrBackground) {
|
||||
_hdrBackground = hdrBackground;
|
||||
if (_hdrBackground < 0.0) {
|
||||
LERROR("HDR Background constant must be greater than zero.");
|
||||
_hdrBackground = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ABufferRenderer::setGamma(const float gamma) {
|
||||
_gamma = gamma;
|
||||
if (_gamma < 0.0) {
|
||||
LERROR("Gamma value must be greater than zero.");
|
||||
_gamma = 2.2;
|
||||
}
|
||||
}
|
||||
|
||||
float ABufferRenderer::hdrBackground() const {
|
||||
return _hdrBackground;
|
||||
}
|
||||
|
||||
void ABufferRenderer::clear() {
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _anchorPointerTextureInitializer);
|
||||
glBindTexture(GL_TEXTURE_2D, _anchorPointerTexture);
|
||||
|
||||
@@ -68,6 +68,9 @@ FramebufferRenderer::FramebufferRenderer()
|
||||
: _camera(nullptr)
|
||||
, _scene(nullptr)
|
||||
, _resolution(glm::vec2(0))
|
||||
, _hdrExposure(0.4)
|
||||
, _hdrBackground(2.8)
|
||||
, _gamma(2.2)
|
||||
{}
|
||||
|
||||
FramebufferRenderer::~FramebufferRenderer() {}
|
||||
@@ -550,6 +553,9 @@ void FramebufferRenderer::updateHDRData() {
|
||||
"${SHADERS}/framebuffer/hdrBackground.vert",
|
||||
"${SHADERS}/framebuffer/hdrBackground.frag"
|
||||
);
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_hdrBackGroundProgram->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_hdrBackGroundProgram->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
@@ -686,7 +692,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
|
||||
glDrawBuffers(1, dBuffer);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// HDR Background Image Control
|
||||
// HDR Image Control and Resolve
|
||||
_hdrBackGroundProgram->activate();
|
||||
|
||||
ghoul::opengl::TextureUnit mainColorTextureUnit;
|
||||
@@ -695,7 +701,9 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
|
||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainColorTexture);
|
||||
_hdrBackGroundProgram->setUniform("mainColorTexture", mainColorTextureUnit);
|
||||
_hdrBackGroundProgram->setUniform("nAaSamples", _nAaSamples);
|
||||
_hdrBackGroundProgram->setUniform("backgroundExposure", _hdrExposure);
|
||||
_hdrBackGroundProgram->setUniform("exposure", _hdrExposure);
|
||||
_hdrBackGroundProgram->setUniform("backgroundExposure", _hdrBackground);
|
||||
_hdrBackGroundProgram->setUniform("gamma", _gamma);
|
||||
glBindVertexArray(_screenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glBindVertexArray(0);
|
||||
@@ -753,6 +761,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
|
||||
|
||||
|
||||
deferredcastProgram->setUniform("nAaSamples", _nAaSamples);
|
||||
//deferredcastProgram->setUniform("hdrExposure", _nAaSamples);
|
||||
|
||||
deferredcaster->preRaycast(deferredcasterTask.renderData,
|
||||
_deferredcastData[deferredcaster],
|
||||
@@ -870,6 +879,26 @@ void FramebufferRenderer::setHDRExposure(const float hdrExposure) {
|
||||
}
|
||||
}
|
||||
|
||||
void FramebufferRenderer::setHDRBackground(const float hdrBackground) {
|
||||
_hdrBackground = hdrBackground;
|
||||
if (_hdrBackground < 0.0) {
|
||||
LERROR("HDR Background constant must be greater than zero.");
|
||||
_hdrBackground = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
void FramebufferRenderer::setGamma(const float gamma) {
|
||||
_gamma = gamma;
|
||||
if (_gamma < 0.0) {
|
||||
LERROR("Gamma value must be greater than zero.");
|
||||
_gamma = 2.2;
|
||||
}
|
||||
}
|
||||
|
||||
float FramebufferRenderer::hdrBackground() const {
|
||||
return _hdrBackground;
|
||||
}
|
||||
|
||||
void FramebufferRenderer::updateRendererData() {
|
||||
ghoul::Dictionary dict;
|
||||
dict.setValue("fragmentRendererPath", std::string(RenderFragmentShaderPath));
|
||||
|
||||
@@ -130,7 +130,9 @@ RenderEngine::RenderEngine()
|
||||
, _currentFadeTime(0.f)
|
||||
, _fadeDirection(0)
|
||||
, _nAaSamples("nAaSamples", "Number of Antialiasing samples", 8, 1, 16)
|
||||
, _hdrExposure("backgroundExposure", "HDR Exposure", 1.8f, 0.01f, 10.0f)
|
||||
, _hdrExposure("hdrExposure", "HDR Exposure", 0.4f, 0.01f, 10.0f)
|
||||
, _hdrBackground("backgroundExposure", "HDR Background Exposure", 2.8f, 0.01f, 10.0f)
|
||||
, _gamma("gamma", "Gamma Constant", 2.2f, 0.01f, 10.0f)
|
||||
, _frameNumber(0)
|
||||
{
|
||||
_performanceMeasurements.onChange([this]() {
|
||||
@@ -170,9 +172,21 @@ RenderEngine::RenderEngine()
|
||||
_renderer->setHDRExposure(_hdrExposure);
|
||||
}
|
||||
});
|
||||
_hdrBackground.onChange([this]() {
|
||||
if (_renderer) {
|
||||
_renderer->setHDRBackground(_hdrBackground);
|
||||
}
|
||||
});
|
||||
_gamma.onChange([this]() {
|
||||
if (_renderer) {
|
||||
_renderer->setGamma(_gamma);
|
||||
}
|
||||
});
|
||||
|
||||
addProperty(_nAaSamples);
|
||||
addProperty(_hdrExposure);
|
||||
addProperty(_hdrBackground);
|
||||
addProperty(_gamma);
|
||||
addProperty(_applyWarping);
|
||||
|
||||
_takeScreenshot.onChange([this](){
|
||||
@@ -1166,8 +1180,8 @@ void RenderEngine::renderInformation() {
|
||||
"Active Instruments:"
|
||||
);
|
||||
|
||||
for (auto t : activeMap) {
|
||||
if (t.second == false) {
|
||||
for (auto ac : activeMap) {
|
||||
if (ac.second == false) {
|
||||
RenderFont(*_fontInfo,
|
||||
penPosition,
|
||||
glm::vec4(0.3, 0.3, 0.3, 1),
|
||||
@@ -1177,7 +1191,7 @@ void RenderEngine::renderInformation() {
|
||||
penPosition,
|
||||
glm::vec4(0.3, 0.3, 0.3, 1),
|
||||
" %5s",
|
||||
t.first.c_str()
|
||||
ac.first.c_str()
|
||||
);
|
||||
|
||||
}
|
||||
@@ -1187,7 +1201,7 @@ void RenderEngine::renderInformation() {
|
||||
glm::vec4(0.3, 0.3, 0.3, 1),
|
||||
"|"
|
||||
);
|
||||
if (t.first == "NH_LORRI") {
|
||||
if (ac.first == "NH_LORRI") {
|
||||
RenderFont(*_fontInfo,
|
||||
penPosition,
|
||||
firing,
|
||||
@@ -1203,7 +1217,7 @@ void RenderEngine::renderInformation() {
|
||||
penPosition,
|
||||
active,
|
||||
" %5s",
|
||||
t.first.c_str()
|
||||
ac.first.c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user