Projective Texturing

Created test class based on renderableplanet & co.
Doing it this way carries some implications that need discussing.
This commit is contained in:
michal
2014-11-24 14:06:50 -05:00
parent 484dfefbee
commit 4c8814b237
18 changed files with 649 additions and 87 deletions
+1 -1
View File
@@ -24,7 +24,7 @@
<Pos x="-1.778" y="-1.0" z="0.0" />
<!-- Upper left -->
<Pos x="-1.778" y="1.0" z="0.0" />
<!-- Upper right -->
<!-- Upper right 1.778-->
<Pos x="1.778" y="1.0" z="0.0" />
</Viewplane>
</Viewport>
@@ -0,0 +1,53 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
#ifndef __PlanetGeometryProjection_H__
#define __PlanetGeometryProjection_H__
#include <openspace/properties/propertyowner.h>
#include <openspace/rendering/planets/RenderablePlanetProjection.h>
#include <ghoul/misc/dictionary.h>
namespace openspace {
namespace planetgeometryprojection {
class PlanetGeometryProjection : public properties::PropertyOwner {
public:
static PlanetGeometryProjection* createFromDictionary(const ghoul::Dictionary& dictionary);
PlanetGeometryProjection();
virtual ~PlanetGeometryProjection();
virtual bool initialize(RenderablePlanetProjection* parent);
virtual void deinitialize();
virtual void render() = 0;
protected:
RenderablePlanetProjection* _parent;
};
} // namespace planetgeometry
} // namespace openspace
#endif // __PLANETGEOMETRY_H__
@@ -22,8 +22,8 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __RENDERABLEPLANET_H__
#define __RENDERABLEPLANET_H__
#ifndef __RENDERABLEPLANETPROJECTION_H__
#define __RENDERABLEPLANETPROJECTION_H__
// open space includes
#include <openspace/rendering/renderable.h>
@@ -34,17 +34,18 @@
// ghoul includes
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <openspace/query/query.h>
namespace openspace {
namespace planetgeometry {
class PlanetGeometry;
namespace planetgeometryprojection {
class PlanetGeometryProjection;
}
class RenderablePlanet : public Renderable {
class RenderablePlanetProjection : public Renderable {
public:
RenderablePlanet(const ghoul::Dictionary& dictionary);
~RenderablePlanet();
RenderablePlanetProjection(const ghoul::Dictionary& dictionary);
~RenderablePlanetProjection();
bool initialize() override;
bool deinitialize() override;
@@ -57,15 +58,22 @@ protected:
private:
properties::StringProperty _colorTexturePath;
properties::StringProperty _projectionTexturePath;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
planetgeometry::PlanetGeometry* _geometry;
ghoul::opengl::Texture* _textureProj;
planetgeometryprojection::PlanetGeometryProjection* _geometry;
glm::dmat3 _stateMatrix;
glm::dmat3 _instrumentMatrix;
double _time;
openspace::SceneGraphNode* _targetNode;
std::string _target;
};
} // namespace openspace
#endif // __RENDERABLEPLANET_H__
#endif // __RENDERABLEPLANETPROJECTION_H__
@@ -0,0 +1,61 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
#ifndef __SIMPLESPHEREGEOMETRYPROJECTION_H__
#define __SIMPLESPHEREGEOMETRYPROJECTION_H__
#include <openspace/rendering/planets/planetgeometryprojection.h>
#include <openspace/properties/vectorproperty.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/util/powerscaledsphere.h>
namespace openspace {
class RenderablePlanet;
namespace planetgeometryprojection {
class SimpleSphereGeometryProjection : public PlanetGeometryProjection {
public:
SimpleSphereGeometryProjection(const ghoul::Dictionary& dictionary);
~SimpleSphereGeometryProjection();
bool initialize(RenderablePlanetProjection* parent) override;
void deinitialize() override;
void render() override;
private:
void createSphere();
properties::Vec2Property _radius;
properties::IntProperty _segments;
PowerScaledSphere* _planet;
};
} // namespace planetgeometry
} // namespace openspace
#endif // __SIMPLESPHEREGEOMETRY_H__
-26
View File
@@ -1,26 +0,0 @@
return {
Paths = {
SGCT = "${BASE_PATH}/config/sgct",
SCRIPTS = "${BASE_PATH}/scripts",
SHADERS = "${BASE_PATH}/shaders",
SHADERS_GENERATED = "${SHADERS}/generated",
OPENSPACE_DATA = "${BASE_PATH}/openspace-data",
TESTDIR = "${BASE_PATH}/src/tests",
CONFIG = "${BASE_PATH}/config",
CACHE = "${BASE_PATH}/cache",
TEMPORARY = "${BASE_PATH}/tmp",
FONTS = "${OPENSPACE_DATA}/fonts"
},
SpiceKernel = {
Time = "${OPENSPACE_DATA}/spice/naif0010.tls",
LeapSecond = "${OPENSPACE_DATA}/spice/pck00010.tpc",
NewHorizons = "${OPENSPACE_DATA}/spice/nhmeta.tm"
},
SGCTConfig = "${SGCT}/single.xml",
--SGCTConfig = "${SGCT}/two_nodes.xml",
--SGCTConfig = "${SGCT}/single_sbs_stereo.xml",
Scene = "${OPENSPACE_DATA}/scene/default.scene",
StartupScripts = {
"${SCRIPTS}/default_startup.lua"
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
openspace.time.setTime("2007-02-26T17:37:00")
openspace.time.setTime("2007-02-28T11:48:16.364")
--openspace.time.setTime("2006-08-22T20:00:00")
--openspace.time.setDeltaTime(200000.0)
+101
View File
@@ -0,0 +1,101 @@
/*****************************************************************************************
* *
* 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
uniform vec4 campos;
uniform vec4 objpos;
//uniform vec3 camdir; // add this for specular
uniform float time;
uniform sampler2D texture1;
uniform sampler2D texture2;
in vec2 vs_st;
in vec4 vs_normal;
in vec4 vs_position;
in vec4 ProjTexCoord;
in vec3 vs_boresight;
#include "ABuffer/abufferStruct.hglsl"
#include "ABuffer/abufferAddToBuffer.hglsl"
#include "PowerScaling/powerScaling_fs.hglsl"
//#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
vec4 position = vs_position;
float depth = pscDepth(position);
vec4 diffuse = texture(texture1, vs_st);
// directional lighting
vec3 origin = vec3(0.0);
vec4 spec = vec4(0.0);
vec3 n = normalize(vs_normal.xyz);
//vec3 e = normalize(camdir);
vec3 l_pos = vec3(0.0); // sun.
vec3 l_dir = normalize(l_pos-objpos.xyz);
float intensity = min(max(5*dot(n,l_dir), 0.0), 1);
float shine = 0.0001;
vec4 specular = vec4(0.5);
vec4 ambient = vec4(0.f,0.f,0.f,1);
/* Specular
if(intensity > 0.f){
// halfway vector
vec3 h = normalize(l_dir + e);
// specular factor
float intSpec = max(dot(h,n),0.0);
spec = specular * pow(intSpec, shine);
}
*/
//diffuse = max(intensity * diffuse, ambient);
// PROJECTIVE TEXTURE
vec4 projTexColor = textureProj(texture2, ProjTexCoord);
vec4 shaded = max(intensity * diffuse, ambient);
if (ProjTexCoord[0] > 0.0 ||
ProjTexCoord[1] > 0.0 ||
ProjTexCoord[0] < ProjTexCoord[2] ||
ProjTexCoord[1] < ProjTexCoord[2]){
diffuse = shaded;
}else if(dot(n,vs_boresight) < 0 ){
diffuse = projTexColor;
}else{
diffuse = shaded;
}
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
discard;
}
+74
View File
@@ -0,0 +1,74 @@
/*****************************************************************************************
* *
* 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
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
//texture projection matrix
uniform mat4 ProjectorMatrix;
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 vec3 boresight;
out vec2 vs_st;
out vec4 vs_normal;
out vec4 vs_position;
out float s;
out vec3 vs_boresight;
out vec4 ProjTexCoord;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
vs_boresight = boresight;
// set variables
vs_st = in_st;
//vs_stp = in_position.xyz;
vs_position = in_position;
vec4 tmp = in_position;
// this is wrong for the normal.
// The normal transform is the transposed inverse of the model transform
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
vec4 position = pscTransform(tmp, ModelTransform);
vs_position = tmp;
vec4 raw_pos = psc_to_meter(in_position, scaling);
ProjTexCoord = ProjectorMatrix * ModelTransform * raw_pos;
position = ViewProjection * position;
gl_Position = z_normalization(position);
}
+3 -3
View File
@@ -60,7 +60,7 @@ void main()
float shine = 0.0001;
vec4 specular = vec4(0.5);
vec4 ambient = vec4(0.3,0.3,0.3,1);
vec4 ambient = vec4(0.0,0.0,0.0,1);
/*
if(intensity > 0.f){
// halfway vector
@@ -70,9 +70,9 @@ void main()
spec = specular * pow(intSpec, shine);
}
*/
vec4 tmpdiff = diffuse*0.6f;
vec4 tmpdiff = diffuse;
tmpdiff[3] = 1;
diffuse = max(intensity * diffuse, tmpdiff);
diffuse = max(intensity * diffuse, ambient);
//diffuse[3] = 0.6f;
//diffuse = vec4(1);
@@ -0,0 +1,80 @@
/*****************************************************************************************
* *
* 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/planets/PlanetGeometryProjection.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/constants.h>
#include <openspace/util/factorymanager.h>
namespace {
const std::string _loggerCat = "PlanetGeometryProjection";
}
namespace openspace {
namespace planetgeometryprojection {
PlanetGeometryProjection* PlanetGeometryProjection::createFromDictionary(const ghoul::Dictionary& dictionary)
{
std::string geometryType;
const bool success = dictionary.getValue(
constants::planetgeometry::keyType, geometryType);
if (!success) {
LERROR("PlanetGeometry did not contain a correct value of the key '"
<< constants::planetgeometry::keyType << "'");
return nullptr;
}
ghoul::TemplateFactory<PlanetGeometryProjection>* factory
= FactoryManager::ref().factory<PlanetGeometryProjection>();
PlanetGeometryProjection* result = factory->create(geometryType, dictionary);
if (result == nullptr) {
LERROR("Failed to create a PlanetGeometry object of type '" << geometryType
<< "'");
return nullptr;
}
return result;
}
PlanetGeometryProjection::PlanetGeometryProjection()
: _parent(nullptr)
{
setName("PlanetGeometryProjection");
}
PlanetGeometryProjection::~PlanetGeometryProjection()
{
}
bool PlanetGeometryProjection::initialize(RenderablePlanetProjection* parent)
{
_parent = parent;
return true;
}
void PlanetGeometryProjection::deinitialize()
{
}
} // namespace planetgeometry
} // namespace openspace
@@ -23,9 +23,9 @@
****************************************************************************************/
// open space includes
#include <openspace/rendering/planets/renderableplanet.h>
#include <openspace/rendering/planets/RenderablePlanetProjection.h>
#include <openspace/util/constants.h>
#include <openspace/rendering/planets/planetgeometry.h>
#include <openspace/rendering/planets/planetgeometryprojection.h>
#include <ghoul/opengl/texturereader.h>
#include <ghoul/opengl/textureunit.h>
@@ -36,18 +36,23 @@
#include <openspace/engine/openspaceengine.h>
#include <sgct.h>
#include <iomanip>
namespace {
const std::string _loggerCat = "RenderablePlanet";
const std::string _loggerCat = "RenderablePlanetProjection";
}
namespace openspace {
RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _projectionTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _texture(nullptr)
, _textureProj(nullptr)
, _geometry(nullptr)
{
std::string name;
@@ -64,7 +69,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
if (success) {
geometryDictionary.setValue(constants::scenegraphnode::keyName, name);
geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
_geometry = planetgeometryprojection::PlanetGeometryProjection::createFromDictionary(geometryDictionary);
}
dictionary.getValue(constants::renderableplanet::keyFrame, _target);
@@ -73,45 +78,55 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
// as the requirements are fixed (ab)
std::string texturePath = "";
success = dictionary.getValue("Textures.Color", texturePath);
if (success)
_colorTexturePath = path + "/" + texturePath;
if (success){
_colorTexturePath = path + "/" + texturePath;
}
success = dictionary.getValue("Textures.Project", texturePath);
if (success){
_projectionTexturePath = path + "/" + texturePath;
}
addPropertySubOwner(_geometry);
addProperty(_colorTexturePath);
_colorTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this));
_colorTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadTexture, this));
addProperty(_projectionTexturePath);
_projectionTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadTexture, this));
}
RenderablePlanet::~RenderablePlanet(){
RenderablePlanetProjection::~RenderablePlanetProjection(){
deinitialize();
}
bool RenderablePlanet::initialize(){
bool RenderablePlanetProjection::initialize(){
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess
&= OsEng.ref().configurationManager().getValue("pscShader", _programObject);
&= OsEng.ref().configurationManager().getValue("projectiveProgram", _programObject);
loadTexture();
completeSuccess &= (_texture != nullptr);
completeSuccess &= (_textureProj != nullptr);
completeSuccess &= _geometry->initialize(this);
return completeSuccess;
}
bool RenderablePlanet::deinitialize(){
bool RenderablePlanetProjection::deinitialize(){
_geometry->deinitialize();
delete _geometry;
_geometry = nullptr;
delete _texture;
_texture = nullptr;
delete _textureProj;
_textureProj = nullptr;
return true;
}
void RenderablePlanet::render(const RenderData& data)
void RenderablePlanetProjection::render(const RenderData& data)
{
if (!_programObject) return;
if (!_texture) return;
if (!_textureProj) return;
// activate shader
_programObject->activate();
@@ -128,18 +143,52 @@ void RenderablePlanet::render(const RenderData& data)
}
}
transform = transform* rot;
if (_target == "IAU_JUPITER"){ //x = 0.935126
transform *= glm::scale(glm::mat4(1), glm::vec3(1, 0.93513, 1));
if (_target == "IAU_JUPITER"){ // tmp scale of jupiterx = 0.935126
transform *= glm::scale(glm::mat4(1), glm::vec3(1, 0.935126, 1));
}
glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix();
glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz;
// PROJECTIVE TEXTURING----------------------------------------------------------
// get fov
std::string shape, instrument;
std::vector<glm::dvec3> bounds;
glm::dvec3 boresight;
bool found = openspace::SpiceManager::ref().getFieldOfView("NH_LORRI", shape, instrument, boresight, bounds);
if (!found) LERROR("Could not locate instrument");
psc position;
double lightTime = 0.0;
SpiceManager::ref().getTargetPosition("NEW HORIZONS", "JUPITER BARYCENTER","GALACTIC", "NONE", _time, position, lightTime);
position[3] += 3;
glm::vec3 nh_pos = position.vec3();
//get up-vecto
//rotate boresight into correct alignment
glm::vec3 bsight(_instrumentMatrix*boresight); // lookat must be vec3
glm::vec3 uptmp(_instrumentMatrix*glm::dvec3(data.camera.lookUpVector()));
//create view matrix
glm::vec3 e3 = glm::normalize(bsight);
glm::vec3 e1 = glm::normalize(glm::cross(uptmp, e3));
glm::vec3 e2 = glm::normalize(glm::cross(e3, e1));
glm::mat4 projViewMatrix = glm::mat4( e1.x, e2.x, e3.x, 0.f,
e1.y, e2.y, e3.y, 0.f,
e1.z, e2.z, e3.z, 0.f,
-glm::dot(e1, nh_pos), -glm::dot(e2, nh_pos), -glm::dot(e3, nh_pos), 1.f);
//create perspective projection matrix
glm::mat4 projProjectionMatrix = glm::perspective(0.2907f, 1.f, 0.2f, 1000000.0f);
//bias matrix
glm::mat4 projNormalizationMatrix = glm::mat4(0.5f, 0 , 0 , 0,
0 , 0.5f, 0 , 0,
0 , 0 , 0.5f, 0,
0.5f, 0.5f, 0.5f, 1 );
glm::mat4 m = projNormalizationMatrix*projProjectionMatrix*projViewMatrix;
// setup the data to the shader
// _programObject->setUniform("camdir", camSpaceEye);
_programObject->setUniform("ProjectorMatrix", m);
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
_programObject->setAttribute("boresight", bsight);
setPscUniforms(_programObject, &data.camera, data.position);
// Bind texture
@@ -148,6 +197,11 @@ void RenderablePlanet::render(const RenderData& data)
_texture->bind();
_programObject->setUniform("texture1", unit);
ghoul::opengl::TextureUnit unit2;
unit2.activate();
_textureProj->bind();
_programObject->setUniform("texture2", unit2);
// render
_geometry->render();
@@ -155,12 +209,15 @@ void RenderablePlanet::render(const RenderData& data)
_programObject->deactivate();
}
void RenderablePlanet::update(const UpdateData& data){
void RenderablePlanetProjection::update(const UpdateData& data){
// set spice-orientation in accordance to timestamp
_time = data.time;
openspace::SpiceManager::ref().getPositionTransformMatrix(_target, "GALACTIC", data.time, _stateMatrix);
openspace::SpiceManager::ref().getPositionTransformMatrix("NH_LORRI", "GALACTIC", data.time, _instrumentMatrix);
}
void RenderablePlanet::loadTexture()
void RenderablePlanetProjection::loadTexture()
{
delete _texture;
_texture = nullptr;
@@ -171,9 +228,29 @@ void RenderablePlanet::loadTexture()
_texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
}
}
delete _textureProj;
_textureProj = nullptr;
if (_colorTexturePath.value() != "") {
_textureProj = ghoul::opengl::loadTexture(absPath(_projectionTexturePath));
if (_textureProj) {
LDEBUG("Loaded texture from '" << absPath(_projectionTexturePath) << "'");
_textureProj->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_textureProj->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
}
}
}
} // namespace openspace
/*
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER);
*/
@@ -0,0 +1,118 @@
/*****************************************************************************************
* *
* 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/planets/SimpleSphereGeometryProjection.h>
#include <openspace/util/constants.h>
namespace {
const std::string _loggerCat = "SimpleSphereGeometryProjection";
}
namespace openspace {
namespace constants {
namespace simplespheregeometryprojection {
const std::string keyRadius = "Radius";
const std::string keySegments = "Segments";
} // namespace simplespheregeometry
}
namespace planetgeometryprojection {
SimpleSphereGeometryProjection::SimpleSphereGeometryProjection(const ghoul::Dictionary& dictionary)
: PlanetGeometryProjection()
, _radius("radius", "Radius", glm::vec2(1.f, 0.f), glm::vec2(-10.f, -20.f),
glm::vec2(10.f, 20.f))
, _segments("segments", "Segments", 20, 1, 1000)
, _planet(nullptr)
{
using constants::scenegraphnode::keyName;
using constants::simplespheregeometryprojection::keyRadius;
using constants::simplespheregeometryprojection::keySegments;
// The name is passed down from the SceneGraphNode
std::string name;
bool success = dictionary.getValue(keyName, name);
assert(success);
glm::vec2 radius;
success = dictionary.getValue(keyRadius, radius);
if (!success) {
LERROR("SimpleSphereGeometry of '" << name << "' did not provide a key '"
<< keyRadius << "'");
}
else
_radius = radius;
double segments;
success = dictionary.getValue(keySegments, segments);
if (!success) {
LERROR("SimpleSphereGeometry of '" << name << "' did not provide a key '"
<< keySegments << "'");
}
else
_segments = static_cast<int>(segments);
addProperty(_radius);
_radius.onChange(std::bind(&SimpleSphereGeometryProjection::createSphere, this));
addProperty(_segments);
_segments.onChange(std::bind(&SimpleSphereGeometryProjection::createSphere, this));
}
SimpleSphereGeometryProjection::~SimpleSphereGeometryProjection()
{
}
bool SimpleSphereGeometryProjection::initialize(RenderablePlanetProjection* parent)
{
bool success = PlanetGeometryProjection::initialize(parent);
createSphere();
return success;
}
void SimpleSphereGeometryProjection::deinitialize()
{
delete _planet;
_planet = nullptr;
}
void SimpleSphereGeometryProjection::render()
{
_planet->render();
}
void SimpleSphereGeometryProjection::createSphere()
{
//create the power scaled scalar
PowerScaledScalar planetSize(_radius);
_parent->setBoundingSphere(planetSize);
delete _planet;
_planet = new PowerScaledSphere(planetSize, _segments);
_planet->initialize();
}
} // namespace planetgeometry
} // namespace openspace
+1 -14
View File
@@ -393,26 +393,13 @@ void RenderableFov::render(const RenderData& data){
}
//somehow get target in there.
_targetNode = sceneGraphNode(_fovTarget);
//_targetNode = sceneGraphNode(_fovTarget);
/*std::vector<PropertyOwner*> properties = _targetNode->subOwners();
for (auto & element : properties) {
std::cout << element->name() << std::endl;
}*/
//std::cout << _targetNode->renderable.hasProperty("PlanetGeometry") << std::endl;
// if (_targetNode->renderable.hasProperty("PlanetGeometry")) std::cout << "Found property!" << std::endl;
glm::vec3 up = data.camera.lookUpVector();
glm::vec3 bsight(boresight);
/* glm::vec3 e3 = glm::normalize(bsight);
glm::vec3 e1 = glm::normalize(glm::cross(up, e3));
glm::vec3 e2 = glm::cross(e1, e2);*/
glm::mat4 nhLorriViewMatrix = glm::lookAt(data.position.vec3(), bsight, up);
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
std::cout << nhLorriViewMatrix[i][j] << std::endl;
}
}
// for each FOV vector
for (int i = 0; i < 4; i++){
+3 -3
View File
@@ -41,7 +41,7 @@ namespace {
namespace openspace {
// needs to be set from dictionary - REMEMBER
//const PowerScaledScalar radius = PowerScaledScalar(1.f, 20.f);
const PowerScaledScalar radius = PowerScaledScalar(1.f, 20.f);
RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
@@ -65,9 +65,9 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio
dictionary.getValue(constants::renderablesphericalgrid::gridSegments, s);
glm::vec2 radius;
/*glm::vec2 radius;
dictionary.getValue(constants::renderablesphericalgrid::gridRadius, radius);
*/
_segments = s[0];
_isize = int(6 * _segments * _segments);
+8 -3
View File
@@ -102,9 +102,14 @@ void RenderableTrail::fullYearSweep(){
_isize = (segments + 2);
_vsize = (segments + 2);
_iarray = new int[_isize];
for (int i = 0; i < segments+2; i++){
SpiceManager::ref().getTargetState(_target, _observer, _frame, "CN+S", et, _pscpos, _pscvel, lightTime);
/*if (_target == "NEW HORIZONS"){
SpiceManager::ref().getTargetState(_target, _observer, _frame, "CN+S", _startTrail, _pscpos, _pscvel, lightTime);
}
else{*/
SpiceManager::ref().getTargetState(_target, _observer, _frame, "CN+S", et, _pscpos, _pscvel, lightTime);
//}
_pscpos[3] += 3;
for (int k = 0; k < 4; k++)
@@ -171,7 +176,7 @@ bool RenderableTrail::initialize(){
completeSuccess &= (_texture != nullptr);
_startTrail;
SpiceManager::ref().getETfromDate("2007 jan 26 17:42:00", _startTrail);
SpiceManager::ref().getETfromDate("2007 feb 28 11:48:00.000", _startTrail);
_dtEt = _startTrail;
fullYearSweep();
+11 -2
View File
@@ -169,14 +169,23 @@ bool SceneGraph::initialize()
typedef std::chrono::duration<double, std::ratio<1> > second_;
std::chrono::time_point<clock_> beginning(clock_::now());
// pscstandard
tmpProgram = ProgramObject::Build("projectiveProgram",
"${SHADERS}/projectiveTexture_vs.glsl",
"${SHADERS}/projectiveTexture_fs.glsl",
cb);
if( ! tmpProgram) return false;
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager().setValue("projectiveProgram", tmpProgram);
// pscstandard
tmpProgram = ProgramObject::Build("pscstandard",
"${SHADERS}/pscstandard_vs.glsl",
"${SHADERS}/pscstandard_fs.glsl",
cb);
if( ! tmpProgram) return false;
if (!tmpProgram) return false;
_programs.push_back(tmpProgram);
OsEng.ref().configurationManager().setValue("pscShader", tmpProgram);
OsEng.ref().configurationManager().setValue("pscShader", tmpProgram);
// pscstandard
tmpProgram = ProgramObject::Build("EphemerisProgram",
+15
View File
@@ -49,6 +49,12 @@
#include <openspace/rendering/model/modelgeometry.h>
#include <openspace/rendering/model/WavefrontGeometry.h>
#include <openspace/rendering/planets/renderableplanetprojection.h>
#include <openspace/rendering/planets/simplespheregeometryprojection.h>
#include <openspace/rendering/planets/planetgeometryprojection.h>
namespace openspace {
FactoryManager* FactoryManager::_manager = nullptr;
@@ -63,6 +69,9 @@ void FactoryManager::initialize()
// TODO: This has to be moved into a sort of module structure (ab)
// Add Renderables
_manager->addFactory(new ghoul::TemplateFactory<Renderable>);
//TODELETE
_manager->factory<Renderable>()->registerClass<RenderablePlanetProjection>(
"RenderablePlanetProjection");
_manager->factory<Renderable>()->registerClass<RenderablePlanet>(
"RenderablePlanet");
_manager->factory<Renderable>()->registerClass<RenderableStars>(
@@ -96,6 +105,12 @@ void FactoryManager::initialize()
_manager->addFactory(new ghoul::TemplateFactory<planetgeometry::PlanetGeometry>);
_manager->factory<planetgeometry::PlanetGeometry>()
->registerClass<planetgeometry::SimpleSphereGeometry>("SimpleSphere");
// Add PlanetGeometryProjection
_manager->addFactory(new ghoul::TemplateFactory<planetgeometryprojection::PlanetGeometryProjection>);
_manager->factory<planetgeometryprojection::PlanetGeometryProjection>()
->registerClass<planetgeometryprojection::SimpleSphereGeometryProjection>("SimpleSphereProjection");
// Add ModelGeometry
_manager->addFactory(new ghoul::TemplateFactory<modelgeometry::ModelGeometry>);