diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index dc68cc93e6..64fdf8ea67 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -81,8 +81,8 @@ namespace { "resolution" }; - constexpr std::array UniformOpacityNames = { - "opacity", "colorTexture", "depthTexture" + constexpr std::array UniformOpacityNames = { + "opacity", "colorTexture", "depthTexture", "viewport", "resolution" }; constexpr openspace::properties::Property::PropertyInfo EnableAnimationInfo = { @@ -875,6 +875,23 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ); _quadProgram->setUniform(_uniformOpacityCache.depthTexture, depthTextureUnit); + // Will also need the resolution and viewport to get a texture coordinate + _quadProgram->setUniform( + _uniformOpacityCache.resolution, + glm::vec2(global::windowDelegate->currentDrawBufferResolution()) + ); + + GLint vp[4] = { 0 }; + global::renderEngine->openglStateCache().viewport(vp); + glm::ivec4 viewport = glm::ivec4(vp[0], vp[1], vp[2], vp[3]); + _quadProgram->setUniform( + _uniformOpacityCache.viewport, + static_cast(viewport[0]), + static_cast(viewport[1]), + static_cast(viewport[2]), + static_cast(viewport[3]) + ); + // Draw glBindVertexArray(_quadVao); glDrawArrays(GL_TRIANGLES, 0, 6); diff --git a/modules/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 7733fd005a..ba40bb4d80 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -123,7 +123,8 @@ private: // Opacity program ghoul::opengl::ProgramObject* _quadProgram = nullptr; - UniformCache(opacity, colorTexture, depthTexture) _uniformOpacityCache; + UniformCache(opacity, colorTexture, depthTexture, viewport, + resolution) _uniformOpacityCache; // Store the original RenderBin Renderable::RenderBin _originalRenderBin; diff --git a/modules/base/shaders/modelOpacity_fs.glsl b/modules/base/shaders/modelOpacity_fs.glsl index 1f19bef9ec..4ce6761239 100644 --- a/modules/base/shaders/modelOpacity_fs.glsl +++ b/modules/base/shaders/modelOpacity_fs.glsl @@ -32,10 +32,24 @@ uniform float opacity = 1.0; uniform sampler2D colorTexture; uniform sampler2D depthTexture; +uniform vec4 viewport; +uniform vec2 resolution; + Fragment getFragment() { Fragment frag; - vec4 textureColor = texture(colorTexture, vs_st); + // Modify the texCoord based on the Viewport and Resolution. This modification is + // necessary in case of side-by-side stereo as we only want to access the part of the + // feeding texture that we are currently responsible for. Otherwise we would map the + // entire feeding texture into our half of the result texture, leading to a doubling of + // the "missing" half. If you don't believe me, load a configuration file with the + // side_by_side stereo mode enabled, disable FXAA, and remove this modification. + // The same calculation is done in the HDR resolving shader + vec2 st = vs_st; + st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x); + st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y); + + vec4 textureColor = texture(colorTexture, st); if (textureColor.a == 0.0 || opacity == 0.0) { discard; }