Merge remote-tracking branch 'origin/develop' into feature/updateSGCT

This commit is contained in:
Joakim Kilby
2015-02-12 14:58:54 +01:00
13 changed files with 338 additions and 501 deletions
+45 -61
View File
@@ -25,83 +25,67 @@
#ifndef __RENDERABLETRAIL_H__
#define __RENDERABLETRAIL_H__
// open space includes
#include <openspace/rendering/renderable.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/properties/vectorproperty.h>
// ghoul includes
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
//#include <openspace/util/runtimedata.h>
namespace ghoul {
namespace opengl {
class ProgramObject;
class Texture;
}
}
namespace openspace {
class RenderableTrail : public Renderable{
class RenderableTrail : public Renderable {
public:
RenderableTrail(const ghoul::Dictionary& dictionary);
~RenderableTrail();
RenderableTrail(const ghoul::Dictionary& dictionary);
bool initialize() override;
bool deinitialize() override;
bool initialize() override;
bool deinitialize() override;
bool isReady() const override;
bool isReady() const override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
private:
properties::StringProperty _colorTexturePath;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
void loadTexture();
void fullYearSweep();
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
bool _successfullDictionaryFetch;
private:
struct TrailVBOLayout {
float x, y, z, e;
};
// modfile reads
// spice
std::string _target;
std::string _observer;
std::string _frame;
std::string _orbitVariety;
// color
glm::vec3 _c;
float _r, _g, _b;
// orbit relational data
float _tropic;
float _ratio;
float _day;
void fullYearSweep(double time);
void sendToGPU();
// need to write robust method for vbo id selection
GLuint _vaoID ;
GLuint _vBufferID ;
GLuint _iBufferID;
properties::Vec3Property _lineColor;
properties::FloatProperty _lineFade;
void updateTrail();
void sendToGPU();
ghoul::opengl::ProgramObject* _programObject;
bool _programIsDirty;
GLenum _mode;
unsigned int _isize;
unsigned int _vsize;
unsigned int _vtotal;
unsigned int _stride;
bool _successfullDictionaryFetch;
double _startTrail;
std::string _target;
std::string _observer;
std::string _frame;
//Vertex* _varray;
std::vector<float> _varray;
std::vector<int> _iarray;
float _tropic;
float _ratio;
float _day;
//bool _once = false;
double lightTime;
//used for update of trail
psc _pscpos, _pscvel;
float _increment;
float _time = 0;
float _oldTime = 0;
float _dtEt;
GLuint _vaoID;
GLuint _vBufferID;
int _delta = 0;
//int _dtprogress = 0;
bool _needsSweep;
std::vector<TrailVBOLayout> _vertexArray;
float _increment;
float _oldTime = 0;
float _dtEt;
};
}
#endif
} // namespace openspace
#endif // __RENDERABLETRAIL_H__
@@ -73,7 +73,8 @@ private:
properties::OptionProperty _colorOption;
bool _dataIsDirty;
properties::FloatProperty _spriteSize;
properties::FloatProperty _spriteBaseSize;
properties::FloatProperty _spriteResponseSize;
ghoul::opengl::ProgramObject* _program;
bool _programIsDirty;
@@ -34,8 +34,7 @@ out vec4 vs_position;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
void main() {
vec4 tmp = vec4(in_position, exponent);
vs_position = tmp;
+11 -16
View File
@@ -73,23 +73,18 @@ void main() {
break;
}
framebuffer_output_color = texture(psfTexture, texCoord) * color;
// framebuffer_output_color = vec4(vs_position.rgb, 1.0);
// framebuffer_output_color = p;
// framebuffer_output_color = vec4(vec3(ge_brightness.z), 1.0);
// framebuffer_output_color = vec4(vec3(abs(ge_brightness.z)), 1.0);
vec4 fullColor = texture(psfTexture, texCoord) * color;
// This check can be removed once we get a better star psf texture ---abock
if (fullColor.a <= 0.1)
discard;
vec4 position = vs_position;
float depth = pscDepth(position);
gl_FragDepth = depth;
// 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(vec4(1,0,0,1), position, depth);
//ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
//addToBuffer(frag);
//discard;
ABufferStruct_t frag = createGeometryFragment(fullColor, position, depth);
addToBuffer(frag);
// discard;
}
+44 -46
View File
@@ -26,9 +26,9 @@
const vec2 corners[4] = vec2[4](
vec2(0.0, 1.0),
vec2(0.0, 0.0),
vec2(1.0, 1.0),
vec2(1.0, 0.0)
vec2(0.0, 0.0),
vec2(1.0, 1.0),
vec2(1.0, 0.0)
);
#include "PowerScaling/powerScalingMath.hglsl"
@@ -53,53 +53,51 @@ layout(location = 4) out vec2 texCoord;
uniform mat4 projection; // we do this after distance computation.
uniform float spriteSize;
uniform float spriteBaseSize;
uniform float spriteResponseSize;
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.
vec4 cam = vec4(-cam_position[0].xyz, cam_position[0].w); // get negative camera position
vec4 pos = psc_position[0]; // get OK star position
vec4 result = psc_addition(pos, cam); // compute vec from camera to position
vec2 pc = vec2(
length(result.xyz),
result.w
);
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.
vec4 cam = vec4(-cam_position[0].xyz, cam_position[0].w); // get negative camera position
vec4 pos = psc_position[0]; // get OK star position
vec4 result = psc_addition(pos, cam); // compute vec from camera to position
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));
// 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);
// p = vec4(vec3(apparent), 1.0);
vec4 P = gl_in[0].gl_Position;
// check everything below this ---abock
float weight = 0.00001f; // otherwise this takes over.
double depth = pc[0] * pow(10, pc[1]);
depth *= pow(apparent,3);
// 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 = spriteSize + (depth*weight);
// float modifiedSpriteSize = (depth*weight);
// EMIT QUAD
for(int i = 0; i < 4; i++){
vec4 p1 = P;
p1.xy += vec2(modifiedSpriteSize * (corners[i] - vec2(0.5)));
vs_position = p1;
gl_Position = projection * p1;
// gl_Position = z_normalization(projection * p1);
texCoord = corners[i];
// p = psc_position[0];
EmitVertex();
}
EndPrimitive();
double modifiedSpriteSize = (spriteBaseSize * 0.0005f) + (depth*weight);
modifiedSpriteSize *= spriteResponseSize;
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);
texCoord = corners[i];
// p = psc_position[0];
EmitVertex();
}
EndPrimitive();
}
@@ -24,33 +24,21 @@
#version __CONTEXT__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
in vec4 vs_point_position;
in vec4 vs_point_velocity;
in float fade;
//out vec4 diffuse;
uniform vec3 color;
#include "ABuffer/abufferStruct.hglsl"
#include "ABuffer/abufferAddToBuffer.hglsl"
#include "PowerScaling/powerScaling_fs.hglsl"
void main()
{
void main() {
vec4 position = vs_point_position;
float depth = pscDepth(position);
vec4 position = vs_point_position;
float depth = pscDepth(position);
// set the depth
//gl_FragDepth = depth;
//float l = length(vs_point_velocity);
vec4 diffuse = vs_point_velocity;
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
vec4 c = vec4(color, fade);
ABufferStruct_t frag = createGeometryFragment(c, position, depth);
addToBuffer(frag);
}
@@ -26,53 +26,26 @@
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
//uniform vec4 etColor;
uniform vec4 objectVelocity;
layout(location = 0) in vec4 in_point_position;
layout(location = 1) in vec4 in_point_velocity;
layout(location = 2) in vec2 in_point_timeindex;
out vec4 vs_point_position;
out vec4 vs_point_velocity;
out float fade;
uniform uint nVertices;
uniform float lineFade;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
vs_point_velocity = in_point_velocity;
void main() {
float id = float(gl_VertexID) / float(nVertices * lineFade);
fade = 1.0 - id;
vec4 tmp = in_point_position;
vec4 position = pscTransform(tmp, ModelTransform);
vs_point_position = tmp;
position = ViewProjection * position;
gl_Position = z_normalization(position);
/*
//vs_point_position = objpos;
// rotate and scale vertex with model transform and add the translation
vec3 local_vertex_pos = mat3(ModelTransform) * in_point_position.xyz;
//vec4 lvp = ModelTransform * in_point_position;
// PSC addition; local vertex position and the object power scaled world position
vs_point_position = psc_addition(vec4(local_vertex_pos,in_point_position.w),objpos);
//vs_point_position = psc_addition(lvp,objpos);
// PSC addition; rotated and viewscaled vertex and the cmaeras negative position
vs_point_position = psc_addition(vs_point_position,vec4(-campos.xyz,campos.w));
// rotate the camera
local_vertex_pos = mat3(camrot) * vs_point_position.xyz;
vs_point_position = vec4(local_vertex_pos, vs_point_position.w);
//vs_point_position = camrot* vs_point_position;
// project using the rescaled coordinates,
//vec4 vs_point_position_rescaled = psc_scaling(vs_point_position, scaling);
vec4 vs_point_position_rescaled = psc_to_meter(vs_point_position, scaling);
//vs_point_position = vs_point_position_rescaled;
// project the position to view space
gl_Position = ViewProjection * vs_point_position_rescaled;
*/
}
+3 -3
View File
@@ -528,9 +528,9 @@ void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz
glm::vec3 cameraRight = glm::cross(_camera->viewDirection(), cameraUp);
glm::mat4 transform;
transform = glm::rotate(dx, cameraUp) * transform;
transform = glm::rotate(dy, cameraRight) * transform;
transform = glm::rotate(dz, _camera->viewDirection()) * transform;
transform = glm::rotate(dx * 10, cameraUp) * transform;
transform = glm::rotate(dy * 10, cameraRight) * transform;
transform = glm::rotate(dz * 10, _camera->viewDirection()) * transform;
// should be changed to something more dynamic =)
psc origin;
+206 -300
View File
@@ -1,39 +1,35 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
* *
* 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. *
****************************************************************************************/
#include <openspace/rendering/renderabletrail.h>
#include <sgct.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/constants.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/util/spicemanager.h>
#include <iomanip>
#include <utility>
#include <openspace/util/updatestructures.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/misc/highresclock.h>
/* TODO for this class:
* In order to add geometry shader (for pretty-draw),
* need to pack each consecutive point pair into a vec2
@@ -41,54 +37,164 @@
*/
namespace {
const std::string _loggerCat = "RenderableTrail";
//constants
const std::string keyBody = "Body";
const std::string keyObserver = "Observer";
const std::string keyFrame = "Frame";
const std::string keyPathModule = "ModulePath";
const std::string keyColor = "RGB";
const std::string keyTropicalOrbitPeriod = "TropicalOrbitPeriod";
const std::string keyEarthOrbitRatio = "EarthOrbitRatio";
const std::string keyDayLength = "DayLength";
const std::string _loggerCat = "RenderableTrail";
//constants
const std::string keyBody = "Body";
const std::string keyObserver = "Observer";
const std::string keyFrame = "Frame";
const std::string keyPathModule = "ModulePath";
const std::string keyColor = "RGB";
const std::string keyTropicalOrbitPeriod = "TropicalOrbitPeriod";
const std::string keyEarthOrbitRatio = "EarthOrbitRatio";
const std::string keyDayLength = "DayLength";
}
//#define DEBUG
namespace openspace{
namespace openspace {
RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _texture(nullptr)
, _vaoID(0)
, _vBufferID(0)
, _iBufferID(0)
, _mode(GL_LINE_STRIP)
, _oldTime(std::numeric_limits<float>::max())
: Renderable(dictionary)
, _lineColor("lineColor", "Line Color")
, _lineFade("lineFade", "Line Fade", 0.75f, 0.f, 5.f)
//, _lineFade("lineFade", "Line Fade", 5.f, 0.f, 5.f)
, _programObject(nullptr)
, _programIsDirty(true)
, _vaoID(0)
, _vBufferID(0)
, _oldTime(std::numeric_limits<float>::max())
, _successfullDictionaryFetch(true)
, _needsSweep(true)
{
_successfullDictionaryFetch &= dictionary.getValue(keyBody, _target);
_successfullDictionaryFetch &= dictionary.getValue(keyObserver, _observer);
_successfullDictionaryFetch &= dictionary.getValue(keyFrame, _frame);
_successfullDictionaryFetch &= dictionary.getValue(keyTropicalOrbitPeriod, _tropic);
_successfullDictionaryFetch &= dictionary.getValue(keyEarthOrbitRatio, _ratio);
_successfullDictionaryFetch &= dictionary.getValue(keyDayLength, _day);
_successfullDictionaryFetch = true;
_successfullDictionaryFetch &= dictionary.getValue(keyBody, _target);
_successfullDictionaryFetch &= dictionary.getValue(keyObserver, _observer);
_successfullDictionaryFetch &= dictionary.getValue(keyFrame, _frame);
_successfullDictionaryFetch &= dictionary.getValue(keyTropicalOrbitPeriod, _tropic);
_successfullDictionaryFetch &= dictionary.getValue(keyEarthOrbitRatio, _ratio);
_successfullDictionaryFetch &= dictionary.getValue(keyDayLength, _day);
// values in modfiles set from here
// http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html
// values in modfiles set from here
// http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html
glm::vec3 color(0.f);
if (dictionary.hasKeyAndValue<glm::vec3>(keyColor))
dictionary.getValue(keyColor, color);
_lineColor = color;
_lineColor.setViewOption(properties::Property::ViewOptions::Color);
addProperty(_lineColor);
//white is default col
if (!dictionary.getValue(keyColor, _c)){
_c = glm::vec3(0.0);
}else{ //to understand, ref to line 115.
_r = 1 / _c[0];
_g = 1 / _c[1];
_b = 1 / _c[2];
}
addProperty(_lineFade);
}
bool RenderableTrail::initialize() {
if (!_successfullDictionaryFetch) {
LERROR("The following keys need to be set in the Dictionary. Cannot initialize!");
LERROR(keyBody << ": " << _target);
LERROR(keyObserver << ": " << _observer);
LERROR(keyFrame << ": " << _frame);
LERROR(keyTropicalOrbitPeriod << ": " << _tropic);
LERROR(keyEarthOrbitRatio << ": " << _ratio);
LERROR(keyDayLength << ": " << _day);
return false;
}
bool completeSuccess = true;
_programObject = ghoul::opengl::ProgramObject::Build("EphemerisProgram",
"${SHADERS}/modules/trails/ephemeris_vs.glsl",
"${SHADERS}/modules/trails/ephemeris_fs.glsl");
if (!_programObject)
return false;
_programObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*){ _programIsDirty = true; });
return completeSuccess;
}
bool RenderableTrail::deinitialize() {
glDeleteVertexArrays(1, &_vaoID);
glDeleteBuffers(1, &_vBufferID);
return true;
}
bool RenderableTrail::isReady() const {
return (_programObject != nullptr) && _successfullDictionaryFetch;
}
void RenderableTrail::render(const RenderData& data) {
_programObject->activate();
psc currentPosition = data.position;
psc campos = data.camera.position();
glm::mat4 camrot = data.camera.viewRotationMatrix();
glm::mat4 transform = glm::mat4(1);
// setup the data to the shader
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, data.position);
_programObject->setUniform("color", _lineColor);
_programObject->setUniform("nVertices", unsigned int(_vertexArray.size()));
_programObject->setUniform("lineFade", _lineFade);
glBindVertexArray(_vaoID);
glDrawArrays(GL_LINE_STRIP, 0, _vertexArray.size());
glBindVertexArray(0);
_programObject->deactivate();
}
void RenderableTrail::update(const UpdateData& data) {
// needsSweep also needs to be done when the time has been changed abruptly ---abock
if (_needsSweep) {
fullYearSweep(data.time);
sendToGPU();
_needsSweep = false;
return;
}
if (_programIsDirty) {
_programObject->rebuildFromFile();
_programIsDirty = false;
}
double lightTime = 0.0;
psc pscPos, pscVel;
// Points in the vertex array should always have a fixed distance. For this reason we
// keep the first entry in the array floating and always pointing to the current date
// As soon as the time difference between the current time and the last time is bigger
// than the fixed distance, we need to create a new fixed point
double deltaTime = abs(data.time - _oldTime);
int nValues = floor(deltaTime / _increment);
// Update the floating current time
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] };
if (nValues != 0) {
// If we have new values to create, we do that here. nValues should always be
// close to 1
// But you never know
nValues = std::min(nValues, int(_vertexArray.size()));
//LINFO(nValues);
std::vector<TrailVBOLayout> tmp = _vertexArray;
for (int i = nValues; i > 0; --i) {
double et = _oldTime + i * _increment;
SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", et, pscPos, pscVel, lightTime);
pscPos[3] += 3;
_vertexArray[i] = { pscPos[0], pscPos[1], pscPos[2], pscPos[3] };
}
for (size_t i = 0; i < tmp.size() - (nValues + 1); ++i)
_vertexArray[nValues + 1 + i] = tmp[i + 1];
_oldTime += nValues * _increment;
}
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(TrailVBOLayout), &_vertexArray[0]);
}
/* This algorithm estimates and precomputes the number of segments required for
* any planetary object in space, given a tropical orbit period and earth-to-planet
* orbit ratio. In doing so, it finds the exact increment of time corresponding
@@ -97,241 +203,41 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
* and most likely heuristic measure to easily estimate a nodal time-increment.
* Trivial, yet - a TODO.
*/
void RenderableTrail::fullYearSweep(){
double lightTime = 0.0;
double et = _startTrail;
float planetYear = 31540000.0f * _ratio;
int segments = static_cast<int>(_tropic);
void RenderableTrail::fullYearSweep(double time) {
const int SecondsPerEarthYear = 31540000;
_increment = planetYear / _tropic;
_isize = (segments + 2);
_vsize = (segments + 2);
//_iarray.clear();
//_iarray = new int[_isize];
for (int i = 0; i < segments+2; i++){
SpiceManager::ref().getTargetState(_target, _observer, _frame, "LT+S", et, _pscpos, _pscvel, lightTime);
_pscpos[3] += 3;
double lightTime = 0.0;
float planetYear = SecondsPerEarthYear * _ratio;
int segments = static_cast<int>(_tropic);
for (int k = 0; k < 4; k++)
_varray.push_back(_pscpos[k]);
_increment = planetYear / _tropic;
_oldTime = time;
#ifndef DEBUG
float p = (float)i / _tropic;
_varray.push_back(1.f - p * _r);
_varray.push_back(1.f - p * _g);
_varray.push_back(1.f - p * _b);
_varray.push_back(1.f - p);
#else
_varray.push_back(1.f );
_varray.push_back(1.f );
_varray.push_back(1.f );
_varray.push_back(1.f );
#endif
//_iarray[i] = i;
//_iarray.push_back(i);
//if (i != 0) //very first point needs to be alllocated twice.
et -= _increment;
}
_stride = 8;
_vsize = static_cast<unsigned int>(_varray.size());
_vtotal = static_cast<int>(_vsize / _stride);
}
psc pscPos, pscVel;
_vertexArray.resize(segments+2);
for (int i = 0; i < segments+2; i++){
SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", time, pscPos, pscVel, lightTime);
pscPos[3] += 3;
RenderableTrail::~RenderableTrail(){
}
bool RenderableTrail::isReady() const {
bool ready = true;
ready &= (_programObject != nullptr);
return ready;
}
void RenderableTrail::sendToGPU(){
// Initialize and upload to graphics card
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vBufferID);
//glGenBuffers(1, &_iBufferID);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferData(GL_ARRAY_BUFFER, _vsize * sizeof(GLfloat), NULL, GL_STREAM_DRAW); // orphaning the buffer, sending NULL data.
glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(GLfloat), &_varray[0]);
GLsizei st = sizeof(GLfloat) * _stride;
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, st, (void*)0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, st, (void*)(4 * sizeof(GLfloat)));
/*glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray.data(), GL_STATIC_DRAW);*/
glBindVertexArray(0);
}
bool RenderableTrail::initialize(){
if (!_successfullDictionaryFetch) {
LERROR("The following keys need to be set in the Dictionary. Cannot initialize!");
LERROR(keyBody << ": " << _target);
LERROR(keyObserver << ": " << _observer);
LERROR(keyFrame << ": " << _frame);
LERROR(keyTropicalOrbitPeriod << ": " << _tropic);
LERROR(keyEarthOrbitRatio << ": " << _ratio);
LERROR(keyDayLength << ": " << _day);
return false;
}
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess
&= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject);
//TEXTURES DISABLED FOR NOW
//loadTexture();
completeSuccess &= (_texture != nullptr);
// SpiceManager::ref().getETfromDate("2006 Aug 22 17:00:00", _startTrail);
SpiceManager::ref().getETfromDate("2007 feb 26 17:30:00", _startTrail);
_dtEt = static_cast<float>(_startTrail);
fullYearSweep();
sendToGPU();
return completeSuccess;
}
bool RenderableTrail::deinitialize(){
if (_texture)
delete _texture;
_texture = nullptr;
glDeleteVertexArrays(1, &_vaoID);
glDeleteBuffers(1, &_vBufferID);
glDeleteBuffers(1, &_iBufferID);
return true;
}
// Tried interpolation but then realised this still gives straight lines (latenight thing).
// Not allowed Splines so therefore - query spice for each point (bah...)
// From psc paper:
/*
psc pscInterpolate(psc p0, psc p1, float t){
assert(t >= 0 && t <= 1);
float s = (1.f - t)*p0[3] + t*p1[3];
float x = ((1.f - t)*p0[0] + t*p1[0]);
float y = ((1.f - t)*p0[1] + t*p1[1]);
float z = ((1.f - t)*p0[2] + t*p1[2]);
return PowerScaledCoordinate::PowerScaledCoordinate(x,y,z,s);
}
*/
void RenderableTrail::updateTrail(){
#ifndef NDEBUG
if (!_successfullDictionaryFetch)
return;
#endif
int m = _stride;
float *begin = &_varray[0];
//float *end = &_varray[_vsize - 1] + 1;
//fix so that updatetrail is not run on the first update pass even though no time has passed.
//also != operator is iffy for floating point values, _oldTime is now std::numeric_limits<float>::max()
if (_oldTime < _time){
// update only when time progresses
//if (_oldTime != _time){
// if time progressed more than N _increments
while (_dtEt < _time){
// get intermediary points
psc dtPoint;
SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", _dtEt, dtPoint, _pscvel, lightTime);
dtPoint[3] += 3;
// overwrite the old position
memcpy(begin, glm::value_ptr(dtPoint.vec4()), 4 * sizeof(float));
// shift array
for (int k = _vsize-m; k > 0; k -= m){
memcpy(&_varray[k], &_varray[k - m], 4 * sizeof(float));
}
// keep track of progression
_dtEt += _increment;
}
//add earths current position
memcpy(&_varray[0], glm::value_ptr(_pscpos.vec4()), 4 * sizeof(float));
_varray[4] = 1.f;
_varray[5] = 1.f;
_varray[6] = 1.f;
_varray[7] = 1.f;
}_oldTime = _time;
// update GPU
// NOTE: vbo interleaved, makes possible color update more efficient - tightly packed.
// if NO color update : would be more efficient to have these as separate
// => N/2 updates per drawcall.
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(GLfloat), &_varray[0]);
}
void RenderableTrail::render(const RenderData& data){
_programObject->activate();
// fetch data
psc currentPosition = data.position;
psc campos = data.camera.position();
glm::mat4 camrot = data.camera.viewRotationMatrix();
glm::mat4 transform = glm::mat4(1);
// setup the data to the shader
//_programObject->setUniform("objectVelocity", pscvel.vec4());
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, data.position);
updateTrail();
glBindVertexArray(_vaoID);
glDrawArrays(_mode, 0, _vtotal);
glBindVertexArray(0);
glPointSize(2.f);
// nodes of equal time
glBindVertexArray(_vaoID);
glDrawArrays(GL_POINTS, 0, _vtotal);
glBindVertexArray(0);
_programObject->deactivate();
_vertexArray[i] = {pscPos[0], pscPos[1], pscPos[2], pscPos[3]};
time -= _increment;
}
}
void RenderableTrail::update(const UpdateData& data){
_time = static_cast<float>(data.time);
_delta = static_cast<int>(data.delta);
SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", data.time, _pscpos, _pscvel, lightTime);
_pscpos[3] += 3; // KM to M
void RenderableTrail::sendToGPU() {
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vBufferID);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferData(GL_ARRAY_BUFFER, _vertexArray.size() * sizeof(TrailVBOLayout), NULL, GL_STREAM_DRAW); // orphaning the buffer, sending NULL data.
glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(TrailVBOLayout), &_vertexArray[0]);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glBindVertexArray(0);
}
void RenderableTrail::loadTexture()
{
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
}
}
}
}
} // namespace openspace
+7 -6
View File
@@ -84,7 +84,8 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
, _colorTextureIsDirty(true)
, _colorOption("colorOption", "Color Option")
, _dataIsDirty(true)
, _spriteSize("spriteSize", "Sprite Size", 0.0000005f, 0.f, 1.f)
, _spriteBaseSize("spriteBaseSize", "Sprite Base Size", 0.1f, 0.f, 10.f)
, _spriteResponseSize("spriteResponseSize", "Sprite Response Size", 1.f, 0.f, 10.f)
, _program(nullptr)
, _programIsDirty(false)
, _speckFile("")
@@ -113,7 +114,8 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
addProperty(_colorOption);
_colorOption.onChange([&]{ _dataIsDirty = true;});
addProperty(_spriteSize);
addProperty(_spriteBaseSize);
addProperty(_spriteResponseSize);
addProperty(_pointSpreadFunctionTexturePath);
_pointSpreadFunctionTexturePath.onChange([&]{ _pointSpreadFunctionTextureIsDirty = true;});
@@ -183,7 +185,8 @@ void RenderableStars::render(const RenderData& data) {
setPscUniforms(_program, &data.camera, data.position);
_program->setUniform("scaling", scaling);
_program->setUniform("spriteSize", _spriteSize);
_program->setUniform("spriteBaseSize", _spriteBaseSize);
_program->setUniform("spriteResponseSize", _spriteResponseSize);
ghoul::opengl::TextureUnit psfUnit;
psfUnit.activate();
@@ -199,9 +202,7 @@ void RenderableStars::render(const RenderData& data) {
glBindVertexArray(_vao);
const GLsizei nStars = static_cast<GLsizei>(_fullData.size() / _nValuesPerStar);
//glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
glDrawArrays(GL_POINTS, 0, nStars);
//glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
glDrawArrays(GL_POINTS, 0, nStars);
glBindVertexArray(0);
_program->setIgnoreUniformLocationError(false);
-10
View File
@@ -172,16 +172,6 @@ bool SceneGraph::initialize()
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager().setValue("pscShader", tmpProgram);
// pscstandard
tmpProgram = ProgramObject::Build("EphemerisProgram",
"${SHADERS}/ephemeris_vs.glsl",
"${SHADERS}/ephemeris_fs.glsl");
if (!tmpProgram) return false;
tmpProgram->setProgramObjectCallback(cb);
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager().setValue("EphemerisProgram", tmpProgram);
// RaycastProgram
tmpProgram = ProgramObject::Build("RaycastProgram",
"${SHADERS}/exitpoints.vert",
+2
View File
@@ -204,6 +204,8 @@ double Time::deltaTime() const {
void Time::setTime(std::string time) {
SpiceManager::ref().getETfromDate(std::move(time), _time);
// Add callback to OpenSpaceEngine that signals that the next update phase
// needs total invalidation ---abock
}
std::string Time::currentTimeUTC() const {