diff --git a/data/scene/newhorizons/pluto/charon/charon.data b/data/scene/newhorizons/pluto/charon/charon.data index 73ecb53d87..0e0214f515 100644 --- a/data/scene/newhorizons/pluto/charon/charon.data +++ b/data/scene/newhorizons/pluto/charon/charon.data @@ -1,5 +1,5 @@ return { FileRequest = { - { Identifier = "charon_textures", Destination = "textures", Version = 1 } + { Identifier = "charon_textures", Destination = "textures", Version = 2 } }, } \ No newline at end of file diff --git a/data/scene/newhorizons/pluto/pluto/pluto.data b/data/scene/newhorizons/pluto/pluto/pluto.data index fff1025604..13ab280e5a 100644 --- a/data/scene/newhorizons/pluto/pluto/pluto.data +++ b/data/scene/newhorizons/pluto/pluto/pluto.data @@ -1,8 +1,8 @@ return { FileRequest = { { Identifier = "newhorizons_plutoencounter_pluto_assets", Destination = "assets", Version = 1 }, - { Identifier = "newhorizons_plutoencounter_pluto_textures", Destination = "textures", Version = 3 }, - { Identifier = "pluto_textures", Destination = "textures", Version = 2 }, + { Identifier = "newhorizons_plutoencounter_pluto_textures", Destination = "textures", Version = 4 }, + { Identifier = "pluto_textures", Destination = "textures", Version = 4 }, { Identifier = "newhorizons_plutoencounter_pluto_images", Destination = "images", Version = 1 } }, } \ No newline at end of file diff --git a/data/scene/pluto/pluto.data b/data/scene/pluto/pluto.data index bc793cb889..264a9ff830 100644 --- a/data/scene/pluto/pluto.data +++ b/data/scene/pluto/pluto.data @@ -1,6 +1,6 @@ return { FileRequest = { { Identifier = "charon_textures", Destination = "textures", Version = 1 }, - { Identifier = "pluto_textures", Destination = "textures", Version = 2 } + { Identifier = "pluto_textures", Destination = "textures", Version = 4 } } } \ No newline at end of file diff --git a/data/scene/rosetta.scene b/data/scene/rosetta.scene index 39dc7b087b..54c810af07 100644 --- a/data/scene/rosetta.scene +++ b/data/scene/rosetta.scene @@ -31,6 +31,8 @@ function postInitialization() openspace.setPropertyValue("MilkyWay.renderable.transparency", 0.55) openspace.setPropertyValue("MilkyWay.renderable.segments", 50) + openspace.setPropertyValue('67P.renderable.performShading', false); + openspace.printInfo("Done setting default values") end diff --git a/data/scene/rosetta/67P/67P.mod b/data/scene/rosetta/67P/67P.mod index a6ec406f4c..209304b8e1 100644 --- a/data/scene/rosetta/67P/67P.mod +++ b/data/scene/rosetta/67P/67P.mod @@ -28,6 +28,7 @@ return { Observer = "ROSETTA", Target = "CHURYUMOV-GERASIMENKO", Aberration = "NONE", + TextureMap = true }, DataInputTranslation = { Instrument = { diff --git a/data/scene/rosetta/rosetta/RosettaKernels_New.torrent b/data/scene/rosetta/rosetta/RosettaKernels_New.torrent new file mode 100644 index 0000000000..cdb32f8b5d Binary files /dev/null and b/data/scene/rosetta/rosetta/RosettaKernels_New.torrent differ diff --git a/data/scene/rosetta/rosetta/rosetta.data b/data/scene/rosetta/rosetta/rosetta.data index 1554d25842..98c46c37a2 100644 --- a/data/scene/rosetta/rosetta/rosetta.data +++ b/data/scene/rosetta/rosetta/rosetta.data @@ -4,6 +4,7 @@ return { { Identifier = "rosetta_textures", Destination = "textures", Version = 1 } }, TorrentFiles = { - { File = "RosettaKernels.torrent", Destination = "${SPICE}" } + { File = "RosettaKernels.torrent", Destination = "${SPICE}" }, + { File = "RosettaKernels_New.torrent", Destination = "${SPICE}" } } } \ No newline at end of file diff --git a/modules/debugging/rendering/renderabledebugplane.cpp b/modules/debugging/rendering/renderabledebugplane.cpp index 544dc26c72..e3cbf67c47 100644 --- a/modules/debugging/rendering/renderabledebugplane.cpp +++ b/modules/debugging/rendering/renderabledebugplane.cpp @@ -65,6 +65,12 @@ RenderableDebugPlane::RenderableDebugPlane(const ghoul::Dictionary& dictionary) dictionary.getValue("Name", _nodeName); } + if (dictionary.hasKey("Texture")) { + int t; + dictionary.getValue("Texture", t); + _texture = t; + } + std::string origin; if (dictionary.getValue("Origin", origin)) { if (origin == "LowerLeft") { diff --git a/modules/newhorizons/rendering/renderablemodelprojection.cpp b/modules/newhorizons/rendering/renderablemodelprojection.cpp index 477e2b62ca..aff65ca58b 100644 --- a/modules/newhorizons/rendering/renderablemodelprojection.cpp +++ b/modules/newhorizons/rendering/renderablemodelprojection.cpp @@ -199,11 +199,15 @@ void RenderableModelProjection::render(const RenderData& data) { } void RenderableModelProjection::update(const UpdateData& data) { - if (_programObject->isDirty()) + if (_programObject->isDirty()) { _programObject->rebuildFromFile(); + } - if (_fboProgramObject->isDirty()) + if (_fboProgramObject->isDirty()) { _fboProgramObject->rebuildFromFile(); + } + + _projectionComponent.update(); _time = data.time; diff --git a/modules/newhorizons/rendering/renderablemodelprojection.h b/modules/newhorizons/rendering/renderablemodelprojection.h index 644af7b905..9f9d0227ab 100644 --- a/modules/newhorizons/rendering/renderablemodelprojection.h +++ b/modules/newhorizons/rendering/renderablemodelprojection.h @@ -55,7 +55,7 @@ public: bool isReady() const override; void render(const RenderData& data) override; - void update(const UpdateData& data) override; + virtual void update(const UpdateData& data) final override; ghoul::opengl::Texture& baseTexture() const; diff --git a/modules/newhorizons/rendering/renderableplanetprojection.cpp b/modules/newhorizons/rendering/renderableplanetprojection.cpp index 13516f1e5f..35aac4f50d 100644 --- a/modules/newhorizons/rendering/renderableplanetprojection.cpp +++ b/modules/newhorizons/rendering/renderableplanetprojection.cpp @@ -364,8 +364,11 @@ void RenderablePlanetProjection::update(const UpdateData& data) { _fboProgramObject->rebuildFromFile(); } - if (_programObject->isDirty()) + if (_programObject->isDirty()) { _programObject->rebuildFromFile(); + } + + _projectionComponent.update(); _time = Time::ref().currentTime(); _capture = false; diff --git a/modules/newhorizons/shaders/dilation_fs.glsl b/modules/newhorizons/shaders/dilation_fs.glsl new file mode 100644 index 0000000000..d5a740d681 --- /dev/null +++ b/modules/newhorizons/shaders/dilation_fs.glsl @@ -0,0 +1,94 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * 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 __CONTEXT__ + +in vec2 vs_uv; +out vec4 color; + +uniform sampler2D tex; +uniform sampler2D stencil; + +// We conside the 8-neighborhood of a texel, so going a stepsize of '1' in both +// directions +vec2 offsets[8] = { + vec2(-1.0, -1.0), + vec2(-1.0, 0.0), + vec2(-1.0, 1.0), + vec2(0.0, -1.0), + vec2(0.0, 1.0), + vec2(1.0, -1.0), + vec2(1.0, 0.0), + vec2(1.0, 1.0) +}; + +// Collect the contributing colors from the neighboring texels and return the +// averaged value of all texels that passed the masking test based on 'stencil' +vec3 gatherNeighboringColors() { + vec2 texSize = textureSize(tex, 0); + + // The total number of contributing texels + int nContributions = 0; + + // The summed color of all contributing texels + vec3 totalColor = vec3(0.0); + + for (int i = 0; i < 8; i++) { + // gl_FragCoord is in pixel coordinates; the ProjectionComponent sets + // the viewport such that pixels=texels, so we can use gl_FragCoord as an + // integer texel coordinate + // First offsetting them, then dividing by the texture size to get to [0,1] + vec2 samplePosition = (gl_FragCoord.xy + offsets[i]) / texSize; + + // The stencelling determines the areas that we have to enlarge, such that we + // do not enlarge a previously enlarged area + if (texture(stencil, samplePosition).r != 0.0) { + totalColor += texture(tex, samplePosition).rgb; + nContributions++; + } + } + + // GLSL normally doesn't have a problem taking vec3(0.0)/0.0 but we don't want to + // tempt the compiler gods + if (nContributions > 0) { + return totalColor / nContributions; + } + else { + return vec3(0.0); + } + +} + +void main() { + if (texture(stencil, vs_uv).r == 0.0) { + // This means that the current fragment/texel we are looking at has not been + // projected on and we only want to do the dilation into these texels + color = vec4(gatherNeighboringColors(), 1.0); + } + else { + // We are in a region where an image has been projected, so we can reuse the + // already sampled version + color = texture(tex, vs_uv); + } +} diff --git a/modules/newhorizons/shaders/dilation_vs.glsl b/modules/newhorizons/shaders/dilation_vs.glsl new file mode 100644 index 0000000000..2efb3027e4 --- /dev/null +++ b/modules/newhorizons/shaders/dilation_vs.glsl @@ -0,0 +1,34 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * 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 __CONTEXT__ + +layout(location = 0) in vec2 in_position; + +out vec2 vs_uv; + +void main() { + vs_uv = (in_position + vec2(1.0)) / vec2(2.0); + gl_Position = vec4(in_position, 0.0, 1.0); +} diff --git a/modules/newhorizons/shaders/renderableModelProjection_fs.glsl b/modules/newhorizons/shaders/renderableModelProjection_fs.glsl index 0d0bcbec89..30d4da79dd 100644 --- a/modules/newhorizons/shaders/renderableModelProjection_fs.glsl +++ b/modules/newhorizons/shaders/renderableModelProjection_fs.glsl @@ -24,14 +24,15 @@ #version __CONTEXT__ -#include "PowerScaling/powerScaling_vs.hglsl" - in vec4 vs_position; in vec4 vs_normal; in vec2 vs_uv; in vec4 ProjTexCoord; -out vec4 color; +layout (location = 0) out vec4 color; +// Even though the stencel texture is only a single channel, we still need to +// output a vec4, or the result will disappear +layout (location = 1) out vec4 stencil; uniform sampler2D projectionTexture; @@ -44,22 +45,24 @@ bool inRange(float x, float a, float b) { } void main() { - vec2 uv = vec2(0.5,0.5)*vs_uv+vec2(0.5,0.5); + vec2 uv = vec2(0.5,0.5)*vs_uv+vec2(0.5,0.5); - vec3 n = normalize(vs_normal.xyz); - vec4 projected = ProjTexCoord; + vec3 n = normalize(vs_normal.xyz); + vec4 projected = ProjTexCoord; - //normalize - projected.x /= projected.w; - projected.y /= projected.w; - //invert gl coordinates - projected.x = 1 - projected.x; - - if ((inRange(projected.x, 0, 1) && inRange(projected.y, 0, 1)) && (dot(n, boresight) < 0)) { + // normalize + projected.x /= projected.w; + projected.y /= projected.w; + // invert gl coordinates + projected.x = 1 - projected.x; + + if ((inRange(projected.x, 0, 1) && inRange(projected.y, 0, 1)) && (dot(n, boresight) < 0)) { color = texture(projectionTexture, projected.xy); color.a = 1.0; - } - else { - color = vec4(vec3(0.0), 1.0); - } + stencil = vec4(1.0); + } + else { + color = vec4(vec3(0.0), 1.0); + stencil = vec4(0.0); + } } diff --git a/modules/newhorizons/shaders/renderableModel_fs.glsl b/modules/newhorizons/shaders/renderableModel_fs.glsl index 8b42731ec2..a5a431042b 100644 --- a/modules/newhorizons/shaders/renderableModel_fs.glsl +++ b/modules/newhorizons/shaders/renderableModel_fs.glsl @@ -74,7 +74,7 @@ Fragment getFragment() { textureColor.rgb = mix( textureColor.rgb, projectionColor.rgb, - min(_projectionFading, projectionColor.a) + _projectionFading ); } diff --git a/modules/newhorizons/shaders/renderablePlanetProjection_fs.glsl b/modules/newhorizons/shaders/renderablePlanetProjection_fs.glsl index 3f6e2be3ba..7213c6c22f 100644 --- a/modules/newhorizons/shaders/renderablePlanetProjection_fs.glsl +++ b/modules/newhorizons/shaders/renderablePlanetProjection_fs.glsl @@ -27,7 +27,9 @@ #include "PowerScaling/powerScaling_vs.hglsl" in vec4 vs_position; -out vec4 color; + +layout (location = 0) out vec4 color; +layout (location = 1) out vec4 stencil; uniform sampler2D projectionTexture; @@ -82,8 +84,10 @@ void main() { // The 1-x is in this texture call because of flipped textures // to be fixed soon ---abock color = texture(projectionTexture, vec2(projected.x, 1-projected.y)); + stencil = vec4(1.0); } else { color = vec4(0.0); + stencil = vec4(0.0); } } \ No newline at end of file diff --git a/modules/newhorizons/shaders/renderablePlanetProjection_vs.glsl b/modules/newhorizons/shaders/renderablePlanetProjection_vs.glsl index 6db9f30f55..d709738859 100644 --- a/modules/newhorizons/shaders/renderablePlanetProjection_vs.glsl +++ b/modules/newhorizons/shaders/renderablePlanetProjection_vs.glsl @@ -24,8 +24,6 @@ #version __CONTEXT__ -#include "PowerScaling/powerScaling_vs.hglsl" - layout(location = 0) in vec4 in_position; out vec4 vs_position; diff --git a/modules/newhorizons/util/projectioncomponent.cpp b/modules/newhorizons/util/projectioncomponent.cpp index 56548b1d88..530f6e1aa7 100644 --- a/modules/newhorizons/util/projectioncomponent.cpp +++ b/modules/newhorizons/util/projectioncomponent.cpp @@ -52,6 +52,8 @@ namespace { const std::string keySequenceType = "Projection.SequenceType"; const std::string keyTranslation = "DataInputTranslation"; + const std::string keyNeedsTextureMapDilation = "Projection.TextureMap"; + const std::string sequenceTypeImage = "image-sequence"; const std::string sequenceTypePlaybook = "playbook"; const std::string sequenceTypeHybrid = "hybrid"; @@ -72,6 +74,7 @@ ProjectionComponent::ProjectionComponent() , _clearAllProjections("clearAllProjections", "Clear Projections", false) , _projectionFading("projectionFading", "Projection Fading", 1.f, 0.f, 1.f) , _projectionTexture(nullptr) + , _needsTextureMapDilation(false) { setName("ProjectionComponent"); @@ -98,6 +101,42 @@ bool ProjectionComponent::initialize() { } _placeholderTexture = std::move(texture); + + if (_needsTextureMapDilation) { + _dilation.program = ghoul::opengl::ProgramObject::Build( + "Dilation", + "${MODULE_NEWHORIZONS}/shaders/dilation_vs.glsl", + "${MODULE_NEWHORIZONS}/shaders/dilation_fs.glsl" + ); + + const GLfloat plane[] = { + -1, -1, + 1, 1, + -1, 1, + -1, -1, + 1, -1, + 1, 1, + }; + + glGenVertexArrays(1, &_dilation.vao); + glGenBuffers(1, &_dilation.vbo); + + glBindVertexArray(_dilation.vao); + glBindBuffer(GL_ARRAY_BUFFER, _dilation.vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(plane), plane, GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer( + 0, + 2, + GL_FLOAT, + GL_FALSE, + sizeof(GLfloat) * 2, + reinterpret_cast(0) + ); + + glBindVertexArray(0); + } + return a && b; } @@ -106,6 +145,15 @@ bool ProjectionComponent::deinitialize() { glDeleteFramebuffers(1, &_fboID); + if (_needsTextureMapDilation) { + glDeleteFramebuffers(1, &_dilation.fbo); + glDeleteVertexArrays(1, &_dilation.vao); + glDeleteBuffers(1, &_dilation.vbo); + + _dilation.program = nullptr; + _dilation.texture = nullptr; + } + return true; } @@ -143,6 +191,11 @@ bool ProjectionComponent::initializeProjectionSettings(const Dictionary& diction _potentialTargets[i] = target; } } + + if (dictionary.hasKeyAndValue(keyNeedsTextureMapDilation)) { + _needsTextureMapDilation = dictionary.value(keyNeedsTextureMapDilation); + } + return completeSuccess; } @@ -225,13 +278,50 @@ void ProjectionComponent::imageProjectBegin() { static_cast(_projectionTexture->width()), static_cast(_projectionTexture->height()) ); + + if (_needsTextureMapDilation) { + GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; + glDrawBuffers(2, buffers); + } } void ProjectionComponent::imageProjectEnd() { + if (_needsTextureMapDilation) { + glBindFramebuffer(GL_FRAMEBUFFER, _dilation.fbo); + + glDisable(GL_BLEND); + + ghoul::opengl::TextureUnit unit[2]; + unit[0].activate(); + _projectionTexture->bind(); + + unit[1].activate(); + _dilation.stencilTexture->bind(); + + _dilation.program->activate(); + _dilation.program->setUniform("tex", unit[0]); + _dilation.program->setUniform("stencil", unit[1]); + + glBindVertexArray(_dilation.vao); + glDrawArrays(GL_TRIANGLES, 0, 6); + + _dilation.program->deactivate(); + + glEnable(GL_BLEND); + } + glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO); glViewport(_viewport[0], _viewport[1], _viewport[2], _viewport[3]); } +void ProjectionComponent::update() { + if (_needsTextureMapDilation) { + if (_dilation.program->isDirty()) { + _dilation.program->rebuildFromFile(); + } + } +} + bool ProjectionComponent::auxiliaryRendertarget() { bool completeSuccess = true; @@ -250,8 +340,47 @@ bool ProjectionComponent::auxiliaryRendertarget() { ); // check FBO status GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) + if (status != GL_FRAMEBUFFER_COMPLETE) { + LERROR("Main Framebuffer incomplete"); completeSuccess &= false; + } + + + if (_needsTextureMapDilation) { + // We only need the stencil texture if we need to dilate + glFramebufferTexture2D( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT1, + GL_TEXTURE_2D, + *_dilation.stencilTexture, + 0 + ); + + // check FBO status + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + LERROR("Main Framebuffer incomplete"); + completeSuccess &= false; + } + + glGenFramebuffers(1, &_dilation.fbo); + glBindFramebuffer(GL_FRAMEBUFFER, _dilation.fbo); + glFramebufferTexture2D( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, + *_dilation.texture, + 0 + ); + + // check FBO status + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + LERROR("Dilation Framebuffer incomplete"); + completeSuccess &= false; + } + } + // switch back to window-system-provided framebuffer glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); @@ -274,18 +403,24 @@ glm::mat4 ProjectionComponent::computeProjectorMatrix(const glm::vec3 loc, glm:: glm::vec3 e3 = glm::normalize(boreSight); glm::vec3 e1 = glm::normalize(glm::cross(uptmp, e3)); glm::vec3 e2 = glm::normalize(glm::cross(e3, e1)); - glm::mat4 projViewMatrix = glm::mat4(e1.x, e2.x, e3.x, 0.f, - e1.y, e2.y, e3.y, 0.f, - e1.z, e2.z, e3.z, 0.f, - -glm::dot(e1, loc), -glm::dot(e2, loc), -glm::dot(e3, loc), 1.f); + glm::mat4 projViewMatrix = glm::mat4( + e1.x, e2.x, e3.x, 0.f, + e1.y, e2.y, e3.y, 0.f, + e1.z, e2.z, e3.z, 0.f, + -glm::dot(e1, loc), -glm::dot(e2, loc), -glm::dot(e3, loc), 1.f + ); // create perspective projection matrix - glm::mat4 projProjectionMatrix = glm::perspective(glm::radians(fieldOfViewY), aspectRatio, nearPlane, farPlane); + glm::mat4 projProjectionMatrix = glm::perspective( + glm::radians(fieldOfViewY), aspectRatio, nearPlane, farPlane + ); // bias matrix - glm::mat4 projNormalizationMatrix = glm::mat4(0.5f, 0, 0, 0, - 0, 0.5f, 0, 0, - 0, 0, 0.5f, 0, - 0.5f, 0.5f, 0.5f, 1); - return projNormalizationMatrix*projProjectionMatrix*projViewMatrix; + glm::mat4 projNormalizationMatrix = glm::mat4( + 0.5f, 0.f, 0.f, 0.f, + 0.f, 0.5f, 0.f, 0.f, + 0.f, 0.f, 0.5f, 0.f, + 0.5f, 0.5f, 0.5f, 1.f + ); + return projNormalizationMatrix * projProjectionMatrix * projViewMatrix; } bool ProjectionComponent::doesPerformProjection() const { @@ -301,7 +436,12 @@ float ProjectionComponent::projectionFading() const { } ghoul::opengl::Texture& ProjectionComponent::projectionTexture() const { - return *_projectionTexture; + if (_needsTextureMapDilation) { + return *_dilation.texture; + } + else { + return *_projectionTexture; + } } std::string ProjectionComponent::projectorId() const { @@ -344,14 +484,18 @@ void ProjectionComponent::clearAllProjections() { GLint m_viewport[4]; glGetIntegerv(GL_VIEWPORT, m_viewport); //counter = 0; - glBindFramebuffer(GL_FRAMEBUFFER, _fboID); - glViewport(0, 0, static_cast(_projectionTexture->width()), static_cast(_projectionTexture->height())); + glBindFramebuffer(GL_FRAMEBUFFER, _fboID); + glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT); - //bind back to default + if (_needsTextureMapDilation) { + glBindFramebuffer(GL_FRAMEBUFFER, _dilation.fbo); + glClear(GL_COLOR_BUFFER_BIT); + } + glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); glViewport(m_viewport[0], m_viewport[1], m_viewport[2], m_viewport[3]); @@ -368,8 +512,9 @@ std::shared_ptr ProjectionComponent::loadProjectionTextu using ghoul::io::TextureReader; - if (isPlaceholder) + if (isPlaceholder) { return _placeholderTexture; + } unique_ptr texture = TextureReader::ref().loadTexture(absPath(texturePath)); @@ -395,9 +540,35 @@ bool ProjectionComponent::generateProjectionLayerTexture() { glm::uvec3(maxSize, maxSize / 2, 1), ghoul::opengl::Texture::Format::RGBA ); - if (_projectionTexture) + if (_projectionTexture) { _projectionTexture->uploadTexture(); + //_projectionTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); + } + if (_needsTextureMapDilation) { + _dilation.texture = std::make_unique( + glm::uvec3(maxSize, maxSize / 2, 1), + ghoul::opengl::Texture::Format::RGBA + ); + + if (_dilation.texture) { + _dilation.texture->uploadTexture(); + //_dilation.texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); + } + + _dilation.stencilTexture = std::make_unique( + glm::uvec3(maxSize, maxSize / 2, 1), + ghoul::opengl::Texture::Format::Red, + ghoul::opengl::Texture::Format::Red + ); + + if (_dilation.stencilTexture) { + _dilation.stencilTexture->uploadTexture(); + //_dilation.texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); + } + } + + return _projectionTexture != nullptr; } diff --git a/modules/newhorizons/util/projectioncomponent.h b/modules/newhorizons/util/projectioncomponent.h index 197a886dc4..3386b63a1d 100644 --- a/modules/newhorizons/util/projectioncomponent.h +++ b/modules/newhorizons/util/projectioncomponent.h @@ -32,6 +32,14 @@ #include #include +namespace ghoul { +namespace opengl { + +class ProgramObject; + +} // namespace opengl +} // namespace ghoul + namespace openspace { class ProjectionComponent : public properties::PropertyOwner { @@ -49,6 +57,8 @@ public: void imageProjectBegin(); void imageProjectEnd(); + void update(); + bool generateProjectionLayerTexture(); bool auxiliaryRendertarget(); @@ -108,6 +118,16 @@ protected: GLint _defaultFBO; GLint _viewport[4]; + + bool _needsTextureMapDilation; + struct { + GLuint fbo; + GLuint vao; + GLuint vbo; + std::unique_ptr program; + std::unique_ptr texture; + std::unique_ptr stencilTexture; + } _dilation; }; } // namespace openspace diff --git a/support/cmake/support_macros.cmake b/support/cmake/support_macros.cmake index 97162c2eda..f53cca192c 100644 --- a/support/cmake/support_macros.cmake +++ b/support/cmake/support_macros.cmake @@ -69,10 +69,10 @@ function (set_compile_settings project) if (MSVC) target_compile_options(${project} PUBLIC - "/MP" # Multi-threading support - "/ZI" # Edit and continue support - "/wd4201" # Disable nameless struct warning - "/wd4127" # Disable conditional expression is constant warning + "/MP" # Multi-threading support + "/ZI" # Edit and continue support + "/wd4201" # Disable "nameless struct" warning + "/wd4127" # Disable "conditional expression is constant" warning ) if (OPENSPACE_WARNINGS_AS_ERRORS) target_compile_options(${project} PUBLIC "/WX")