Add gamma correction to screen space renderable (SSR) shader, property for SSR and default value gamma = 2.2 for sky browser display copies

This commit is contained in:
Ylva Selling
2022-06-21 10:47:44 -04:00
parent 1511d85d9f
commit d23969b8d3
4 changed files with 21 additions and 4 deletions

View File

@@ -130,6 +130,7 @@ protected:
properties::Vec3Property _localRotation;
properties::FloatProperty _scale;
properties::FloatProperty _gamma;
properties::Vec3Property _multiplyColor;
properties::Vec4Property _backgroundColor;
properties::FloatProperty _opacity;
@@ -137,7 +138,7 @@ protected:
properties::TriggerProperty _delete;
glm::ivec2 _objectSize = glm::ivec2(0);
UniformCache(color, opacity, mvp, texture, backgroundColor) _uniformCache;
UniformCache(color, opacity, mvp, texture, backgroundColor, gamma) _uniformCache;
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
};

View File

@@ -32,6 +32,7 @@ uniform sampler2D tex;
uniform vec3 color = vec3(1.0);
uniform float opacity = 1.0;
uniform vec4 backgroundColor = vec4(0.0);
uniform float gamma = 1.0;
Fragment getFragment() {
Fragment frag;
@@ -44,5 +45,6 @@ Fragment getFragment() {
}
frag.depth = vs_depth;
frag.color.rgb = pow(frag.color.rgb, vec3(1.0/(gamma + 0.000001)));
return frag;
}

View File

@@ -435,6 +435,7 @@ namespace {
"Name = '" + nameBrowser + "',"
"Url = '" + url + "',"
"FaceCamera = false,"
"Gamma = 2.2,"
"CartesianPosition = " + ghoul::to_string(positionBrowser) +
"}";

View File

@@ -42,8 +42,8 @@
#include <variant>
namespace {
constexpr const std::array<const char*, 5> UniformNames = {
"color", "opacity", "mvpMatrix", "tex", "backgroundColor"
constexpr const std::array<const char*, 6> UniformNames = {
"color", "opacity", "mvpMatrix", "tex", "backgroundColor", "gamma"
};
constexpr openspace::properties::Property::PropertyInfo EnabledInfo = {
@@ -150,6 +150,12 @@ namespace {
"the camera."
};
constexpr openspace::properties::Property::PropertyInfo GammaInfo = {
"Gamma",
"Gamma Correction",
"Sets the gamma correction of the texture."
};
float wrap(float value, float min, float max) {
return glm::mod(value - min, max - min) + min;
}
@@ -190,6 +196,9 @@ namespace {
// [[codegen::verbatim(ScaleInfo.description)]]
std::optional<float> scale;
// [[codegen::verbatim(UseRadiusAzimuthElevationInfo.description)]]
std::optional<float> gamma;
// [[codegen::verbatim(UsePerspectiveProjectionInfo.description)]]
std::optional<bool> usePerspectiveProjection;
@@ -286,6 +295,7 @@ ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary
, _opacity(OpacityInfo, 1.f, 0.f, 1.f)
, _fade(FadeInfo, 1.f, 0.f, 1.f)
, _delete(DeleteInfo)
, _gamma(GammaInfo, 1.f, 0.f, 10.f)
{
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -303,6 +313,7 @@ ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary
addProperty(_faceCamera);
addProperty(_cartesianPosition);
addProperty(_raePosition);
addProperty(_gamma);
// Setting spherical/euclidean onchange handler
_useRadiusAzimuthElevation.onChange([this]() {
@@ -329,6 +340,8 @@ ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary
_backgroundColor.setViewOption(properties::Property::ViewOptions::Color);
_enabled = p.enabled.value_or(_enabled);
_gamma = p.gamma.value_or(_gamma);
_useRadiusAzimuthElevation =
p.useRadiusAzimuthElevation.value_or(_useRadiusAzimuthElevation);
@@ -591,7 +604,7 @@ void ScreenSpaceRenderable::draw(glm::mat4 modelTransform) {
_shader->setUniform(_uniformCache.color, _multiplyColor);
_shader->setUniform(_uniformCache.opacity, opacity());
_shader->setUniform(_uniformCache.backgroundColor, _backgroundColor);
_shader->setUniform(_uniformCache.gamma, _gamma);
_shader->setUniform(
_uniformCache.mvp,
global::renderEngine->scene()->camera()->viewProjectionMatrix() * modelTransform