diff --git a/simgear/scene/viewer/Compositor.cxx b/simgear/scene/viewer/Compositor.cxx index b212ae96..b0cb67e0 100644 --- a/simgear/scene/viewer/Compositor.cxx +++ b/simgear/scene/viewer/Compositor.cxx @@ -136,6 +136,7 @@ Compositor::Compositor(osg::View *view, _viewport(viewport), _uniforms{ new osg::Uniform("fg_Viewport", osg::Vec4f()), + new osg::Uniform("fg_PixelSize", osg::Vec2f()), new osg::Uniform("fg_ViewMatrix", osg::Matrixf()), new osg::Uniform("fg_ViewMatrixInverse", osg::Matrixf()), new osg::Uniform("fg_ProjectionMatrix", osg::Matrixf()), @@ -217,10 +218,6 @@ Compositor::update(const osg::Matrix &view_matrix, for (int i = 0; i < SG_TOTAL_BUILTIN_UNIFORMS; ++i) { osg::ref_ptr u = _uniforms[i]; switch (i) { - case SG_UNIFORM_VIEWPORT: - u->set(osg::Vec4f(_viewport->x(), _viewport->y(), - _viewport->width(), _viewport->height())); - break; case SG_UNIFORM_VIEW_MATRIX: u->set(view_matrix); break; @@ -281,7 +278,10 @@ Compositor::resized() // viewport size. for (const auto &pass : _passes) { osg::Camera *camera = pass->camera; - if (camera && camera->isRenderToTextureCamera() + if (!camera) + continue; + + if (camera->isRenderToTextureCamera() && pass->viewport_width_scale != 0.0f && pass->viewport_height_scale != 0.0f) { @@ -292,6 +292,17 @@ Compositor::resized() // Force the OSG rendering backend to handle the new sizes camera->dirtyAttachmentMap(); } + + // Update the uniforms even if it isn't a RTT camera + osg::Viewport *viewport = camera->getViewport(); + _uniforms[SG_UNIFORM_VIEWPORT]->set( + osg::Vec4f(viewport->x(), + viewport->y(), + viewport->width(), + viewport->height())); + _uniforms[Compositor::SG_UNIFORM_PIXEL_SIZE]->set( + osg::Vec2f(1.0f / viewport->width(), + 1.0f / viewport->height())); } // Resize buffers that must be a multiple of the screen size diff --git a/simgear/scene/viewer/Compositor.hxx b/simgear/scene/viewer/Compositor.hxx index 5d9efdab..94849ba9 100644 --- a/simgear/scene/viewer/Compositor.hxx +++ b/simgear/scene/viewer/Compositor.hxx @@ -47,6 +47,7 @@ class Compositor { public: enum BuiltinUniform { SG_UNIFORM_VIEWPORT = 0, + SG_UNIFORM_PIXEL_SIZE, SG_UNIFORM_VIEW_MATRIX, SG_UNIFORM_VIEW_MATRIX_INV, SG_UNIFORM_PROJECTION_MATRIX, diff --git a/simgear/scene/viewer/CompositorPass.cxx b/simgear/scene/viewer/CompositorPass.cxx index 9fa5f1fa..f97ece7d 100644 --- a/simgear/scene/viewer/CompositorPass.cxx +++ b/simgear/scene/viewer/CompositorPass.cxx @@ -401,6 +401,17 @@ PassBuilder::build(Compositor *compositor, const SGPropertyNode *root, } } + osg::Viewport *viewport = camera->getViewport(); + auto &uniforms = compositor->getBuiltinUniforms(); + uniforms[Compositor::SG_UNIFORM_VIEWPORT]->set( + osg::Vec4f(viewport->x(), + viewport->y(), + viewport->width(), + viewport->height())); + uniforms[Compositor::SG_UNIFORM_PIXEL_SIZE]->set( + osg::Vec2f(1.0f / viewport->width(), + 1.0f / viewport->height())); + return pass.release(); }