diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 3826fd5f6..37abb1ec3 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -255,7 +255,7 @@ namespace MWRender mRootNode->getOrCreateStateSet()->addUniform(mUniformRainIntensity); - mSky.reset(new SkyManager(sceneRoot, resourceSystem->getSceneManager())); + mSky.reset(new SkyManager(sceneRoot, resourceSystem->getSceneManager(), this)); source->setStateSetModes(*mRootNode->getOrCreateStateSet(), osg::StateAttribute::ON); diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 178c753c6..0603c18a1 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -46,6 +47,8 @@ #include "vismask.hpp" #include "renderbin.hpp" +#define PARTICLE_WIDTH 600.0 + namespace { @@ -1091,8 +1094,9 @@ private: } }; -SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager) +SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager, MWRender::RenderingManager *renderingManager) : mSceneManager(sceneManager) + , mRendering(renderingManager) , mAtmosphereNightRoll(0.f) , mCreated(false) , mIsStorm(false) @@ -1337,6 +1341,43 @@ protected: osg::Uniform* mRainIntensityUniform; }; +class WeatherParticleDrawCallback : public osg::Drawable::DrawCallback +{ +public: + WeatherParticleDrawCallback(MWRender::RenderingManager *renderingManager) : osg::Drawable::DrawCallback() + { + mRendering = renderingManager; + } + + virtual void drawImplementation(osg::RenderInfo& renderInfo, const osg::Drawable *drawable) const + { + osg::Vec3 cameraPos = mRendering->getCameraPosition(); + osg::Vec3 cameraOffset = osg::Vec3( + PARTICLE_WIDTH - fmod(cameraPos.x(), PARTICLE_WIDTH / 2), + PARTICLE_WIDTH - fmod(cameraPos.y(), PARTICLE_WIDTH / 2), + 0); + + osgParticle::ParticleSystem *ps = (osgParticle::ParticleSystem *) drawable; + + for (int xOff = 0; xOff < 3; xOff++) + for (int yOff = 0; yOff < 3; yOff++) + { + osg::Vec3 offset = cameraOffset + osg::Vec3(-1 * xOff * PARTICLE_WIDTH, -1 * yOff * PARTICLE_WIDTH,0); + + for(int i = 0; i < ps->numParticles(); i++) + ps->getParticle(i)->setPosition(ps->getParticle(i)->getPosition() + offset); + + ps->drawImplementation(renderInfo); + + for(int i = 0; i < ps->numParticles(); i++) + ps->getParticle(i)->setPosition(ps->getParticle(i)->getPosition() - offset); + } + } + +protected: + MWRender::RenderingManager *mRendering; +}; + void SkyManager::createRain() { if (mRainNode) @@ -1345,6 +1386,8 @@ void SkyManager::createRain() mRainNode = new osg::Group; mRainParticleSystem = new osgParticle::ParticleSystem; + mRainParticleSystem->setDrawCallback(new WeatherParticleDrawCallback(mRendering)); + mRainParticleSystem->setParticleAlignment(osgParticle::ParticleSystem::FIXED); mRainParticleSystem->setAlignVectorX(osg::Vec3f(0.1,0,0)); mRainParticleSystem->setAlignVectorY(osg::Vec3f(0,0,1)); @@ -1370,8 +1413,8 @@ void SkyManager::createRain() emitter->setParticleSystem(mRainParticleSystem); osg::ref_ptr placer (new osgParticle::BoxPlacer); - placer->setXRange(-300, 300); // Rain_Diameter - placer->setYRange(-300, 300); + placer->setXRange(-PARTICLE_WIDTH / 2, PARTICLE_WIDTH / 2); // Rain_Diameter + placer->setYRange(-PARTICLE_WIDTH / 2, PARTICLE_WIDTH / 2); placer->setZRange(300, 300); emitter->setPlacer(placer); @@ -1559,6 +1602,12 @@ void SkyManager::setWeather(const WeatherResult& weather) SceneUtil::DisableFreezeOnCullVisitor disableFreezeOnCullVisitor; mParticleEffect->accept(disableFreezeOnCullVisitor); + + osgParticle::ParticleSystem *ps = (osgParticle::ParticleSystem *) + (mParticleEffect->asGroup()->getChild(1)->asGroup()->getChild(0) + ->asGroup()->getChild(2)); + + ps->setDrawCallback(new WeatherParticleDrawCallback(mRendering)); } } diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index 59a8ddc4e..37c999563 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -9,6 +9,8 @@ #include #include +#include + namespace osg { class Group; @@ -108,7 +110,7 @@ namespace MWRender class SkyManager { public: - SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager); + SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager, MWRender::RenderingManager *renderingManager); ~SkyManager(); void update(float duration); @@ -170,6 +172,7 @@ namespace MWRender void updateRainParameters(); Resource::SceneManager* mSceneManager; + MWRender::RenderingManager *mRendering; osg::ref_ptr mRootNode; osg::ref_ptr mEarlyRenderBinRoot;