Merge branch 'feature/projectiontexturemap' into develop

This commit is contained in:
Alexander Bock
2016-08-19 08:36:12 +02:00
20 changed files with 392 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
return {
FileRequest = {
{ Identifier = "charon_textures", Destination = "textures", Version = 1 }
{ Identifier = "charon_textures", Destination = "textures", Version = 2 }
},
}

View File

@@ -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 }
},
}

View File

@@ -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 }
}
}

View File

@@ -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

View File

@@ -28,6 +28,7 @@ return {
Observer = "ROSETTA",
Target = "CHURYUMOV-GERASIMENKO",
Aberration = "NONE",
TextureMap = true
},
DataInputTranslation = {
Instrument = {

Binary file not shown.

View File

@@ -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}" }
}
}

View File

@@ -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") {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -74,7 +74,7 @@ Fragment getFragment() {
textureColor.rgb = mix(
textureColor.rgb,
projectionColor.rgb,
min(_projectionFading, projectionColor.a)
_projectionFading
);
}

View File

@@ -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);
}
}

View File

@@ -24,8 +24,6 @@
#version __CONTEXT__
#include "PowerScaling/powerScaling_vs.hglsl"
layout(location = 0) in vec4 in_position;
out vec4 vs_position;

View File

@@ -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<void*>(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<bool>(keyNeedsTextureMapDilation)) {
_needsTextureMapDilation = dictionary.value<bool>(keyNeedsTextureMapDilation);
}
return completeSuccess;
}
@@ -225,13 +278,50 @@ void ProjectionComponent::imageProjectBegin() {
static_cast<GLsizei>(_projectionTexture->width()),
static_cast<GLsizei>(_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<GLsizei>(_projectionTexture->width()), static_cast<GLsizei>(_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<ghoul::opengl::Texture> ProjectionComponent::loadProjectionTextu
using ghoul::io::TextureReader;
if (isPlaceholder)
if (isPlaceholder) {
return _placeholderTexture;
}
unique_ptr<Texture> 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<ghoul::opengl::Texture>(
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<ghoul::opengl::Texture>(
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;
}

View File

@@ -32,6 +32,14 @@
#include <ghoul/misc/dictionary.h>
#include <ghoul/opengl/texture.h>
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<ghoul::opengl::ProgramObject> program;
std::unique_ptr<ghoul::opengl::Texture> texture;
std::unique_ptr<ghoul::opengl::Texture> stencilTexture;
} _dilation;
};
} // namespace openspace

View File

@@ -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")