Merge branch 'master' into feature/NewAtmosphere

# Conflicts:
#	modules/digitaluniverse/rendering/renderablebillboardscloud.cpp
This commit is contained in:
Alexander Bock
2017-12-18 14:49:08 -05:00
5 changed files with 32 additions and 226 deletions

View File

@@ -161,45 +161,11 @@ namespace {
"astronomical objects."
};
static const openspace::properties::Property::PropertyInfo TransformationMatrixInfo = {
"TransformationMatrix",
"Transformation Matrix",
"Transformation matrix to be applied to each astronomical object."
};
static const openspace::properties::Property::PropertyInfo RenderOptionInfo = {
"RenderOptionInfo",
"Render Option",
"Debug option for rendering of billboards and texts."
};
static const 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."
};
static const openspace::properties::Property::PropertyInfo DisableFadeInInfo = {
"DisableFadeIn",
"Disable Fade-in effect",
"Enables/Disables the Fade-in effect."
};
static const openspace::properties::Property::PropertyInfo BillboardMaxSizeInfo = {
"BillboardMaxSize",
"Billboard Max Size in Pixels",
"The max size (in pixels) for the billboard representing the astronomical "
"object."
};
static const openspace::properties::Property::PropertyInfo BillboardMinSizeInfo = {
"BillboardMinSize",
"Billboard Min Size in Pixels",
"The min size (in pixels) for the billboard representing the astronomical "
"object."
};
} // namespace
namespace openspace {
@@ -305,37 +271,7 @@ documentation::Documentation RenderableBillboardsCloud::Documentation() {
new Vector2ListVerifier<float>,
Optional::Yes,
ColorRangeInfo.description
},
{
TransformationMatrixInfo.identifier,
new Matrix4x4Verifier<double>,
Optional::Yes,
TransformationMatrixInfo.description
},
{
FadeInDistancesInfo.identifier,
new Vector2Verifier<double>,
Optional::Yes,
FadeInDistancesInfo.description
},
{
DisableFadeInInfo.identifier,
new BoolVerifier,
Optional::Yes,
DisableFadeInInfo.description
},
{
BillboardMaxSizeInfo.identifier,
new DoubleVerifier,
Optional::Yes,
BillboardMaxSizeInfo.description
},
{
BillboardMinSizeInfo.identifier,
new DoubleVerifier,
Optional::Yes,
BillboardMinSizeInfo.description
},
}
}
};
}
@@ -370,10 +306,6 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
, _drawElements(DrawElementsInfo, true)
, _drawLabels(DrawLabelInfo, false)
, _colorOption(ColorOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
, _fadeInDistance(FadeInDistancesInfo, glm::vec2(0.0f), glm::vec2(0.0), glm::vec2(100.0))
, _disableFadeInDistance(DisableFadeInInfo, true)
, _billboardMaxSize(BillboardMaxSizeInfo, 400.0, 0.0, 1000.0)
, _billboardMinSize(BillboardMinSizeInfo, 0.0, 0.0, 100.0)
, _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
, _polygonTexture(nullptr)
, _spriteTexture(nullptr)
@@ -385,8 +317,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
, _labelFile("")
, _colorOptionString("")
, _unit(Parsec)
, _nValuesPerAstronomicalObject(0)
, _transformationMatrix(glm::dmat4(1.0))
, _nValuesPerAstronomicalObject(0)
, _vao(0)
, _vbo(0)
, _polygonVao(0)
@@ -413,7 +344,6 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
_renderOption.addOption(1, "Camera Position Normal");
_renderOption.addOption(2, "Screen center Position Normal");
addProperty(_renderOption);
//_renderOption.set(1);
if (dictionary.hasKey(keyUnit)) {
std::string unit = dictionary.value<std::string>(keyUnit);
@@ -557,28 +487,6 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
}
addProperty(_textMaxSize);
}
if (dictionary.hasKey(TransformationMatrixInfo.identifier)) {
_transformationMatrix = dictionary.value<glm::dmat4>(TransformationMatrixInfo.identifier);
}
if (dictionary.hasKey(FadeInDistancesInfo.identifier)) {
glm::vec2 fadeInValue = dictionary.value<glm::vec2>(FadeInDistancesInfo.identifier);
_fadeInDistance.set(fadeInValue);
_disableFadeInDistance.set(false);
addProperty(_fadeInDistance);
addProperty(_disableFadeInDistance);
}
if (dictionary.hasKey(BillboardMaxSizeInfo.identifier)) {
_billboardMaxSize = static_cast<float>(dictionary.value<double>(BillboardMaxSizeInfo.identifier));
addProperty(_billboardMaxSize);
}
if (dictionary.hasKey(BillboardMinSizeInfo.identifier)) {
_billboardMinSize = static_cast<float>(dictionary.value<double>(BillboardMinSizeInfo.identifier));
addProperty(_billboardMinSize);
}
}
bool RenderableBillboardsCloud::isReady() const {
@@ -647,8 +555,7 @@ void RenderableBillboardsCloud::deinitializeGL() {
}
void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const glm::dmat4& modelViewMatrix,
const glm::dmat4& worldToModelTransform, const glm::dvec3& orthoRight, const glm::dvec3& orthoUp,
const float fadeInVariable) {
const glm::dmat4& projectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp) {
glDepthMask(false);
// Saving current OpenGL state
@@ -676,26 +583,18 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
_program->setIgnoreUniformLocationError(IgnoreError::Yes);
glm::dmat4 projMatrix = glm::dmat4(data.camera.projectionMatrix());
_program->setUniform("screenSize", glm::vec2(OsEng.renderEngine().renderingResolution()));
_program->setUniform("projection", projMatrix);
_program->setUniform("projection", projectionMatrix);
_program->setUniform("modelViewTransform", modelViewMatrix);
_program->setUniform("modelViewProjectionTransform", projMatrix * modelViewMatrix);
_program->setUniform("cameraPosition", glm::dvec3(worldToModelTransform *
glm::dvec4(data.camera.positionVec3(), 1.0)));
_program->setUniform("cameraLookUp", glm::dvec3(worldToModelTransform *
glm::dvec4(data.camera.lookUpVectorWorldSpace(), 1.0)));
//_program->setUniform("cameraPosition", data.camera.positionVec3());
//_program->setUniform("cameraLookUp", data.camera.lookUpVectorWorldSpace());
_program->setUniform("modelViewProjectionTransform", glm::dmat4(projectionMatrix) * modelViewMatrix);
_program->setUniform("cameraPosition", data.camera.positionVec3());
_program->setUniform("cameraLookUp", data.camera.lookUpVectorWorldSpace());
_program->setUniform("renderOption", _renderOption.value());
glm::dvec4 centerScreenWorld = glm::inverse(data.camera.combinedViewMatrix()) *
glm::dvec4(0.0, 0.0, 0.0, 1.0);
glm::dvec4 centerScreenWorld = glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0);
_program->setUniform("centerScreenInWorldPosition", centerScreenWorld);
_program->setUniform("minBillboardSize", _billboardMinSize); // in pixels
_program->setUniform("maxBillboardSize", _billboardMaxSize); // in pixels
_program->setUniform("minBillboardSize", 1.f); // in pixels
_program->setUniform("color", _pointColor);
_program->setUniform("sides", 4);
_program->setUniform("alphaValue", _alphaValue);
@@ -704,12 +603,6 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g
_program->setUniform("up", orthoUp);
_program->setUniform("right", orthoRight);
_program->setUniform("fadeInValue", fadeInVariable);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
_program->setUniform("screenSize", glm::vec2(viewport[2], viewport[3]));
ghoul::opengl::TextureUnit spriteTextureUnit;
if (_hasSpriteTexture) {
spriteTextureUnit.activate();
@@ -725,6 +618,7 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g
_program->setUniform("hasPolygon", _hasPolygon);
}
if (_hasColorMapFile) {
_program->setUniform("hasColorMap", true);
}
@@ -754,7 +648,7 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g
}
void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVariable) {
const glm::vec3& orthoRight, const glm::vec3& orthoUp) {
RenderEngine& renderEngine = OsEng.renderEngine();
_fontRenderer->setFramebufferSize(renderEngine.renderingResolution());
@@ -784,8 +678,6 @@ void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm::
break;
}
glm::vec4 textColor = _textColor;
textColor.a *= fadeInVariable;
for (const std::pair<glm::vec3, std::string>& pair : _labelData) {
//glm::vec3 scaledPos(_transformationMatrix * glm::dvec4(pair.first, 1.0));
glm::vec3 scaledPos(pair.first);
@@ -793,8 +685,7 @@ void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm::
_fontRenderer->render(
*_font,
scaledPos,
//_textColor,
textColor,
_textColor,
pow(10.0, _textSize.value()),
_textMinSize,
_textMaxSize,
@@ -810,57 +701,6 @@ 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 (!_disableFadeInDistance) {
float distCamera = glm::length(data.camera.positionVec3());
/*
// Linear Fading
float funcValue = static_cast<float>((1.0 / double(_fadeInDistance*scale))*(distCamera));
fadeInVariable *= funcValue > 1.0 ? 1.0 : funcValue;
if (funcValue < 0.01) {
return;
}
*/
glm::vec2 fadeRange = _fadeInDistance;
float a = 1.0f / ((fadeRange.y - fadeRange.x) * scale);
float b = -(fadeRange.x / (fadeRange.y - fadeRange.x));
float funcValue = a * distCamera + b;
fadeInVariable *= funcValue > 1.0 ? 1.0 : funcValue;
if (funcValue < 0.01) {
return;
}
}
glm::dmat4 modelMatrix =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
@@ -869,50 +709,25 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) {
glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix;
glm::mat4 viewMatrix = data.camera.viewMatrix();
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) *
modelViewMatrix;
glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix);
/*glm::dmat4 internalCameraMatrix = data.camera.viewRotationMatrix() *
glm::inverse(glm::translate(glm::dmat4(1.0), data.camera.positionVec3()));
glm::dmat4 invInternalCameraMatrix = glm::inverse(internalCameraMatrix);
glm::vec3 lookup = worldToModelTransform * invInternalCameraMatrix * glm::dvec4(data.camera.lookUpVectorWorldSpace(), 0.0);
glm::vec3 viewDirection = worldToModelTransform * invInternalCameraMatrix * glm::dvec4(data.camera.viewDirectionWorldSpace(), 0.0);
glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) * modelViewMatrix;
glm::vec3 lookup = data.camera.lookUpVectorWorldSpace();
glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace();
glm::vec3 right = glm::cross(viewDirection, lookup);
glm::vec3 up = glm::cross(right, viewDirection);
glm::vec3 orthoRight = glm::normalize(right);
glm::vec3 orthoUp = glm::normalize(up);*/
/*
glm::dmat4 internalCameraMatrix = data.camera.viewRotationMatrix() *
glm::inverse(glm::translate(glm::dmat4(1.0), data.camera.positionVec3()));
glm::dmat4 invInternalCameraMatrix = glm::inverse(internalCameraMatrix);
glm::dvec4 lookup = worldToModelTransform * glm::dvec4(data.camera.lookUpVectorWorldSpace(), 0.0);
glm::dvec4 viewDirection = worldToModelTransform * glm::dvec4(data.camera.viewDirectionWorldSpace(), 0.0);
glm::vec3 right = glm::cross(glm::vec3(viewDirection), glm::vec3(lookup));
glm::vec3 up = glm::cross(right, glm::vec3(viewDirection));
glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix);
glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)));
glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0)));
glm::vec3 orthoRight = glm::normalize(right);
glm::vec3 orthoUp = glm::normalize(up);
*/
// Almost Working
glm::dmat4 invMVPParts = worldToModelTransform * glm::inverse(data.camera.combinedViewMatrix()) *
glm::inverse(glm::dmat4(projectionMatrix));
glm::dvec3 orthoRight = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(1.0, 0.0, 0.0, 0.0))));
glm::dvec3 orthoUp = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0))));
if (_hasSpeckFile) {
renderBillboards(data, modelViewMatrix, worldToModelTransform, orthoRight, orthoUp, fadeInVariable);
renderBillboards(data, modelViewMatrix, projectionMatrix, orthoRight, orthoUp);
}
if (_drawLabels && _hasLabel) {
renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp, fadeInVariable);
}
renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp);
}
}
void RenderableBillboardsCloud::update(const UpdateData&) {
@@ -1304,16 +1119,12 @@ bool RenderableBillboardsCloud::readLabelFile() {
dummy.clear();
while (str >> dummy) {
if (dummy == "#") {
break;
}
label += " " + dummy;
dummy.clear();
}
glm::vec3 transformedPos = glm::vec3(_transformationMatrix * glm::dvec4(position, 1.0));
_labelData.push_back(std::make_pair(transformedPos, label));
_labelData.push_back(std::make_pair(position, label));
} while (!file.eof());
return true;
@@ -1436,15 +1247,13 @@ void RenderableBillboardsCloud::createDataSlice() {
}
}
float biggestCoord = -1.0f;
for (size_t i = 0; i < _fullData.size(); i += _nValuesPerAstronomicalObject) {
glm::dvec4 transformedPos = _transformationMatrix * glm::dvec4(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2], 1.0);
glm::dvec4 transformedPos = glm::dvec4(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2], 1.0);
glm::vec4 position(glm::vec3(transformedPos), static_cast<float>(_unit));
if (_hasColorMapFile) {
for (auto j = 0; j < 4; ++j) {
_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
@@ -1470,8 +1279,6 @@ void RenderableBillboardsCloud::createDataSlice() {
}
}
}
_fadeInDistance.setMaxValue(glm::vec2(10.0f * biggestCoord));
}
void RenderableBillboardsCloud::createPolygonTexture() {
@@ -1556,8 +1363,7 @@ void RenderableBillboardsCloud::renderPolygonGeometry(GLuint vao) {
ghoul::opengl::ProgramObject::Build("RenderableBillboardsCloud_Polygon",
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_vs.glsl"),
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_fs.glsl"),
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_gs.glsl")
);
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_gs.glsl"));
program->activate();
static const float black[] = { 0.0f, 0.0f, 0.0f, 0.0f };

View File

@@ -48,6 +48,7 @@
#include <openspace/interaction/navigationhandler.h>
#include <openspace/util/factorymanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/misc/templatefactory.h>
#include <ghoul/misc/assert.h>
#include <ghoul/systemcapabilities/generalcapabilitiescomponent.h>
@@ -298,7 +299,7 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const {
#endif // GLOBEBROWSING_USE_GDAL
},
{
"${MODULE_GLOBEBROWSING}/scripts/layer_support.lua"
absPath("${MODULE_GLOBEBROWSING}/scripts/layer_support.lua")
},
{
// Documentation

View File

@@ -943,8 +943,7 @@ void OpenSpaceEngine::loadFonts() {
_fontManager = std::make_unique<ghoul::fontrendering::FontManager>(FontAtlasSize);
for (const std::string& key : fonts.keys()) {
std::string font = fonts.value<std::string>(key);
font = absPath(font);
std::string font = absPath(fonts.value<std::string>(key));
if (!FileSys.fileExists(font)) {
LERROR("Could not find font '" << font << "'");

View File

@@ -271,7 +271,7 @@ void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library,
for (const std::string& script : library.scripts) {
// First we run the script to set its values in the current state
ghoul::lua::runScriptFile(state, absPath(script));
ghoul::lua::runScriptFile(state, script);
library.documentations.clear();

View File

@@ -102,7 +102,7 @@ std::string OpenSpaceModule::modulePath() const {
else { // Otherwise, it might be one of the external directories
for (const char* dir : ModulePaths) {
const std::string path = std::string(dir) + '/' + moduleName;
if (FileSys.directoryExists(path)) {
if (FileSys.directoryExists(absPath(path))) {
return absPath(path);
}
}