mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 03:00:58 -06:00
WIP3: problems with texture coordinates, needs fix.
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
|
||||
namespace openspace{
|
||||
|
||||
@@ -44,17 +46,23 @@ public:
|
||||
void render(const Camera* camera, const psc& position) override;
|
||||
void update() override;
|
||||
|
||||
protected:
|
||||
void loadTexture();
|
||||
|
||||
private:
|
||||
std::ifstream& skipToLine(std::ifstream& file, unsigned int num);
|
||||
bool readSpeckFile(const std::string& path);
|
||||
|
||||
properties::StringProperty _colorTexturePath;
|
||||
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
ghoul::opengl::Texture* _texture;
|
||||
|
||||
std::string _speckPath;
|
||||
|
||||
GLuint _vboID;
|
||||
GLuint _vaoID;
|
||||
//GLint positionAttrib;
|
||||
GLint positionAttrib;
|
||||
int v_size;
|
||||
};
|
||||
|
||||
|
||||
@@ -97,6 +97,15 @@ public:
|
||||
void setPosition(psc pos);
|
||||
const psc& position() const;
|
||||
|
||||
void setModelMatrix(glm::mat4 modelMatrix);
|
||||
const glm::mat4& modelMatrix() const;
|
||||
|
||||
void setViewMatrix(glm::mat4 viewMatrix);
|
||||
const glm::mat4& viewMatrix() const;
|
||||
|
||||
void setProjectionMatrix(glm::mat4 projectionMatrix);
|
||||
const glm::mat4& projectionMatrix() const;
|
||||
|
||||
void setViewProjectionMatrix(glm::mat4 viewProjectionMatrix);
|
||||
const glm::mat4& viewProjectionMatrix() const;
|
||||
|
||||
@@ -126,10 +135,12 @@ private:
|
||||
float _sinMaxFov;
|
||||
psc _position;
|
||||
glm::mat4 _viewProjectionMatrix;
|
||||
glm::mat4 _modelMatrix;
|
||||
glm::mat4 _viewMatrix;
|
||||
glm::mat4 _projectionMatrix;
|
||||
glm::vec3 _viewDirection;
|
||||
glm::vec3 _cameraDirection;
|
||||
glm::vec2 _scaling;
|
||||
|
||||
glm::quat _viewRotation;
|
||||
glm::mat4 _viewRotationMatrix; // compiled from the quaternion
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace renderableplanet {
|
||||
|
||||
namespace renderablestars {
|
||||
const std::string keySpeckFile = "SpeckFile";
|
||||
const std::string keyPathModule = "ModulePath";
|
||||
} // namespace renderablestars
|
||||
|
||||
namespace planetgeometry {
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,31 +1,9 @@
|
||||
/**
|
||||
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;
|
||||
#version 440
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
uniform sampler2D texture3;
|
||||
uniform float TessLevel;
|
||||
uniform bool Wireframe;
|
||||
uniform bool Lightsource;
|
||||
uniform bool UseTexture;
|
||||
uniform vec3 Color;
|
||||
|
||||
in vec2 vs_st;
|
||||
//in vec3 vs_stp;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
in vec2 texCoord;
|
||||
|
||||
out vec4 diffuse;
|
||||
|
||||
@@ -44,9 +22,8 @@ vec4 psc_normlization(vec4 invec) {
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
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;
|
||||
@@ -66,7 +43,6 @@ void main()
|
||||
depth = vs_position.w+log(abs(vs_position.z));
|
||||
}
|
||||
|
||||
|
||||
// DEBUG
|
||||
float depth_orig = depth;
|
||||
float x = 0.0f;
|
||||
@@ -98,19 +74,10 @@ void main()
|
||||
// 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);
|
||||
diffuse = vec4(Color, 1); //<--- works, obviously
|
||||
// diffuse = texture(texture1, texCoord); //<--- SHOULD work, but doesn't. agh!!
|
||||
|
||||
}
|
||||
28
shaders/star_ge.glsl
Normal file
28
shaders/star_ge.glsl
Normal file
@@ -0,0 +1,28 @@
|
||||
#version 440
|
||||
|
||||
const vec2 corners[4] = {
|
||||
vec2(0.0, 1.0),
|
||||
vec2(0.0, 0.0),
|
||||
vec2(1.0, 1.0),
|
||||
vec2(1.0, 0.0)
|
||||
};
|
||||
|
||||
layout(points) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
|
||||
uniform mat4 projection;
|
||||
float spriteSize = 1.0; // set here for now.
|
||||
out vec2 texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
// make quad + corresp. UV coordinates.
|
||||
for(int i=0; i<4; ++i){
|
||||
vec4 pos = gl_in[0].gl_Position; //start with point position
|
||||
pos.xy += spriteSize * (corners[i] - vec2(0.5)); //add corner position
|
||||
gl_Position = projection * pos; //complete transformation
|
||||
texCoord = corners[i]; //use corner as texCoord
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
@@ -1,50 +1,19 @@
|
||||
/**
|
||||
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;
|
||||
#version 440
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
//uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 campos;
|
||||
uniform mat4 camrot;
|
||||
uniform vec2 scaling;
|
||||
//uniform vec4 objpos;
|
||||
uniform float time;
|
||||
uniform vec4 objpos;
|
||||
|
||||
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;
|
||||
in vec4 in_position;
|
||||
|
||||
out vec4 vs_position;
|
||||
|
||||
const float k = 10.0;
|
||||
@@ -76,15 +45,7 @@ vec4 psc_scaling(vec4 v1, vec2 v2) {
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -100,11 +61,7 @@ void main()
|
||||
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);
|
||||
@@ -112,5 +69,6 @@ void main()
|
||||
|
||||
|
||||
// project the position to view space
|
||||
gl_Position = ViewProjection * vs_position_rescaled;
|
||||
//gl_Position = ViewProjection * vs_position_rescaled;
|
||||
gl_Position = view * model * vs_position_rescaled;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#version 440
|
||||
out vec4 vFragColor;
|
||||
|
||||
uniform vec3 Color;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// calculate normal from texture coordinates
|
||||
vFragColor = vec4(Color,1);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#version 440
|
||||
|
||||
in vec3 in_position;
|
||||
|
||||
uniform mat4 MVP;
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVP*vec4(in_position,1.0);
|
||||
}
|
||||
@@ -162,6 +162,16 @@ void RenderEngine::render()
|
||||
_mainCamera->setViewProjectionMatrix(
|
||||
sgct::Engine::instance()->getActiveModelViewProjectionMatrix() * view);
|
||||
|
||||
_mainCamera->setModelMatrix(
|
||||
sgct::Engine::instance()->getModelMatrix());
|
||||
|
||||
_mainCamera->setViewMatrix(
|
||||
sgct::Engine::instance()->getActiveViewMatrix());
|
||||
|
||||
_mainCamera->setProjectionMatrix(
|
||||
sgct::Engine::instance()->getActiveProjectionMatrix());
|
||||
|
||||
|
||||
// render the scene starting from the root node
|
||||
_sceneGraph->render(_mainCamera);
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
// open space includes
|
||||
#include <openspace/rendering/stars/renderablestars.h>
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
#include <ghoul/opengl/texturereader.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <sgct.h>
|
||||
@@ -62,37 +65,34 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary),
|
||||
_programObject(nullptr){
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _programObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
{
|
||||
|
||||
//setBoundingSphere(PowerScaledScalar::CreatePSS(100));
|
||||
std::string path;
|
||||
dictionary.getValue(constants::renderablestars::keyPathModule, path);
|
||||
|
||||
std::string texturePath = "";
|
||||
if (dictionary.hasKey("Textures.Color")) {
|
||||
dictionary.getValue("Textures.Color", texturePath);
|
||||
_colorTexturePath = path + "/" + texturePath;
|
||||
std::cout << _colorTexturePath.value() << std::endl;
|
||||
}
|
||||
dictionary.getValue(constants::renderablestars::keySpeckFile, path);
|
||||
|
||||
_speckPath = FileSys.absolutePath(path);
|
||||
|
||||
addProperty(_colorTexturePath);
|
||||
_colorTexturePath.onChange(std::bind(&RenderableStars::loadTexture, this));
|
||||
}
|
||||
|
||||
RenderableStars::~RenderableStars(){
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
GLuint createVBO(const void* data, int dataSize, GLenum target, GLenum usage){
|
||||
GLuint id = 0; // 0 is reserved, glGenBuffersARB() will return non-zero id if success
|
||||
glGenBuffers(1, &id); // create a vbo
|
||||
glBindBuffer(target, id); // activate vbo id to use
|
||||
glBufferData(target, dataSize, data, usage); // upload data to video card
|
||||
|
||||
// check data size in VBO is same as input array, if not return 0 and delete VBO
|
||||
int bufferSize = 0;
|
||||
glGetBufferParameteriv(target, GL_BUFFER_SIZE, &bufferSize);
|
||||
if (dataSize != bufferSize)
|
||||
{
|
||||
glDeleteBuffers(1, &id);
|
||||
id = 0;
|
||||
printf("[createVBO()] Data size is mismatch with input array\n");
|
||||
}
|
||||
glBindBuffer(target, 0);
|
||||
return id; // return VBO id
|
||||
}
|
||||
|
||||
std::ifstream& RenderableStars::skipToLine(std::ifstream& file, unsigned int num){
|
||||
file.seekg(std::ios::beg);
|
||||
@@ -108,6 +108,10 @@ bool RenderableStars::readSpeckFile(const std::string& path){
|
||||
std::vector<std::string> strvec;
|
||||
std::vector<float> positions;
|
||||
std::vector<float> doubleData;
|
||||
std::vector<float> luminocities;
|
||||
std::vector<float> absoluteMagnitudes;
|
||||
std::vector<float> apparentMagnitudes;
|
||||
|
||||
int count = 0;
|
||||
|
||||
const std::string absPath = FileSys.absolutePath(path);
|
||||
@@ -120,6 +124,7 @@ bool RenderableStars::readSpeckFile(const std::string& path){
|
||||
|
||||
// check if cache exists, if not create it.
|
||||
if (!FileSys.fileExists(cacheName)){
|
||||
//if (FileSys.fileExists(cacheName)){ // TODO: fix so that reads/writes cache.
|
||||
std::ofstream cache;
|
||||
cache.open(cacheName, std::ios::binary);
|
||||
|
||||
@@ -158,8 +163,16 @@ 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); });
|
||||
|
||||
luminocities.push_back(doubleData[3]);
|
||||
absoluteMagnitudes.push_back(doubleData[4]);
|
||||
apparentMagnitudes.push_back(doubleData[5]);
|
||||
|
||||
// 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];
|
||||
@@ -193,15 +206,15 @@ bool RenderableStars::readSpeckFile(const std::string& path){
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
|
||||
glBufferData(GL_ARRAY_BUFFER, v_size*sizeof(GLfloat), &positions[0], GL_DYNAMIC_DRAW);
|
||||
|
||||
positionAttrib = _programObject->attributeLocation("in_position");
|
||||
|
||||
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("StarProgram", _programObject);
|
||||
@@ -209,12 +222,16 @@ bool RenderableStars::initialize(){
|
||||
if (!readSpeckFile(_speckPath))
|
||||
LERROR("Failed to read speck file for path : '" << _speckPath << "'");
|
||||
|
||||
loadTexture();
|
||||
completeSuccess &= (_texture != nullptr);
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderableStars::deinitialize(){
|
||||
// TODO: set private VBO and deinitialize here..
|
||||
return true;
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableStars::render(const Camera* camera, const psc& thisPosition){
|
||||
@@ -231,36 +248,57 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition){
|
||||
// scale the planet to appropriate size since the planet is a unit sphere
|
||||
glm::mat4 transform = glm::mat4(1);
|
||||
|
||||
//scaling = glm::vec2(1,0);
|
||||
/*
|
||||
//PowerScaledScalar scaling = glm::vec2(1, -4);
|
||||
|
||||
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("model", camera->modelMatrix());
|
||||
_programObject->setUniform("view", camera->viewMatrix());
|
||||
_programObject->setUniform("projection", camera->projectionMatrix());
|
||||
|
||||
//_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));
|
||||
_programObject->setUniform("Color", glm::vec3(1, 0, 1));
|
||||
|
||||
glPointSize(1.0);
|
||||
//glPointSize(1.0);
|
||||
|
||||
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);
|
||||
glVertexAttribPointer(positionAttrib, 4,
|
||||
GL_FLOAT, GL_FALSE, 0, (void*)0);
|
||||
glDrawArrays(GL_POINTS, 0, vertsToDraw);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glDisableVertexAttribArray(positionAttrib);
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
||||
// Bind texure
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_programObject->setUniform("texture1", unit);
|
||||
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void RenderableStars::loadTexture(){
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = ghoul::opengl::loadTexture(absPath(_colorTexturePath));
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
_texture->uploadTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableStars::update()
|
||||
|
||||
@@ -110,10 +110,14 @@ bool SceneGraph::initialize()
|
||||
|
||||
ProgramObject* _starProgram = new ProgramObject("StarProgram");
|
||||
ShaderObject* starvs = new ShaderObject(ShaderObject::ShaderTypeVertex,
|
||||
absPath("${SHADERS}/simpleVert.glsl"));
|
||||
absPath("${SHADERS}/star_vs.glsl"));
|
||||
ShaderObject* starge = new ShaderObject(ShaderObject::ShaderTypeGeometry,
|
||||
absPath("${SHADERS}/star_ge.glsl"));
|
||||
|
||||
ShaderObject* starfs = new ShaderObject(ShaderObject::ShaderTypeFragment,
|
||||
absPath("${SHADERS}/simpleFrag.glsl"));
|
||||
absPath("${SHADERS}/star_fs.glsl"));
|
||||
_starProgram->attachObject(starvs);
|
||||
_starProgram->attachObject(starge);
|
||||
_starProgram->attachObject(starfs);
|
||||
_starProgram->compileShaderObjects();
|
||||
_starProgram->linkProgramObject();
|
||||
|
||||
@@ -55,6 +55,30 @@ const psc& Camera::position() const
|
||||
return _position;
|
||||
}
|
||||
|
||||
void Camera::setModelMatrix(glm::mat4 modelMatrix){
|
||||
_modelMatrix = std::move(modelMatrix);
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::modelMatrix() const{
|
||||
return _modelMatrix;
|
||||
}
|
||||
|
||||
void Camera::setViewMatrix(glm::mat4 viewMatrix){
|
||||
_viewMatrix = std::move(viewMatrix);
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::viewMatrix() const{
|
||||
return _viewMatrix;
|
||||
}
|
||||
|
||||
void Camera::setProjectionMatrix(glm::mat4 projectionMatrix){
|
||||
_projectionMatrix = std::move(projectionMatrix);
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::projectionMatrix() const{
|
||||
return _projectionMatrix;
|
||||
}
|
||||
|
||||
void Camera::setViewProjectionMatrix(glm::mat4 viewProjectionMatrix)
|
||||
{
|
||||
_viewProjectionMatrix = std::move(viewProjectionMatrix);
|
||||
|
||||
Reference in New Issue
Block a user