From f60840754fcf7da27bb41640ee9c5ab3cb91cfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Thu, 9 Nov 2017 14:44:42 +0100 Subject: [PATCH] disable water effects for spherical screenshots --- apps/openmw/mwrender/renderingmanager.cpp | 14 ++++------- apps/openmw/mwrender/water.cpp | 29 +++++++++++++++++++---- apps/openmw/mwrender/water.hpp | 1 + 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 9e2773870..b1f1888d0 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -644,7 +644,7 @@ namespace MWRender for (int j = 0; j < h; ++j) for (int i = 0; i < w; ++i) - dest->setColor(getColorByDirection(smallPlanetCoords(i / ((float) w), j / ((float) h))),i,j); + dest->setColor(getColorByDirection(sphericalCoords(i / ((float) w), j / ((float) h))),i,j); } osg::Vec3d cylindricalCoords(double x, double y) @@ -766,12 +766,6 @@ namespace MWRender { osg::Image *sideImage = s.getImage(i); screenshot(sideImage,w,w,directions[i]); - - // if (i == 0) - //image->allocateImage(resultW,resultH,sideImage->r(),sideImage->getPixelFormat(),sideImage->getDataType()); - //image->allocateImage(6 * w,w,sideImage->r(),sideImage->getPixelFormat(),sideImage->getDataType()); - - // osg::copyImage(sideImage,0,0,0,sideImage->s(),sideImage->t(),sideImage->r(),image,w * i,0,0); } if (mCamera->isFirstPerson()) @@ -795,8 +789,6 @@ namespace MWRender mViewer->getCamera()->getViewMatrix() * osg::Matrixd::rotate(osg::Vec3(0,0,-1),direction) ); -// TODO: water reflections have to be transformed as well!!!!! - rttCamera->setViewport(0, 0, w, h); osg::ref_ptr texture (new osg::Texture2D); @@ -823,10 +815,14 @@ namespace MWRender // at the time this function is called we are in the middle of a frame, // so out of order calls are necessary to get a correct frameNumber for the next frame. // refer to the advance() and frame() order in Engine::go() + mWater->setEffectsEnabled(false); + mViewer->eventTraversal(); mViewer->updateTraversal(); mViewer->renderingTraversals(); + mWater->setEffectsEnabled(true); + callback->waitTillDone(); // now that we've "used up" the current frame, get a fresh framenumber for the next frame() following after the screenshot is completed diff --git a/apps/openmw/mwrender/water.cpp b/apps/openmw/mwrender/water.cpp index c4dffb7a4..70e7b36ad 100644 --- a/apps/openmw/mwrender/water.cpp +++ b/apps/openmw/mwrender/water.cpp @@ -207,7 +207,6 @@ osg::ref_ptr readPngImage (const std::string& file) return result.getImage(); } - class Refraction : public osg::Camera { public: @@ -221,7 +220,7 @@ public: setSmallFeatureCullingPixelSize(Settings::Manager::getInt("small feature culling pixel size", "Water")); setName("RefractionCamera"); - setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_Actor|Mask_ParticleSystem|Mask_Sky|Mask_Sun|Mask_Player|Mask_Lighting); + setupCullMask(true); setNodeMask(Mask_RenderToTexture); setViewport(0, 0, rttSize, rttSize); @@ -262,6 +261,12 @@ public: attach(osg::Camera::DEPTH_BUFFER, mRefractionDepthTexture); } + void setupCullMask(bool enabled) + { + setCullMask(!enabled ? 0 : + Mask_Effect|Mask_Scene|Mask_Terrain|Mask_Actor|Mask_ParticleSystem|Mask_Sky|Mask_Sun|Mask_Player|Mask_Lighting); + } + void setScene(osg::Node* scene) { if (mScene) @@ -304,9 +309,9 @@ public: setSmallFeatureCullingPixelSize(Settings::Manager::getInt("small feature culling pixel size", "Water")); setName("ReflectionCamera"); - bool reflectActors = Settings::Manager::getBool("reflect actors", "Water"); + mReflectActors = Settings::Manager::getBool("reflect actors", "Water"); - setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_ParticleSystem|Mask_Sky|Mask_Player|Mask_Lighting|(reflectActors ? Mask_Actor : 0)); + setupCullMask(true); setNodeMask(Mask_RenderToTexture); unsigned int rttSize = Settings::Manager::getInt("rtt size", "Water"); @@ -334,6 +339,12 @@ public: addChild(mClipCullNode); } + void setupCullMask(bool enabled) + { + setCullMask(!enabled ? 0 : + Mask_Effect|Mask_Scene|Mask_Terrain|Mask_ParticleSystem|Mask_Sky|Mask_Player|Mask_Lighting|(mReflectActors ? Mask_Actor : 0)); + } + void setWaterLevel(float waterLevel) { setViewMatrix(osg::Matrix::scale(1,1,-1) * osg::Matrix::translate(0,0,2 * waterLevel)); @@ -357,6 +368,7 @@ private: osg::ref_ptr mReflectionTexture; osg::ref_ptr mClipCullNode; osg::ref_ptr mScene; + bool mReflectActors; }; /// DepthClampCallback enables GL_DEPTH_CLAMP for the current draw, if supported. @@ -697,4 +709,13 @@ void Water::clearRipples() mSimulation->clear(); } +void Water::setEffectsEnabled(bool enabled) +{ + if (mReflection) + mReflection->setupCullMask(enabled); + + if (mRefraction) + mRefraction->setupCullMask(enabled); +} + } diff --git a/apps/openmw/mwrender/water.hpp b/apps/openmw/mwrender/water.hpp index a4fd1ed36..ed6e40f1a 100644 --- a/apps/openmw/mwrender/water.hpp +++ b/apps/openmw/mwrender/water.hpp @@ -106,6 +106,7 @@ namespace MWRender void removeCell(const MWWorld::CellStore* store); ///< remove all emitters in this cell void clearRipples(); + void setEffectsEnabled(bool enabled); void changeCell(const MWWorld::CellStore* store); void setHeight(const float height);