Feature/du updates (#972)

* Updating DU for new data.
* Changed how OS handles partiview colormaps.
* Multiple changes to adapt OS' behavior for cmaps.
* Small tweaks. MW sphere is now fading in the correct spacetime.
* Added all the Star Orbits.
* Fixing bug in speck reading procedure.
* Changed code to allow comments into data region of a speck file.
* Added deep sky objects.
* Added Home label
* Fixed bug in drawelements.
* Added Sun as a separated star for better control.
* Update version numbers on DU assets
* Move starorbits into their own asset file
* Making some of the digital universe renderables fully opaque for performance gains
This commit is contained in:
Alexander Bock
2019-09-09 13:46:57 +02:00
committed by GitHub
parent 334b8d1269
commit c6c2eb85fb
42 changed files with 880 additions and 223 deletions
@@ -56,12 +56,12 @@ namespace {
constexpr const char* ProgramObjectName = "RenderableBillboardsCloud";
constexpr const char* RenderToPolygonProgram = "RenderableBillboardsCloud_Polygon";
constexpr const std::array<const char*, 19> UniformNames = {
constexpr const std::array<const char*, 20> UniformNames = {
"cameraViewProjectionMatrix", "modelMatrix", "cameraPosition", "cameraLookUp",
"renderOption", "minBillboardSize", "maxBillboardSize",
"correctionSizeEndDistance", "correctionSizeFactor", "color", "alphaValue",
"scaleFactor", "up", "right", "fadeInValue", "screenSize", "spriteTexture",
"hasColorMap", "enabledRectSizeControl"
"hasColorMap", "enabledRectSizeControl", "hasDvarScaling"
};
constexpr const char* KeyFile = "File";
@@ -106,6 +106,20 @@ namespace {
"The path to the color map file of the astronomical object."
};
constexpr openspace::properties::Property::PropertyInfo ExactColorMapInfo = {
"ExactColorMap",
"Exact Color Map File",
"Set a 1 to 1 relationship between the color index variable and the colormap"
" entrered value."
};
constexpr openspace::properties::Property::PropertyInfo ColorRangeInfo = {
"ColorRange",
"Color Range",
"This value determines the colormap ranges for the color parameters of the "
"astronomical objects."
};
constexpr openspace::properties::Property::PropertyInfo PolygonSidesInfo = {
"PolygonSides",
"Polygon Sides",
@@ -160,15 +174,15 @@ namespace {
constexpr openspace::properties::Property::PropertyInfo ColorOptionInfo = {
"ColorOption",
"Color Option",
"This value determines which paramenter is used default color of the "
"This value determines which paramenter is used for default color of the "
"astronomical objects."
};
constexpr openspace::properties::Property::PropertyInfo ColorRangeInfo = {
"ColorRange",
"Color Range",
"This value determines the color ranges for the color parameter of the "
"astronomical objects."
constexpr openspace::properties::Property::PropertyInfo SizeOptionInfo = {
"SizeOption",
"Size Option Variable",
"This value determines which paramenter (datavar) is used for scaling "
"of the astronomical objects."
};
constexpr openspace::properties::Property::PropertyInfo TransformationMatrixInfo = {
@@ -275,6 +289,12 @@ documentation::Documentation RenderableBillboardsCloud::Documentation() {
Optional::Yes,
ColorMapInfo.description
},
{
ExactColorMapInfo.identifier,
new BoolVerifier,
Optional::Yes,
ExactColorMapInfo.description
},
{
PolygonSidesInfo.identifier,
new IntVerifier,
@@ -323,6 +343,12 @@ documentation::Documentation RenderableBillboardsCloud::Documentation() {
Optional::Yes,
ColorOptionInfo.description
},
{
SizeOptionInfo.identifier,
new StringListVerifier,
Optional::Yes,
SizeOptionInfo.description
},
{
ColorRangeInfo.identifier,
new Vector2ListVerifier<float>,
@@ -384,12 +410,7 @@ documentation::Documentation RenderableBillboardsCloud::Documentation() {
RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 600.f)
, _pointColor(
ColorInfo,
glm::vec3(1.f, 0.4f, 0.2f),
glm::vec3(0.f, 0.f, 0.f),
glm::vec3(1.0f, 1.0f, 1.0f)
)
, _pointColor(ColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f))
, _spriteTexturePath(SpriteTextureInfo)
, _textColor(
TextColorInfo,
@@ -404,6 +425,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
, _drawLabels(DrawLabelInfo, false)
, _pixelSizeControl(PixelSizeControlInfo, false)
, _colorOption(ColorOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
, _datavarSizeOption(SizeOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
, _fadeInDistance(
FadeInDistancesInfo,
glm::vec2(0.f),
@@ -426,10 +448,15 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
if (dictionary.hasKey(KeyFile)) {
_speckFile = absPath(dictionary.value<std::string>(KeyFile));
_hasSpeckFile = true;
_drawElements.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; });
addProperty(_drawElements);
}
if (dictionary.hasKey(DrawElementsInfo.identifier)) {
_drawElements = dictionary.value<bool>(DrawElementsInfo.identifier);
}
_drawElements.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; });
addProperty(_drawElements);
_renderOption.addOption(RenderOptionViewDirection, "Camera View Direction");
_renderOption.addOption(RenderOptionPositionNormal, "Camera Position Normal");
@@ -521,6 +548,10 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
);
}
}
if (dictionary.hasKey(ExactColorMapInfo.identifier)) {
_isColorMapExact = dictionary.value<bool>(ExactColorMapInfo.identifier);
}
}
else if (dictionary.hasKey(keyColor)) {
_pointColor = dictionary.value<glm::vec3>(keyColor);
@@ -537,6 +568,28 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
}
addProperty(_scaleFactor);
if (dictionary.hasKey(SizeOptionInfo.identifier)) {
ghoul::Dictionary sizeOptionDataDic = dictionary.value<ghoul::Dictionary>(
SizeOptionInfo.identifier
);
for (int i = 0; i < static_cast<int>(sizeOptionDataDic.size()); ++i) {
std::string datavarSizeInUseName(
sizeOptionDataDic.value<std::string>(std::to_string(i + 1))
);
_datavarSizeOption.addOption(i, datavarSizeInUseName);
_optionConversionSizeMap.insert({ i, datavarSizeInUseName });
_datavarSizeOptionString = datavarSizeInUseName;
}
_datavarSizeOption.onChange([&]() {
_dataIsDirty = true;
_datavarSizeOptionString = _optionConversionSizeMap[_datavarSizeOption.value()];
});
addProperty(_datavarSizeOption);
_hasDatavarSize = true;
}
if (dictionary.hasKey(PolygonSidesInfo.identifier)) {
_polygonSides = static_cast<int>(
dictionary.value<double>(PolygonSidesInfo.identifier)
@@ -617,13 +670,16 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
_correctionSizeFactor = static_cast<float>(
dictionary.value<double>(CorrectionSizeFactorInfo.identifier)
);
addProperty(_correctionSizeFactor);
}
addProperty(_correctionSizeFactor);
if (dictionary.hasKey(PixelSizeControlInfo.identifier)) {
_pixelSizeControl = dictionary.value<bool>(PixelSizeControlInfo.identifier);
addProperty(_pixelSizeControl);
}
addProperty(_pixelSizeControl);
}
bool RenderableBillboardsCloud::isReady() const {
@@ -636,7 +692,7 @@ void RenderableBillboardsCloud::initialize() {
throw ghoul::RuntimeError("Error loading data");
}
if (!_colorOptionString.empty()) {
if (!_colorOptionString.empty() && (_colorRangeData.size() > 1)) {
// Following DU behavior here. The last colormap variable
// entry is the one selected by default.
_colorOption.setValue(static_cast<int>(_colorRangeData.size() - 1));
@@ -783,6 +839,8 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data,
_program->setUniform(_uniformCache.enabledRectSizeControl, _pixelSizeControl);
_program->setUniform(_uniformCache.hasDvarScaling, _hasDatavarSize);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
_program->setUniform(_uniformCache.screenSize, glm::vec2(viewport[2], viewport[3]));
@@ -946,7 +1004,7 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) {
}
glm::dvec3 orthoUp = glm::normalize(glm::cross(cameraViewDirectionWorld, orthoRight));
if (_hasSpeckFile) {
if (_hasSpeckFile && _drawElements) {
renderBillboards(
data,
modelMatrix,
@@ -994,12 +1052,40 @@ void RenderableBillboardsCloud::update(const UpdateData&) {
);
GLint positionAttrib = _program->attributeLocation("in_position");
if (_hasColorMapFile) {
/*const size_t nAstronomicalObjects = _fullData.size() /
_nValuesPerAstronomicalObject;
const size_t nValues = _slicedData.size() / nAstronomicalObjects;
GLsizei stride = static_cast<GLsizei>(sizeof(float) * nValues);*/
if (_hasColorMapFile && _hasDatavarSize) {
glEnableVertexAttribArray(positionAttrib);
glVertexAttribPointer(
positionAttrib,
4,
GL_FLOAT,
GL_FALSE,
sizeof(float) * 9,
nullptr
);
GLint colorMapAttrib = _program->attributeLocation("in_colormap");
glEnableVertexAttribArray(colorMapAttrib);
glVertexAttribPointer(
colorMapAttrib,
4,
GL_FLOAT,
GL_FALSE,
sizeof(float) * 9,
reinterpret_cast<void*>(sizeof(float) * 4)
);
GLint dvarScalingAttrib = _program->attributeLocation("in_dvarScaling");
glEnableVertexAttribArray(dvarScalingAttrib);
glVertexAttribPointer(
dvarScalingAttrib,
1,
GL_FLOAT,
GL_FALSE,
sizeof(float) * 9,
reinterpret_cast<void*>(sizeof(float) * 8)
);
}
else if (_hasColorMapFile) {
glEnableVertexAttribArray(positionAttrib);
glVertexAttribPointer(
positionAttrib,
@@ -1021,6 +1107,28 @@ void RenderableBillboardsCloud::update(const UpdateData&) {
reinterpret_cast<void*>(sizeof(float) * 4)
);
}
else if (_hasDatavarSize) {
glEnableVertexAttribArray(positionAttrib);
glVertexAttribPointer(
positionAttrib,
4,
GL_FLOAT,
GL_FALSE,
sizeof(float) * 8,
nullptr
);
GLint dvarScalingAttrib = _program->attributeLocation("in_dvarScaling");
glEnableVertexAttribArray(dvarScalingAttrib);
glVertexAttribPointer(
dvarScalingAttrib,
1,
GL_FLOAT,
GL_FALSE,
sizeof(float) * 5,
reinterpret_cast<void*>(sizeof(float) * 4)
);
}
else {
glEnableVertexAttribArray(positionAttrib);
glVertexAttribPointer(
@@ -1174,7 +1282,6 @@ bool RenderableBillboardsCloud::readSpeckFile() {
// (signaled by the keywords 'datavar', 'texturevar', and 'texture')
std::string line;
while (true) {
std::streampos position = file.tellg();
std::getline(file, line);
// Guard against wrong line endings (copying files from Windows to Mac) causes
@@ -1193,9 +1300,7 @@ bool RenderableBillboardsCloud::readSpeckFile() {
line.substr(0, 10) != "polyorivar" &&
line.substr(0, 10) != "maxcomment")
{
// we read a line that doesn't belong to the header, so we have to jump back
// before the beginning of the current line
file.seekg(position);
// Started reading data
break;
}
@@ -1222,11 +1327,9 @@ bool RenderableBillboardsCloud::readSpeckFile() {
_nValuesPerAstronomicalObject += 3; // X Y Z are not counted in the Speck file indices
do {
std::vector<float> values(_nValuesPerAstronomicalObject);
std::getline(file, line);
// Guard against wrong line endings (copying files from Windows to Mac) causes
// lines to have a final \r
if (!line.empty() && line.back() == '\r') {
@@ -1234,16 +1337,25 @@ bool RenderableBillboardsCloud::readSpeckFile() {
}
if (line.empty()) {
std::getline(file, line);
continue;
}
else if (line[0] == '#') {
std::getline(file, line);
continue;
}
std::stringstream str(line);
std::vector<float> values(_nValuesPerAstronomicalObject);
for (int i = 0; i < _nValuesPerAstronomicalObject; ++i) {
str >> values[i];
}
_fullData.insert(_fullData.end(), values.begin(), values.end());
// reads new line
std::getline(file, line);
} while (!file.eof());
return true;
@@ -1288,6 +1400,7 @@ bool RenderableBillboardsCloud::readColorMapFile() {
std::stringstream str(line);
glm::vec4 color;
// Each color in the colormap must be defined as (R,G,B,A)
for (int j = 0; j < 4; ++j) {
str >> color[j];
}
@@ -1491,22 +1604,33 @@ void RenderableBillboardsCloud::createDataSlice() {
_slicedData.reserve(4 * (_fullData.size() / _nValuesPerAstronomicalObject));
}
// Generate the color bins for the colomap
int colorMapInUse = 0;
std::vector<float> colorBins;
if (_hasColorMapFile) {
colorMapInUse = _variableDataPositionMap[_colorOptionString];
glm::vec2 currentColorRange = _colorRangeData[_colorOption.value()];
float colorMapBinSize = (currentColorRange.y - currentColorRange.x) /
static_cast<float>(_colorMapData.size());
float bin = colorMapBinSize;
for (size_t i = 0; i < _colorMapData.size(); ++i) {
colorBins.push_back(bin);
bin += colorMapBinSize;
// what datavar in use for the index color
int colorMapInUse = _hasColorMapFile ? _variableDataPositionMap[_colorOptionString] : 0;
// what datavar in use for the size scaling (if present)
int sizeScalingInUse = _hasDatavarSize ?
_variableDataPositionMap[_datavarSizeOptionString] : -1;
auto addDatavarSizeScalling = [&](size_t i, int datavarInUse) {
_slicedData.push_back(_fullData[i + 3 + datavarInUse]);
};
auto addPosition = [&](const glm::vec4 &pos) {
for (int j = 0; j < 4; ++j) {
_slicedData.push_back(pos[j]);
}
};
float minColorIdx = std::numeric_limits<float>::max();
float maxColorIdx = std::numeric_limits<float>::min();
for (size_t i = 0; i < _fullData.size(); i += _nValuesPerAstronomicalObject) {
float colorIdx = _fullData[i + 3 + colorMapInUse];
maxColorIdx = colorIdx >= maxColorIdx ? colorIdx : maxColorIdx;
minColorIdx = colorIdx < minColorIdx ? colorIdx : minColorIdx;
}
float biggestCoord = -1.0f;
float biggestCoord = -1.f;
for (size_t i = 0; i < _fullData.size(); i += _nValuesPerAstronomicalObject) {
glm::dvec4 transformedPos = _transformationMatrix * glm::dvec4(
_fullData[i + 0],
@@ -1514,6 +1638,8 @@ void RenderableBillboardsCloud::createDataSlice() {
_fullData[i + 2],
1.0
);
// W-normalization
transformedPos /= transformedPos.w;
glm::vec4 position(glm::vec3(transformedPos), static_cast<float>(_unit));
if (_hasColorMapFile) {
@@ -1521,29 +1647,49 @@ void RenderableBillboardsCloud::createDataSlice() {
_slicedData.push_back(position[j]);
biggestCoord = biggestCoord < position[j] ? position[j] : biggestCoord;
}
// Finds from which bin to get the color.
// Note: the first color in the colormap file
// is the outliers color.
glm::vec4 itemColor;
float variableColor = _fullData[i + 3 + colorMapInUse];
int c = static_cast<int>(colorBins.size() - 1);
while (variableColor < colorBins[c]) {
--c;
if (c == 0) {
break;
}
// Note: if exact colormap option is not selected, the first color and the
// last color in the colormap file are the outliers colors.
int variableColor = static_cast<int>(_fullData[i + 3 + colorMapInUse]);
int colorIndex = 0;
float cmax, cmin;
if (_colorRangeData.empty()) {
cmax = maxColorIdx; // Max value of datavar used for the index color
cmin = minColorIdx; // Min value of datavar used for the index color
}
else {
glm::vec2 currentColorRange = _colorRangeData[_colorOption.value()];
cmax = currentColorRange.y;
cmin = currentColorRange.x;
}
int colorIndex = c == static_cast<int>(colorBins.size() - 1) ? 0 : c + 1;
if (_isColorMapExact) {
colorIndex = variableColor + cmin;
}
else {
float ncmap = static_cast<float>(_colorMapData.size());
float normalization = ((cmax != cmin) && (ncmap > 2)) ?
(ncmap - 2) / (cmax - cmin) : 0;
colorIndex = (variableColor - cmin) * normalization + 1;
colorIndex = colorIndex < 0 ? 0 : colorIndex;
colorIndex = colorIndex >= ncmap ? ncmap - 1 : colorIndex;
}
for (int j = 0; j < 4; ++j) {
_slicedData.push_back(_colorMapData[colorIndex][j]);
}
if (_hasDatavarSize) {
addDatavarSizeScalling(i, sizeScalingInUse);
}
}
else if (_hasDatavarSize) {
addDatavarSizeScalling(i, sizeScalingInUse);
addPosition(position);
}
else {
for (int j = 0; j < 4; ++j) {
_slicedData.push_back(position[j]);
}
addPosition(position);
}
}
_fadeInDistance.setMaxValue(glm::vec2(10.0f * biggestCoord));
@@ -103,6 +103,8 @@ private:
bool _hasSpriteTexture = false;
bool _spriteTextureIsDirty = true;
bool _hasColorMapFile = false;
bool _isColorMapExact = false;
bool _hasDatavarSize = false;
bool _hasPolygon = false;
bool _hasLabel = false;
@@ -121,6 +123,7 @@ private:
properties::BoolProperty _drawLabels;
properties::BoolProperty _pixelSizeControl;
properties::OptionProperty _colorOption;
properties::OptionProperty _datavarSizeOption;
properties::Vec2Property _fadeInDistance;
properties::BoolProperty _disableFadeInDistance;
properties::FloatProperty _billboardMaxSize;
@@ -139,24 +142,27 @@ private:
UniformCache(cameraViewProjectionMatrix, modelMatrix, cameraPos, cameraLookup,
renderOption, minBillboardSize, maxBillboardSize, correctionSizeEndDistance,
correctionSizeFactor, color, alphaValue, scaleFactor, up, right, fadeInValue,
screenSize, spriteTexture, hasColormap, enabledRectSizeControl
screenSize, spriteTexture, hasColormap, enabledRectSizeControl, hasDvarScaling
) _uniformCache;
std::shared_ptr<ghoul::fontrendering::Font> _font;
std::string _speckFile;
std::string _colorMapFile;
std::string _labelFile;
std::string _colorOptionString;
std::string _datavarSizeOptionString;
Unit _unit = Parsec;
std::vector<float> _slicedData;
std::vector<float> _fullData;
std::vector<glm::vec4> _colorMapData;
std::vector<glm::vec2> _colorRangeData;
std::vector<std::pair<glm::vec3, std::string>> _labelData;
std::unordered_map<std::string, int> _variableDataPositionMap;
std::unordered_map<int, std::string> _optionConversionMap;
std::vector<glm::vec2> _colorRangeData;
std::unordered_map<int, std::string> _optionConversionSizeMap;
int _nValuesPerAstronomicalObject = 0;
@@ -164,7 +164,7 @@ documentation::Documentation RenderableDUMeshes::Documentation() {
{
keyColor,
new Vector3Verifier<float>,
Optional::No,
Optional::Yes,
"Astronomical Object Color (r,g,b)."
},
{
@@ -715,8 +715,9 @@ bool RenderableDUMeshes::readSpeckFile() {
//if (line.substr(0, 4) != "mesh") {
// we read a line that doesn't belong to the header, so we have to jump back
// before the beginning of the current line
file.seekg(position);
break;
//file.seekg(position);
//break;
continue;
} else {
//if (line.substr(0, 4) == "mesh") {
@@ -298,7 +298,7 @@ documentation::Documentation RenderablePlanesCloud::Documentation() {
RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _alphaValue(TransparencyInfo, 1.f, 0.f, 1.f)
, _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 50.f)
, _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 10000.f)
, _textColor(
TextColorInfo,
glm::vec4(1.0f, 1.0, 1.0f, 1.f),
@@ -598,6 +598,7 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&,
continue;
}
// We only bind a new texture when it is needed
if (currentTextureIndex != pAMapItem.first) {
_textureMap[pAMapItem.first]->bind();
currentTextureIndex = pAMapItem.first;
@@ -708,12 +709,14 @@ void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) {
float fadeInVariable = 1.f;
if (!_disableFadeInDistance) {
double distCamera = glm::length(data.camera.positionVec3());
float distCamera = static_cast<float>(glm::length(data.camera.positionVec3()));
distCamera /= scale;
const glm::vec2 fadeRange = _fadeInDistance;
const float a = 1.0f / ((fadeRange.y - fadeRange.x) * scale);
//const float a = 1.f / ((fadeRange.y - fadeRange.x) * scale);
const float a = 1.f / ((fadeRange.y - fadeRange.x));
const float b = -(fadeRange.x / (fadeRange.y - fadeRange.x));
const float funcValue = static_cast<float>(a * distCamera + b);
fadeInVariable *= std::min(funcValue, 1.f);
const float funcValue = a * distCamera + b;
fadeInVariable *= funcValue > 1.f ? 1.f : funcValue;
if (funcValue < 0.01f) {
return;
@@ -881,7 +884,6 @@ bool RenderablePlanesCloud::readSpeckFile() {
// (signaled by the keywords 'datavar', 'texturevar', and 'texture')
std::string line;
while (true) {
std::streampos position = file.tellg();
std::getline(file, line);
// Guard against wrong line endings (copying files from Windows to Mac) causes
@@ -900,9 +902,7 @@ bool RenderablePlanesCloud::readSpeckFile() {
line.substr(0, 10) != "polyorivar" &&
line.substr(0, 10) != "maxcomment")
{
// we read a line that doesn't belong to the header, so we have to jump back
// before the beginning of the current line
file.seekg(position);
// Started reading data
break;
}
@@ -993,9 +993,6 @@ bool RenderablePlanesCloud::readSpeckFile() {
_nValuesPerAstronomicalObject += 3; // X Y Z are not counted in the Speck file indices
do {
std::vector<float> values(_nValuesPerAstronomicalObject);
std::getline(file, line);
// Guard against wrong line endings (copying files from Windows to Mac) causes
// lines to have a final \r
@@ -1004,6 +1001,11 @@ bool RenderablePlanesCloud::readSpeckFile() {
}
if (line.empty()) {
std::getline(file, line);
continue;
}
else if (line[0] == '#') {
std::getline(file, line);
continue;
}
@@ -1013,6 +1015,8 @@ bool RenderablePlanesCloud::readSpeckFile() {
glm::vec3 v(0.f);
int textureIndex = 0;
std::vector<float> values(_nValuesPerAstronomicalObject);
for (int i = 0; i < _nValuesPerAstronomicalObject; ++i) {
str >> values[i];
if ((i >= _planeStartingIndexPos) &&
@@ -1046,6 +1050,9 @@ bool RenderablePlanesCloud::readSpeckFile() {
}
}
_fullData.insert(_fullData.end(), values.begin(), values.end());
// reads new line
std::getline(file, line);
} while (!file.eof());
return true;
@@ -24,12 +24,12 @@
#include "fragment.glsl"
in vec4 gs_colorMap;
flat in vec4 gs_colorMap;
in float vs_screenSpaceDepth;
in vec2 texCoord;
in float ta;
uniform float alphaValue;
uniform float alphaValue; // opacity
uniform vec3 color;
uniform sampler2D spriteTexture;
uniform bool hasColorMap;
@@ -64,6 +64,7 @@ Fragment getFragment() {
// with the ATM.
frag.gPosition = vec4(-1e32, -1e32, -1e32, 1.0);
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
//frag.disableLDR2HDR = true;
return frag;
@@ -47,9 +47,13 @@ uniform float correctionSizeEndDistance;
uniform bool enabledRectSizeControl;
in vec4 colorMap[];
uniform bool hasDvarScaling;
flat in vec4 colorMap[];
flat in float dvarScaling[];
flat out vec4 gs_colorMap;
out vec4 gs_colorMap;
out vec2 texCoord;
out float vs_screenSpaceDepth;
out float ta;
@@ -65,11 +69,11 @@ const vec2 corners[4] = vec2[4](
void main() {
ta = 1.0f;
vec4 pos = gl_in[0].gl_Position; // in object space
gs_colorMap = colorMap[0];
double unit = PARSEC;
ta = 1.0f;
vec4 pos = gl_in[0].gl_Position; // in object space
gs_colorMap = colorMap[0];
double unit = PARSEC;
// Must be the same as the enum in RenderableBillboardsCloud.h
if (pos.w == 1.f) {
@@ -91,8 +95,11 @@ void main() {
dpos = modelMatrix * dpos;
double scaleMultiply = exp(scaleFactor * 0.10);
scaleMultiply = hasDvarScaling ? dvarScaling[0] * scaleMultiply : scaleMultiply;
dvec3 scaledRight = dvec3(0.0);
dvec3 scaledUp = dvec3(0.0);
vec4 initialPosition, secondPosition, thirdPosition, crossCorner;
if (renderOption == 0) {
@@ -139,11 +146,12 @@ void main() {
scaledRight *= correctionScale;
scaledUp *= correctionScale;
} else {
} else {
// linear alpha decay
if (sizes.x < 2.0f * minBillboardSize) {
float maxVar = 2.0f * minBillboardSize;
float minVar = minBillboardSize;
float var = (sizes.y + sizes.x);
float var = (sizes.y + sizes.x);
ta = ( (var - minVar)/(maxVar - minVar) );
if (ta == 0.0f)
return;
@@ -28,10 +28,13 @@
in vec4 in_position;
in vec4 in_colormap;
in float in_dvarScaling;
out vec4 colorMap;
flat out vec4 colorMap;
flat out float dvarScaling;
void main() {
colorMap = in_colormap;
gl_Position = vec4(in_position);
}
colorMap = in_colormap;
dvarScaling = in_dvarScaling;
gl_Position = in_position;
}
+67 -2
View File
@@ -69,6 +69,8 @@ namespace {
constexpr const int PsfMethodSpencer = 0;
constexpr const int PsfMethodMoffat = 1;
constexpr double PARSEC = 0.308567756E17;
struct CommonDataLayout {
std::array<float, 3> position;
float value;
@@ -276,6 +278,20 @@ namespace {
"Beta",
"Moffat's Beta Constant."
};
constexpr openspace::properties::Property::PropertyInfo FadeInDistancesInfo = {
"FadeInDistances",
"Fade-In Start and End Distances",
"These values determine the initial and final distances from the center of "
"our galaxy from which the astronomical object will start and end "
"fading-in."
};
constexpr openspace::properties::Property::PropertyInfo DisableFadeInInfo = {
"DisableFadeIn",
"Disable Fade-in effect",
"Enables/Disables the Fade-in effect."
};
} // namespace
namespace openspace {
@@ -374,6 +390,18 @@ documentation::Documentation RenderableStars::Documentation() {
Optional::No,
SizeCompositionOptionInfo.description
},
{
FadeInDistancesInfo.identifier,
new Vector2Verifier<double>,
Optional::Yes,
FadeInDistancesInfo.description
},
{
DisableFadeInInfo.identifier,
new BoolVerifier,
Optional::Yes,
DisableFadeInInfo.description
},
}
};
}
@@ -425,6 +453,13 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
, _userProvidedTextureOwner(UserProvidedTextureOptionInfo)
, _parametersOwner(ParametersOwnerOptionInfo)
, _moffatMethodOwner(MoffatMethodOptionInfo)
, _fadeInDistance(
FadeInDistancesInfo,
glm::vec2(0.f),
glm::vec2(0.f),
glm::vec2(100.f)
)
, _disableFadeInDistance(DisableFadeInInfo, true)
{
using File = ghoul::filesystem::File;
@@ -634,6 +669,14 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
addPropertySubOwner(_userProvidedTextureOwner);
addPropertySubOwner(_parametersOwner);
addPropertySubOwner(_moffatMethodOwner);
if (dictionary.hasKey(FadeInDistancesInfo.identifier)) {
glm::vec2 v = dictionary.value<glm::vec2>(FadeInDistancesInfo.identifier);
_fadeInDistance = v;
_disableFadeInDistance = false;
addProperty(_fadeInDistance);
addProperty(_disableFadeInDistance);
}
}
RenderableStars::~RenderableStars() {}
@@ -944,7 +987,22 @@ void RenderableStars::render(const RenderData& data, RendererTasks&) {
_program->setUniform(_uniformCache.radiusCent, _radiusCent);
_program->setUniform(_uniformCache.brightnessCent, _brightnessCent);
_program->setUniform(_uniformCache.alphaValue, _alphaValue);
float fadeInVariable = 1.f;
if (!_disableFadeInDistance) {
float distCamera = static_cast<float>(glm::length(data.camera.positionVec3()));
const glm::vec2 fadeRange = _fadeInDistance;
const float a = 1.f / ((fadeRange.y - fadeRange.x) * PARSEC);
const float b = -(fadeRange.x / (fadeRange.y - fadeRange.x));
const float funcValue = a * distCamera + b;
fadeInVariable *= funcValue > 1.f ? 1.f : funcValue;
_program->setUniform(_uniformCache.alphaValue, _alphaValue * fadeInVariable);
}
else {
_program->setUniform(_uniformCache.alphaValue, _alphaValue);
}
ghoul::opengl::TextureUnit psfUnit;
psfUnit.activate();
@@ -1392,10 +1450,17 @@ void RenderableStars::readSpeckFile() {
float minLumValue = std::numeric_limits<float>::max();
float maxLumValue = std::numeric_limits<float>::min();
bool first = true;
do {
std::vector<float> values(_nValuesPerStar);
std::getline(file, line);
if (!first) {
std::getline(file, line);
}
else {
first = false;
}
std::stringstream str(line);
for (int i = 0; i < _nValuesPerStar; ++i) {
@@ -123,6 +123,8 @@ private:
properties::PropertyOwner _userProvidedTextureOwner;
properties::PropertyOwner _parametersOwner;
properties::PropertyOwner _moffatMethodOwner;
properties::Vec2Property _fadeInDistance;
properties::BoolProperty _disableFadeInDistance;
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
UniformCache(
+11 -15
View File
@@ -60,6 +60,7 @@ uniform dmat4 cameraViewProjectionMatrix;
uniform dmat4 modelMatrix;
const double PARSEC = 3.08567756E16;
//const double PARSEC = 3.08567782E16;
const vec2 corners[4] = vec2[4](
vec2(0.0, 0.0),
@@ -78,16 +79,6 @@ float bvToKelvin(float bv) {
}
void main() {
vs_position = gl_in[0].gl_Position; // in object space
// JCC: Don't display the Sun for now.
if ((vs_position.x == 0.0) &&
(vs_position.y == 0.0) &&
(vs_position.z == 0.0))
{
return;
}
vs_position = gl_in[0].gl_Position; // in object space
dvec4 dpos = modelMatrix * dvec4(vs_position);
@@ -112,13 +103,15 @@ void main() {
double distanceToStar = length((dpos.xyz - eyePosition));
double apparentBrightness = pSize * luminosity / (distanceToStar);
scaleMultiply = apparentBrightness;
} else if (psfParamConf == 1) {
}
else if (psfParamConf == 1) {
float L_over_Lsun = pow(2.51f, SunAbsMagnitude - ge_bvLumAbsMagAppMag.z);
float starTemperature = bvToKelvin(ge_bvLumAbsMagAppMag.x);
float starRadius = SunRadius * pow(SunTemperature/starTemperature, 2.f) * sqrt(L_over_Lsun);
scaleMultiply = ((lumCent * (ge_bvLumAbsMagAppMag.y + 5E9)) +
(radiusCent * double(starRadius))) * pow(10.0, magnitudeExponent);
} else if (psfParamConf == 2) {
}
else if (psfParamConf == 2) {
double luminosity = double(1.0 - ge_bvLumAbsMagAppMag.y);
double distanceToStarInParsecs = trunc(length(dpos.xyz - eyePosition) / PARSEC);
double apparentBrightness = luminosity / distanceToStarInParsecs;
@@ -130,10 +123,12 @@ void main() {
(radiusCent * double(starRadius)) +
(brightnessCent * apparentBrightness * 5E15)) *
pow(10.0, magnitudeExponent);
} else if (psfParamConf == 3) {
}
else if (psfParamConf == 3) {
float absMag = ge_bvLumAbsMagAppMag.z;
scaleMultiply = (-absMag + 35.f) * pow(10.0, magnitudeExponent + 8.5f);
} else if (psfParamConf == 4) {
}
else if (psfParamConf == 4) {
float absMag = vs_bvLumAbsMagAppMag[0].z;
double distanceToStarInMeters = length(dpos.xyz - eyePosition);
double distanceToCenterInMeters = length(eyePosition);
@@ -151,7 +146,8 @@ void main() {
//scaleMultiply = appMag * pow(10.0, magnitudeExponent + 8.5f);
scaleMultiply = exp((-30.0 - appMag) * 0.45) * pow(10.0, magnitudeExponent + 8.f);
//scaleMultiply = pow(10.0, (appMag - absMag)*(1.0/5.0) + 1.0) * pow(10.0, magnitudeExponent + 3.f);
} else if (psfParamConf == 5) {
}
else if (psfParamConf == 5) {
float absMag = ge_bvLumAbsMagAppMag.z;
scaleMultiply = exp((-30.623 - absMag) * 0.462) * pow(10.0, magnitudeExponent + 12.5f) * 2000;
}