mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-13 15:31:17 -06:00
Merge branch 'thesis/2021/skybrowser' of https://github.com/OpenSpace/OpenSpace into thesis/2021/skybrowser
This commit is contained in:
@@ -22,24 +22,19 @@ namespace openspace {
|
||||
ScreenSpaceSkyTarget(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ScreenSpaceSkyTarget() = default;
|
||||
|
||||
// from SSR
|
||||
bool initializeGL() override;
|
||||
bool isReady() const override;
|
||||
|
||||
void render() override;
|
||||
void update() override;
|
||||
|
||||
void createShaders();
|
||||
|
||||
void setBrowser(ScreenSpaceSkyBrowser* browser);
|
||||
ScreenSpaceSkyBrowser* getSkyBrowser();
|
||||
|
||||
void setDimensions(glm::vec2 currentBrowserDimensions);
|
||||
void updateFOV(float fov);
|
||||
void updateFOV(float browserFOV);
|
||||
|
||||
glm::vec2 getScreenSpacePosition();
|
||||
glm::vec2 getAnglePosition();
|
||||
void setScale(float scale);
|
||||
void setConnectedBrowser();
|
||||
void setBorderColor(glm::ivec3 color);
|
||||
glm::ivec3 getColor();
|
||||
@@ -58,8 +53,10 @@ namespace openspace {
|
||||
private:
|
||||
|
||||
properties::Vec2Property _targetDimensions;
|
||||
properties::FloatProperty _showCrosshairThreshold;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
UniformCache(modelTransform, viewProj, texture, fieldOfView, borderWidth, targetRatio, borderColor) _uniformCache;
|
||||
|
||||
UniformCache(modelTransform, viewProj, texture, showCrosshair, borderWidth, targetDimensions, borderColor) _uniformCache;
|
||||
GLuint _vertexArray = 0;
|
||||
GLuint _vertexBuffer = 0;
|
||||
float _fieldOfView = 100.f;
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
uniform sampler2D texture1;
|
||||
uniform float borderWidth;
|
||||
uniform vec2 targetRatio;
|
||||
uniform float fieldOfView;
|
||||
uniform vec2 targetDimensions;
|
||||
uniform bool showCrosshair;
|
||||
uniform vec3 borderColor;
|
||||
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec4 vs_position;
|
||||
|
||||
float box(in vec2 _st, in vec2 _size){
|
||||
_size = vec2(0.5) - _size*0.5;
|
||||
vec2 uv = smoothstep(_size,_size, vs_st);
|
||||
uv *= smoothstep(_size,_size,vec2(1.0)-vs_st);
|
||||
return uv.x*uv.y;
|
||||
}
|
||||
|
||||
float cross(in vec2 _st, float _size){
|
||||
return box(vs_st, vec2(_size/.6, _size/3.)) +
|
||||
box(vs_st, vec2(_size/5.,_size/.4));
|
||||
float crossLine(in float _width, in float _coord) {
|
||||
|
||||
float center = 0.5f;
|
||||
|
||||
float line = smoothstep(center, center+(_width/2) , _coord) -
|
||||
smoothstep(center-(_width/2), center, _coord);
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
#include "fragment.glsl"
|
||||
@@ -24,19 +24,22 @@ float cross(in vec2 _st, float _size){
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
|
||||
// draw cross
|
||||
vec3 crosshair = vec3(cross(vs_st, 0.1));
|
||||
// draw crosshair
|
||||
float crossWidth = 0.1f;
|
||||
float ratio = targetDimensions.y / targetDimensions.x;
|
||||
vec3 crosshair = vec3(crossLine(crossWidth*ratio, (vs_st).x) + crossLine(crossWidth, (vs_st).y));
|
||||
|
||||
// draw square border
|
||||
vec2 bl = step(vec2(borderWidth),(1.0-vs_st)*targetRatio); // bottom-left line
|
||||
vec2 tr = step(vec2(borderWidth),vs_st*targetRatio); // top-right line
|
||||
vec2 bl = step(vec2(borderWidth),(1.0-vs_st)); // bottom-left line
|
||||
vec2 tr = step(vec2(borderWidth),vs_st); // top-right line
|
||||
vec3 border = vec3(tr.x * tr.y * bl.x * bl.y);
|
||||
|
||||
// show crosshair or border
|
||||
frag.color = vec4(1,1,1,1);
|
||||
frag.color.rgb = vec3(borderColor / 255);
|
||||
|
||||
if(fieldOfView < 10.f) {
|
||||
if(showCrosshair) {
|
||||
|
||||
frag.color = vec4(1,1,1,1);
|
||||
if(crosshair == vec3(0.0)) {
|
||||
frag.color.a = 0.0;
|
||||
@@ -45,31 +48,9 @@ Fragment getFragment() {
|
||||
else {
|
||||
if(border == vec3(1.0)) {
|
||||
frag.color.a = 0.0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if(crosshair == vec3(0.0) {
|
||||
frag.color.a = 0.0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
// draw square border
|
||||
vec2 bl = step(vec2(borderWidth),(1.0-vs_st)*targetRatio); // bottom-left line
|
||||
vec2 tr = step(vec2(borderWidth),vs_st*targetRatio); // top-right line
|
||||
vec3 border = vec3(tr.x * tr.y * bl.x * bl.y);
|
||||
|
||||
frag.color = vec4(1,1,1,1);
|
||||
|
||||
if(border == vec3(1.0)) {
|
||||
frag.color.a = 0.0;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@@ -79,7 +79,8 @@ namespace openspace {
|
||||
setConnectedTarget();
|
||||
}
|
||||
else {
|
||||
_skyTarget->setDimensions(getScreenSpaceBrowserDimension());
|
||||
glm::vec2 dim = getScreenSpaceBrowserDimension();
|
||||
_skyTarget->setDimensions(dim);
|
||||
}
|
||||
});
|
||||
addProperty(_browserDimensions);
|
||||
@@ -97,8 +98,6 @@ namespace openspace {
|
||||
_fieldOfView.onChange([&]() {
|
||||
if (_skyTarget) {
|
||||
_skyTarget->updateFOV(_fieldOfView);
|
||||
float scaleWhenFovIs10 = static_cast<float>(10.f / global::windowDelegate->getHorizFieldOfView());
|
||||
_skyTarget->setScale(std::max(static_cast<float>(_fieldOfView / global::windowDelegate->getHorizFieldOfView()), scaleWhenFovIs10));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -2,32 +2,26 @@
|
||||
#include <modules/skybrowser/include/screenspaceskybrowser.h>
|
||||
#include <modules/skybrowser/skybrowsermodule.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <ghoul/misc/dictionaryluaformatter.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <openspace/rendering/helper.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/helper.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <ghoul/misc/dictionaryluaformatter.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureconversion.h>
|
||||
#include <optional>
|
||||
#include <ghoul/opengl/openglstatecache.h>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "ScreenSpaceSkyTarget";
|
||||
@@ -40,7 +34,7 @@ namespace {
|
||||
};
|
||||
|
||||
constexpr const std::array<const char*, 7> UniformNames = {
|
||||
"ModelTransform", "ViewProjectionMatrix", "texture1", "fieldOfView", "borderWidth", "targetRatio", "borderColor"
|
||||
"ModelTransform", "ViewProjectionMatrix", "texture1", "showCrosshair", "borderWidth", "targetDimensions", "borderColor"
|
||||
};
|
||||
|
||||
constexpr const openspace::properties::Property::PropertyInfo BrowserIDInfo =
|
||||
@@ -50,6 +44,13 @@ namespace {
|
||||
"tjobidabidobidabidopp plupp"
|
||||
};
|
||||
|
||||
constexpr const openspace::properties::Property::PropertyInfo CrosshairThresholdInfo =
|
||||
{
|
||||
"CrosshairThreshold",
|
||||
"Crosshair Threshold Info",
|
||||
"tjobidabidobidabidopp plupp"
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(ScreenSpaceSkyTarget)]] Parameters {
|
||||
|
||||
// [[codegen::verbatim(TargetDimensionInfo.description)]]
|
||||
@@ -57,6 +58,9 @@ namespace {
|
||||
|
||||
// [[codegen::verbatim(BrowserIDInfo.description)]]
|
||||
std::optional<std::string> browserID;
|
||||
|
||||
// [[codegen::verbatim(CrosshairThresholdInfo.description)]]
|
||||
std::optional<float> crosshairThreshold;
|
||||
};
|
||||
|
||||
#include "screenspaceskytarget_codegen.cpp"
|
||||
@@ -68,15 +72,18 @@ namespace openspace {
|
||||
: ScreenSpaceRenderable(dictionary)
|
||||
, _targetDimensions(TargetDimensionInfo, glm::ivec2(1000.f), glm::ivec2(0.f), glm::ivec2(6000.f))
|
||||
, _skyBrowserID(BrowserIDInfo)
|
||||
, _showCrosshairThreshold(CrosshairThresholdInfo, 3.f, 1.f, 70.f)
|
||||
, _borderColor(220.f, 220.f, 220.f)
|
||||
{
|
||||
// Handle target dimension property
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
_targetDimensions = p.targetDimensions.value_or(_targetDimensions);
|
||||
|
||||
addProperty(_targetDimensions);
|
||||
_skyBrowserID = p.browserID.value_or(_skyBrowserID);
|
||||
_showCrosshairThreshold = p.crosshairThreshold.value_or(_showCrosshairThreshold);
|
||||
|
||||
addProperty(_targetDimensions);
|
||||
addProperty(_skyBrowserID);
|
||||
addProperty(_showCrosshairThreshold);
|
||||
|
||||
_skyBrowserID.onChange([&]() {
|
||||
setConnectedBrowser();
|
||||
@@ -111,10 +118,6 @@ namespace openspace {
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyTarget::setScale(float scale) {
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyTarget::setConnectedBrowser() {
|
||||
_skyBrowser = dynamic_cast<ScreenSpaceSkyBrowser*>(global::renderEngine->screenSpaceRenderable(_skyBrowserID.value()));
|
||||
}
|
||||
@@ -146,7 +149,7 @@ namespace openspace {
|
||||
_texture = std::move(texture);
|
||||
_objectSize = _texture->dimensions();
|
||||
}
|
||||
|
||||
|
||||
createShaders();
|
||||
|
||||
return isReady();
|
||||
@@ -201,15 +204,17 @@ namespace openspace {
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glm::mat4 modelTransform = globalRotationMatrix() * translationMatrix() * localRotationMatrix() * scaleMatrix();
|
||||
float borderWidth = 0.005f / (_scale.value() * 2.f);
|
||||
glm::vec2 targetRatio;
|
||||
float fov = _fieldOfView;
|
||||
_targetDimensions.value() == glm::vec2(0) ? targetRatio = glm::vec2(1) : targetRatio = _targetDimensions.value() / _targetDimensions.value().y;
|
||||
float borderWidth = 0.004f /(_scale.value());
|
||||
glm::vec2 targetDim;
|
||||
bool showCrosshair;
|
||||
_targetDimensions.value() == glm::vec2(0) ? targetDim = glm::vec2(1) : targetDim = _targetDimensions.value();
|
||||
_shader->activate();
|
||||
|
||||
_shader->setUniform(_uniformCache.fieldOfView, fov);
|
||||
_fieldOfView < _showCrosshairThreshold ? showCrosshair = true : showCrosshair = false;
|
||||
|
||||
_shader->setUniform(_uniformCache.showCrosshair, showCrosshair);
|
||||
_shader->setUniform(_uniformCache.borderWidth, borderWidth);
|
||||
_shader->setUniform(_uniformCache.targetRatio, targetRatio);
|
||||
_shader->setUniform(_uniformCache.targetDimensions, targetDim);
|
||||
_shader->setUniform(_uniformCache.modelTransform, modelTransform);
|
||||
_shader->setUniform(_uniformCache.borderColor, _borderColor);
|
||||
|
||||
@@ -223,6 +228,7 @@ namespace openspace {
|
||||
bindTexture();
|
||||
_shader->setUniform(_uniformCache.texture, unit);
|
||||
|
||||
|
||||
glBindVertexArray(rendering::helper::vertexObjects.square.vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
@@ -232,11 +238,6 @@ namespace openspace {
|
||||
unbindTexture();
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyTarget::update() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyTarget::translate(glm::vec2 translation, glm::vec2 position) {
|
||||
_cartesianPosition = glm::translate(glm::mat4(1.f), glm::vec3(translation, 0.0f)) * glm::vec4(position, _cartesianPosition.value().z, 1.0f);
|
||||
}
|
||||
@@ -270,13 +271,14 @@ namespace openspace {
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyTarget::setDimensions(glm::vec2 currentBrowserDimensions) {
|
||||
_targetDimensions = currentBrowserDimensions;
|
||||
_targetDimensions = currentBrowserDimensions;
|
||||
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyTarget::updateFOV(float fov) {
|
||||
_fieldOfView = fov;
|
||||
void ScreenSpaceSkyTarget::updateFOV(float browserFOV) {
|
||||
float horizFOV = global::windowDelegate->getHorizFieldOfView();
|
||||
_scale = std::max((browserFOV/horizFOV),(_showCrosshairThreshold.value()/horizFOV));
|
||||
_fieldOfView = browserFOV;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user