diff --git a/data/scene/earth/earth.mod b/data/scene/earth/earth.mod index 987ed1f0be..487891577a 100644 --- a/data/scene/earth/earth.mod +++ b/data/scene/earth/earth.mod @@ -86,6 +86,17 @@ return { Type = "Static", Position = {0, 0, 0, 5} } + }, + { + Name = "EarthPlane", + Parent = "Earth", + Renderable = { + Type = "RenderableDataPlane" + }, + Ephemeris = { + Type = "Static", + Position = {10, 0, 0, 1} + } } -- Plane -- { diff --git a/data/test.png b/data/test.png new file mode 100644 index 0000000000..a67058ce50 Binary files /dev/null and b/data/test.png differ diff --git a/ext/ghoul b/ext/ghoul index a9b5025618..ae36394e9c 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit a9b5025618ecd83353c923c81a31b305d509dbb1 +Subproject commit ae36394e9c12ae302d88931ff6963998125f94cc diff --git a/modules/datasurface/CMakeLists.txt b/modules/datasurface/CMakeLists.txt index bf479df2d0..ff9ea8694d 100644 --- a/modules/datasurface/CMakeLists.txt +++ b/modules/datasurface/CMakeLists.txt @@ -36,8 +36,10 @@ set(SOURCE_FILES source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES - + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_vs.glsl ) + source_group("Shader Files" FILES ${SHADER_FILES}) create_new_module( diff --git a/modules/datasurface/rendering/renderabledataplane.cpp b/modules/datasurface/rendering/renderabledataplane.cpp index 1b4a9c0de7..baaf6bfe8c 100644 --- a/modules/datasurface/rendering/renderabledataplane.cpp +++ b/modules/datasurface/rendering/renderabledataplane.cpp @@ -23,22 +23,162 @@ ****************************************************************************************/ #include +#include +#include +#include +#include +#include +#include +#include +#include + namespace openspace { -RenderableDataPlane::RenderableDataPlane(const ghoul::Dictionary& dictionary) : - Renderable(dictionary) +RenderableDataPlane::RenderableDataPlane(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + ,_texturePath("texture", "Texture", "${OPENSPACE_DATA}/test.png") + ,_size("size", "Size", glm::vec2(0.7,8), glm::vec2(0.f), glm::vec2(10.0f)) + ,_roatation("rotation", "Roatation", glm::vec3(0.3,0.4,0.0), glm::vec3(0), glm::vec3(2*M_PI)) + ,_origin("origin", "Origin", glm::vec2(0.05, 0.001), glm::vec2(-0.1), glm::vec2(0.1)) + , _shader(nullptr) + , _texture(nullptr) + , _quad(0) + , _vertexPositionBuffer(0) { + addProperty(_size); + addProperty(_texturePath); + addProperty(_roatation); + addProperty(_origin); + _texturePath.onChange(std::bind(&RenderableDataPlane::loadTexture, this)); + _size.onChange([this](){ _planeIsDirty = true; }); + } RenderableDataPlane::~RenderableDataPlane(){ } -bool RenderableDataPlane::initialize() {}; -bool RenderableDataPlane::deinitialize() {}; +bool RenderableDataPlane::initialize() { + glGenVertexArrays(1, &_quad); // generate array + glGenBuffers(1, &_vertexPositionBuffer); // generate buffer + createPlane(); -bool RenderableDataPlane::isReady() const {}; + if (_shader == nullptr) { + // Plane Program -void RenderableDataPlane::render(const RenderData& data){}; -void RenderableDataPlane::update(const UpdateData& data){}; + RenderEngine& renderEngine = OsEng.renderEngine(); + _shader = renderEngine.buildRenderProgram("PlaneProgram", + "${MODULE_DATASURFACE}/shaders/dataplane_vs.glsl", + "${MODULE_DATASURFACE}/shaders/dataplane_fs.glsl" + ); + if (!_shader) + return false; + } + loadTexture(); + + return isReady(); +}; +bool RenderableDataPlane::deinitialize() { + glDeleteVertexArrays(1, &_quad); + _quad = 0; + + glDeleteBuffers(1, &_vertexPositionBuffer); + _vertexPositionBuffer = 0; + + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_shader) { + renderEngine.removeRenderProgram(_shader); + _shader = nullptr; + } + + return true; +}; + +bool RenderableDataPlane::isReady() const { + bool ready = true; + if (!_shader) + ready &= false; + if(!_texture) + ready &= false; + return ready; +}; + +void RenderableDataPlane::render(const RenderData& data) +{ + float w = (float)_texture->width(); + float h = (float)_texture->height(); + float textureRatio = h/w; + + glm::mat4 transform = glm::mat4(1.0); + transform = glm::scale(transform, glm::vec3(1.0, textureRatio, 1.0f)); + glm::mat4 translate = glm::translate(glm::mat4(1.0), glm::vec3(_origin.value()[0], _origin.value()[1], 0.0f)); + transform = glm::rotate(transform, _roatation.value()[0], glm::vec3(1,0,0)); + transform = glm::rotate(transform, _roatation.value()[1], glm::vec3(0,1,0)); + transform = glm::rotate(transform, _roatation.value()[2], glm::vec3(0,0,1)); + + // Activate shader + _shader->activate(); + + _shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); + _shader->setUniform("ModelTransform", transform); + _shader->setUniform("Translate", translate); + setPscUniforms(_shader.get(), &data.camera, data.position); + + ghoul::opengl::TextureUnit unit; + unit.activate(); + _texture->bind(); + _shader->setUniform("texture1", unit); + + glBindVertexArray(_quad); + glDrawArrays(GL_TRIANGLES, 0, 6); + + _shader->deactivate(); +}; +void RenderableDataPlane::update(const UpdateData& data){ + if (_planeIsDirty) + createPlane(); +}; + + +void RenderableDataPlane::loadTexture() { + if (_texturePath.value() != "") { + std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath)); + if (texture) { + std::cout << "texture path: " << absPath(_texturePath) << std::endl; + // LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'"); + texture->uploadTexture(); + + // Textures of planets looks much smoother with AnisotropicMipMap rather than linear + texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + + _texture = std::move(texture); + } + } +} + +void RenderableDataPlane::createPlane() { + // ============================ + // GEOMETRY (quad) + // ============================ + const GLfloat size = _size.value()[0]; + const GLfloat w = _size.value()[1]; + const GLfloat vertex_data[] = { // square of two triangles (sigh) + // x y z w s t + -size, -size, 0.0f, w, 0, 1, + size, size, 0.0f, w, 1, 0, + -size, size, 0.0f, w, 0, 0, + -size, -size, 0.0f, w, 0, 1, + size, -size, 0.0f, w, 1, 1, + size, size, 0.0f, w, 1, 0, + }; + + glBindVertexArray(_quad); // bind array + glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer + 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(0)); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); + _planeIsDirty = false; +} }// namespace openspace \ No newline at end of file diff --git a/modules/datasurface/rendering/renderabledataplane.h b/modules/datasurface/rendering/renderabledataplane.h index d7a438f194..68deeed237 100644 --- a/modules/datasurface/rendering/renderabledataplane.h +++ b/modules/datasurface/rendering/renderabledataplane.h @@ -1,31 +1,34 @@ /***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2015 * - * * - * 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-2015 * +* * +* 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 __RENDERABLEDATAPLANE_H__ - #define __RENDERABLEDATAPLANE_H__ +#ifndef __RENDERABLEDATAPLANE_H__ +#define __RENDERABLEDATAPLANE_H__ - #include +#include +#include +#include +#include namespace openspace{ @@ -43,7 +46,22 @@ virtual void update(const UpdateData& data) override; private: + void loadTexture(); + void createPlane(); + properties::StringProperty _texturePath; + properties::Vec2Property _size; + properties::Vec3Property _roatation; + properties::Vec2Property _origin; + // Origin _origin; + + std::unique_ptr _shader; + std::unique_ptr _texture; + + GLuint _quad; + GLuint _vertexPositionBuffer; + + bool _planeIsDirty; }; } // namespace openspace diff --git a/modules/datasurface/shaders/dataplane_fs.glsl b/modules/datasurface/shaders/dataplane_fs.glsl new file mode 100644 index 0000000000..1a90e669ac --- /dev/null +++ b/modules/datasurface/shaders/dataplane_fs.glsl @@ -0,0 +1,57 @@ +/***************************************************************************************** + * * + * 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. * + ****************************************************************************************/ + +uniform float time; +uniform sampler2D texture1; + +in vec2 vs_st; +in vec4 vs_position; + +#include "PowerScaling/powerScaling_fs.hglsl" +#include "fragment.glsl" + +Fragment getFragment() { + vec4 position = vs_position; + float depth = pscDepth(position); + vec4 diffuse; + if(gl_FrontFacing) + diffuse = texture(texture1, vs_st); + else + diffuse = texture(texture1, vec2(1-vs_st.s,vs_st.t)); + + //vec4 diffuse = vec4(1,vs_st,1); + //vec4 diffuse = vec4(1,0,0,1); + // if(position.w > 9.0) { + // diffuse = vec4(1,0,0,1); + // } + + if (diffuse.a == 0.0) + discard; + + Fragment frag; + frag.color = diffuse; + frag.depth = depth; + return frag; + +} diff --git a/modules/datasurface/shaders/dataplane_vs.glsl b/modules/datasurface/shaders/dataplane_vs.glsl new file mode 100644 index 0000000000..0cf739232b --- /dev/null +++ b/modules/datasurface/shaders/dataplane_vs.glsl @@ -0,0 +1,51 @@ +/***************************************************************************************** + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ + +uniform mat4 ViewProjection; +uniform mat4 ModelTransform; +uniform mat4 Translate; + +layout(location = 0) in vec4 in_position; +layout(location = 1) in vec2 in_st; + +out vec2 vs_st; +out vec4 vs_position; +out float s; + +#include "PowerScaling/powerScaling_vs.hglsl" + +void main() +{ + vec4 tmp = Translate*in_position; + + vec4 position = pscTransform(tmp, ModelTransform); + + vs_position = tmp; + vs_st = in_st; + + position = ViewProjection * position; + gl_Position = z_normalization(position); +} \ No newline at end of file diff --git a/openspace.cfg b/openspace.cfg index 811a824b90..3ff2a0f8cf 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -7,7 +7,7 @@ return { -- Sets the scene that is to be loaded by OpenSpace. A scene file is a description -- of all entities that will be visible during an instance of OpenSpace - Scene = "${SCENE}/default_nh.scene", + Scene = "${SCENE}/default.scene", Paths = { SGCT = "${BASE_PATH}/config/sgct", diff --git a/scripts/default_settings.lua b/scripts/default_settings.lua index edd1057278..ed7b120614 100644 --- a/scripts/default_settings.lua +++ b/scripts/default_settings.lua @@ -4,8 +4,8 @@ openspace.printInfo("Setting default values") openspace.setPropertyValue("Sun.renderable.enabled", false) -openspace.setPropertyValue("SunMarker.renderable.enabled", true) -openspace.setPropertyValue("EarthMarker.renderable.enabled", true) +openspace.setPropertyValue("SunMarker.renderable.enabled", false) +openspace.setPropertyValue("EarthMarker.renderable.enabled", false) --openspace.setPropertyValue("Constellation Bounds.renderable.enabled", false) openspace.setPropertyValue("PlutoTrail.renderable.enabled", false) openspace.setPropertyValue("PlutoTexture.renderable.enabled", false)