Merge branch 'plutoViz' of openspace.itn.liu.se:/openspace into plutoViz

This commit is contained in:
Michal Marcinkowski
2015-02-22 13:11:03 -05:00
21 changed files with 493 additions and 272 deletions

View File

@@ -59,7 +59,8 @@ public:
static bool isInitialized();
bool initialize();
bool isMaster();
void setMaster(bool master);
static bool findConfiguration(std::string& filename);
// Guaranteed to return a valid pointer
@@ -110,6 +111,7 @@ private:
LuaConsole* _console;
gui::GUI* _gui;
double _dt;
bool _isMaster;
SyncBuffer* _syncBuffer;
};

View File

@@ -86,9 +86,9 @@ protected:
std::set<properties::Property*> _vec3Properties;
std::set<properties::Property*> _vec4Properties;
std::set<properties::Property*> _stringProperties;
std::set<properties::Property*> _optionProperty;
std::set<properties::Property*> _selectionProperty;
std::set<properties::Property*> _triggerProperty;
std::set<properties::Property*> _optionProperties;
std::set<properties::Property*> _selectionProperties;
std::set<properties::Property*> _triggerProperties;
std::map<std::string, std::vector<properties::Property*>> _propertiesByOwner;
//std::vector<Property> _properties;

View File

@@ -73,6 +73,9 @@ public:
void serialize(SyncBuffer* syncBuffer);
void deserialize(SyncBuffer* syncBuffer);
float globalOpacity();
void setGlobalOpacity(float opacity);
/**
* Returns the Lua library that contains all Lua functions available to affect the
@@ -84,6 +87,12 @@ public:
*/
static scripting::ScriptEngine::LuaLibrary luaLibrary();
// This is a temporary method to change the origin of the coordinate system ---abock
void changeViewPoint(std::string origin);
//temporaray fade functionality
void startFading(int direction, float fadeDuration);
private:
void storePerformanceMeasurements();
@@ -101,6 +110,11 @@ private:
void generateGlslConfig();
float _globalOpactity;
float _fadeDuration;
float _currentFadeTime;
int _fadeDirection;
bool _visualizeABuffer;
ABufferVisualizer* _visualizer;
};

View File

@@ -85,6 +85,12 @@ public:
const Renderable* renderable() const;
Renderable* renderable();
// @TODO Remove once the scalegraph is in effect ---abock
void setEphemeris(Ephemeris* eph) {
delete _ephemeris;
_ephemeris = eph;
}
private:
bool sphereInsideFrustum(const psc& s_pos, const PowerScaledScalar& s_rad, const Camera* camera);

View File

@@ -31,7 +31,7 @@ return {
LogLevel = "Debug",
ImmediateFlush = true,
Logs = {
{ Type = "HTML", FileName = "${BASE_PATH}/log.html", Append = false }
-- { Type = "HTML", FileName = "${BASE_PATH}/log.html", Append = false }
}
},
LuaDocumentationFile = {
@@ -42,5 +42,5 @@ return {
--SGCTConfig = "${SGCT}/single_fisheye.xml",
--SGCTConfig = "${SGCT}/two_nodes.xml",
--SGCTConfig = "${SGCT}/single_sbs_stereo.xml",
Scene = "${OPENSPACE_DATA}/scene/default_michal.scene",
Scene = "${OPENSPACE_DATA}/scene/default.scene",
}

View File

@@ -1,10 +1,5 @@
openspace.clearKeys()
function setEarthAsOrigin()
openspace.setOrigin('Earth')
end
interaction_speed = 2.75
-- Key Bindings
@@ -14,6 +9,11 @@ openspace.bindKey("f3", "openspace.setPerformanceMeasurement(false)")
openspace.bindKey("f4", "openspace.takeScreenshot()")
openspace.bindKey("f5", "loadKeyBindings()")
openspace.bindKey("f9", "openspace.changeViewPointToPluto(); openspace.printInfo('Changing Viewpoint to Pluto-in-center');");
openspace.bindKey("f10", "openspace.changeViewPointToSun(); openspace.printInfo('Changing Viewpoint to Sun-in-center');");
openspace.bindKey("f11", "openspace.fadeOut(2);")
openspace.bindKey("f12", "openspace.fadeIn(2);")
openspace.bindKey("T", "openspace.distance(-interaction_speed * openspace.dt(), 6.0)")
openspace.bindKey("G", "openspace.distance(interaction_speed * openspace.dt(), 6.0)")
openspace.bindKey("Y", "openspace.distance(-interaction_speed * openspace.dt(), 10.0)")

View File

@@ -1,12 +1,11 @@
openspace.printInfo("Setting default values");
openspace.setPropertyValue("Constellation Bounds.renderable.enabled", false);
openspace.setPropertyValue("Stars.renderable.magnitudeClamp", {0.941, 4.191});
openspace.setPropertyValue("Stars.renderable.exponentialOffset", 6.180);
openspace.setPropertyValue("Stars.renderable.exponentialDampening", 0.838);
openspace.setPropertyValue("Stars.renderable.scaleFactor", 0.563);
openspace.setPropertyValue("Stars.renderable.exponentialDampening", 0.400);
openspace.setPropertyValue("Stars.renderable.exponentialOffset", 19.222);
openspace.setPropertyValue("Stars.renderable.scaleFactor", 9.201);
openspace.setPropertyValue("MilkyWay.renderable.transparency", 0.65);
openspace.setPropertyValue("MilkyWay.renderable.transparency", 0.85);
openspace.setPropertyValue("MilkyWay.renderable.segments", 50);
openspace.printInfo("Done setting default values");

View File

@@ -31,7 +31,6 @@ const int COLOROPTION_SPEED = 2;
uniform sampler2D psfTexture;
uniform sampler1D colorTexture;
uniform vec3 Color;
uniform int colorOption;
@@ -40,11 +39,14 @@ layout(location = 1) in vec3 ge_brightness;
layout(location = 2) in vec3 ge_velocity;
layout(location = 3) in float ge_speed;
layout(location = 4) in vec2 texCoord;
layout(location = 5) in float billboardSize;
#include "ABuffer/abufferStruct.hglsl"
#include "ABuffer/abufferAddToBuffer.hglsl"
#include "PowerScaling/powerScaling_fs.hglsl"
uniform vec2 magnitudeClamp;
//---------------------------------------------------------------------------
vec4 bv2rgb(float bv) {
@@ -54,53 +56,43 @@ vec4 bv2rgb(float bv) {
}
void main() {
// Something in the color calculations need to be changed because before it was dependent
// on the gl blend functions since the abuffer was not involved
// Something in the color calculations need to be changed because before it was dependent
// on the gl blend functions since the abuffer was not involved
vec4 color = vec4(0.0);
switch (colorOption) {
case COLOROPTION_COLOR:
color = bv2rgb(ge_brightness.x);
break;
case COLOROPTION_VELOCITY:
color = vec4(abs(ge_velocity), 0.5);
break;
case COLOROPTION_SPEED:
// @TODO Include a transfer function here ---abock
color = vec4(vec3(ge_speed), 0.5);
break;
}
vec4 color = vec4(0.0);
switch (colorOption) {
case COLOROPTION_COLOR:
color = bv2rgb(ge_brightness.x);
break;
case COLOROPTION_VELOCITY:
color = vec4(abs(ge_velocity), 0.5);
break;
case COLOROPTION_SPEED:
// @TODO Include a transfer function here ---abock
color = vec4(vec3(ge_speed), 0.5);
break;
}
// These can be removed once we get a better star psf texture ---abock
vec4 textureColor = texture(psfTexture, texCoord);
// textureColor.a = (textureColor.a - 0.25) / (0.85);
vec4 textureColor = texture(psfTexture, texCoord);
// textureColor.a = sqrt(textureColor.a);
vec4 fullColor = vec4(color.rgb, textureColor.a);
vec4 fullColor = vec4(color.rgb, textureColor.a);
// vec4 fullColor = textureColor * color;
// if (fullColor.a <= 0.125)
// discard;
const float minPixelSize = 15;
float M = ge_brightness.z;
// if (M > 10)
// discard;
float targetM = 6;
float maxM = 14.0;
if (M > targetM) {
float alpha = (M - targetM) / (maxM - targetM);
fullColor.a *= alpha;
float normSize = (billboardSize - 1.0) / (minPixelSize - 1.0);
normSize = pow(normSize, 3);
fullColor *= clamp(normSize, 0.0, 1.0);
}
vec4 position = vs_position;
// This has to be fixed when the scale graph is in place ---abock
float depth = pscDepth(position) + 1;
// float depth = 10000.0;
// gl_FragDepth = depth;
// if (ge_brightness.z > 7.0)
// discard;
// Ease the workload on the abuffer a bit
if (textureColor.a < 0.1)
discard;
vec4 position = vs_position;
// This has to be fixed when the scale graph is in place ---abock
float depth = pscDepth(position) + 1000;
// float depth = 10000.0;
// gl_FragDepth = depth;
ABufferStruct_t frag = createGeometryFragment(fullColor, position, depth);
addToBuffer(frag);
// discard;
}
ABufferStruct_t frag = createGeometryFragment(fullColor, position, depth);
addToBuffer(frag);
}

View File

@@ -32,7 +32,7 @@ const vec2 corners[4] = vec2[4](
);
#include "PowerScaling/powerScalingMath.hglsl"
#include <${SHADERS_GENERATED}/constants.hglsl>:notrack
layout(points) in;
layout(triangle_strip, max_vertices = 4) out;
@@ -48,6 +48,7 @@ layout(location = 1) out vec3 ge_brightness;
layout(location = 2) out vec3 ge_velocity;
layout(location = 3) out float ge_speed;
layout(location = 4) out vec2 texCoord;
layout(location = 5) out float billboardSize;
uniform mat4 projection;
@@ -56,119 +57,40 @@ uniform float exponentialOffset;
uniform float exponentialDampening;
uniform float scaleFactor;
// As soon as the scalegraph is in place, replace this by a dynamic calculation
// of apparent magnitude in relation to the camera position ---abock
void main() {
// Skip the Sun
if (psc_position[0].x == 0.0 && psc_position[0].y == 0.0 && psc_position[0].z == 0.0) {
ge_brightness = vs_brightness[0];
ge_velocity = vs_velocity[0];
ge_speed = vs_speed[0];
float absoluteMagnitude = vs_brightness[0].z;
float modifiedSpriteSize = exp((-exponentialOffset - absoluteMagnitude) * exponentialDampening) * scaleFactor;
vec4 projPos[4];
for (int i = 0; i < 4; ++i) {
vec4 p1 = gl_in[0].gl_Position;
p1.xy += vec2(modifiedSpriteSize * (corners[i] - vec2(0.5)));
projPos[i] = projection * p1;
}
// Calculate the positions of the lower left and upper right corners of the
// billboard in screen-space
const vec2 screenSize = vec2(SCREEN_WIDTH, SCREEN_HEIGHT);
vec2 ll = (((projPos[1].xy / projPos[1].w) + 1) / 2) * screenSize;
vec2 ur = (((projPos[2].xy / projPos[2].w) + 1) / 2) * screenSize;
// The billboard is smaller than one pixel, we can discard it
vec2 distance = abs(ll - ur);
float sizeInPixels = length(distance);
if (sizeInPixels < 1)
return;
}
ge_brightness = vs_brightness[0];
ge_velocity = vs_velocity[0];
ge_speed = vs_speed[0];
float M = vs_brightness[0].z;
// M = clamp(M, 1.0, 4.0);
M = clamp(M, magnitudeClamp[0], magnitudeClamp[1]);
// float modifiedSpriteSize = exp((-5 - M) * 0.871);
float modifiedSpriteSize = exp((-exponentialOffset - M) * exponentialDampening) * scaleFactor;
for(int i = 0; i < 4; i++){
vec4 p1 = gl_in[0].gl_Position;
p1.xy += vec2(modifiedSpriteSize * (corners[i] - vec2(0.5)));
vs_position = p1;
gl_Position = projection * p1;
// gl_Position = z_normalization(projection * p1);
vs_position = gl_in[0].gl_Position;
gl_Position = projPos[i];
// gl_Position = z_normalization(projPos[i]);
texCoord = corners[i];
billboardSize = sizeInPixels;
EmitVertex();
}
EndPrimitive();
}
// Old method, still in the code for reference ---abock
#if 0
void main() {
ge_brightness = vs_brightness[0];
ge_velocity = vs_velocity[0];
ge_speed = vs_speed[0];
// float M = vs_brightness[0][0]; // get ABSOLUTE magnitude (x param)
float M = vs_brightness[0].z; // if NOT running test-target.
// We are using a fixed position until the scalegraph is implemented ---abock
// vec4 cam = vec4(-cam_position[0].xyz, cam_position[0].w); // get negative camera position
// vec4 cam = vec4(0.0);
vec4 pos = psc_position[0]; // get OK star position
// vec4 result = psc_addition(pos, cam); // compute vec from camera to position
vec4 result = pos;
vec2 pc = vec2(
length(result.xyz),
result.w
);
// convert meters into parsecs
// pc[0] *= 0.324077929f;
// pc[1] -= 18.0f;
float distLog = log10(pc[0]) + pc[1];
float apparent = (M - 5.f * (1.f - distLog));
// p = vec4(vec3(apparent), 1.0);
// check everything below this ---abock
float weight = 0.000025f; // otherwise this takes over.
double depth = pc[0] * pow(10, pc[1]);
depth *= pow(apparent,3);
double modifiedSpriteSize = (spriteBaseSize * 0.0005f) + (depth*weight);
modifiedSpriteSize *= spriteResponseSize;
// // modifiedSpriteSize = min(modifiedSpriteSize, -0.0025f);
// {
// vec4 p = gl_in[0].gl_Position;
// p.xy += vec2(modifiedSpriteSize * (corners[1] - vec2(0.5)));
// p = projection * p;
// vec4 q = gl_in[0].gl_Position;
// q.xy += vec2(modifiedSpriteSize * (corners[2] - vec2(0.5)));
// q = projection * q;
// if (length(p.xyz-q.xyz) < 0.025)
// return;
// // if (sin(dot(p,q)) < 0.1)
// // return;
// }
// if (depth < -0.00000001)
// return;
// float distLy = vs_brightness[0].w;
// float distParsec = distLy * 0.306594845;
// if (distParsec > 200 && -apparent > 1.0)
// return;
for(int i = 0; i < 4; i++){
vec4 p1 = gl_in[0].gl_Position;
// vec4 p1 = psc_position[0];
p1.w = 1.0;
// p1.w = 1.0;
p1.xy += vec2(modifiedSpriteSize * (corners[i] - vec2(0.5)));
vs_position = p1;
gl_Position = projection * p1;
// gl_Position = p1;
// if (modifiedSpriteSize > -0.001f)
// texCoord = vec2(0.5);
// else
texCoord = corners[i];
EmitVertex();
}
EndPrimitive();
}
#endif

36
shaders/postFX_fs.glsl Normal file
View File

@@ -0,0 +1,36 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version 430
in vec2 UV;
out vec4 Color;
uniform sampler2D Tex;
uniform float Opacity;
void main()
{
Color = texture(Tex, UV) * Opacity;
}

36
shaders/postFX_vs.glsl Normal file
View File

@@ -0,0 +1,36 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version 430
layout (location = 0) in vec2 TexCoords;
layout (location = 1) in vec3 Position;
out vec2 UV;
void main()
{
gl_Position = vec4(Position, 1.0);
UV = TexCoords;
}

View File

@@ -93,6 +93,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName)
, _console(new LuaConsole)
, _gui(new gui::GUI)
, _syncBuffer(nullptr)
, _isMaster(false)
{
SpiceManager::initialize();
Time::initialize();
@@ -530,9 +531,17 @@ bool OpenSpaceEngine::initializeGL() {
return success;
}
bool OpenSpaceEngine::isMaster(){
return _isMaster;
}
void OpenSpaceEngine::setMaster(bool master){
_isMaster = master;
}
void OpenSpaceEngine::preSynchronization() {
FileSys.triggerFilesystemEvents();
if (sgct::Engine::instance()->isMaster()) {
if (_isMaster) {
//const double dt = sgct::Engine::instance()->getDt();
const double dt = sgct::Engine::instance()->getAvgDt();
@@ -552,7 +561,7 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
_scriptEngine->postSynchronizationPreDraw();
_renderEngine->postSynchronizationPreDraw();
if (sgct::Engine::instance()->isMaster() && _gui->isEnabled()) {
if (_isMaster && _gui->isEnabled()) {
double posX, posY;
sgct::Engine::instance()->getMousePos(0, &posX, &posY);
@@ -571,10 +580,10 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
void OpenSpaceEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix) {
_renderEngine->render(projectionMatrix, viewMatrix);
if (sgct::Engine::instance()->isMaster()) {
if (_isMaster) {
// If currently writing a command, render it to screen
sgct::SGCTWindow* w = sgct::Engine::instance()->getActiveWindowPtr();
if (sgct::Engine::instance()->isMaster() && !w->isUsingFisheyeRendering() && _console->isVisible()) {
if (_isMaster && !w->isUsingFisheyeRendering() && _console->isVisible()) {
_console->render();
}
@@ -584,14 +593,14 @@ void OpenSpaceEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4
}
void OpenSpaceEngine::postDraw() {
if (sgct::Engine::instance()->isMaster())
if (_isMaster)
//_interactionHandler.unlockControls();
_renderEngine->postDraw();
}
void OpenSpaceEngine::keyboardCallback(int key, int action) {
if (sgct::Engine::instance()->isMaster()) {
if (_isMaster) {
if (_gui->isEnabled()) {
bool isConsumed = _gui->keyCallback(key, action);
if (isConsumed)
@@ -611,7 +620,7 @@ void OpenSpaceEngine::keyboardCallback(int key, int action) {
}
void OpenSpaceEngine::charCallback(unsigned int codepoint) {
if (sgct::Engine::instance()->isMaster()) {
if (_isMaster) {
if (_gui->isEnabled()) {
bool isConsumed = _gui->charCallback(codepoint);
if (isConsumed)
@@ -625,7 +634,7 @@ void OpenSpaceEngine::charCallback(unsigned int codepoint) {
}
void OpenSpaceEngine::mouseButtonCallback(int key, int action) {
if (sgct::Engine::instance()->isMaster()) {
if (_isMaster) {
if (_gui->isEnabled()) {
bool isConsumed = _gui->mouseButtonCallback(key, action);
if (isConsumed && action != SGCT_RELEASE)
@@ -637,13 +646,13 @@ void OpenSpaceEngine::mouseButtonCallback(int key, int action) {
}
void OpenSpaceEngine::mousePositionCallback(int x, int y) {
if (sgct::Engine::instance()->isMaster()) {
if (_isMaster) {
_interactionHandler->mousePositionCallback(x, y);
}
}
void OpenSpaceEngine::mouseScrollWheelCallback(int pos) {
if (sgct::Engine::instance()->isMaster()) {
if (_isMaster) {
if (_gui->isEnabled()) {
bool isConsumed = _gui->mouseWheelCallback(pos);
if (isConsumed)

View File

@@ -30,8 +30,10 @@
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/selectionproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/vectorproperty.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/lua/lua_helper.h>
#include <ghoul/misc/assert.h>
#include "imgui.h"
@@ -103,6 +105,20 @@ namespace {
}
}
void renderStringProperty(Property* prop, const std::string& ownerName) {
StringProperty* p = static_cast<StringProperty*>(prop);
std::string name = p->guiName();
static const int bufferSize = 256;
static char buffer[bufferSize];
strcpy(buffer, p->value().c_str());
ImGui::InputText((ownerName + "." + name).c_str(), buffer, bufferSize);
std::string newValue(buffer);
if (newValue != p->value() && FileSys.fileExists(newValue))
executeScript(p->fullyQualifiedIdentifier(), "'" + newValue + "'");
}
void renderIntProperty(Property* prop, const std::string& ownerName) {
IntProperty* p = static_cast<IntProperty*>(prop);
std::string name = p->guiName();
@@ -336,11 +352,11 @@ void GuiPropertyComponent::registerProperty(properties::Property* prop) {
else if (className == "Vec4Property")
_vec4Properties.insert(prop);
else if (className == "OptionProperty")
_optionProperty.insert(prop);
_optionProperties.insert(prop);
else if (className == "TriggerProperty")
_triggerProperty.insert(prop);
_triggerProperties.insert(prop);
else if (className == "SelectionProperty")
_selectionProperty.insert(prop);
_selectionProperties.insert(prop);
else {
LWARNING("Class name '" << className << "' not handled in GUI generation");
return;
@@ -447,20 +463,25 @@ void GuiPropertyComponent::render() {
continue;
}
if (_optionProperty.find(prop) != _optionProperty.end()) {
if (_optionProperties.find(prop) != _optionProperties.end()) {
renderOptionProperty(prop, p.first);
continue;
}
if (_triggerProperty.find(prop) != _triggerProperty.end()) {
if (_triggerProperties.find(prop) != _triggerProperties.end()) {
renderTriggerProperty(prop, p.first);
continue;
}
if (_selectionProperty.find(prop) != _selectionProperty.end()) {
if (_selectionProperties.find(prop) != _selectionProperties.end()) {
renderSelectionProperty(prop, p.first);
continue;
}
if (_stringProperties.find(prop) != _stringProperties.end()) {
renderStringProperty(prop, p.first);
continue;
}
}
}
}

View File

@@ -23,8 +23,9 @@
****************************************************************************************/
#include <openspace/engine/openspaceengine.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logging>
#include <openspace/rendering/renderengine.h>
#include <sgct.h>
sgct::Engine* _sgctEngine;
@@ -42,13 +43,14 @@ void mainMousePosCallback(double x, double y);
void mainMouseScrollCallback(double posX, double posY);
void mainEncodeFun();
void mainDecodeFun();
#if 0
// @TODO Remove the ifdef hen the next SGCT version is available ---abock
void mainExternalControlCallback(const char * receivedChars, int size);
#else
void mainExternalControlCallback(const char * receivedChars, int size, int clientId);
#endif
void mainLogCallback(const char* msg);
//temporary post-FX functions, TODO make a more permanent solution to this @JK
void postFXPass();
void setupPostFX();
GLint _postFXTexLoc;
GLint _postFXOpacityLoc;
namespace {
const std::string _loggerCat = "main";
@@ -68,18 +70,11 @@ int main(int argc, char** argv)
for (int i = 0; i < newArgc; ++i)
newArgv[i] = const_cast<char*>(sgctArguments.at(i).c_str());
#if 0
// @TODO Remove the ifdef (enabling the functions) when the next SGCT version is available
// that enables the logging redirect ---abock
sgct::MessageHandler::instance()->setLogToConsole(false);
sgct::MessageHandler::instance()->setShowTime(false);
sgct::MessageHandler::instance()->setLogToCallback(true);
sgct::MessageHandler::instance()->setLogCallback([](const char* msg) {
std::string message = msg;
// Remove the trailing \n that is passed along
LINFOC("SGCT", message.substr(0, message.size()-1));
});
#endif
sgct::MessageHandler::instance()->setLogCallback(mainLogCallback);
LDEBUG("Creating SGCT Engine");
_sgctEngine = new sgct::Engine(newArgc, newArgv);
@@ -121,6 +116,9 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}
//is this node the master? (must be set after call to _sgctEngine->init())
OsEng.ref().setMaster(_sgctEngine->isMaster());
// Main loop
LDEBUG("Starting rendering loop");
_sgctEngine->render();
@@ -148,6 +146,9 @@ void mainInitFunc()
std::cin.ignore(100);
exit(EXIT_FAILURE);
}
//temporary post-FX solution, TODO add a more permanent solution @JK
setupPostFX();
}
void mainPreSyncFunc()
@@ -163,12 +164,13 @@ void mainPostSyncPreDrawFunc()
void mainRenderFunc()
{
//not the most efficient, but for clarity @JK
glm::mat4 userMatrix = glm::translate(glm::mat4(1.f), _sgctEngine->getUserPtr()->getPos());
glm::mat4 userMatrix = glm::translate(glm::mat4(1.f), _sgctEngine->getDefaultUserPtr()->getPos());
glm::mat4 sceneMatrix = _sgctEngine->getModelMatrix();
glm::mat4 viewMatrix = _sgctEngine->getActiveViewMatrix() * userMatrix;
//dont shift nav-direction on master, makes it very tricky to navigate @JK
if (!_sgctEngine->isMaster()){
if (!OsEng.ref().isMaster()){
viewMatrix = viewMatrix * sceneMatrix;
}
@@ -181,50 +183,41 @@ void mainPostDrawFunc()
OsEng.postDraw();
}
#if 0
// @TODO Remove the ifdef hen the next SGCT version is available ---abock
void mainExternalControlCallback(const char* receivedChars, int size)
{
if (_sgctEngine->isMaster())
if (OsEng.ref().isMaster())
OsEng.externalControlCallback(receivedChars, size, 0);
}
#else
void mainExternalControlCallback(const char* receivedChars, int size, int clientId)
{
if (_sgctEngine->isMaster())
OsEng.externalControlCallback(receivedChars, size, clientId);
}
#endif
void mainKeyboardCallback(int key, int action)
{
if (_sgctEngine->isMaster())
if (OsEng.ref().isMaster())
OsEng.keyboardCallback(key, action);
}
void mainMouseButtonCallback(int key, int action)
{
if (_sgctEngine->isMaster())
if (OsEng.ref().isMaster())
OsEng.mouseButtonCallback(key, action);
}
void mainMousePosCallback(double x, double y)
{
// TODO use float instead
if (_sgctEngine->isMaster())
if (OsEng.ref().isMaster())
OsEng.mousePositionCallback(static_cast<int>(x), static_cast<int>(y));
}
void mainMouseScrollCallback(double posX, double posY)
{
// TODO use float instead
if (_sgctEngine->isMaster())
if (OsEng.ref().isMaster())
OsEng.mouseScrollWheelCallback(static_cast<int>(posY));
}
void mainCharCallback(unsigned int codepoint) {
if (_sgctEngine->isMaster())
if (OsEng.ref().isMaster())
OsEng.charCallback(codepoint);
}
@@ -237,3 +230,32 @@ void mainDecodeFun()
{
OsEng.decode();
}
void mainLogCallback(const char* msg){
std::string message = msg;
// Remove the trailing \n that is passed along
LINFOC("SGCT", message.substr(0, std::max<size_t>(message.size() - 1, 0)));
}
void postFXPass(){
glUniform1i(_postFXTexLoc, 0);
if (OsEng.isMaster()){
glUniform1f(_postFXOpacityLoc, 1.f);
}
else{
glUniform1f(_postFXOpacityLoc, OsEng.ref().renderEngine()->globalOpacity());
}
}
void setupPostFX(){
sgct::PostFX fx[1];
sgct::ShaderProgram *shader;
fx[0].init("OpacityControl", absPath("${SHADERS}/postFX_vs.glsl"), absPath("${SHADERS}/postFX_fs.glsl"));
fx[0].setUpdateUniformsFunction(postFXPass);
shader = fx[0].getShaderProgram();
shader->bind();
_postFXTexLoc = shader->getUniformLocation("Tex");
_postFXOpacityLoc = shader->getUniformLocation("Opacity");
shader->unbind();
_sgctEngine->addPostFX(fx[0]);
}

View File

@@ -82,7 +82,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
dictionary.getValue(keyFrame, _frame);
bool b1 = dictionary.getValue(keyBody, _target);
assert(b1 == true);
//assert(b1 == true);
// TODO: textures need to be replaced by a good system similar to the geometry as soon
// as the requirements are fixed (ab)

View File

@@ -170,7 +170,7 @@ void RenderableTrail::update(const UpdateData& data) {
// Update the floating current time
// Is 'CN+S' correct? It has to be chosen to be the same as in SpiceEphemeris, but
// unsure if it is correct ---abock
SpiceManager::ref().getTargetState(_target, _observer, _frame, "CN+S", data.time, pscPos, pscVel, lightTime);
SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", data.time, pscPos, pscVel, lightTime);
pscPos[3] += 3; // KM to M
_vertexArray[0] = { pscPos[0], pscPos[1], pscPos[2], pscPos[3] };

View File

@@ -57,6 +57,10 @@
#include <fstream>
#include <sgct.h>
// These are temporary ---abock
#include <openspace/scenegraph/spiceephemeris.h>
#include <openspace/scenegraph/staticephemeris.h>
// ABuffer defines
#define ABUFFER_FRAMEBUFFER 0
#define ABUFFER_SINGLE_LINKED 1
@@ -80,6 +84,22 @@ namespace openspace {
namespace luascriptfunctions {
int changeToPlutoViewPoint(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 0)
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
OsEng.renderEngine()->changeViewPoint("Pluto");
return 0;
}
int changeToSunViewPoint(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 0)
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
OsEng.renderEngine()->changeViewPoint("Sun");
return 0;
}
/**
* \ingroup LuaScripts
* takeScreenshot():
@@ -140,6 +160,37 @@ namespace openspace {
return 0;
}
/**
* \ingroup LuaScripts
* fadeIn(float):
* start a global fadein over (float) seconds
*/
int fadeIn(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 1)
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
double t = luaL_checknumber(L, -1);
OsEng.renderEngine()->startFading(1, t);
return 0;
}
/**
* \ingroup LuaScripts
* fadeIn(float):
* start a global fadeout over (float) seconds
*/
int fadeOut(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 1)
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
double t = luaL_checknumber(L, -1);
OsEng.renderEngine()->startFading(-1, t);
return 0;
}
} // namespace luascriptfunctions
@@ -155,6 +206,11 @@ namespace openspace {
, _performanceMemory(nullptr)
, _visualizeABuffer(false)
, _visualizer(nullptr)
, _globalOpactity(1.f)
, _fadeDuration(2.f)
, _currentFadeTime(0.f)
, _fadeDirection(0)
{
}
@@ -219,7 +275,7 @@ namespace openspace {
// set the close clip plane and the far clip plane to extreme values while in
// development
sgct::Engine::instance()->setNearAndFarClippingPlanes(0.01f, 10000.0f);
sgct::Engine::instance()->setNearAndFarClippingPlanes(0.001f, 1000.0f);
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f, 30.0f);
// calculating the maximum field of view for the camera, used to
@@ -252,18 +308,19 @@ namespace openspace {
const glm::vec3 center = (corners[0] + corners[1] + corners[2] + corners[3])
/ 4.0f;
#if 0
// @TODO Remove the ifdef when the next SGCT version is released that requests the
// getUserPtr to get a name parameter ---abock
// set the eye position, useful during rendering
const glm::vec3 eyePosition
= sgct_core::ClusterManager::instance()->getUserPtr("")->getPos();
#else
const glm::vec3 eyePosition
= sgct_core::ClusterManager::instance()->getUserPtr()->getPos();
#endif
//#if 0
// // @TODO Remove the ifdef when the next SGCT version is released that requests the
// // getUserPtr to get a name parameter ---abock
//
// // set the eye position, useful during rendering
// const glm::vec3 eyePosition
// = sgct_core::ClusterManager::instance()->getUserPtr("")->getPos();
//#else
// const glm::vec3 eyePosition
// = sgct_core::ClusterManager::instance()->getUserPtr()->getPos();
//#endif
const glm::vec3 eyePosition = sgct_core::ClusterManager::instance()->getDefaultUserPtr()->getPos();
// get viewdirection, stores the direction in the camera, used for culling
const glm::vec3 viewdir = glm::normalize(eyePosition - center);
_mainCamera->setCameraDirection(-viewdir);
@@ -306,6 +363,24 @@ namespace openspace {
void RenderEngine::postSynchronizationPreDraw()
{
//temporary fade funtionality
if (_fadeDirection != 0){
if (_currentFadeTime > _fadeDuration){
_fadeDirection = 0;
_globalOpactity = fminf(1.f, fmaxf(0.f, _globalOpactity));
}
else{
if (_fadeDirection < 0){
_globalOpactity = glm::smoothstep(1.f, 0.f, _currentFadeTime / _fadeDuration);
}
else{
_globalOpactity = glm::smoothstep(0.f, 1.f, _currentFadeTime / _fadeDuration);
}
_currentFadeTime += static_cast<float>(sgct::Engine::instance()->getAvgDt());
}
}
if (_mainCamera){
_mainCamera->postSynchronizationPreDraw();
}
@@ -366,26 +441,10 @@ namespace openspace {
#endif
// setup the camera for the current frame
#if 0
// @TODO: Use this as soon as the new SGCT version is available ---abock
const glm::vec3 eyePosition
= sgct_core::ClusterManager::instance()->getUserPtr("")->getPos();
#else
const glm::vec3 eyePosition
= sgct_core::ClusterManager::instance()->getUserPtr()->getPos();
#endif
//@CHECK does the dome disparity disappear if this line disappears? ---abock
//const glm::mat4 view
// = glm::translate(glm::mat4(1.0),
// eyePosition); // make sure the eye is in the center
//
_mainCamera->setViewMatrix(
viewMatrix );
_mainCamera->setProjectionMatrix(
projectionMatrix);
//Is this really necessary to store? @JK
_mainCamera->setViewProjectionMatrix(projectionMatrix * viewMatrix);
@@ -411,7 +470,7 @@ namespace openspace {
#if 1
// Print some useful information on the master viewport
if (sgct::Engine::instance()->isMaster() && !w->isUsingFisheyeRendering()) {
if (OsEng.ref().isMaster() && !w->isUsingFisheyeRendering()) {
// TODO: Adjust font_size properly when using retina screen
const int font_size_mono = 10;
@@ -602,6 +661,20 @@ namespace openspace {
return _abuffer;
}
float RenderEngine::globalOpacity(){
return _globalOpactity;
}
void RenderEngine::setGlobalOpacity(float opacity){
_globalOpactity = opacity;
}
void RenderEngine::startFading(int direction, float fadeDuration){
_fadeDirection = direction;
_fadeDuration = fadeDuration;
_currentFadeTime = 0.f;
}
void RenderEngine::generateGlslConfig() {
LDEBUG("Generating GLSLS config, expect shader recompilation");
int xSize = sgct::Engine::instance()->getActiveWindowPtr()->getXFramebufferResolution();;
@@ -663,7 +736,34 @@ namespace openspace {
&luascriptfunctions::setPerformanceMeasurement,
"bool",
"Sets the performance measurements"
}
},
// These are temporary ---abock
{
"changeViewPointToPluto",
&luascriptfunctions::changeToPlutoViewPoint,
"",
""
},
{
"changeViewPointToSun",
&luascriptfunctions::changeToSunViewPoint,
"",
""
},
//also temporary @JK
{
"fadeIn",
&luascriptfunctions::fadeIn,
"number",
""
},
//also temporary @JK
{
"fadeOut",
&luascriptfunctions::fadeOut,
"number",
""
},
},
};
}
@@ -753,4 +853,43 @@ namespace openspace {
_performanceMemory->releaseLock();
}
// This method is temporary and will be removed once the scalegraph is in effect ---abock
void RenderEngine::changeViewPoint(std::string origin) {
SceneGraphNode* solarSystemBarycenterNode = sceneGraph()->sceneGraphNode("SolarSystemBarycenter");
SceneGraphNode* plutoBarycenterNode = sceneGraph()->sceneGraphNode("PlutoBarycenter");
if (origin == "Pluto") {
ghoul::Dictionary solarDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body") , std::string("PLUTO BARYCENTER") },
{ std::string("Reference"), std::string("ECLIPJ2000") },
{ std::string("Observer") , std::string("SUN") },
{ std::string("Kernels") , ghoul::Dictionary() }
};
ghoul::Dictionary t;
t.setValue("Position", glm::vec4(1.f, 0.f, 0.f, 12.f));
solarSystemBarycenterNode->setEphemeris(new SpiceEphemeris(solarDictionary));
plutoBarycenterNode->setEphemeris(new StaticEphemeris);
return;
}
if (origin == "Sun") {
ghoul::Dictionary plutoDictionary =
{
{ std::string("Type"), std::string("Spice") },
{ std::string("Body"), std::string("PLUTO BARYCENTER") },
{ std::string("Reference"), std::string("ECLIPJ2000") },
{ std::string("Observer"), std::string("SUN") },
{ std::string("Kernels"), ghoul::Dictionary() }
};
solarSystemBarycenterNode->setEphemeris(new StaticEphemeris);
plutoBarycenterNode->setEphemeris(new SpiceEphemeris(plutoDictionary));
return;
}
ghoul_assert(false, "??");
}
}// namespace openspace

View File

@@ -39,6 +39,9 @@
namespace {
const std::string _loggerCat = "RenderableStars";
ghoul::filesystem::File* _psfTextureFile;
ghoul::filesystem::File* _colorTextureFile;
const int8_t CurrentCacheVersion = 1;
struct ColorVBOLayout {
@@ -91,7 +94,7 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
glm::vec2(-15.f),
glm::vec2(15.f)
)
, _exponentialOffset("exponentialOffset", "Exponential Offset", 5.f, 0.f, 10.f)
, _exponentialOffset("exponentialOffset", "Exponential Offset", 5.f, 0.f, 50.f)
, _exponentialDampening("exponentialDampening", "Exponential Dampening", 0.871f, 0.f, 1.f)
, _scaleFactor("scaleFactor", "Scale Factor", 1.f, 0.f, 10.f)
, _program(nullptr)
@@ -101,12 +104,16 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
, _vao(0)
, _vbo(0)
{
using ghoul::filesystem::File;
std::string texturePath = "";
dictionary.getValue(constants::renderablestars::keyTexture, texturePath);
_pointSpreadFunctionTexturePath = absPath(texturePath);
_psfTextureFile = new File(_pointSpreadFunctionTexturePath);
dictionary.getValue(constants::renderablestars::keyColorMap, texturePath);
_colorTexturePath = absPath(texturePath);
_colorTextureFile = new File(_colorTexturePath);
bool success = dictionary.getValue(constants::renderablestars::keyFile, _speckFile);
if (!success) {
@@ -123,10 +130,12 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
_colorOption.onChange([&]{ _dataIsDirty = true;});
addProperty(_pointSpreadFunctionTexturePath);
_pointSpreadFunctionTexturePath.onChange([&]{ _pointSpreadFunctionTextureIsDirty = true;});
_pointSpreadFunctionTexturePath.onChange([&]{ _pointSpreadFunctionTextureIsDirty = true; });
_psfTextureFile->setCallback([&](const File&) { _pointSpreadFunctionTextureIsDirty = true; });
addProperty(_colorTexturePath);
_colorTexturePath.onChange([&]{ _colorTextureIsDirty = true; });
_colorTextureFile->setCallback([&](const File&) { _colorTextureIsDirty = true; });
addProperty(_magnitudeClamp);
addProperty(_exponentialOffset);
@@ -135,6 +144,8 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
}
RenderableStars::~RenderableStars() {
delete _psfTextureFile;
delete _colorTextureFile;
}
bool RenderableStars::isReady() const {
@@ -314,6 +325,10 @@ void RenderableStars::update(const UpdateData& data) {
LDEBUG("Loaded texture from '" << absPath(_pointSpreadFunctionTexturePath) << "'");
_pointSpreadFunctionTexture->uploadTexture();
}
delete _psfTextureFile;
_psfTextureFile = new ghoul::filesystem::File(_pointSpreadFunctionTexturePath);
_psfTextureFile->setCallback([&](const ghoul::filesystem::File&) { _pointSpreadFunctionTextureIsDirty = true; });
}
_pointSpreadFunctionTextureIsDirty = false;
}
@@ -328,6 +343,10 @@ void RenderableStars::update(const UpdateData& data) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_colorTexture->uploadTexture();
}
delete _colorTextureFile;
_colorTextureFile = new ghoul::filesystem::File(_colorTexturePath);
_colorTextureFile->setCallback([&](const ghoul::filesystem::File&) { _colorTextureIsDirty = true; });
}
_colorTextureIsDirty = false;
}
@@ -501,23 +520,24 @@ void RenderableStars::createDataSlice(ColorOption option) {
}
for (size_t i = 0; i < _fullData.size(); i+=_nValuesPerStar) {
glm::vec3 p = glm::vec3(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2]);
// This is only temporary until the scalegraph is in place. It places all stars
// on a sphere with a small variation in the distance to account for blending
// issues ---abock
glm::vec3 p = glm::vec3(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2]);
if (p != glm::vec3(0.f))
p = glm::normalize(p);
//if (p != glm::vec3(0.f))
// p = glm::normalize(p);
float distLy = _fullData[i + 6];
float normalizedDist = (distLy - minDistance) / (maxDistance - minDistance);
float distance = 18.f - normalizedDist / 1.f ;
//float distLy = _fullData[i + 6];
//float normalizedDist = (distLy - minDistance) / (maxDistance - minDistance);
//float distance = 18.f - normalizedDist / 1.f ;
psc position = psc(glm::vec4(p, distance));
//psc position = psc(glm::vec4(p, distance));
// Convert parsecs -> meter
psc position = psc(glm::vec4(p * 0.308567756f, 17));
// Convert parsecs -> meter
//PowerScaledScalar parsecsToMetersFactor = PowerScaledScalar(0.308567758f, 17.f);
//position[0] *= parsecsToMetersFactor[0];
//position[1] *= parsecsToMetersFactor[0];
//position[2] *= parsecsToMetersFactor[0];
//position[3] += parsecsToMetersFactor[1];
@@ -536,8 +556,8 @@ void RenderableStars::createDataSlice(ColorOption option) {
layout.value.bvColor = _fullData[i + 3];
layout.value.luminance = _fullData[i + 4];
//layout.value.absoluteMagnitude = _fullData[i + 5];
layout.value.absoluteMagnitude = _fullData[i + 6];
layout.value.absoluteMagnitude = _fullData[i + 5];
//layout.value.absoluteMagnitude = _fullData[i + 6];
_slicedData.insert(_slicedData.end(),
layout.data.begin(),

View File

@@ -52,8 +52,6 @@ SpiceEphemeris::SpiceEphemeris(const ghoul::Dictionary& dictionary)
ghoul::Dictionary kernels;
dictionary.getValue(keyKernels, kernels);
if (kernels.size() == 0)
_kernelsLoadedSuccessfully = false;
for (size_t i = 1; i <= kernels.size(); ++i) {
std::string kernel;
bool success = kernels.getValue(std::to_string(i), kernel);

View File

@@ -31,7 +31,7 @@ namespace openspace {
using namespace constants::staticephemeris;
StaticEphemeris::StaticEphemeris(const ghoul::Dictionary& dictionary)
: _position(0.1f, 0.f, 0.f, 0.f)
: _position(0.f, 0.f, 0.f, 0.f)
{
const bool hasPosition = dictionary.hasKeyAndValue<glm::vec4>(keyPosition);
if (hasPosition) {

View File

@@ -260,8 +260,11 @@ void ScriptEngine::addLibrary(LuaLibrary library) {
}
bool ScriptEngine::runScript(const std::string& script) {
if (script.empty())
return false;
if (script.empty()){
LWARNING("Script was empty");
return false;
}
int status = luaL_loadstring(_state, script.c_str());
if (status != LUA_OK) {
LERROR("Error loading script: '" << lua_tostring(_state, -1) << "'");
@@ -269,6 +272,7 @@ bool ScriptEngine::runScript(const std::string& script) {
}
//LDEBUG("Executing script");
//LINFO(script);
if (lua_pcall(_state, 0, LUA_MULTRET, 0)) {
LERROR("Error executing script: " << lua_tostring(_state, -1));
return false;
@@ -608,6 +612,7 @@ bool ScriptEngine::writeDocumentation(const std::string& filename, const std::st
void ScriptEngine::serialize(SyncBuffer* syncBuffer){
syncBuffer->encode(_currentSyncedScript);
_currentSyncedScript.clear();
}
void ScriptEngine::deserialize(SyncBuffer* syncBuffer){
@@ -622,7 +627,7 @@ void ScriptEngine::deserialize(SyncBuffer* syncBuffer){
void ScriptEngine::postSynchronizationPreDraw(){
_mutex.lock();
if (!_receivedScripts.empty()){
while(!_receivedScripts.empty()){
runScript(_receivedScripts.back());
_receivedScripts.pop_back();
}