mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 12:39:24 -05:00
Merge branch 'feature/screenspaceimage' of github.com:OpenSpace/OpenSpace-Development into feature/screenspaceimage
Conflicts: include/openspace/rendering/screenspacerenderable.h modules/base/rendering/screenspaceimage.cpp src/rendering/screenspacerenderable.cpp
This commit is contained in:
@@ -38,6 +38,10 @@ ScreenSpaceImage::ScreenSpaceImage(std::string texturePath)
|
||||
,_texturePath("texturePath", "Texture path", texturePath)
|
||||
{
|
||||
addProperty(_texturePath);
|
||||
:ScreenSpaceRenderable(texturePath)
|
||||
, _vertexPath("${MODULE_BASE}/shaders/screnspace_vs.glsl")
|
||||
, _fragmentPath("${MODULE_BASE}/shaders/screnspace_fs.glsl")
|
||||
OsEng.gui()._property.registerProperty(&_useFlatScreen);
|
||||
|
||||
_id = id();
|
||||
setName("ScreenSpaceImage" + std::to_string(_id));
|
||||
@@ -67,15 +71,13 @@ ScreenSpaceImage::~ScreenSpaceImage(){}
|
||||
|
||||
|
||||
void ScreenSpaceImage::render(){
|
||||
GLfloat m_viewport[4];
|
||||
glGetFloatv(GL_VIEWPORT, m_viewport);
|
||||
|
||||
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
|
||||
//to scale the plane
|
||||
float textureRatio = (float(_texture->height())/float(_texture->width()));
|
||||
|
||||
//to keep the texture ratio after viewport is distorted.
|
||||
float scalingRatioX = m_viewport[2] / _originalViewportSize[0];
|
||||
float scalingRatioY = m_viewport[3] / _originalViewportSize[1];
|
||||
float scalingRatioX = resolution[0] / _originalViewportSize[0];
|
||||
float scalingRatioY = resolution[1] / _originalViewportSize[1];
|
||||
|
||||
glm::mat4 modelTransform;
|
||||
if(!_useEuclideanCoordinates){
|
||||
@@ -116,19 +118,29 @@ bool ScreenSpaceImage::initialize(){
|
||||
createPlane();
|
||||
|
||||
if(_shader == nullptr) {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_shader = renderEngine.buildRenderProgram("ScreenSpaceProgram",
|
||||
"${MODULE_BASE}/shaders/screnspace_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/screnspace_fs.glsl"
|
||||
);
|
||||
|
||||
ghoul::Dictionary dict = ghoul::Dictionary();
|
||||
|
||||
dict.setValue("rendererData", _rendererData);
|
||||
dict.setValue("fragmentPath", _fragmentPath);
|
||||
_shader = ghoul::opengl::ProgramObject::Build("ScreenSpaceProgram",
|
||||
_vertexPath,
|
||||
"${SHADERS}/render.frag",
|
||||
dict
|
||||
);
|
||||
|
||||
if (!_shader)
|
||||
return false;
|
||||
}
|
||||
GLfloat m_viewport[4];
|
||||
glGetFloatv(GL_VIEWPORT, m_viewport);
|
||||
_originalViewportSize = glm::vec2(m_viewport[2], m_viewport[3]);
|
||||
|
||||
_originalViewportSize = OsEng.windowWrapper().currentWindowResolution();
|
||||
|
||||
loadTexture();
|
||||
|
||||
// Setting spherical/euclidean onchange handler
|
||||
_useFlatScreen.onChange([this](){
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
});
|
||||
return isReady();
|
||||
}
|
||||
|
||||
@@ -152,24 +164,25 @@ bool ScreenSpaceImage::deinitialize(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ScreenSpaceImage::update(){
|
||||
if(_flatScreen.value() != _useEuclideanCoordinates){
|
||||
_useEuclideanCoordinates = _flatScreen.value();
|
||||
|
||||
}
|
||||
|
||||
if(_useEuclideanCoordinates){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
_euclideanPosition.onChange([this](){
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
});
|
||||
_sphericalPosition.onChange([this](){});
|
||||
} else {
|
||||
void ScreenSpaceImage::useEuclideanCoordinates(bool b){
|
||||
_useEuclideanCoordinates = b;
|
||||
if(_useEuclideanCoordinates){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
_euclideanPosition.onChange([this](){
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
_sphericalPosition.onChange([this](){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
});
|
||||
_euclideanPosition.onChange([this](){});
|
||||
}
|
||||
|
||||
});
|
||||
_sphericalPosition.onChange([this](){});
|
||||
} else {
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
_sphericalPosition.onChange([this](){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
});
|
||||
_euclideanPosition.onChange([this](){});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
bool deinitialize() override;
|
||||
void update() override;
|
||||
bool isReady() const override;
|
||||
void useEuclideanCoordinates(bool b);
|
||||
private:
|
||||
void loadTexture();
|
||||
static int id();
|
||||
@@ -47,6 +48,8 @@ private:
|
||||
properties::StringProperty _texturePath;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture; // The image to render
|
||||
int _id;
|
||||
const std::string _vertexPath;
|
||||
const std::string _fragmentPath;
|
||||
};
|
||||
|
||||
} //namespace openspace
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* 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 sampler2D texture1;
|
||||
uniform float OcclusionDepth;
|
||||
|
||||
@@ -40,4 +40,12 @@ Fragment getFragment(){
|
||||
frag.depth = depth;
|
||||
|
||||
return frag;
|
||||
}
|
||||
}
|
||||
|
||||
/* out vec4 _out_color_;
|
||||
|
||||
void main() {
|
||||
Fragment f = getFragment();
|
||||
_out_color_ = f.color;
|
||||
gl_FragDepth = f.depth;
|
||||
} */
|
||||
Reference in New Issue
Block a user