From 67033c45834061a8cec3aa0e5c7c2cd6ccc14945 Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Wed, 15 Nov 2017 17:35:00 -0500 Subject: [PATCH] Tentative fix for billbords alingment problems. --- ext/ghoul | 2 +- include/openspace/util/camera.h | 3 ++ .../rendering/renderablebillboardscloud.cpp | 42 +++++++++---------- .../rendering/renderablebillboardscloud.h | 4 +- .../rendering/renderableplanescloud.cpp | 13 ++++-- .../rendering/renderableplanescloud.h | 2 +- .../shaders/billboard2_gs.glsl | 11 ++--- openspace.cfg | 9 ++-- src/rendering/renderengine.cpp | 1 + src/util/camera.cpp | 14 ++++++- 10 files changed, 60 insertions(+), 41 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 4dce717aac..a6244a16f9 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 4dce717aac293edd8662d03cc336da355c797343 +Subproject commit a6244a16f98687c9196c4ba8ced11a3d68a88b46 diff --git a/include/openspace/util/camera.h b/include/openspace/util/camera.h index ccd767ad2d..5020ca2641 100644 --- a/include/openspace/util/camera.h +++ b/include/openspace/util/camera.h @@ -133,9 +133,11 @@ public: class SgctInternal { friend class Camera; public: + void setSceneMatrix(glm::mat4 sceneMatrix); void setViewMatrix(glm::mat4 viewMatrix); void setProjectionMatrix(glm::mat4 projectionMatrix); + const glm::mat4& sceneMatrix() const; const glm::mat4& viewMatrix() const; const glm::mat4& projectionMatrix() const; const glm::mat4& viewProjectionMatrix() const; @@ -148,6 +150,7 @@ public: {} // State + glm::mat4 _sceneMatrix; glm::mat4 _viewMatrix; glm::mat4 _projectionMatrix; diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index f04da60c62..e744e47ae0 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -384,7 +384,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di _renderOption.addOption(1, "Camera Position Normal"); _renderOption.addOption(2, "Screen center Position Normal"); addProperty(_renderOption); - _renderOption.set(1); + //_renderOption.set(1); if (dictionary.hasKey(keyUnit)) { std::string unit = dictionary.value(keyUnit); @@ -606,7 +606,7 @@ void RenderableBillboardsCloud::deinitialize() { } void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const glm::dmat4& modelViewMatrix, - const glm::dmat4& projectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp, + const glm::dmat4& worldToModelTransform, const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVariable) { glDepthMask(false); @@ -635,17 +635,11 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; _program->setIgnoreUniformLocationError(IgnoreError::Yes); + glm::dmat4 projMatrix = glm::dmat4(data.camera.projectionMatrix()); _program->setUniform("screenSize", glm::vec2(OsEng.renderEngine().renderingResolution())); - _program->setUniform("projection", projectionMatrix); + _program->setUniform("projection", projMatrix); _program->setUniform("modelViewTransform", modelViewMatrix); - _program->setUniform("modelViewProjectionTransform", glm::dmat4(projectionMatrix) * modelViewMatrix); - - glm::dmat4 modelMatrix = - glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation - glm::dmat4(data.modelTransform.rotation) * // Spice rotation - glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); - glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix); - + _program->setUniform("modelViewProjectionTransform", projMatrix * modelViewMatrix); _program->setUniform("cameraPosition", glm::dvec3(worldToModelTransform * glm::dvec4(data.camera.positionVec3(), 1.0))); _program->setUniform("cameraLookUp", glm::dvec3(worldToModelTransform * @@ -719,7 +713,7 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g } void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, - const glm::vec3& orthoRight, const glm::vec3& orthoUp, const float fadeInVariable) { + const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVariable) { RenderEngine& renderEngine = OsEng.renderEngine(); _fontRenderer->setFramebufferSize(renderEngine.renderingResolution()); @@ -837,20 +831,22 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) { modelViewMatrix; glm::vec3 lookup = data.camera.lookUpVectorWorldSpace(); - - /*glm::vec3 viewDirection = glm::vec3(glm::dmat4(OsEng.renderEngine().getSGCTModelMatrix()) * - glm::dvec4(data.camera.viewDirectionWorldSpace(), 1.0));*/ - - glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace(); - glm::vec3 right = glm::cross(viewDirection, lookup); - glm::vec3 up = glm::cross(right, viewDirection); - + glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix); - glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0))); - glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0))); + glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace(); + //glm::vec3 right = glm::cross(viewDirection, lookup); + //glm::vec3 up = glm::cross(right, viewDirection); + //glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0))); + //glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0))); + + //glm::dmat4 invMVP = glm::inverse(modelViewProjectionMatrix); + glm::dmat4 invMVPParts = glm::inverse(modelMatrix) * glm::inverse(data.camera.combinedViewMatrix()) * + glm::inverse(glm::dmat4(projectionMatrix)); + glm::dvec3 orthoRight = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(1.0, 0.0, 0.0, 0.0)))); + glm::dvec3 orthoUp = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0)))); if (_hasSpeckFile) { - renderBillboards(data, modelViewMatrix, projectionMatrix, orthoRight, orthoUp, fadeInVariable); + renderBillboards(data, modelViewMatrix, worldToModelTransform, orthoRight, orthoUp, fadeInVariable); } if (_drawLabels && _hasLabel) { diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.h b/modules/digitaluniverse/rendering/renderablebillboardscloud.h index 7629ca8a41..48f1fdbc63 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.h +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.h @@ -89,10 +89,10 @@ private: void loadPolygonGeometryForRendering(); void renderPolygonGeometry(GLuint vao); void renderBillboards(const RenderData& data, const glm::dmat4& modelViewMatrix, - const glm::dmat4& projectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp, + const glm::dmat4& worldToModelTransform, const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVariable); void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, - const glm::vec3& orthoRight, const glm::vec3& orthoUp, const float fadeInVariable); + const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVariable); bool loadData(); bool readSpeckFile(); diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 005b1700bd..964963ffee 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -323,7 +323,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary _renderOption.addOption(1, "Camera Position Normal"); _renderOption.addOption(2, "Screen center Position Normal"); addProperty(_renderOption); - _renderOption.set(1); + //_renderOption.set(1); if (dictionary.hasKey(keyUnit)) { std::string unit = dictionary.value(keyUnit); @@ -586,7 +586,7 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&, } void RenderablePlanesCloud::renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, - const glm::vec3& orthoRight, const glm::vec3& orthoUp, const float fadeInVariable) { + const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVariable) { RenderEngine& renderEngine = OsEng.renderEngine(); _fontRenderer->setFramebufferSize(renderEngine.renderingResolution()); @@ -688,15 +688,20 @@ void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) { glm::mat4 projectionMatrix = data.camera.projectionMatrix(); glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) * modelViewMatrix; - glm::vec3 lookup = data.camera.lookUpVectorWorldSpace(); + /*glm::vec3 lookup = data.camera.lookUpVectorWorldSpace(); glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace(); glm::vec3 right = glm::cross(viewDirection, lookup); glm::vec3 up = glm::cross(right, viewDirection); glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix); glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0))); - glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0))); + glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0)));*/ + //glm::dmat4 invMVP = glm::inverse(modelViewProjectionMatrix); + glm::dmat4 invMVPParts = glm::inverse(modelMatrix) * glm::inverse(data.camera.combinedViewMatrix()) * + glm::inverse(glm::dmat4(projectionMatrix)); + glm::dvec3 orthoRight = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(1.0, 0.0, 0.0, 0.0)))); + glm::dvec3 orthoUp = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0)))); if (_hasSpeckFile) { renderPlanes(data, modelViewMatrix, projectionMatrix, fadeInVariable); diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index 4bcbb60f8b..3f273c01d1 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -94,7 +94,7 @@ namespace openspace { void renderPlanes(const RenderData& data, const glm::dmat4& modelViewMatrix, const glm::dmat4& projectionMatrix, const float fadeInVariable); void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, - const glm::vec3& orthoRight, const glm::vec3& orthoUp, const float fadeInVarible); + const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVarible); bool loadData(); bool loadTextures(); diff --git a/modules/digitaluniverse/shaders/billboard2_gs.glsl b/modules/digitaluniverse/shaders/billboard2_gs.glsl index 8a5c9f494d..2cfa563845 100644 --- a/modules/digitaluniverse/shaders/billboard2_gs.glsl +++ b/modules/digitaluniverse/shaders/billboard2_gs.glsl @@ -32,8 +32,8 @@ layout(triangle_strip, max_vertices = 6) out; //uniform dmat4 transformMatrix; uniform dmat4 modelViewProjectionTransform; uniform float scaleFactor; -uniform vec3 up; -uniform vec3 right; +uniform dvec3 up; +uniform dvec3 right; uniform dvec3 cameraPosition; uniform dvec3 cameraLookUp; uniform dvec4 centerScreenInWorldPosition; @@ -139,12 +139,13 @@ void main() { // EndPrimitive(); // Second Triangle // Testing size: - vec4 topLeft = thirdPosition/thirdPosition.w; - topLeft = ((topLeft + vec4(1.0)) / vec4(2.0)) * vec4(screenSize.x, screenSize.y, 1.0, 1.0); + vec4 topRight = secondPosition/secondPosition.w; + topRight = ((topRight + vec4(1.0)) / vec4(2.0)) * vec4(screenSize.x, screenSize.y, 1.0, 1.0); vec4 bottomLeft = initialPosition/initialPosition.w; bottomLeft = ((bottomLeft + vec4(1.0)) / vec4(2.0)) * vec4(screenSize.x, screenSize.y, 1.0, 1.0); - if ((topLeft.y - bottomLeft.y) > maxBillboardSize) { + if (((topRight.y - bottomLeft.y) > maxBillboardSize) || + ((topRight.x - bottomLeft.x) > maxBillboardSize)) { return; } else { // Build primitive diff --git a/openspace.cfg b/openspace.cfg index d71a1bbccb..ddb4cb601f 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -7,11 +7,12 @@ return { -- occurs in a single window, a fisheye projection, or a dome cluster system -- A regular 1280x720 window - --SGCTConfig = sgct.config.single{1280, 720, scene={orientation = { yaw = 120, pitch = 15, roll = 0.0 }}}, - --SGCTConfig = "${CONFIG}/single_two_win.xml", + SGCTConfig = sgct.config.single{1280, 720}, + -- SGCTConfig = sgct.config.single{1280, 720, scene={orientation = { yaw = 120, pitch = 15, roll = 0.0 }}}, + -- SGCTConfig = "${CONFIG}/single_two_win.xml", -- A regular 1920x1080 window - SGCTConfig = sgct.config.single{1920, 1080}, + -- SGCTConfig = sgct.config.single{1920, 1080}, -- A windowed 1920x1080 fullscreen -- SGCTConfig = sgct.config.single{1920, 1080, border=false, windowPos={0,0}, shared=true, name="WV_OBS_SPOUT1"}, @@ -20,7 +21,7 @@ return { --SGCTConfig = sgct.config.fisheye{1024, 1024}, -- A 4k fisheye rendering in a 1024x1024 window - --SGCTConfig = sgct.config.fisheye{1024, 1024, res={4096, 4096}, quality="2k", tilt=27}, + -- SGCTConfig = sgct.config.fisheye{1024, 1024, res={4096, 4096}, quality="2k", tilt=27}, -- Streaming OpenSpace via Spout to OBS -- SGCTConfig = sgct.config.single{2560, 1440, shared=true, name="WV_OBS_SPOUT1"}, diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 6de25981e9..2f3d893a24 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -576,6 +576,7 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat } else { _camera->sgctInternal.setViewMatrix(viewMatrix * sceneMatrix); + _camera->sgctInternal.setSceneMatrix(sceneMatrix); } _camera->sgctInternal.setProjectionMatrix(projectionMatrix); diff --git a/src/util/camera.cpp b/src/util/camera.cpp index e41a0b872b..02656bc218 100644 --- a/src/util/camera.cpp +++ b/src/util/camera.cpp @@ -226,10 +226,18 @@ namespace openspace { // SGCT INTERNAL // ////////////////////////////////////////////////////////////////////////////////////// Camera::SgctInternal::SgctInternal() - : _viewMatrix() + : _sceneMatrix() + , _viewMatrix() , _projectionMatrix() { } + void Camera::SgctInternal::setSceneMatrix(glm::mat4 sceneMatrix) { + std::lock_guard _lock(_mutex); + + _sceneMatrix = std::move(sceneMatrix); + //_cachedViewProjectionMatrix.isDirty = true; + } + void Camera::SgctInternal::setViewMatrix(glm::mat4 viewMatrix) { std::lock_guard _lock(_mutex); @@ -244,6 +252,10 @@ namespace openspace { _cachedViewProjectionMatrix.isDirty = true; } + const glm::mat4& Camera::SgctInternal::sceneMatrix() const { + return _sceneMatrix; + } + const glm::mat4& Camera::SgctInternal::viewMatrix() const { return _viewMatrix; }