mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 18:51:17 -06:00
Added RenderablePlane
- Only first version of the RenderablePlane Todo: - Support rotation of planes - Support billboarding - Support different local origin (LowerLeft, LowerRight, Center...)
This commit is contained in:
70
include/openspace/rendering/renderableplane.h
Normal file
70
include/openspace/rendering/renderableplane.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 RENDERABLEPLANE_H_
|
||||
#define RENDERABLEPLANE_H_
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
struct LinePoint;
|
||||
|
||||
class RenderablePlane : public Renderable {
|
||||
|
||||
enum class Origin {
|
||||
LowerLeft, LowerRight, UpperLeft, UpperRight, Center
|
||||
};
|
||||
|
||||
public:
|
||||
RenderablePlane(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlane();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
private:
|
||||
void loadTexture();
|
||||
|
||||
properties::StringProperty _texturePath;
|
||||
|
||||
glm::vec2 _size;
|
||||
Origin _origin;
|
||||
|
||||
ghoul::opengl::ProgramObject* _shader;
|
||||
ghoul::opengl::Texture* _texture;
|
||||
GLuint _quad;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
#endif // RENDERABLEFIELDLINES_H_
|
||||
Submodule openspace-data updated: f11e50b102...1b18fedd39
57
shaders/plane_fs.glsl
Normal file
57
shaders/plane_fs.glsl
Normal file
@@ -0,0 +1,57 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 float time;
|
||||
uniform sampler2D texture1;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec4 vs_position;
|
||||
|
||||
#include "ABuffer/abufferStruct.hglsl"
|
||||
#include "ABuffer/abufferAddToBuffer.hglsl"
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
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);
|
||||
// }
|
||||
|
||||
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
|
||||
addToBuffer(frag);
|
||||
|
||||
discard;
|
||||
}
|
||||
49
shaders/plane_vs.glsl
Normal file
49
shaders/plane_vs.glsl
Normal file
@@ -0,0 +1,49 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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;
|
||||
|
||||
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 = in_position;
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
|
||||
vs_position = tmp;
|
||||
vs_st = in_st;
|
||||
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
}
|
||||
188
src/rendering/renderableplane.cpp
Normal file
188
src/rendering/renderableplane.cpp
Normal file
@@ -0,0 +1,188 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/renderableplane.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <ghoul/opengl/texturereader.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderablePlane";
|
||||
|
||||
const std::string keyFieldlines = "Fieldlines";
|
||||
const std::string keyFilename = "File";
|
||||
const std::string keyHints = "Hints";
|
||||
const std::string keyShaders = "Shaders";
|
||||
const std::string keyVertexShader = "VertexShader";
|
||||
const std::string keyFragmentShader = "FragmentShader";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _texturePath("texture", "Texture")
|
||||
, _size(glm::vec2(1,1))
|
||||
, _origin(Origin::Center)
|
||||
, _shader(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _quad(0)
|
||||
{
|
||||
|
||||
dictionary.getValue("Size", _size);
|
||||
|
||||
std::string origin;
|
||||
if (dictionary.getValue("Origin", origin)) {
|
||||
if (origin == "LowerLeft") {
|
||||
_origin = Origin::LowerLeft;
|
||||
}
|
||||
else if (origin == "LowerRight") {
|
||||
_origin = Origin::LowerRight;
|
||||
}
|
||||
else if (origin == "UpperLeft") {
|
||||
_origin = Origin::UpperLeft;
|
||||
}
|
||||
else if (origin == "UpperRight") {
|
||||
_origin = Origin::UpperRight;
|
||||
}
|
||||
else if (origin == "Center") {
|
||||
_origin = Origin::Center;
|
||||
}
|
||||
}
|
||||
|
||||
std::string texturePath = "";
|
||||
bool success = dictionary.getValue("Texture", texturePath);
|
||||
if (success)
|
||||
_texturePath = findPath(texturePath);
|
||||
|
||||
|
||||
addProperty(_texturePath);
|
||||
_texturePath.onChange(std::bind(&RenderablePlane::loadTexture, this));
|
||||
|
||||
setBoundingSphere(_size);
|
||||
}
|
||||
|
||||
RenderablePlane::~RenderablePlane() {
|
||||
}
|
||||
|
||||
bool RenderablePlane::initialize() {
|
||||
|
||||
// ============================
|
||||
// GEOMETRY (quad)
|
||||
// ============================
|
||||
const GLfloat size = _size[0];
|
||||
const GLfloat w = _size[1];
|
||||
LDEBUG("size:" << size);
|
||||
LDEBUG("w:" << w);
|
||||
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,
|
||||
};
|
||||
|
||||
GLuint vertexPositionBuffer;
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glBindVertexArray(_quad); // bind array
|
||||
glGenBuffers(1, &vertexPositionBuffer); // generate buffer
|
||||
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<void*>(0));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
|
||||
|
||||
OsEng.ref().configurationManager().getValue("PlaneProgram", _shader);
|
||||
assert(_shader);
|
||||
|
||||
loadTexture();
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderablePlane::deinitialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderablePlane::render(const RenderData& data) {
|
||||
|
||||
if (!_shader)
|
||||
return;
|
||||
if (!_texture)
|
||||
return;
|
||||
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
//transform = glm::scale(transform, glm::vec3(0.01));
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
|
||||
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(_shader, &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 RenderablePlane::update(const UpdateData& data) {
|
||||
}
|
||||
|
||||
void RenderablePlane::loadTexture()
|
||||
{
|
||||
LDEBUG("loadTexture");
|
||||
if (_texturePath.value() != "") {
|
||||
LDEBUG("loadTexture2");
|
||||
ghoul::opengl::Texture* texture = ghoul::opengl::loadTexture(absPath(_texturePath));
|
||||
if (texture) {
|
||||
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::AnisotropicMipMap);
|
||||
|
||||
if (_texture)
|
||||
delete _texture;
|
||||
_texture = texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -213,6 +213,15 @@ bool SceneGraph::initialize()
|
||||
_programs.push_back(tmpProgram);
|
||||
OsEng.ref().configurationManager().setValue("GridProgram", tmpProgram);
|
||||
|
||||
// Plane program
|
||||
tmpProgram = ProgramObject::Build("Plane",
|
||||
"${SHADERS}/plane_vs.glsl",
|
||||
"${SHADERS}/plane_fs.glsl",
|
||||
cb);
|
||||
if (!tmpProgram) return false;
|
||||
_programs.push_back(tmpProgram);
|
||||
OsEng.ref().configurationManager().setValue("PlaneProgram", tmpProgram);
|
||||
|
||||
// Done building shaders
|
||||
double elapsed = std::chrono::duration_cast<second_>(clock_::now()-beginning).count();
|
||||
LINFO("Time to load shaders: " << elapsed);
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <openspace/rendering/renderablefieldlines.h>
|
||||
#include <openspace/rendering/planets/renderableplanet.h>
|
||||
#include <openspace/rendering/renderablevolumeexpert.h>
|
||||
#include <openspace/rendering/renderablevolumecl.h>
|
||||
#include <openspace/rendering/renderableplane.h>
|
||||
#include <openspace/rendering/renderablevolumegl.h>
|
||||
#include <openspace/flare/flare.h>
|
||||
|
||||
@@ -62,8 +62,8 @@ void FactoryManager::initialize()
|
||||
"RenderableStars");
|
||||
_manager->factory<Renderable>()->registerClass<RenderableSphericalGrid>(
|
||||
"RenderableSphericalGrid");
|
||||
//_manager->factory<Renderable>()->registerClass<RenderableVolumeCL>(
|
||||
// "RenderableVolumeCL");
|
||||
_manager->factory<Renderable>()->registerClass<RenderablePlane>(
|
||||
"RenderablePlane");
|
||||
_manager->factory<Renderable>()->registerClass<RenderableVolumeGL>(
|
||||
"RenderableVolumeGL");
|
||||
_manager->factory<Renderable>()->registerClass<RenderableFieldlines>("RenderableFieldlines");
|
||||
|
||||
Reference in New Issue
Block a user