mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-01 16:29:43 -05:00
Initial fade-in methods for DU objects.
This commit is contained in:
@@ -14,6 +14,8 @@ return {
|
||||
ColorOption = {"redshift", "prox5Mpc"},
|
||||
ColorRange = { { 0.0, 0.075 }, { 1.0, 50.0 } },
|
||||
Texture = "textures/point3.png",
|
||||
-- Fade in value in the same unit as "Unit"
|
||||
FadeInThreshould = 40.0,
|
||||
Unit = "Mpc"
|
||||
},
|
||||
GuiPath = "/Universe/Galaxies"
|
||||
|
||||
@@ -24,6 +24,8 @@ return {
|
||||
0.67314530211, 0.73127116582, 0.11008126223, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
},
|
||||
-- Fade in value in the same unit as "Unit"
|
||||
FadeInThreshould = 2.0,
|
||||
Unit = "Mpc"
|
||||
},
|
||||
GuiPath = "/Universe/Galaxies"
|
||||
@@ -49,6 +51,8 @@ return {
|
||||
0.67314530211, 0.73127116582, 0.11008126223, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
},
|
||||
-- Fade in value in the same unit as "Unit"
|
||||
FadeInThreshould = 0.1,
|
||||
Unit = "Mpc",
|
||||
},
|
||||
GuiPath = "/Universe/Galaxies"
|
||||
|
||||
@@ -165,6 +165,13 @@ namespace {
|
||||
"Render Option",
|
||||
"Debug option for rendering of billboards and texts."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo FadeInThreshouldInfo = {
|
||||
"FadeInThreshould",
|
||||
"Fade-In Threshould",
|
||||
"This value determines percentage of the astronomical object is visible before starting "
|
||||
"fading-in it."
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -271,6 +278,12 @@ documentation::Documentation RenderableBillboardsCloud::Documentation() {
|
||||
Optional::Yes,
|
||||
TransformationMatrixInfo.description
|
||||
},
|
||||
{
|
||||
FadeInThreshouldInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
FadeInThreshouldInfo.description
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -315,7 +328,8 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
|
||||
, _labelFile("")
|
||||
, _colorOptionString("")
|
||||
, _unit(Parsec)
|
||||
, _nValuesPerAstronomicalObject(0)
|
||||
, _nValuesPerAstronomicalObject(0)
|
||||
, _fadeInThreshold(0.0)
|
||||
, _transformationMatrix(glm::dmat4(1.0))
|
||||
, _vao(0)
|
||||
, _vbo(0)
|
||||
@@ -485,6 +499,10 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
|
||||
if (dictionary.hasKey(TransformationMatrixInfo.identifier)) {
|
||||
_transformationMatrix = dictionary.value<glm::dmat4>(TransformationMatrixInfo.identifier);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(FadeInThreshouldInfo.identifier)) {
|
||||
_fadeInThreshold = static_cast<float>(dictionary.value<double>(FadeInThreshouldInfo.identifier));
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderableBillboardsCloud::isReady() const {
|
||||
@@ -549,7 +567,8 @@ void RenderableBillboardsCloud::deinitialize() {
|
||||
}
|
||||
|
||||
void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& projectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp) {
|
||||
const glm::dmat4& projectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp,
|
||||
const float fadeInVariable) {
|
||||
glDepthMask(false);
|
||||
|
||||
// Saving current OpenGL state
|
||||
@@ -606,6 +625,8 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g
|
||||
_program->setUniform("up", orthoUp);
|
||||
_program->setUniform("right", orthoRight);
|
||||
|
||||
_program->setUniform("fadeInValue", fadeInVariable);
|
||||
|
||||
ghoul::opengl::TextureUnit spriteTextureUnit;
|
||||
if (_hasSpriteTexture) {
|
||||
spriteTextureUnit.activate();
|
||||
@@ -621,7 +642,6 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g
|
||||
_program->setUniform("hasPolygon", _hasPolygon);
|
||||
}
|
||||
|
||||
|
||||
if (_hasColorMapFile) {
|
||||
_program->setUniform("hasColorMap", true);
|
||||
}
|
||||
@@ -703,6 +723,48 @@ void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm::
|
||||
}
|
||||
|
||||
void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
float scale = 0.0;
|
||||
switch (_unit) {
|
||||
case Meter:
|
||||
scale = 1.0;
|
||||
break;
|
||||
case Kilometer:
|
||||
scale = 1e3;
|
||||
break;
|
||||
case Parsec:
|
||||
scale = PARSEC;
|
||||
break;
|
||||
case Kiloparsec:
|
||||
scale = 1e3 * PARSEC;
|
||||
break;
|
||||
case Megaparsec:
|
||||
scale = 1e6 * PARSEC;
|
||||
break;
|
||||
case Gigaparsec:
|
||||
scale = 1e9 * PARSEC;
|
||||
break;
|
||||
case GigalightYears:
|
||||
scale = 306391534.73091 * PARSEC;
|
||||
break;
|
||||
}
|
||||
|
||||
float fadeInVariable = 1.0f;
|
||||
if (_fadeInThreshold > 0.0) {
|
||||
float distCamera = glm::distance(data.camera.positionVec3(), data.position.dvec3());
|
||||
double term = std::exp(distCamera / scale - _fadeInThreshold);
|
||||
float func = static_cast<float>(term / (term + 1.0));
|
||||
|
||||
// Let's not waste performance
|
||||
if (func < 0.001) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!std::isinf(term)) {
|
||||
fadeInVariable = func;
|
||||
}
|
||||
}
|
||||
|
||||
glm::dmat4 modelMatrix =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
|
||||
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
|
||||
@@ -728,7 +790,7 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
|
||||
if (_hasSpeckFile) {
|
||||
renderBillboards(data, modelViewMatrix, projectionMatrix, orthoRight, orthoUp);
|
||||
renderBillboards(data, modelViewMatrix, projectionMatrix, orthoRight, orthoUp, fadeInVariable);
|
||||
}
|
||||
|
||||
if (_drawLabels && _hasLabel) {
|
||||
|
||||
@@ -89,7 +89,8 @@ private:
|
||||
void loadPolygonGeometryForRendering();
|
||||
void renderPolygonGeometry(GLuint vao);
|
||||
void renderBillboards(const RenderData& data, const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& projectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp);
|
||||
const glm::dmat4& projectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp,
|
||||
const float fadeInVariable);
|
||||
void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::vec3& orthoRight, const glm::vec3& orthoUp);
|
||||
|
||||
@@ -151,6 +152,8 @@ private:
|
||||
std::unordered_map<int, std::string> _optionConversionMap;
|
||||
std::vector<glm::vec2> _colorRangeData;
|
||||
|
||||
float _fadeInThreshold;
|
||||
|
||||
int _nValuesPerAstronomicalObject;
|
||||
|
||||
glm::dmat4 _transformationMatrix;
|
||||
|
||||
@@ -150,6 +150,12 @@ namespace {
|
||||
"Debug option for rendering of billboards and texts."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo FadeInThreshouldInfo = {
|
||||
"FadeInThreshould",
|
||||
"Fade-In Threshould",
|
||||
"This value determines percentage of the astronomical object is visible before starting "
|
||||
"fading-in it."
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -239,6 +245,12 @@ documentation::Documentation RenderablePlanesCloud::Documentation() {
|
||||
Optional::Yes,
|
||||
ScaleFactorInfo.description,
|
||||
},
|
||||
{
|
||||
FadeInThreshouldInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
FadeInThreshouldInfo.description
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -276,6 +288,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary
|
||||
, _unit(Parsec)
|
||||
, _nValuesPerAstronomicalObject(0)
|
||||
, _sluminosity(1.f)
|
||||
, _fadeInThreshold(0.0f)
|
||||
, _transformationMatrix(glm::dmat4(1.0))
|
||||
{
|
||||
documentation::testSpecificationAndThrow(
|
||||
@@ -413,6 +426,10 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary
|
||||
if (dictionary.hasKey(ScaleLuminosityInfo.identifier)) {
|
||||
_sluminosity = static_cast<float>(dictionary.value<double>(ScaleLuminosityInfo.identifier));
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(FadeInThreshouldInfo.identifier)) {
|
||||
_fadeInThreshold = static_cast<float>(dictionary.value<double>(FadeInThreshouldInfo.identifier));
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderablePlanesCloud::isReady() const {
|
||||
@@ -467,7 +484,8 @@ void RenderablePlanesCloud::deinitialize() {
|
||||
|
||||
void RenderablePlanesCloud::renderPlanes(const RenderData&,
|
||||
const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& projectionMatrix)
|
||||
const glm::dmat4& projectionMatrix,
|
||||
const float fadeInVariable)
|
||||
{
|
||||
// Saving current OpenGL state
|
||||
GLboolean blendEnabled = glIsEnabled(GL_BLEND);
|
||||
@@ -498,6 +516,7 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&,
|
||||
_program->setUniform("modelViewProjectionTransform", glm::dmat4(projectionMatrix) * modelViewMatrix);
|
||||
_program->setUniform("alphaValue", _alphaValue);
|
||||
_program->setUniform("scaleFactor", _scaleFactor);
|
||||
_program->setUniform("fadeInValue", fadeInVariable);
|
||||
//_program->setUniform("minPlaneSize", 1.f); // in pixels
|
||||
|
||||
//bool usingFramebufferRenderer =
|
||||
@@ -602,6 +621,47 @@ void RenderablePlanesCloud::renderLabels(const RenderData& data, const glm::dmat
|
||||
}
|
||||
|
||||
void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) {
|
||||
float scale = 0.0;
|
||||
switch (_unit) {
|
||||
case Meter:
|
||||
scale = 1.0;
|
||||
break;
|
||||
case Kilometer:
|
||||
scale = 1e3;
|
||||
break;
|
||||
case Parsec:
|
||||
scale = PARSEC;
|
||||
break;
|
||||
case Kiloparsec:
|
||||
scale = 1e3 * PARSEC;
|
||||
break;
|
||||
case Megaparsec:
|
||||
scale = 1e6 * PARSEC;
|
||||
break;
|
||||
case Gigaparsec:
|
||||
scale = 1e9 * PARSEC;
|
||||
break;
|
||||
case GigalightYears:
|
||||
scale = 306391534.73091 * PARSEC;
|
||||
break;
|
||||
}
|
||||
|
||||
float fadeInVariable = 1.0f;
|
||||
if (_fadeInThreshold > 0.0) {
|
||||
float distCamera = glm::distance(data.camera.positionVec3(), data.position.dvec3());
|
||||
double term = std::exp(distCamera / scale - _fadeInThreshold);
|
||||
float func = static_cast<float>(term / (term + 1.0));
|
||||
|
||||
// Let's not waste performance
|
||||
if (func < 0.001) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!std::isinf(term)) {
|
||||
fadeInVariable = func;
|
||||
}
|
||||
}
|
||||
|
||||
glm::dmat4 modelMatrix =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
|
||||
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
|
||||
@@ -622,7 +682,7 @@ void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
|
||||
if (_hasSpeckFile) {
|
||||
renderPlanes(data, modelViewMatrix, projectionMatrix);
|
||||
renderPlanes(data, modelViewMatrix, projectionMatrix, fadeInVariable);
|
||||
}
|
||||
|
||||
if (_hasLabel) {
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace openspace {
|
||||
void deleteDataGPU();
|
||||
void createPlanes();
|
||||
void renderPlanes(const RenderData& data, const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& projectionMatrix);
|
||||
const glm::dmat4& projectionMatrix, const float fadeInVariable);
|
||||
void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::vec3& orthoRight, const glm::vec3& orthoUp);
|
||||
|
||||
@@ -144,6 +144,7 @@ namespace openspace {
|
||||
int _nValuesPerAstronomicalObject;
|
||||
|
||||
float _sluminosity;
|
||||
float _fadeInThreshold;
|
||||
|
||||
glm::dmat4 _transformationMatrix;
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ uniform sampler2D spriteTexture;
|
||||
uniform sampler2D polygonTexture;
|
||||
uniform bool hasColorMap;
|
||||
uniform bool hasPolygon;
|
||||
uniform float fadeInValue;
|
||||
|
||||
Fragment getFragment() {
|
||||
|
||||
@@ -50,6 +51,8 @@ Fragment getFragment() {
|
||||
fullColor = vec4(color.rgb * textureColor.rgb, textureColor.a * alphaValue);
|
||||
}
|
||||
|
||||
fullColor.a *= fadeInValue;
|
||||
|
||||
if (fullColor.a == 0.f) {
|
||||
discard;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ in vec2 vs_st;
|
||||
uniform sampler2D galaxyTexture;
|
||||
//uniform bool additiveBlending;
|
||||
uniform float alphaValue;
|
||||
uniform float fadeInValue;
|
||||
|
||||
|
||||
Fragment getFragment() {
|
||||
@@ -44,6 +45,8 @@ Fragment getFragment() {
|
||||
frag.color = texture(galaxyTexture, vs_st);
|
||||
frag.color *= alphaValue;
|
||||
|
||||
frag.color.a *= fadeInValue;
|
||||
|
||||
if (frag.color.a == 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user