diff --git a/ext/ghoul b/ext/ghoul index a6244a16f9..2b350ca6a6 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit a6244a16f98687c9196c4ba8ced11a3d68a88b46 +Subproject commit 2b350ca6a63111ce585f6969202ba1a4e0ad704b diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index fc73ba0e48..2f4122727a 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -832,26 +832,45 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) { glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix); - //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::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 internalCameraMatrix = data.camera.viewRotationMatrix() * + glm::inverse(glm::translate(glm::dmat4(1.0), data.camera.positionVec3())); + glm::dmat4 invInternalCameraMatrix = glm::inverse(internalCameraMatrix); + glm::vec3 lookup = worldToModelTransform * invInternalCameraMatrix * glm::dvec4(data.camera.lookUpVectorWorldSpace(), 0.0); + glm::vec3 viewDirection = worldToModelTransform * invInternalCameraMatrix * glm::dvec4(data.camera.viewDirectionWorldSpace(), 0.0); + glm::vec3 right = glm::cross(viewDirection, lookup); + glm::vec3 up = glm::cross(right, viewDirection); + + glm::vec3 orthoRight = glm::normalize(right); + glm::vec3 orthoUp = glm::normalize(up);*/ - //glm::dmat4 invMVP = glm::inverse(modelViewProjectionMatrix); + /* + glm::dmat4 internalCameraMatrix = data.camera.viewRotationMatrix() * + glm::inverse(glm::translate(glm::dmat4(1.0), data.camera.positionVec3())); + glm::dmat4 invInternalCameraMatrix = glm::inverse(internalCameraMatrix); + glm::dvec4 lookup = worldToModelTransform * glm::dvec4(data.camera.lookUpVectorWorldSpace(), 0.0); + glm::dvec4 viewDirection = worldToModelTransform * glm::dvec4(data.camera.viewDirectionWorldSpace(), 0.0); + glm::vec3 right = glm::cross(glm::vec3(viewDirection), glm::vec3(lookup)); + glm::vec3 up = glm::cross(right, glm::vec3(viewDirection)); + + glm::vec3 orthoRight = glm::normalize(right); + glm::vec3 orthoUp = glm::normalize(up); + */ + + + // Almost Working 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)))); - + 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, worldToModelTransform, orthoRight, orthoUp, fadeInVariable); } if (_drawLabels && _hasLabel) { renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp, fadeInVariable); - } + } } void RenderableBillboardsCloud::update(const UpdateData&) { diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index e39b520e26..4dede95003 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -486,9 +486,9 @@ void RenderablePlanesCloud::initializeGL() { void RenderablePlanesCloud::deleteDataGPU() { - for (auto pair : _renderingPlanesMap) { - glDeleteVertexArrays(1, &pair.second.vao); - glDeleteBuffers(1, &pair.second.vbo); + for (auto renderingPlane : _renderingPlanesArray) { + glDeleteVertexArrays(1, &renderingPlane.vao); + glDeleteBuffers(1, &renderingPlane.vbo); } } @@ -555,13 +555,16 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&, // glBlendFunc(GL_SRC_ALPHA, GL_ONE); //} - for (auto pair : _renderingPlanesMap) { - ghoul::opengl::TextureUnit unit; - unit.activate(); - _textureMap[pair.second.planeIndex]->bind(); - _program->setUniform("galaxyTexture", unit); - - glBindVertexArray(pair.second.vao); + ghoul::opengl::TextureUnit unit; + unit.activate(); + _program->setUniform("galaxyTexture", unit); + int currentTextureIndex = -1; + for (auto renderingPlane : _renderingPlanesArray) { + if (currentTextureIndex != renderingPlane.planeIndex) { + _textureMap[renderingPlane.planeIndex]->bind(); + currentTextureIndex = renderingPlane.planeIndex; + } + glBindVertexArray(renderingPlane.vao); glDrawArrays(GL_TRIANGLES, 0, 6); } @@ -1240,7 +1243,7 @@ void RenderablePlanesCloud::createPlanes() { reinterpret_cast(sizeof(GLfloat) * 4) ); - _renderingPlanesMap.insert({planeNumber++, plane}); + _renderingPlanesArray.push_back(plane); } glBindVertexArray(0); @@ -1252,6 +1255,15 @@ void RenderablePlanesCloud::createPlanes() { _labelDataIsDirty = false; } + + // Sort planes by texture index + if (!_renderingPlanesArray.empty()) { + std::sort(_renderingPlanesArray.begin(), _renderingPlanesArray.end(), + [](const RenderingPlane& planeA, const RenderingPlane& planeB) { + return planeA.planeIndex < planeB.planeIndex; + }); + + } } } // namespace openspace diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index aba5317dff..e3cb7e61c9 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -149,7 +149,7 @@ namespace openspace { glm::dmat4 _transformationMatrix; - std::unordered_map _renderingPlanesMap; + std::vector _renderingPlanesArray; }; diff --git a/openspace.cfg b/openspace.cfg index dfb7465db9..6141749313 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -9,10 +9,10 @@ return { -- A regular 1280x720 window 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", + --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"},