WIP: intermediary commit, will attempt to run HC's code on this machine.

This commit is contained in:
michal
2014-08-25 17:37:23 -04:00
parent 2797dcf0b9
commit 013d4c5bb6
17 changed files with 516 additions and 87 deletions

View File

@@ -52,7 +52,9 @@ private:
ghoul::opengl::ProgramObject* _programObject;
std::string _speckPath;
GLuint _starPositionsVBO;
GLuint _vboID;
GLuint _vaoID;
//GLint positionAttrib;
int v_size;
};

View File

@@ -36,7 +36,8 @@ namespace openspace {
class PowerScaledSphere {
public:
// initializers
PowerScaledSphere(const PowerScaledScalar& radius, int segments = 8);
PowerScaledSphere(const PowerScaledScalar& radius,
int segments = 8);
~PowerScaledSphere();
bool initialize();

View File

@@ -100,7 +100,7 @@ void main()
// set the depth
gl_FragDepth = depth;
// gl_FragDepth = depth;
//gl_FragDepth = 0.5;
// color

View File

@@ -87,7 +87,7 @@ void main()
// rotate and scale vertex with model transform and add the translation
vec3 local_vertex_pos = mat3(ModelTransform) * in_position.xyz;
//vec4 lvp = ModelTransform * in_position;
// PSC addition; local vertex position and the object power scaled world position
vs_position = psc_addition(vec4(local_vertex_pos,in_position.w),objpos);
//vs_position = psc_addition(lvp,objpos);

81
shaders/simpleFrag.glsl Normal file
View File

@@ -0,0 +1,81 @@
#version 440
out vec4 diffuse;
uniform vec3 Color;
in vec4 vs_position;
const float k = 10.0;
vec4 psc_normlization(vec4 invec) {
float xymax = max(invec.x,invec.y);
if(invec.z > 0.0f || invec.z < 0.0f) {
return invec / abs(invec.z);
} else if (xymax != 0.0f) {
return invec / xymax;
} else {
return invec / -.0;
}
}
void main(void)
{
// Observable universe is 10^27m, setting the far value to extremely high, aka 30!! ERMAHGERD!
float s_far = 27.0; //= gl_DepthRange.far; // 40
float s_farcutoff = 12.0;
float s_nearcutoff = 7.0;
float s_near = 0.0f;// gl_DepthRange.near; // 0.1
float depth;
// the value can be normalized to 1
vec4 p = vs_position;
if(vs_position.w <= 0.5) {
//depth = abs(vs_position.z * pow(10, vs_position.w)) / pow(k,s_far);
depth = (vs_position.w+log(abs(vs_position.z)))/pow(k, vs_position.w);
} else if(vs_position.w < 3.0) {
depth = vs_position.w+log(abs(vs_position.z))/pow(k, vs_position.w);
} else {
depth = vs_position.w+log(abs(vs_position.z));
}
// DEBUG
float depth_orig = depth;
float x = 0.0f;
float cutoffs = 0.0;
float orig_z = vs_position.z;
// calculate a normalized depth [0.0 1.0]
if((depth > s_near && depth <= s_nearcutoff) || (depth > s_farcutoff && depth < s_far)) {
// completely linear interpolation [s_near .. depth .. s_far]
depth = (depth - s_near) / (s_far - s_near);
} else if(depth > s_nearcutoff && depth < s_farcutoff) {
// DEBUG
cutoffs = 1.0;
// interpolate [10^s_nearcutoff .. 10^depth .. 10^s_farcutoff]
// calculate between 0..1 where the depth is
x = (pow(10,depth) - pow(10, s_nearcutoff)) / (pow(10,s_farcutoff) - pow(10, s_nearcutoff));
// remap the depth to the 0..1 depth buffer
depth = s_nearcutoff + x * (s_farcutoff - s_nearcutoff);
depth = (depth - s_near) / (s_far - s_near);
} else {
// where am I?
// do I need to be discarded?
// discard;
}
// set the depth
gl_FragDepth = depth;
// calculate normal from texture coordinates
diffuse = vec4(Color,1);
}

76
shaders/simpleVert.glsl Normal file
View File

@@ -0,0 +1,76 @@
#version 440
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform vec4 campos;
uniform mat4 camrot;
uniform vec2 scaling;
uniform vec4 objpos;
in vec4 in_position;
out vec4 vs_position;
const float k = 10.0;
const float dgr_to_rad = 0.0174532925;
vec4 psc_addition(vec4 v1, vec4 v2) {
float ds = v2.w - v1.w;
if(ds >= 0) {
float p = pow(k,-ds);
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
} else {
float p = pow(k,ds);
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
}
}
vec4 psc_to_meter(vec4 v1, vec2 v2) {
float factor = v2.x * pow(k,v2.y + v1.w);
return vec4(v1.xyz * factor, 1.0);
}
vec4 psc_scaling(vec4 v1, vec2 v2) {
float ds = v2.y - v1.w;
if(ds >= 0) {
return vec4(v1.xyz * v2.x * pow(k,v1.w), v2.y);
} else {
return vec4(v1.xyz * v2.x * pow(k,v2.y), v1.w);
}
}
void main()
{
// rotate and scale vertex with model transform and add the translation
vec3 local_vertex_pos = mat3(ModelTransform) * in_position.xyz;
//vec4 lvp = ModelTransform * in_position;
// PSC addition; local vertex position and the object power scaled world position
vs_position = psc_addition(vec4(local_vertex_pos,in_position.w),objpos);
//vs_position = psc_addition(lvp,objpos);
// PSC addition; rotated and viewscaled vertex and the cmaeras negative position
vs_position = psc_addition(vs_position,vec4(-campos.xyz,campos.w));
// rotate the camera
local_vertex_pos = mat3(camrot) * vs_position.xyz;
vs_position = vec4(local_vertex_pos, vs_position.w);
//vs_position = camrot * vs_position;
// rescales the scene to fit inside the view frustum
// is set from the main program, but these are decent values
// scaling = vec2(1.0, -8.0);
// project using the rescaled coordinates,
//vec4 vs_position_rescaled = psc_scaling(vs_position, scaling);
vec4 vs_position_rescaled = psc_to_meter(vs_position, scaling);
//vs_position = vs_position_rescaled;
// project the position to view space
gl_Position = ViewProjection * vs_position_rescaled;
//gl_Position = MVP*in_position;
}

116
shaders/star_fs.glsl Normal file
View File

@@ -0,0 +1,116 @@
/**
Copyright (C) 2012-2014 Jonas Strandstedt
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 400 core
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform vec4 campos;
//uniform vec4 objpos;
uniform float time;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform float TessLevel;
uniform bool Wireframe;
uniform bool Lightsource;
uniform bool UseTexture;
in vec2 vs_st;
//in vec3 vs_stp;
in vec4 vs_normal;
in vec4 vs_position;
out vec4 diffuse;
const float k = 10.0;
vec4 psc_normlization(vec4 invec) {
float xymax = max(invec.x,invec.y);
if(invec.z > 0.0f || invec.z < 0.0f) {
return invec / abs(invec.z);
} else if (xymax != 0.0f) {
return invec / xymax;
} else {
return invec / -.0;
}
}
void main()
{
// Observable universe is 10^27m, setting the far value to extremely high, aka 30!! ERMAHGERD!
float s_far = 27.0; //= gl_DepthRange.far; // 40
float s_farcutoff = 12.0;
float s_nearcutoff = 7.0;
float s_near = 0.0f;// gl_DepthRange.near; // 0.1
float depth;
// the value can be normalized to 1
vec4 p = vs_position;
if(vs_position.w <= 0.5) {
//depth = abs(vs_position.z * pow(10, vs_position.w)) / pow(k,s_far);
depth = (vs_position.w+log(abs(vs_position.z)))/pow(k, vs_position.w);
} else if(vs_position.w < 3.0) {
depth = vs_position.w+log(abs(vs_position.z))/pow(k, vs_position.w);
} else {
depth = vs_position.w+log(abs(vs_position.z));
}
// DEBUG
float depth_orig = depth;
float x = 0.0f;
float cutoffs = 0.0;
float orig_z = vs_position.z;
// calculate a normalized depth [0.0 1.0]
if((depth > s_near && depth <= s_nearcutoff) || (depth > s_farcutoff && depth < s_far)) {
// completely linear interpolation [s_near .. depth .. s_far]
depth = (depth - s_near) / (s_far - s_near);
} else if(depth > s_nearcutoff && depth < s_farcutoff) {
// DEBUG
cutoffs = 1.0;
// interpolate [10^s_nearcutoff .. 10^depth .. 10^s_farcutoff]
// calculate between 0..1 where the depth is
x = (pow(10,depth) - pow(10, s_nearcutoff)) / (pow(10,s_farcutoff) - pow(10, s_nearcutoff));
// remap the depth to the 0..1 depth buffer
depth = s_nearcutoff + x * (s_farcutoff - s_nearcutoff);
depth = (depth - s_near) / (s_far - s_near);
} else {
// where am I?
// do I need to be discarded?
// discard;
}
// set the depth
gl_FragDepth = depth;
//gl_FragDepth = 0.5;
// color
diffuse = vec4(1.0,1.0,1.0,1.0);
// diffuse = texture(texture1, vs_st);
//diffuse = vec4(vs_position.z,0.0, 0.0, 1.0);
// diffuse = vec4(vs_position.xyz * pow(10, vs_position.w), 1.0);
//diffuse = vec4(vs_st, 0.0, 1.0);
//diffuse = vec4(1.0,1.0, 0.0, 1.0);
//diffuse = vec4(depth*5,0.0, 0.0, 1.0);
//diffuse = vec4(vs_position.w,0.0, 0.0, 1.0);
//diffuse = vec4(1.0,0.0,0.0,1.0);
}

116
shaders/star_vs.glsl Normal file
View File

@@ -0,0 +1,116 @@
/**
Copyright (C) 2012-2014 Jonas Strandstedt
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 400 core
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform vec4 campos;
uniform mat4 camrot;
uniform vec2 scaling;
//uniform vec4 objpos;
uniform float time;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform float TessLevel;
uniform bool Wireframe;
uniform bool Lightsource;
uniform bool UseTexture;
layout(location = 0) in vec4 in_position;
//in vec3 in_position;
layout(location = 1) in vec2 in_st;
layout(location = 2) in vec3 in_normal;
layout(location = 3) in vec4 objpos;
out vec2 vs_st;
out vec3 vs_stp;
out vec4 vs_normal;
out vec4 vs_position;
const float k = 10.0;
const float dgr_to_rad = 0.0174532925;
vec4 psc_addition(vec4 v1, vec4 v2) {
float ds = v2.w - v1.w;
if(ds >= 0) {
float p = pow(k,-ds);
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
} else {
float p = pow(k,ds);
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
}
}
vec4 psc_to_meter(vec4 v1, vec2 v2) {
float factor = v2.x * pow(k,v2.y + v1.w);
return vec4(v1.xyz * factor, 1.0);
}
vec4 psc_scaling(vec4 v1, vec2 v2) {
float ds = v2.y - v1.w;
if(ds >= 0) {
return vec4(v1.xyz * v2.x * pow(k,v1.w), v2.y);
} else {
return vec4(v1.xyz * v2.x * pow(k,v2.y), v1.w);
}
}
void main()
{
// set variables
vs_st = in_st;
//vs_stp = in_position.xyz;
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
// fetch model and view translation
//vec4 vertex_translate = ModelTransform[3];
// rotate and scale vertex with model transform and add the translation
vec3 local_vertex_pos = mat3(ModelTransform) * in_position.xyz;
//vec4 lvp = ModelTransform * in_position;
// PSC addition; local vertex position and the object power scaled world position
vs_position = psc_addition(vec4(local_vertex_pos,in_position.w),objpos);
//vs_position = psc_addition(lvp,objpos);
// PSC addition; rotated and viewscaled vertex and the cmaeras negative position
vs_position = psc_addition(vs_position,vec4(-campos.xyz,campos.w));
// rotate the camera
local_vertex_pos = mat3(camrot) * vs_position.xyz;
vs_position = vec4(local_vertex_pos, vs_position.w);
//vs_position = camrot * vs_position;
// rescales the scene to fit inside the view frustum
// is set from the main program, but these are decent values
// scaling = vec2(1.0, -8.0);
// project using the rescaled coordinates,
//vec4 vs_position_rescaled = psc_scaling(vs_position, scaling);
vec4 vs_position_rescaled = psc_to_meter(vs_position, scaling);
//vs_position = vs_position_rescaled;
// project the position to view space
gl_Position = ViewProjection * vs_position_rescaled;
}

View File

@@ -0,0 +1,10 @@
#version 440
out vec4 vFragColor;
uniform vec3 Color;
void main(void)
{
// calculate normal from texture coordinates
vFragColor = vec4(Color,1);
}

View File

@@ -0,0 +1,9 @@
#version 440
in vec3 in_position;
uniform mat4 MVP;
void main()
{
gl_Position = MVP*vec4(in_position,1.0);
}

View File

@@ -352,11 +352,11 @@ void InteractionHandler::keyboardCallback(int key, int action) {
distance(dist);
}
if (key == 'T') {
PowerScaledScalar dist(-speed * 100.0 * dt, 0.0);
PowerScaledScalar dist(-speed * 1000.0 * dt, 0.0);
distance(dist);
}
if (key == 'G') {
PowerScaledScalar dist(speed * 100.0 * dt, 0.0);
PowerScaledScalar dist(speed * 1000.0 * dt, 0.0);
distance(dist);
}
/*

View File

@@ -91,7 +91,7 @@ int main(int argc, char** argv)
_interface = new openspace::Interface(&OsEng);
// try to open a window
if (!_sgctEngine->init(sgct::Engine::OpenGL_3_3_Core_Profile)) {
if (!_sgctEngine->init(sgct::Engine::OpenGL_4_3_Core_Profile)) {
// could not open a window, deallocates and exits
delete _sgctEngine;
openspace::OpenSpaceEngine::destroy();

View File

@@ -126,7 +126,7 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition)
transform = glm::rotate(
transform, 4.1f * static_cast<float>(sgct::Engine::instance()->getTime()),
glm::vec3(0.0f, 1.0f, 0.0f));
// setup the data to the shader
_programObject->setUniform("ViewProjection", camera->viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);

View File

@@ -35,6 +35,27 @@
#include <openspace/engine/openspaceengine.h>
#include <sgct.h>
#define printOpenGLError() printOglError(__FILE__, __LINE__)
#define _USE_MATH_DEFINES
#include <math.h>
int printOglError(char *file, int line)
{
GLenum glErr;
int retCode = 0;
glErr = glGetError();
if (glErr != GL_NO_ERROR)
{
printf("glError in file %s @ line %d: %s\n",
file, line, gluErrorString(glErr));
retCode = 1;
}
return retCode;
}
namespace {
const std::string _loggerCat = "RenderableStars";
}
@@ -44,6 +65,7 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
: Renderable(dictionary),
_programObject(nullptr){
//setBoundingSphere(PowerScaledScalar::CreatePSS(100));
std::string path;
dictionary.getValue(constants::renderablestars::keySpeckFile, path);
_speckPath = FileSys.absolutePath(path);
@@ -84,8 +106,8 @@ bool RenderableStars::readSpeckFile(const std::string& path){
std::ifstream file;
std::string str, starDescription, datastr;
std::vector<std::string> strvec;
std::vector<double> positions;
std::vector<double> doubleData;
std::vector<float> positions;
std::vector<float> doubleData;
int count = 0;
const std::string absPath = FileSys.absolutePath(path);
@@ -136,16 +158,13 @@ bool RenderableStars::readSpeckFile(const std::string& path){
doubleData.reserve(strvec.size());
transform(strvec.begin(), strvec.end(), back_inserter(doubleData),
[](std::string const& val) {return std::stod(val); });
// convert to powerscaled coordinate
const psc powerscaled =
PowerScaledCoordinate::CreatePowerScaledCoordinate(doubleData[0],
doubleData[1],
doubleData[2]);
const psc powerscaled = PowerScaledCoordinate::CreatePowerScaledCoordinate(doubleData[0], doubleData[1], doubleData[2]);
for (int i = 0; i < 4; i++){
positions.push_back(powerscaled[i]);
cache << ' ' << powerscaled[i];
}
strvec.clear();
doubleData.clear();
count++;
@@ -157,50 +176,44 @@ bool RenderableStars::readSpeckFile(const std::string& path){
file.open(cacheName, std::ios::binary);
while (file.good()){
if (file.eof()) break;
double cachedValue;
count++;
float cachedValue;
file >> cachedValue;
positions.push_back(cachedValue);
}
}
// pass in the vectors internal array to create vbo method
v_size = positions.size();
std::cout << v_size << std::endl;
/* // use fread() instead ??
FILE * pFile;
pFile = fopen("myfile.bin", "wb");
fwrite(&positions[0], sizeof(double), positions.size(), pFile);
fclose(pFile);
*/
_starPositionsVBO = createVBO(&positions[0], v_size*sizeof(GLdouble), GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW);
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vboID);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
glBufferData(GL_ARRAY_BUFFER, v_size*sizeof(GLfloat), &positions[0], GL_DYNAMIC_DRAW);
glBindVertexArray(0);
return true;
}
bool RenderableStars::initialize(){
using ghoul::opengl::ShaderObject;
using ghoul::opengl::ProgramObject;
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess &= OsEng.ref().configurationManager().getValue("pscShader", _programObject);
completeSuccess &= OsEng.ref().configurationManager().getValue("StarProgram", _programObject);
if (!readSpeckFile(_speckPath))
LERROR("Failed to read speck file for path : '" << _speckPath << "'");
/*
loadTexture();
completeSuccess &= (_texture != nullptr);
completeSuccess &= _geometry->initialize(this);
*/
return completeSuccess;
}
bool RenderableStars::deinitialize(){
// TODO: set private VBO and deinitialize here..
/*_geometry->deinitialize();
delete _geometry;
_geometry = nullptr;
delete _texture;
_texture = nullptr;*/
glDeleteBuffers(1, &_starPositionsVBO);
return true;
}
@@ -210,46 +223,42 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition){
// activate shader
_programObject->activate();
psc currentPosition = thisPosition;
// fetch data
psc currentPosition = glm::vec4(0);// thisPosition; // NOTE : currentPosition now same as Earth.
psc campos = camera->position();
glm::mat4 camrot = camera->viewRotationMatrix();
PowerScaledScalar scaling = camera->scaling();
// scale the planet to appropriate size since the planet is a unit sphere
glm::mat4 transform = glm::mat4(1);
//scaling = glm::vec2(1,0);
/*
transform = glm::rotate(
transform, 8.1f * static_cast<float>(sgct::Engine::instance()->getTime()),
glm::vec3(0.0f, 1.0f, 0.0f));
*/
_programObject->setUniform("ViewProjection", camera->viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
_programObject->setUniform("campos", campos.vec4());
_programObject->setUniform("objpos", currentPosition.vec4());
_programObject->setUniform("camrot", camrot);
_programObject->setUniform("scaling", scaling.vec2());
_programObject->setUniform("Color", glm::vec3(1, 1, 1));
glPointSize(1.0);
glColor4f(1.f, 1.f, 1.f, 1.f);
glBindBuffer(GL_ARRAY_BUFFER, _starPositionsVBO);
glVertexPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
GLint vertsToDraw = v_size / 4;
GLint positionAttrib = _programObject->attributeLocation("in_position");
glBindVertexArray(_vaoID);
glEnableVertexAttribArray(positionAttrib); // use specific input in shader
glBindBuffer(GL_ARRAY_BUFFER, _vboID); // bind vbo
glVertexAttribPointer(positionAttrib, 4, GL_FLOAT, GL_FALSE, 0, (void*)0);
glDrawArrays(GL_POINTS, 0, vertsToDraw);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableVertexAttribArray(positionAttrib);
glBindVertexArray(0);
glDrawArrays(GL_POINTS, 0, 4*v_size);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
/*
// REQUIRES OWN SHADER.
GLint vertexLoc = _programObject->attributeLocation("in_position");
glEnableVertexAttribArray(vertexLoc);
glBindBuffer(GL_ARRAY_BUFFER, _starPositionsVBO);
glVertexAttribPointer(vertexLoc, // attribute
4, // size
GL_DOUBLE, // type
GL_FALSE, // normalized?
0, // stride
(void*)0);
glDrawElements(GL_POINTS, // mode
v_size/4, // count
GL_DOUBLE, // type
(void*)0); // element array buffer offset
*/
_programObject->deactivate();
}

View File

@@ -108,6 +108,18 @@ bool SceneGraph::initialize()
OsEng.ref().configurationManager().setValue("pscShader", po);
ProgramObject* _starProgram = new ProgramObject("StarProgram");
ShaderObject* starvs = new ShaderObject(ShaderObject::ShaderTypeVertex,
absPath("${SHADERS}/simpleVert.glsl"));
ShaderObject* starfs = new ShaderObject(ShaderObject::ShaderTypeFragment,
absPath("${SHADERS}/simpleFrag.glsl"));
_starProgram->attachObject(starvs);
_starProgram->attachObject(starfs);
_starProgram->compileShaderObjects();
_starProgram->linkProgramObject();
OsEng.ref().configurationManager().setValue("StarProgram", _starProgram);
ProgramObject* _fboProgram = new ProgramObject("RaycastProgram");
ShaderObject* vertexShader = new ShaderObject(ShaderObject::ShaderTypeVertex,
absPath("${SHADERS}/exitpoints.vert"));
@@ -248,6 +260,7 @@ bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath,
_allNodes.emplace(_rootNodeName, _root);
Dictionary dictionary;
//load default.scene
loadDictionaryFromFile(sceneDescriptionFilePath, dictionary);
Dictionary moduleDictionary;
if (dictionary.getValue(constants::scenegraph::keyModules, moduleDictionary)) {
@@ -255,7 +268,7 @@ bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath,
std::sort(keys.begin(), keys.end());
for (const std::string& key : keys) {
std::string moduleFolder;
if (moduleDictionary.getValue(key, moduleFolder))
if (moduleDictionary.getValue(key, moduleFolder))
loadModule(defaultModulePath + "/" + moduleFolder);
}
}
@@ -318,6 +331,7 @@ void SceneGraph::loadModule(const std::string& modulePath)
element.setValue(constants::scenegraph::keyPathModule, modulePath);
//each element in this new dictionary becomes a scenegraph node.
SceneGraphNode* node = SceneGraphNode::createFromDictionary(element);
_allNodes.emplace(node->nodeName(), node);

View File

@@ -176,7 +176,7 @@ void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition)
_renderableVisible = false;
// check if camera is outside the node boundingsphere
if (toCamera.length() > _boundingSphere) {
/* if (toCamera.length() > _boundingSphere) {
// check if the boudningsphere is visible before avaluating children
if (!sphereInsideFrustum(thisPosition, _boundingSphere, camera)) {
// the node is completely outside of the camera view, stop evaluating this
@@ -184,7 +184,7 @@ void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition)
return;
}
}
*/
// inside boudningsphere or parts of the sphere is visible, individual
// children needs to be evaluated
_boundingSphereVisible = true;
@@ -192,8 +192,7 @@ void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition)
// this node has an renderable
if (_renderable) {
// check if the renderable boundingsphere is visible
_renderableVisible = sphereInsideFrustum(
thisPosition, _renderable->getBoundingSphere(), camera);
_renderableVisible = true;// sphereInsideFrustum(thisPosition, _renderable->getBoundingSphere(), camera);
}
// evaluate all the children, tail-recursive function(?)
@@ -207,9 +206,10 @@ void SceneGraphNode::render(const Camera* camera, const psc& parentPosition)
const psc thisPosition = parentPosition + _ephemeris->position();
// check if camera is outside the node boundingsphere
if (!_boundingSphereVisible) {
/*if (!_boundingSphereVisible) {
return;
}
}*/
if (_renderableVisible) {
// LDEBUG("Render");
_renderable->render(camera, thisPosition);
@@ -255,26 +255,22 @@ psc SceneGraphNode::getWorldPosition() const
}
}
std::string SceneGraphNode::nodeName() const
{
std::string SceneGraphNode::nodeName() const{
return _nodeName;
}
SceneGraphNode* SceneGraphNode::parent() const
{
SceneGraphNode* SceneGraphNode::parent() const{
return _parent;
}
const std::vector<SceneGraphNode*>& SceneGraphNode::children() const
{
const std::vector<SceneGraphNode*>& SceneGraphNode::children() const{
return _children;
}
// bounding sphere
PowerScaledScalar SceneGraphNode::calculateBoundingSphere()
{
PowerScaledScalar SceneGraphNode::calculateBoundingSphere(){
// set the bounding sphere to 0.0
_boundingSphere = 0.0;
_boundingSphere = 1000.0;
if (_children.size() > 0) { // node
PowerScaledScalar maxChild;
@@ -296,19 +292,17 @@ PowerScaledScalar SceneGraphNode::calculateBoundingSphere()
if (_renderable)
_boundingSphere += _renderable->getBoundingSphere();
}
return _boundingSphere;
}
// renderable
void SceneGraphNode::setRenderable(Renderable* renderable)
{
void SceneGraphNode::setRenderable(Renderable* renderable) {
_renderable = renderable;
update();
}
const Renderable* SceneGraphNode::getRenderable() const
{
const Renderable* SceneGraphNode::getRenderable() const{
return _renderable;
}

View File

@@ -121,6 +121,7 @@ PowerScaledSphere::~PowerScaledSphere()
glDeleteBuffers(1, &_iBufferID);
glDeleteVertexArrays(1, &_vaoID);
}
#define cppOffsetOf(s, m) ((size_t)&(((s *)NULL)->m))
bool PowerScaledSphere::initialize()
{