mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-27 06:19:51 -05:00
Cleanup of ScreenSpaceRenderable
Add missing includes to other files
This commit is contained in:
@@ -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__
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -25,6 +25,12 @@
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
#include <modules/onscreengui/include/gui.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "ScreenSpaceImage";
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <openspace/engine/downloadmanager.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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/screnspace_fs.glsl");
|
||||
_shader = ghoul::opengl::ProgramObject::Build(
|
||||
"ScreenSpaceProgram",
|
||||
"${MODULE_BASE}/shaders/screnspace_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
|
||||
|
||||
Reference in New Issue
Block a user