make use of renderinfo

pull/313/head
Miloslav Číž 7 years ago
parent 33a1459b11
commit 8114126a62

@ -255,7 +255,7 @@ namespace MWRender
mRootNode->getOrCreateStateSet()->addUniform(mUniformRainIntensity); mRootNode->getOrCreateStateSet()->addUniform(mUniformRainIntensity);
mSky.reset(new SkyManager(sceneRoot, resourceSystem->getSceneManager(), this)); mSky.reset(new SkyManager(sceneRoot, resourceSystem->getSceneManager()));
source->setStateSetModes(*mRootNode->getOrCreateStateSet(), osg::StateAttribute::ON); source->setStateSetModes(*mRootNode->getOrCreateStateSet(), osg::StateAttribute::ON);

@ -1094,9 +1094,8 @@ private:
} }
}; };
SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager, MWRender::RenderingManager *renderingManager) SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager)
: mSceneManager(sceneManager) : mSceneManager(sceneManager)
, mRendering(renderingManager)
, mAtmosphereNightRoll(0.f) , mAtmosphereNightRoll(0.f)
, mCreated(false) , mCreated(false)
, mIsStorm(false) , mIsStorm(false)
@ -1344,40 +1343,50 @@ protected:
class WeatherParticleDrawCallback : public osg::Drawable::DrawCallback class WeatherParticleDrawCallback : public osg::Drawable::DrawCallback
{ {
public: public:
WeatherParticleDrawCallback(MWRender::RenderingManager *renderingManager, float rangeX, float rangeY) : osg::Drawable::DrawCallback() WeatherParticleDrawCallback(float rangeX, float rangeY) : osg::Drawable::DrawCallback()
{ {
mRendering = renderingManager;
mRangeX = rangeX; mRangeX = rangeX;
mRangeY = rangeY; mRangeY = rangeY;
} }
virtual void drawImplementation(osg::RenderInfo& renderInfo, const osg::Drawable *drawable) const virtual void drawImplementation(osg::RenderInfo& renderInfo, const osg::Drawable *drawable) const
{ {
osg::Vec3 cameraPos = mRendering->getCameraPosition(); osgParticle::ParticleSystem *ps = (osgParticle::ParticleSystem *) drawable;
osg::Vec3 cameraPos = renderInfo.getCurrentCamera()->getInverseViewMatrix().getTrans();
osg::Vec3 cameraOffset = osg::Vec3( osg::Vec3 cameraOffset = osg::Vec3(
mRangeX - fmod(cameraPos.x(), mRangeX / 2), fmod(cameraPos.x(), mRangeX),
mRangeY - fmod(cameraPos.y(), mRangeY / 2), fmod(cameraPos.y(), mRangeY),
0); 0.0);
osgParticle::ParticleSystem *ps = (osgParticle::ParticleSystem *) drawable; std::vector<osg::Vec3> positionBackups;
for (int xOff = 0; xOff < 3; xOff++) for (int i = 0; i < ps->numParticles(); i++)
for (int yOff = 0; yOff < 3; yOff++) {
{ osgParticle::Particle *particle = ps->getParticle(i);
osg::Vec3 offset = cameraOffset + osg::Vec3(-1 * xOff * mRangeX, -1 * yOff * mRangeY,0);
for(int i = 0; i < ps->numParticles(); i++) positionBackups.push_back(particle->getPosition());
ps->getParticle(i)->setPosition(ps->getParticle(i)->getPosition() + offset);
ps->drawImplementation(renderInfo); particle->setPosition(particle->getPosition() - cameraOffset);
for(int i = 0; i < ps->numParticles(); i++) if (particle->getPosition().x() > mRangeX / 2.0) // wrap-around effect
ps->getParticle(i)->setPosition(ps->getParticle(i)->getPosition() - offset); particle->setPosition(particle->getPosition() - osg::Vec3(mRangeX,0,0));
} else if (particle->getPosition().x() < -mRangeX / 2.0)
particle->setPosition(particle->getPosition() + osg::Vec3(mRangeX,0,0));
if (particle->getPosition().y() > mRangeY / 2.0)
particle->setPosition(particle->getPosition() - osg::Vec3(0,mRangeY,0));
else if (particle->getPosition().y() < -mRangeY / 2.0)
particle->setPosition(particle->getPosition() + osg::Vec3(0,mRangeY,0));
}
ps->drawImplementation(renderInfo);
for (int i = 0; i < ps->numParticles(); i++) // restore positions
ps->getParticle(i)->setPosition(positionBackups[i]);
} }
protected: protected:
MWRender::RenderingManager *mRendering;
float mRangeX, mRangeY; float mRangeX, mRangeY;
}; };
@ -1389,11 +1398,12 @@ void SkyManager::createRain()
mRainNode = new osg::Group; mRainNode = new osg::Group;
mRainParticleSystem = new osgParticle::ParticleSystem; mRainParticleSystem = new osgParticle::ParticleSystem;
mRainParticleSystem->setDrawCallback(new WeatherParticleDrawCallback(mRendering,RAIN_WIDTH,RAIN_WIDTH)); mRainParticleSystem->setDrawCallback(new WeatherParticleDrawCallback(RAIN_WIDTH,RAIN_WIDTH));
mRainParticleSystem->setParticleAlignment(osgParticle::ParticleSystem::FIXED); mRainParticleSystem->setParticleAlignment(osgParticle::ParticleSystem::FIXED);
mRainParticleSystem->setAlignVectorX(osg::Vec3f(0.1,0,0)); mRainParticleSystem->setAlignVectorX(osg::Vec3f(0.1,0,0));
mRainParticleSystem->setAlignVectorY(osg::Vec3f(0,0,1)); mRainParticleSystem->setAlignVectorY(osg::Vec3f(0,0,1));
mRainParticleSystem->setCullingActive(false);
osg::ref_ptr<osg::StateSet> stateset (mRainParticleSystem->getOrCreateStateSet()); osg::ref_ptr<osg::StateSet> stateset (mRainParticleSystem->getOrCreateStateSet());
@ -1422,7 +1432,8 @@ void SkyManager::createRain()
emitter->setPlacer(placer); emitter->setPlacer(placer);
osg::ref_ptr<osgParticle::ConstantRateCounter> counter (new osgParticle::ConstantRateCounter); osg::ref_ptr<osgParticle::ConstantRateCounter> counter (new osgParticle::ConstantRateCounter);
counter->setNumberOfParticlesPerSecondToCreate(600.0); // counter->setNumberOfParticlesPerSecondToCreate(600.0);
counter->setNumberOfParticlesPerSecondToCreate(2000);
emitter->setCounter(counter); emitter->setCounter(counter);
osg::ref_ptr<RainShooter> shooter (new RainShooter); osg::ref_ptr<RainShooter> shooter (new RainShooter);
@ -1496,6 +1507,9 @@ void SkyManager::update(float duration)
osg::Quat quat; osg::Quat quat;
quat.makeRotate(osg::Vec3f(0,1,0), mStormDirection); quat.makeRotate(osg::Vec3f(0,1,0), mStormDirection);
if (mParticleNode)
mParticleNode->setAttitude(quat);
mCloudNode->setAttitude(quat); mCloudNode->setAttitude(quat);
} }
else else
@ -1587,7 +1601,7 @@ void SkyManager::setWeather(const WeatherResult& weather)
{ {
if (!mParticleNode) if (!mParticleNode)
{ {
mParticleNode = new osg::Group; mParticleNode = new osg::PositionAttitudeTransform;
mParticleNode->addCullCallback(mUnderwaterSwitch); mParticleNode->addCullCallback(mUnderwaterSwitch);
mParticleNode->setNodeMask(Mask_WeatherParticles); mParticleNode->setNodeMask(Mask_WeatherParticles);
mRootNode->addChild(mParticleNode); mRootNode->addChild(mParticleNode);
@ -1621,12 +1635,11 @@ void SkyManager::setWeather(const WeatherResult& weather)
} }
} }
SceneUtil::FindByClassVisitor findPSVisitor(std::string("ParticleSystem")); SceneUtil::FindByClassVisitor findPSVisitor(std::string("ParticleSystem"));
mParticleEffect->accept(findPSVisitor); mParticleEffect->accept(findPSVisitor);
if (findPSVisitor.mFoundNode) if (findPSVisitor.mFoundNode)
((osgParticle::ParticleSystem *) findPSVisitor.mFoundNode)->setDrawCallback(new WeatherParticleDrawCallback(mRendering,rangeX,rangeY)); ((osgParticle::ParticleSystem *) findPSVisitor.mFoundNode)->setDrawCallback(new WeatherParticleDrawCallback(rangeX,rangeY));
} }
} }

@ -9,8 +9,6 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <osg/Vec4f> #include <osg/Vec4f>
#include <apps/openmw/mwrender/renderingmanager.hpp>
namespace osg namespace osg
{ {
class Group; class Group;
@ -110,7 +108,7 @@ namespace MWRender
class SkyManager class SkyManager
{ {
public: public:
SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager, MWRender::RenderingManager *renderingManager); SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager);
~SkyManager(); ~SkyManager();
void update(float duration); void update(float duration);
@ -172,12 +170,11 @@ namespace MWRender
void updateRainParameters(); void updateRainParameters();
Resource::SceneManager* mSceneManager; Resource::SceneManager* mSceneManager;
MWRender::RenderingManager *mRendering;
osg::ref_ptr<osg::Group> mRootNode; osg::ref_ptr<osg::Group> mRootNode;
osg::ref_ptr<osg::Group> mEarlyRenderBinRoot; osg::ref_ptr<osg::Group> mEarlyRenderBinRoot;
osg::ref_ptr<osg::Group> mParticleNode; osg::ref_ptr<osg::PositionAttitudeTransform> mParticleNode;
osg::ref_ptr<osg::Node> mParticleEffect; osg::ref_ptr<osg::Node> mParticleEffect;
std::vector<osg::ref_ptr<AlphaFader> > mParticleFaders; std::vector<osg::ref_ptr<AlphaFader> > mParticleFaders;
osg::ref_ptr<UnderwaterSwitchCallback> mUnderwaterSwitch; osg::ref_ptr<UnderwaterSwitchCallback> mUnderwaterSwitch;

Loading…
Cancel
Save