Added fade-in for background radiation. Changed from sigmoid to linear fading.

This commit is contained in:
Jonathas Costa
2017-11-09 13:03:38 -05:00
15 changed files with 168 additions and 58 deletions

View File

@@ -84,6 +84,19 @@ namespace {
"This value determines percentage of the sphere is visible before starting "
"fading-out it."
};
static const openspace::properties::Property::PropertyInfo FadeInThreshouldInfo = {
"FadeInThreshould",
"Fade-In Threshould",
"Distance from center of MilkyWay from where the astronomical object starts to "
"fade in."
};
static const openspace::properties::Property::PropertyInfo DisableFadeInOuInfo = {
"DisableFadeInOu",
"Disable Fade-In/Fade-Out effects",
"Enables/Disables the Fade-In/Out effects."
};
} // namespace
namespace openspace {
@@ -129,7 +142,19 @@ documentation::Documentation RenderableSphere::Documentation() {
new DoubleInRangeVerifier(0.0, 1.0),
Optional::Yes,
FadeOutThreshouldInfo.description
}
},
{
FadeInThreshouldInfo.identifier,
new DoubleVerifier,
Optional::Yes,
FadeInThreshouldInfo.description
},
{
DisableFadeInOuInfo.identifier,
new BoolVerifier,
Optional::Yes,
DisableFadeInOuInfo.description
},
}
};
}
@@ -142,7 +167,9 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
, _size(SizeInfo, 1.f, 0.f, 1e35f)
, _segments(SegmentsInfo, 8, 4, 1000)
, _transparency(TransparencyInfo, 1.f, 0.f, 1.f)
, _disableFadeInDistance(DisableFadeInOuInfo, true)
, _fadeOutThreshold(-1.0)
, _fadeInThreshold(0.0)
, _shader(nullptr)
, _texture(nullptr)
, _sphere(nullptr)
@@ -209,7 +236,17 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
_texturePath.onChange([this]() { loadTexture(); });
if (dictionary.hasKey(FadeOutThreshouldInfo.identifier)) {
_fadeOutThreshold = static_cast<float>(dictionary.value<double>(FadeOutThreshouldInfo.identifier));
_fadeOutThreshold = static_cast<float>(dictionary.value<double>(FadeOutThreshouldInfo.identifier));
}
if (dictionary.hasKey(FadeInThreshouldInfo.identifier)) {
_fadeInThreshold = static_cast<float>(dictionary.value<double>(FadeInThreshouldInfo.identifier));
}
if (dictionary.hasKey(FadeOutThreshouldInfo.identifier) ||
dictionary.hasKey(FadeInThreshouldInfo.identifier)) {
_disableFadeInDistance.set(false);
addProperty(_disableFadeInDistance);
}
}
@@ -256,16 +293,29 @@ void RenderableSphere::render(const RenderData& data, RendererTasks&) {
setPscUniforms(*_shader.get(), data.camera, data.position);
float adjustedTransparency = _transparency;
if (_fadeInThreshold > 0.0) {
float distCamera = glm::length(data.camera.positionVec3());
float funcValue = static_cast<float>((1.0 / double(_fadeInThreshold/1E24))*(distCamera / 1E24));
adjustedTransparency *= funcValue > 1.0 ? 1.0 : funcValue;
}
if (_fadeOutThreshold > -1.0) {
float distCamera = glm::distance(data.camera.positionVec3(), data.position.dvec3());
double term = std::exp((-distCamera + _size * _fadeOutThreshold) / (_size * _fadeOutThreshold));
_shader->setUniform("alpha", _transparency * static_cast<float>(term / (term + 1.0)));
}
else {
_shader->setUniform("alpha", _transparency);
adjustedTransparency *= static_cast<float>(term / (term + 1.0));
}
// Performance wise
if (adjustedTransparency < 0.01) {
return;
}
_shader->setUniform("alpha", adjustedTransparency);
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();