From 66719c08810f08e3fc7e1970273410f8a49fdb38 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 2 Jul 2020 13:56:14 +0200 Subject: [PATCH] Rename 'transparency' to 'colorFilter' in the ring classes to avoid confusion with opacity name change. Also, the 'transparency' used in the rings had a diffrent meaning than for the rest of the rendered objects. It affects the filtering of the color values. --- modules/globebrowsing/shaders/rings_fs.glsl | 13 +++++---- modules/globebrowsing/src/ringscomponent.cpp | 28 ++++++++++---------- modules/globebrowsing/src/ringscomponent.h | 4 +-- modules/space/rendering/renderablerings.cpp | 28 ++++++++++---------- modules/space/rendering/renderablerings.h | 4 +-- modules/space/shaders/rings_fs.glsl | 14 +++++----- 6 files changed, 46 insertions(+), 45 deletions(-) diff --git a/modules/globebrowsing/shaders/rings_fs.glsl b/modules/globebrowsing/shaders/rings_fs.glsl index b18d5d71a8..04cf03d2cc 100644 --- a/modules/globebrowsing/shaders/rings_fs.glsl +++ b/modules/globebrowsing/shaders/rings_fs.glsl @@ -35,7 +35,7 @@ in vec4 shadowCoords; uniform sampler2DShadow shadowMapTexture; uniform sampler1D ringTexture; uniform vec2 textureOffset; -uniform float transparency; +uniform float colorFilterValue; uniform vec3 sunPosition; uniform float _nightFactor; @@ -67,12 +67,11 @@ Fragment getFragment() { } vec4 diffuse = texture(ringTexture, texCoord); - float colorValue = length(diffuse.rgb); - // times 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want - // to normalize the transparency value to [0,1] - if (colorValue < 3.0 * transparency) { - diffuse.a = pow(colorValue / (3.0 * transparency), 1); - //diffuse.a = (colorValue / 3.0) * transparency; + // divided by 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want + // to normalize the alpha value to [0,1] + float colorValue = length(diffuse.rgb) / 3.0; + if (colorValue < colorFilterValue) { + diffuse.a = colorValue * colorFilterValue; if (diffuse.a < 0.65) discard; } diff --git a/modules/globebrowsing/src/ringscomponent.cpp b/modules/globebrowsing/src/ringscomponent.cpp index 4a45be2517..7bf3a70d73 100644 --- a/modules/globebrowsing/src/ringscomponent.cpp +++ b/modules/globebrowsing/src/ringscomponent.cpp @@ -52,7 +52,7 @@ namespace { constexpr const char* _loggerCat = "RingsComponent"; constexpr const std::array UniformNames = { - "modelViewProjectionMatrix", "textureOffset", "transparency", "_nightFactor", + "modelViewProjectionMatrix", "textureOffset", "colorFilterValue", "_nightFactor", "sunPosition", "ringTexture", "shadowMatrix", "shadowMapTexture", "zFightingPercentage" }; @@ -91,11 +91,11 @@ namespace { "of the night side occurs." }; - constexpr openspace::properties::Property::PropertyInfo TransparencyInfo = { - "Transparency", - "Transparency", - "This value determines the transparency of part of the rings depending on the " - "color values. For this value v, the transparency is equal to length(color) / v." + constexpr openspace::properties::Property::PropertyInfo ColorFilterInfo = { + "ColorFilter", + "Color Filter", + "This value affects the filtering out of part of the rings depending on the " + "color values of the texture. The higher value, the more rings are filtered out." }; constexpr openspace::properties::Property::PropertyInfo ZFightingPercentageInfo = { @@ -146,10 +146,10 @@ documentation::Documentation RingsComponent::Documentation() { NightFactorInfo.description }, { - TransparencyInfo.identifier, + ColorFilterInfo.identifier, new DoubleVerifier, Optional::Yes, - TransparencyInfo.description + ColorFilterInfo.description }, { ZFightingPercentageInfo.identifier, @@ -173,7 +173,7 @@ RingsComponent::RingsComponent(const ghoul::Dictionary& dictionary) , _size(SizeInfo, 1.f, 0.f, 1e25f) , _offset(OffsetInfo, glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(1.f)) , _nightFactor(NightFactorInfo, 0.33f, 0.f, 1.f) - , _transparency(TransparencyInfo, 0.15f, 0.f, 1.f) + , _colorFilter(ColorFilterInfo, 0.15f, 0.f, 1.f) , _enabled({ "Enabled", "Enabled", "Enable/Disable Rings" }, true) , _zFightingPercentage(ZFightingPercentageInfo, 0.995f, 0.000001f, 1.f) , _nShadowSamples(NumberShadowSamplesInfo, 2, 1, 7) @@ -228,9 +228,9 @@ void RingsComponent::initialize() { } addProperty(_nightFactor); - if (_ringsDictionary.hasKeyAndValue(TransparencyInfo.identifier)) { - _transparency = static_cast( - _ringsDictionary.value(TransparencyInfo.identifier) + if (_ringsDictionary.hasKeyAndValue(ColorFilterInfo.identifier)) { + _colorFilter = static_cast( + _ringsDictionary.value(ColorFilterInfo.identifier) ); } @@ -248,7 +248,7 @@ void RingsComponent::initialize() { _nShadowSamples.onChange([this]() { compileShadowShader(); }); addProperty(_nShadowSamples); - addProperty(_transparency); + addProperty(_colorFilter); } bool RingsComponent::isReady() const { @@ -327,7 +327,7 @@ void RingsComponent::draw(const RenderData& data, modelViewProjectionTransform ); _shader->setUniform(_uniformCache.textureOffset, _offset); - _shader->setUniform(_uniformCache.transparency, _transparency); + _shader->setUniform(_uniformCache.colorFilterValue, _colorFilter); _shader->setUniform(_uniformCache.nightFactor, _nightFactor); _shader->setUniform(_uniformCache.sunPosition, _sunPosition); _shader->setUniform(_uniformCache.zFightingPercentage, _zFightingPercentage); diff --git a/modules/globebrowsing/src/ringscomponent.h b/modules/globebrowsing/src/ringscomponent.h index 62980e1bf6..d6c7351a90 100644 --- a/modules/globebrowsing/src/ringscomponent.h +++ b/modules/globebrowsing/src/ringscomponent.h @@ -81,14 +81,14 @@ private: properties::FloatProperty _size; properties::Vec2Property _offset; properties::FloatProperty _nightFactor; - properties::FloatProperty _transparency; + properties::FloatProperty _colorFilter; properties::BoolProperty _enabled; properties::FloatProperty _zFightingPercentage; properties::IntProperty _nShadowSamples; std::unique_ptr _shader; std::unique_ptr _geometryOnlyShader; - UniformCache(modelViewProjectionMatrix, textureOffset, transparency, nightFactor, + UniformCache(modelViewProjectionMatrix, textureOffset, colorFilterValue, nightFactor, sunPosition, ringTexture, shadowMatrix, shadowMapTexture, zFightingPercentage ) _uniformCache; UniformCache(modelViewProjectionMatrix, textureOffset, ringTexture diff --git a/modules/space/rendering/renderablerings.cpp b/modules/space/rendering/renderablerings.cpp index 1a30124232..1291ccbe4d 100644 --- a/modules/space/rendering/renderablerings.cpp +++ b/modules/space/rendering/renderablerings.cpp @@ -39,7 +39,7 @@ namespace { constexpr const std::array UniformNames = { - "modelViewProjectionTransform", "textureOffset", "transparency", "_nightFactor", + "modelViewProjectionTransform", "textureOffset", "colorFilterValue", "_nightFactor", "sunPosition", "texture1" }; @@ -73,11 +73,11 @@ namespace { "of the night side occurs." }; - constexpr openspace::properties::Property::PropertyInfo TransparencyInfo = { - "Transparency", - "Transparency", - "This value determines the transparency of part of the rings depending on the " - "color values. For this value v, the transparency is equal to length(color) / v." + constexpr openspace::properties::Property::PropertyInfo ColorFilterInfo = { + "ColorFilter", + "Color Filter", + "This value affects the filtering out of part of the rings depending on the " + "color values of the texture. The higher value, the more rings are filtered out." }; } // namespace @@ -119,10 +119,10 @@ documentation::Documentation RenderableRings::Documentation() { NightFactorInfo.description }, { - TransparencyInfo.identifier, + ColorFilterInfo.identifier, new DoubleVerifier, Optional::Yes, - TransparencyInfo.description + ColorFilterInfo.description } } }; @@ -134,7 +134,7 @@ RenderableRings::RenderableRings(const ghoul::Dictionary& dictionary) , _size(SizeInfo, 1.f, 0.f, 1e25f) , _offset(OffsetInfo, glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(1.f)) , _nightFactor(NightFactorInfo, 0.33f, 0.f, 1.f) - , _transparency(TransparencyInfo, 0.15f, 0.f, 1.f) + , _colorFilter(ColorFilterInfo, 0.15f, 0.f, 1.f) { using ghoul::filesystem::File; @@ -169,12 +169,12 @@ RenderableRings::RenderableRings(const ghoul::Dictionary& dictionary) } addProperty(_nightFactor); - if (dictionary.hasKeyAndValue(TransparencyInfo.identifier)) { - _transparency = static_cast( - dictionary.value(TransparencyInfo.identifier) + if (dictionary.hasKeyAndValue(ColorFilterInfo.identifier)) { + _colorFilter = static_cast( + dictionary.value(ColorFilterInfo.identifier) ); } - addProperty(_transparency); + addProperty(_colorFilter); } bool RenderableRings::isReady() const { @@ -226,7 +226,7 @@ void RenderableRings::render(const RenderData& data, RendererTasks&) { data.camera.projectionMatrix() * glm::mat4(modelViewTransform) ); _shader->setUniform(_uniformCache.textureOffset, _offset); - _shader->setUniform(_uniformCache.transparency, _transparency); + _shader->setUniform(_uniformCache.colorFilterValue, _colorFilter); _shader->setUniform(_uniformCache.nightFactor, _nightFactor); _shader->setUniform(_uniformCache.sunPosition, _sunPosition); diff --git a/modules/space/rendering/renderablerings.h b/modules/space/rendering/renderablerings.h index d850670051..35152b1629 100644 --- a/modules/space/rendering/renderablerings.h +++ b/modules/space/rendering/renderablerings.h @@ -66,10 +66,10 @@ private: properties::FloatProperty _size; properties::Vec2Property _offset; properties::FloatProperty _nightFactor; - properties::FloatProperty _transparency; + properties::FloatProperty _colorFilter; std::unique_ptr _shader; - UniformCache(modelViewProjection, textureOffset, transparency, nightFactor, + UniformCache(modelViewProjection, textureOffset, colorFilterValue, nightFactor, sunPosition, texture) _uniformCache; std::unique_ptr _texture; std::unique_ptr _textureFile; diff --git a/modules/space/shaders/rings_fs.glsl b/modules/space/shaders/rings_fs.glsl index b9d4e484c8..ffa20731da 100644 --- a/modules/space/shaders/rings_fs.glsl +++ b/modules/space/shaders/rings_fs.glsl @@ -32,7 +32,7 @@ in vec4 vs_position; uniform sampler1D texture1; uniform vec2 textureOffset; -uniform float transparency; +uniform float colorFilterValue; uniform bool hasSunPosition; uniform vec3 sunPosition; @@ -60,11 +60,13 @@ Fragment getFragment() { } vec4 diffuse = texture(texture1, texCoord); - float colorValue = length(diffuse.rgb); - // times 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want - // to normalize the transparency value to [0,1] - if (colorValue < 3.0 * transparency) { - diffuse.a = pow(colorValue / (3.0 * transparency), 1); + // divided by 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want + // to normalize the alpha value to [0,1] + float colorValue = length(diffuse.rgb) / 3.0; + if (colorValue < colorFilterValue) { + diffuse.a = colorValue * colorFilterValue; + if (diffuse.a < 0.65) + discard; } // The normal for the one plane depends on whether we are dealing