Merge branch 'feature/iSWA' of github.com:OpenSpace/OpenSpace-Development into feature/iSWA

This commit is contained in:
Michael Nilsson
2016-06-16 14:40:39 -04:00
28 changed files with 391 additions and 314 deletions

View File

@@ -51,6 +51,7 @@ public:
bool isRegularRendering() const override;
glm::mat4 viewProjectionMatrix() const override;
glm::mat4 modelMatrix() const override;
void setNearFarClippingPlane(float near, float far) override;
glm::ivec4 viewportPixelCoordinates() const override;

View File

@@ -131,6 +131,13 @@ public:
* \return The currently employed view-projection matrix
*/
virtual glm::mat4 viewProjectionMatrix() const;
/**
* Returns the currently employed model matrix. On default, this method will return
* the identity matrix.
* \return The currently employed model matrix
*/
virtual glm::mat4 modelMatrix() const;
/**
* Sets the near and far clipping planes of the rendering window. This method defaults

View File

@@ -24,38 +24,33 @@
#ifndef __SCREENSPACERENDERABLE_H__
#define __SCREENSPACERENDERABLE_H__
#include <ghoul/opengl/programobject.h>
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/vectorproperty.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/triggerproperty.h>
#include <ghoul/opengl/texture.h>
#include <modules/onscreengui/include/gui.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/engine/openspaceengine.h>
#include <ghoul/opengl/textureunit.h>
#include <openspace/util/camera.h>
#ifdef WIN32
#define _USE_MATH_DEFINES
#include <math.h>
#endif
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/triggerproperty.h>
#include <openspace/properties/vectorproperty.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
namespace openspace {
/**
* @brief The base class for screen scape images and screen space framebuffers
* @details This base class handles general functionality specific to planes that
* are rendered infront of the camera. It implements protected methods and properties for converting
* the planes from spherical to euclidean coordinates and back. It also specifies the interface
* that it's children needs to implement.
* The base class for screen space images and screen space framebuffers.
* This base class handles general functionality specific to planes that are rendered in
* front of the camera. It implements protected methods and properties for converting
* the planes from Spherical to Euclidean coordinates and back. It also specifies the
* interface that its children need to implement.
*/
class ScreenSpaceRenderable : public properties::PropertyOwner {
public:
static ScreenSpaceRenderable* createFromDictionary(const ghoul::Dictionary& dictionary);
static ScreenSpaceRenderable* createFromDictionary(
const ghoul::Dictionary& dictionary);
ScreenSpaceRenderable(const ghoul::Dictionary& dictionary);
~ScreenSpaceRenderable();
virtual ~ScreenSpaceRenderable();
virtual void render() = 0;
virtual bool initialize() = 0;
@@ -64,31 +59,30 @@ public:
virtual bool isReady() const = 0;
bool isEnabled() const;
glm::vec2 euclideanPosition() const {return _euclideanPosition.value();};
glm::vec2 sphericalPosition() const {return _sphericalPosition.value();};
float depth() const {return _depth.value();};
glm::vec3 euclideanPosition() const;
glm::vec3 sphericalPosition() const;
float depth() const;
protected:
void createPlane();
void useEuclideanCoordinates(bool b);
/**
* @brief Converts vec2 polar coordinates to euclidean
*
* @param polar the coordinates theta and phi
* @param radius the radius position value of the plane
*
* @return glm::vec2 with the x and y position value of the plane
* Converts Spherical coordinates to Euclidean.
* \param spherical The coordinates theta and phi
* \param radius The radius position value of the plane
* \return The x and y position value of the plane
*/
glm::vec2 toEuclidean(glm::vec2 polar, float radius);
glm::vec2 toEuclidean(const glm::vec2& spherical, float radius);
/**
* @brief Converts vec2 euclidean coordinates to sperical
*
* @param euclidean the coordinates x and y
* @return glm::vec2 with the spherical coordinates theta and phi.
* Converts Euclidean coordinates to Spherical.
* \param euclidean The coordinates x and y
* \return The spherical coordinates theta and phi.
*/
glm::vec2 toSpherical(glm::vec2 euclidean);
glm::vec2 toSpherical(const glm::vec2& euclidean);
void registerProperties();
void unregisterProperties();
@@ -109,18 +103,15 @@ protected:
GLuint _quad;
GLuint _vertexPositionBuffer;
const std::string _rendererPath;
ghoul::Dictionary _rendererData;
const std::string _vertexPath;
const std::string _fragmentPath;
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
bool _useEuclideanCoordinates;
const float _planeDepth = -2.0;
glm::vec2 _originalViewportSize;
float _radius;
};
} // namespace openspace
#endif // __SCREENSPACERENDERABLE_H__
#endif // __SCREENSPACERENDERABLE_H__

View File

@@ -89,8 +89,8 @@ set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_ge.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/screnspace_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/screnspace_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/screenspace_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/screenspace_vs.glsl
)
source_group("Shader Files" FILES ${SHADER_FILES})

View File

@@ -30,6 +30,7 @@
#include <openspace/rendering/renderer.h>
#include <openspace/rendering/abufferrenderer.h>
#include <openspace/rendering/framebufferrenderer.h>
#include <openspace/engine/wrapper/windowwrapper.h>
namespace openspace {
ScreenSpaceFramebuffer::ScreenSpaceFramebuffer(const ghoul::Dictionary& dictionary)

View File

@@ -1,74 +1,80 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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-2016 *
* *
* 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 <modules/base/rendering/screenspaceimage.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/rendering/renderengine.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/filesystem/filesystem>
#include <modules/onscreengui/include/gui.h>
namespace {
const std::string _loggerCat = "ScreenSpaceImage";
const std::string KeyName = "Name";
const std::string KeyTexturePath = "TexturePath";
const std::string KeyUrl = "URL";
}
namespace openspace {
ScreenSpaceImage::ScreenSpaceImage(const ghoul::Dictionary& dictionary)
:ScreenSpaceRenderable(dictionary)
,_texturePath("texturePath", "Texture path", "")
,_downloadImage(false)
: ScreenSpaceRenderable(dictionary)
, _texturePath("texturePath", "Texture path", "")
, _downloadImage(false)
{
std::string name;
if(dictionary.getValue("Name", name)){
if (dictionary.getValue(KeyName, name)) {
setName(name);
}else{
_id = id();
setName("ScreenSpaceImage" + std::to_string(_id));
} else {
static int id = 0;
setName("ScreenSpaceImage " + std::to_string(id));
++id;
}
addProperty(_texturePath);
registerProperties();
std::string texturePath;
bool texturesucces = (dictionary.getValue("TexturePath", texturePath));
if(texturesucces){
_texturePath.set(texturePath);
if (dictionary.getValue(KeyTexturePath, texturePath)) {
_texturePath = texturePath;
OsEng.gui()._screenSpaceProperty.registerProperty(&_texturePath);
_texturePath.onChange([this](){ loadTexture(); });
}
bool urlsucces = dictionary.getValue("URL", _url);
if(urlsucces){
_downloadImage =true;
if (dictionary.getValue(KeyUrl, _url)) {
_downloadImage = true;
}
//screenspaceCygnet does not have url or texturePath
// if(!texturesucces && !urlsucces){
// LERROR("Must specify TexturePath or URL");
// }
}
ScreenSpaceImage::~ScreenSpaceImage(){}
ScreenSpaceImage::~ScreenSpaceImage() {}
bool ScreenSpaceImage::initialize(){
bool ScreenSpaceImage::initialize() {
_originalViewportSize = OsEng.windowWrapper().currentWindowResolution();
createPlane();
@@ -78,7 +84,7 @@ bool ScreenSpaceImage::initialize(){
return isReady();
}
bool ScreenSpaceImage::deinitialize(){
bool ScreenSpaceImage::deinitialize() {
unregisterProperties();
glDeleteVertexArrays(1, &_quad);
@@ -90,47 +96,32 @@ bool ScreenSpaceImage::deinitialize(){
_texturePath = "";
_texture = nullptr;
RenderEngine& renderEngine = OsEng.renderEngine();
if (_shader) {
renderEngine.removeRenderProgram(_shader);
OsEng.renderEngine().removeRenderProgram(_shader);
_shader = nullptr;
}
return true;
}
void ScreenSpaceImage::render(){
if(!isReady()) return;
if(!_enabled) return;
glm::mat4 rotation = rotationMatrix();
glm::mat4 translation = translationMatrix();
glm::mat4 scale = scaleMatrix();
glm::mat4 modelTransform = rotation*translation*scale;
draw(modelTransform);
void ScreenSpaceImage::render() {
draw(rotationMatrix() * translationMatrix() * scaleMatrix());
}
void ScreenSpaceImage::update(){
if(_downloadImage && _futureImage.valid() && DownloadManager::futureReady(_futureImage)){
void ScreenSpaceImage::update() {
bool futureReady = DownloadManager::futureReady(_futureImage);
if (_downloadImage && _futureImage.valid() && futureReady) {
loadTexture();
}
}
bool ScreenSpaceImage::isReady() const{
bool ready = true;
if (!_shader)
ready &= false;
if(!_texture)
ready &= false;
return ready;
bool ScreenSpaceImage::isReady() const {
return _shader && _texture;
}
void ScreenSpaceImage::loadTexture() {
std::unique_ptr<ghoul::opengl::Texture> texture = nullptr;
if(!_downloadImage)
if (!_downloadImage)
texture = std::move(loadFromDisk());
else
texture = std::move(loadFromMemory());
@@ -146,56 +137,54 @@ void ScreenSpaceImage::loadTexture() {
}
}
void ScreenSpaceImage::updateTexture(){
if(!_downloadImage){
void ScreenSpaceImage::updateTexture() {
if (!_downloadImage) {
loadTexture();
} else {
if(_futureImage.valid())
if (_futureImage.valid())
return;
std::future<DownloadManager::MemoryFile> future = downloadImageToMemory(_url);
if(future.valid()){
if (future.valid()) {
_futureImage = std::move(future);
}
}
}
std::unique_ptr<ghoul::opengl::Texture> ScreenSpaceImage::loadFromDisk(){
std::unique_ptr<ghoul::opengl::Texture> ScreenSpaceImage::loadFromDisk() {
if (_texturePath.value() != "")
return (ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath.value())));
return nullptr;
}
std::unique_ptr<ghoul::opengl::Texture> ScreenSpaceImage::loadFromMemory(){
if(_futureImage.valid() && DownloadManager::futureReady(_futureImage) ){
std::unique_ptr<ghoul::opengl::Texture> ScreenSpaceImage::loadFromMemory() {
if (_futureImage.valid() && DownloadManager::futureReady(_futureImage)) {
DownloadManager::MemoryFile imageFile = _futureImage.get();
if(imageFile.corrupted)
if (imageFile.corrupted)
return nullptr;
return (ghoul::io::TextureReader::ref().loadTexture(
(void*) imageFile.buffer,
reinterpret_cast<void*>(imageFile.buffer),
imageFile.size,
imageFile.format));
imageFile.format)
);
}
}
std::future<DownloadManager::MemoryFile> ScreenSpaceImage::downloadImageToMemory(std::string url){
return std::move( DlManager.fetchFile(
url,
[url](const DownloadManager::MemoryFile& file){
LDEBUG("Download to memory finished for screen space image");
},
[url](const std::string& err){
LDEBUG("Download to memory failer for screen space image: " +err);
}
) );
std::future<DownloadManager::MemoryFile> ScreenSpaceImage::downloadImageToMemory(
std::string url)
{
return std::move(DlManager.fetchFile(
url,
[url](const DownloadManager::MemoryFile& file) {
LDEBUG("Download to memory finished for screen space image");
},
[url](const std::string& err) {
LDEBUG("Download to memory failer for screen space image: " +err);
}
));
}
int ScreenSpaceImage::id(){
static int id = 0;
return id++;
}
}
} // namespace openspace

View File

@@ -21,55 +21,46 @@
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __SCREENSPACEIMAGE_H__
#define __SCREENSPACEIMAGE_H__
#include <openspace/rendering/screenspacerenderable.h>
#include <ghoul/opengl/texture.h>
#include <openspace/engine/downloadmanager.h>
#include <openspace/engine/downloadmanager.h>
#include <openspace/properties/stringproperty.h>
#include <ghoul/opengl/texture.h>
namespace openspace {
/**
* @brief Creates a textured plane rendered in screenspace
* @details The plane gets the same ratio as the texture. Implements
* the interface that ScreenSpaceImage speciefies.
*
* @param texturePath Path to the image that should be used as texture
*/
class ScreenSpaceImage : public ScreenSpaceRenderable {
class ScreenSpaceImage : public ScreenSpaceRenderable {
public:
ScreenSpaceImage(std::string texturePath);
ScreenSpaceImage(const ghoul::Dictionary& dictionary);
~ScreenSpaceImage();
bool initialize() override;
bool deinitialize() override;
void render() override;
virtual void update() override;
void update() override;
bool isReady() const override;
protected:
void loadTexture();
void updateTexture();
std::string _url;
bool _downloadImage;
std::future<DownloadManager::MemoryFile> _futureImage;
void loadTexture();
void updateTexture();
private:
static int id();
std::future<DownloadManager::MemoryFile> downloadImageToMemory(std::string url);
std::unique_ptr<ghoul::opengl::Texture> loadFromDisk();
std::unique_ptr<ghoul::opengl::Texture> loadFromMemory();
properties::StringProperty _texturePath;
//std::string _memorybuffer;
int _id;
};
} //namespace openspace
#endif //__SCREENSPACEIMAGE_H__
#endif //__SCREENSPACEIMAGE_H__

View File

@@ -39,7 +39,7 @@ Fragment getFragment(){
// power scale coordinates for depth. w value is set to 1.0.
float depth = (1.0 + log(abs(OcclusionDepth) + 1/pow(k, 1.0))/log(k)) / 27.0;
frag.color = texture(texture1, vec2(vs_st.s, 1-vs_st.t));
frag.color = texture(texture1, vec2(vs_st.s, vs_st.t));
frag.color.a = (frag.color.a != 0.0f) ? Alpha : frag.color.a;
if(frag.color.a == 0.0f){
discard;

View File

@@ -65,10 +65,10 @@ set(SOURCE_FILES
source_group("Source Files" FILES ${SOURCE_FILES})
set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/cygnetplane_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/cygnetplane_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/textureplane_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/textureplane_vs.glsl
)
source_group("Shader Files" FILES ${SHADER_FILES})

View File

@@ -1,3 +1,3 @@
set (OPENSPACE_DEPENDENCIES
base
base kameleon
)

View File

@@ -24,6 +24,8 @@
#include <modules/iswa/rendering/dataplane.h>
#include <modules/iswa/util/dataprocessortext.h>
#include <modules/onscreengui/include/gui.h>
namespace {
const std::string _loggerCat = "DataPlane";
}

View File

@@ -26,6 +26,13 @@
#include <openspace/util/powerscaledsphere.h>
#include <modules/iswa/util/dataprocessorjson.h>
#include <modules/onscreengui/include/gui.h>
#ifdef WIN32
#define _USE_MATH_DEFINES
#include <math.h>
#endif
namespace {
const std::string _loggerCat = "DataSphere";
}

View File

@@ -34,6 +34,7 @@
#include <modules/iswa/rendering/datasphere.h>
#include <modules/iswa/rendering/kameleonplane.h>
#include <modules/onscreengui/include/gui.h>
namespace {
const std::string _loggerCat = "IswaBaseGroup";

View File

@@ -27,6 +27,7 @@
#include <openspace/util/time.h>
#include <openspace/util/transformationmanager.h>
#include <modules/iswa/rendering/iswabasegroup.h>
#include <modules/onscreengui/include/gui.h>
namespace {

View File

@@ -34,6 +34,8 @@
#include <modules/iswa/rendering/datasphere.h>
#include <modules/iswa/rendering/kameleonplane.h>
#include <modules/onscreengui/include/gui.h>
namespace {
const std::string _loggerCat = "IswaDataGroup";
using json = nlohmann::json;

View File

@@ -33,6 +33,7 @@
#include <modules/iswa/rendering/dataplane.h>
#include <modules/iswa/rendering/datasphere.h>
#include <modules/iswa/rendering/kameleonplane.h>
#include <modules/onscreengui/include/gui.h>
namespace {
const std::string _loggerCat = "IswaDataGroup";

View File

@@ -30,6 +30,8 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/scene/scene.h>
#include <modules/onscreengui/include/gui.h>
namespace {
using json = nlohmann::json;
const std::string _loggerCat = "KameleonPlane";

View File

@@ -27,6 +27,7 @@
#include <ghoul/filesystem/filesystem>
#include <openspace/util/time.h>
#include <modules/iswa/util/iswamanager.h>
#include <openspace/engine/openspaceengine.h>
namespace {
const std::string _loggerCat = "ScreenSpaceCygnet";

View File

@@ -24,13 +24,13 @@
#include <modules/iswa/util/dataprocessortext.h>
#include <algorithm>
#include <iterator>
#include <boost/iostreams/device/mapped_file.hpp>
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
//#include <boost/iostreams/device/mapped_file.hpp>
//
//#include <boost/config/warning_disable.hpp>
//#include <boost/spirit/include/qi.hpp>
//#include <boost/spirit/include/phoenix_core.hpp>
//#include <boost/spirit/include/phoenix_operator.hpp>
//#include <boost/spirit/include/phoenix_stl.hpp>
namespace {
const std::string _loggerCat = "DataProcessorText";

View File

@@ -24,6 +24,7 @@
#include <modules/newhorizons/rendering/renderablemodelprojection.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/spicemanager.h>

View File

@@ -26,6 +26,7 @@
#include <modules/base/rendering/planetgeometry.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/factorymanager.h>
@@ -36,6 +37,11 @@
#include <ghoul/opengl/textureconversion.h>
#include <ghoul/opengl/textureunit.h>
#ifdef WIN32
#define _USE_MATH_DEFINES
#include <math.h>
#endif
namespace {
const std::string _loggerCat = "RenderablePlanetProjection";

View File

@@ -115,6 +115,10 @@ bool SGCTWindowWrapper::isRegularRendering() const {
glm::mat4 SGCTWindowWrapper::viewProjectionMatrix() const {
return sgct::Engine::instance()->getCurrentModelViewProjectionMatrix();
}
glm::mat4 SGCTWindowWrapper::modelMatrix() const {
return sgct::Engine::instance()->getModelMatrix();
}
void SGCTWindowWrapper::setNearFarClippingPlane(float nearPlane, float farPlane) {
sgct::Engine::instance()->setNearAndFarClippingPlanes(nearPlane, farPlane);

View File

@@ -75,6 +75,10 @@ bool WindowWrapper::isRegularRendering() const {
glm::mat4 WindowWrapper::viewProjectionMatrix() const {
return glm::mat4(1.f);
}
glm::mat4 WindowWrapper::modelMatrix() const {
return glm::mat4(1.f);
}
void WindowWrapper::setNearFarClippingPlane(float near, float far) {}

View File

@@ -407,7 +407,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
}
for (auto screenSpaceRenderable : _screenSpaceRenderables) {
if(screenSpaceRenderable->isEnabled())
if (screenSpaceRenderable->isEnabled() && screenSpaceRenderable->isReady())
screenSpaceRenderable->render();
}
}
@@ -1482,11 +1482,14 @@ void RenderEngine::renderScreenLog() {
}
}
void RenderEngine::sortScreenspaceRenderables(){
std::sort(_screenSpaceRenderables.begin(), _screenSpaceRenderables.end(),
[](std::shared_ptr<ScreenSpaceRenderable> j, std::shared_ptr<ScreenSpaceRenderable> i){
return i->depth() > j->depth();
});
void RenderEngine::sortScreenspaceRenderables() {
std::sort(
_screenSpaceRenderables.begin(),
_screenSpaceRenderables.end(),
[](auto j, auto i) {
return i->depth() > j->depth();
}
);
}
}// namespace openspace

View File

@@ -21,20 +21,40 @@
* 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/engine/openspaceengine.h>
#include <openspace/rendering/screenspacerenderable.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/camera.h>
#include <openspace/util/factorymanager.h>
#include <sgct.h>
#include <modules/onscreengui/include/gui.h>
#ifdef WIN32
#define _USE_MATH_DEFINES
#include <math.h>
#endif
namespace {
const std::string _loggerCat = "ScreenSpaceRenderable";
const std::string KeyType = "Type";
const std::string KeyFlatScreen = "FlatScreen";
const std::string KeyPosition = "Position";
const std::string KeyScale = "Scale";
const std::string KeyDepth = "Depth";
const std::string KeyAlpha = "Alpha";
const float PlaneDepth = -2.f;
}
namespace openspace {
ScreenSpaceRenderable* ScreenSpaceRenderable::createFromDictionary(const ghoul::Dictionary& dictionary) {
ScreenSpaceRenderable* ScreenSpaceRenderable::createFromDictionary(
const ghoul::Dictionary& dictionary)
{
std::string renderableType;
bool success = dictionary.getValue(KeyType, renderableType);
@@ -43,11 +63,12 @@ ScreenSpaceRenderable* ScreenSpaceRenderable::createFromDictionary(const ghoul::
return nullptr;
}
ghoul::TemplateFactory<ScreenSpaceRenderable>* factory
= FactoryManager::ref().factory<ScreenSpaceRenderable>();
auto factory = FactoryManager::ref().factory<ScreenSpaceRenderable>();
ScreenSpaceRenderable* result = factory->create(renderableType, dictionary);
if (result == nullptr) {
LERROR("Failed to create a ScreenSpaceRenderable object of type '" << renderableType << "'");
LERROR("Failed to create a ScreenSpaceRenderable object of type '" <<
renderableType << "'"
);
return nullptr;
}
@@ -56,150 +77,167 @@ ScreenSpaceRenderable* ScreenSpaceRenderable::createFromDictionary(const ghoul::
ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary)
:_enabled("enabled", "Is Enabled", true)
,_useFlatScreen("flatScreen", "Flat Screen", true)
,_euclideanPosition("euclideanPosition", "Euclidean coordinates", glm::vec2(0),glm::vec2(-4),glm::vec2(4))
,_sphericalPosition("sphericalPosition", "Spherical coordinates", glm::vec2(0, M_PI_2),glm::vec2(-M_PI),glm::vec2(M_PI))
,_depth("depth", "Depth", 0, 0, 1)
,_scale("scale", "Scale" , 0.25, 0, 2)
,_alpha("alpha", "Alpha" , 1, 0, 1)
,_delete("delete", "Delete")
,_quad(0)
,_vertexPositionBuffer(0)
,_rendererPath("${SHADERS}/framebuffer/renderframebuffer.frag")
,_vertexPath("${MODULE_BASE}/shaders/screnspace_vs.glsl")
,_fragmentPath("${MODULE_BASE}/shaders/screnspace_fs.glsl")
,_texture(nullptr)
,_shader(nullptr)
: _enabled("enabled", "Is Enabled", true)
, _useFlatScreen("flatScreen", "Flat Screen", true)
, _euclideanPosition(
"euclideanPosition",
"Euclidean coordinates",
glm::vec2(0.f),
glm::vec2(-4.f),
glm::vec2(4.f)
)
, _sphericalPosition(
"sphericalPosition",
"Spherical coordinates",
glm::vec2(0.f, M_PI_2),
glm::vec2(-M_PI),
glm::vec2(M_PI)
)
, _depth("depth", "Depth", 0.f, 0.f, 1.f)
, _scale("scale", "Scale", 0.25f, 0.f, 2.f)
, _alpha("alpha", "Alpha", 1.f, 0.f, 1.f)
, _delete("delete", "Delete")
, _quad(0)
, _vertexPositionBuffer(0)
, _texture(nullptr)
, _shader(nullptr)
, _radius(PlaneDepth)
{
addProperty(_enabled);
addProperty(_useFlatScreen);
addProperty(_euclideanPosition);
addProperty(_sphericalPosition);
addProperty(_depth);
addProperty(_scale);
addProperty(_alpha);
addProperty(_delete);
_rendererData = ghoul::Dictionary();
_rendererData.setValue("fragmentRendererPath", _rendererPath);
_rendererData.setValue("windowWidth", OsEng.windowWrapper().currentWindowResolution().x);
_rendererData.setValue("windowHeight", OsEng.windowWrapper().currentWindowResolution().y);
_radius = _planeDepth;
if(dictionary.hasValue<bool>("FlatScreen")){
bool useFlatScreen;
dictionary.getValue("FlatScreen", useFlatScreen);
_useFlatScreen.setValue(useFlatScreen);
}
useEuclideanCoordinates(_useFlatScreen.value());
dictionary.getValue(KeyFlatScreen, _useFlatScreen);
useEuclideanCoordinates(_useFlatScreen);
if(dictionary.hasValue<glm::vec2>("Position")){
glm::vec2 pos;
dictionary.getValue("Position", pos);
if(_useFlatScreen)
_euclideanPosition.setValue(pos);
else
_sphericalPosition.setValue(pos);
}
if (_useFlatScreen)
dictionary.getValue(KeyPosition, _euclideanPosition);
else
dictionary.getValue(KeyPosition, _sphericalPosition);
if(dictionary.hasValue<float>("Scale")){
float scale;
dictionary.getValue("Scale", scale);
_scale.setValue(scale);
}
if(dictionary.hasValue<float>("Depth")){
float depth;
dictionary.getValue("Depth", depth);
_depth.setValue(depth);
}
if(dictionary.hasValue<float>("Alpha")){
float alpha;
dictionary.getValue("Scale", alpha);
_alpha.setValue(alpha);
}
dictionary.getValue(KeyScale, _scale);
dictionary.getValue(KeyDepth, _depth);
dictionary.getValue(KeyAlpha, _alpha);
// Setting spherical/euclidean onchange handler
_useFlatScreen.onChange([this](){
if(_useFlatScreen.value()){
OsEng.gui()._screenSpaceProperty.registerProperty(&_euclideanPosition, &_useFlatScreen);
if (_useFlatScreen) {
OsEng.gui()._screenSpaceProperty.registerProperty(
&_euclideanPosition,
&_useFlatScreen
);
addProperty(_euclideanPosition);
OsEng.gui()._screenSpaceProperty.unregisterProperty(&_sphericalPosition);
removeProperty(_sphericalPosition);
} else {
OsEng.gui()._screenSpaceProperty.unregisterProperty(&_euclideanPosition);
OsEng.gui()._screenSpaceProperty.registerProperty(&_sphericalPosition, &_useFlatScreen);
removeProperty(_euclideanPosition);
OsEng.gui()._screenSpaceProperty.registerProperty(
&_sphericalPosition,
&_useFlatScreen
);
addProperty(_sphericalPosition);
}
useEuclideanCoordinates(_useFlatScreen.value());
useEuclideanCoordinates(_useFlatScreen);
});
_delete.onChange([this](){
std::string script = "openspace.unregisterScreenSpaceRenderable('" + name() + "');";
std::string script =
"openspace.unregisterScreenSpaceRenderable('" + name() + "');";
OsEng.scriptEngine().queueScript(script);
});
}
ScreenSpaceRenderable::~ScreenSpaceRenderable(){}
ScreenSpaceRenderable::~ScreenSpaceRenderable() {}
bool ScreenSpaceRenderable::isEnabled() const {
return _enabled;
}
glm::vec3 ScreenSpaceRenderable::euclideanPosition() const {
return glm::vec3(_euclideanPosition.value(), _depth.value());
}
glm::vec3 ScreenSpaceRenderable::sphericalPosition() const {
return glm::vec3(_sphericalPosition.value(), _depth.value());
}
float ScreenSpaceRenderable::depth() const {
return _depth;
}
void ScreenSpaceRenderable::createPlane() {
glGenVertexArrays(1, &_quad); // generate array
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
glGenVertexArrays(1, &_quad);
glGenBuffers(1, &_vertexPositionBuffer);
// ============================
// GEOMETRY (quad)
// ============================
const GLfloat vertex_data[] = { // square of two triangles (sigh)
const GLfloat vertex_data[] = {
// x y z w s t
-1, -1, 0.0f, 1, 0, 1,
1, 1, 0.0f, 1, 1, 0,
-1, 1, 0.0f, 1, 0, 0,
-1, -1, 0.0f, 1, 0, 1,
1, -1, 0.0f, 1, 1, 1,
1, 1, 0.0f, 1, 1, 0,
-1, -1, 0.0f, 1, 0, 0,
1, 1, 0.0f, 1, 1, 1,
-1, 1, 0.0f, 1, 0, 1,
-1, -1, 0.0f, 1, 0, 0,
1, -1, 0.0f, 1, 1, 0,
1, 1, 0.0f, 1, 1, 1,
};
glBindVertexArray(_quad); // bind array
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
glBindVertexArray(_quad);
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
glVertexAttribPointer(
0,
4,
GL_FLOAT,
GL_FALSE,
sizeof(GLfloat) * 6,
reinterpret_cast<void*>(0)
);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
glVertexAttribPointer(
1,
2,
GL_FLOAT,
GL_FALSE,
sizeof(GLfloat) * 6,
reinterpret_cast<void*>(sizeof(GLfloat) * 4)
);
}
void ScreenSpaceRenderable::useEuclideanCoordinates(bool b){
void ScreenSpaceRenderable::useEuclideanCoordinates(bool b) {
_useEuclideanCoordinates = b;
if(_useEuclideanCoordinates){
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
if (_useEuclideanCoordinates) {
_euclideanPosition = toEuclidean(_sphericalPosition.value(), _radius);
} else {
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
_sphericalPosition = toSpherical(_euclideanPosition.value());
}
}
glm::vec2 ScreenSpaceRenderable::toEuclidean(glm::vec2 polar, float r){
float x = r*sin(polar[0])*sin(polar[1]);
float y = r*cos(polar[1]);
glm::vec2 ScreenSpaceRenderable::toEuclidean(const glm::vec2& spherical, float r) {
float x = r * sin(spherical[0]) * sin(spherical[1]);
float y = r * cos(spherical[1]);
return glm::vec2(x, y);
}
glm::vec2 ScreenSpaceRenderable::toSpherical(glm::vec2 euclidean){
_radius = -sqrt(pow(euclidean[0],2)+pow(euclidean[1],2)+pow(_planeDepth,2));
float theta = atan2(-_planeDepth,euclidean[0])-M_PI/2.0;
glm::vec2 ScreenSpaceRenderable::toSpherical(const glm::vec2& euclidean) {
_radius = -sqrt(pow(euclidean[0],2)+pow(euclidean[1],2)+pow(PlaneDepth,2));
float theta = atan2(-PlaneDepth,euclidean[0])-M_PI/2.0;
float phi = acos(euclidean[1]/_radius);
return glm::vec2(theta, phi);
}
void ScreenSpaceRenderable::registerProperties(){
void ScreenSpaceRenderable::registerProperties() {
OsEng.gui()._screenSpaceProperty.registerProperty(&_enabled);
OsEng.gui()._screenSpaceProperty.registerProperty(&_useFlatScreen);
OsEng.gui()._screenSpaceProperty.registerProperty(&_euclideanPosition);
@@ -209,80 +247,98 @@ void ScreenSpaceRenderable::registerProperties(){
OsEng.gui()._screenSpaceProperty.registerProperty(&_delete);
}
void ScreenSpaceRenderable::unregisterProperties(){
void ScreenSpaceRenderable::unregisterProperties() {
OsEng.gui()._screenSpaceProperty.unregisterProperties(name());
}
void ScreenSpaceRenderable::createShaders(){
if(!_shader) {
void ScreenSpaceRenderable::createShaders() {
if (!_shader) {
ghoul::Dictionary dict = ghoul::Dictionary();
dict.setValue("rendererData", _rendererData);
dict.setValue("fragmentPath", _fragmentPath);
_shader = ghoul::opengl::ProgramObject::Build("ScreenSpaceProgram",
_vertexPath,
auto res = OsEng.windowWrapper().currentWindowResolution();
ghoul::Dictionary rendererData = {
{ "fragmentRendererPath", "${SHADERS}/framebuffer/renderframebuffer.frag" },
{ "windowWidth" , res.x },
{ "windowHeight" , res.y }
};
dict.setValue("rendererData", rendererData);
dict.setValue("fragmentPath", "${MODULE_BASE}/shaders/screenspace_fs.glsl");
_shader = ghoul::opengl::ProgramObject::Build(
"ScreenSpaceProgram",
"${MODULE_BASE}/shaders/screenspace_vs.glsl",
"${SHADERS}/render.frag",
dict
);
);
}
}
glm::mat4 ScreenSpaceRenderable::scaleMatrix(){
glm::mat4 scale(1.0);
glm::mat4 ScreenSpaceRenderable::scaleMatrix() {
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
//to scale the plane
float textureRatio = (float(_texture->height())/float(_texture->width()));
float scalingRatioX = _originalViewportSize[0]/ resolution[0];
float scalingRatioY = _originalViewportSize[1]/ resolution[1];
scale = glm::scale(scale, glm::vec3(_scale.value() * scalingRatioX,
_scale.value() * scalingRatioY * textureRatio,
1));
return scale;
float textureRatio =
static_cast<float>(_texture->height()) / static_cast<float>(_texture->width());
float scalingRatioX = _originalViewportSize.x / resolution.x;
float scalingRatioY = _originalViewportSize.y / resolution.y;
return glm::scale(
glm::mat4(1.f),
glm::vec3(
_scale * scalingRatioX,
_scale * scalingRatioY * textureRatio,
1.f
)
);
}
glm::mat4 ScreenSpaceRenderable::rotationMatrix(){
glm::mat4 ScreenSpaceRenderable::rotationMatrix() {
// Get the scene transform
glm::mat4 rotation = sgct::Engine::instance()->getModelMatrix();
if(!_useEuclideanCoordinates){
glm::mat4 rotation = OsEng.windowWrapper().modelMatrix();
if (!_useEuclideanCoordinates) {
glm::vec2 position = _sphericalPosition.value();
float theta = position.x;
float phi = position.y - M_PI/2.0;
float phi = position.y - M_PI_2;
rotation = glm::rotate(rotation, position.x, glm::vec3(0.0f, 1.0f, 0.0f));
rotation = glm::rotate(rotation, (float) (position.y - M_PI/2.0) , glm::vec3(1.0f, 0.0f, 0.0f));
rotation = glm::rotate(rotation, position.x, glm::vec3(0.f, 1.f, 0.f));
rotation = glm::rotate(
rotation,
static_cast<float>(position.y - M_PI_2),
glm::vec3(1.f, 0.f, 0.f)
);
}
return rotation;
}
glm::mat4 ScreenSpaceRenderable::translationMatrix(){
glm::mat4 ScreenSpaceRenderable::translationMatrix() {
glm::mat4 translation(1.0);
if(!_useEuclideanCoordinates){
translation = glm::translate(translation, glm::vec3(0.0f, 0.0f, _planeDepth));
}else{
translation = glm::translate(glm::mat4(1.f), glm::vec3(_euclideanPosition.value(), _planeDepth));
if (!_useEuclideanCoordinates) {
translation = glm::translate(translation, glm::vec3(0.0f, 0.0f, PlaneDepth));
} else {
translation = glm::translate(
glm::mat4(1.f),
glm::vec3(_euclideanPosition.value(), PlaneDepth)
);
}
return translation;
}
void ScreenSpaceRenderable::draw(glm::mat4 modelTransform){
float occlusionDepth = 1-_depth.value();
void ScreenSpaceRenderable::draw(glm::mat4 modelTransform) {
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
_shader->activate();
_shader->setUniform("OcclusionDepth", occlusionDepth);
_shader->setUniform("OcclusionDepth", 1.f - _depth);
_shader->setUniform("Alpha", _alpha);
_shader->setUniform("ModelTransform",modelTransform);
_shader->setUniform("ViewProjectionMatrix", OsEng.renderEngine().camera()->viewProjectionMatrix());
_shader->setUniform("ModelTransform", modelTransform);
_shader->setUniform(
"ViewProjectionMatrix",
OsEng.renderEngine().camera()->viewProjectionMatrix()
);
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();
@@ -290,8 +346,10 @@ void ScreenSpaceRenderable::draw(glm::mat4 modelTransform){
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable(GL_CULL_FACE);
_shader->deactivate();
}
}// namespace openspace
} // namespace openspace

View File

@@ -54,6 +54,7 @@
std::string to,
double ephemerisTime) const
{
#ifdef OPENSPACE_MODULE_KAMELEON_ENABLED
ccmc::Position in0 = {1.f, 0.f, 0.f};
ccmc::Position in1 = {0.f, 1.f, 0.f};
ccmc::Position in2 = {0.f, 0.f, 1.f};
@@ -70,7 +71,10 @@
out0.c0 , out0.c1 , out0.c2,
out1.c0 , out1.c1 , out1.c2,
out2.c0 , out2.c1 , out2.c2
);;
);
#else
return glm::dmat3(0.0);
#endif
}
glm::dmat3 TransformationManager::frameTransformationMatrix(std::string from,