Make use of INI settings for the simple water

openmw-37
scrawl 9 years ago
parent 30c828dff0
commit c0a81030bb

@ -34,6 +34,7 @@
#include <components/esm/loadcell.hpp> #include <components/esm/loadcell.hpp>
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/fallback.hpp"
#include "vismask.hpp" #include "vismask.hpp"
#include "ripplesimulation.hpp" #include "ripplesimulation.hpp"
@ -457,6 +458,7 @@ Water::Water(osg::Group *parent, osg::Group* sceneRoot, Resource::ResourceSystem
: mParent(parent) : mParent(parent)
, mSceneRoot(sceneRoot) , mSceneRoot(sceneRoot)
, mResourceSystem(resourceSystem) , mResourceSystem(resourceSystem)
, mFallback(fallback)
, mResourcePath(resourcePath) , mResourcePath(resourcePath)
, mEnabled(true) , mEnabled(true)
, mToggled(true) , mToggled(true)
@ -480,7 +482,7 @@ Water::Water(osg::Group *parent, osg::Group* sceneRoot, Resource::ResourceSystem
// simple water fallback for the local map // simple water fallback for the local map
osg::ref_ptr<osg::Geode> geode2 (osg::clone(mWaterGeode.get(), osg::CopyOp::DEEP_COPY_NODES)); osg::ref_ptr<osg::Geode> geode2 (osg::clone(mWaterGeode.get(), osg::CopyOp::DEEP_COPY_NODES));
createSimpleWaterStateSet(geode2); // Water_Map_Alpha createSimpleWaterStateSet(geode2, mFallback->getFallbackFloat("Water_Map_Alpha"));
geode2->setNodeMask(Mask_SimpleWater); geode2->setNodeMask(Mask_SimpleWater);
mWaterNode->addChild(geode2); mWaterNode->addChild(geode2);
@ -522,18 +524,18 @@ void Water::updateWaterMaterial()
createShaderWaterStateSet(mWaterGeode, mReflection, mRefraction); createShaderWaterStateSet(mWaterGeode, mReflection, mRefraction);
} }
else else
createSimpleWaterStateSet(mWaterGeode); createSimpleWaterStateSet(mWaterGeode, mFallback->getFallbackFloat("Water_World_Alpha"));
updateVisible(); updateVisible();
} }
void Water::createSimpleWaterStateSet(osg::Node* node) void Water::createSimpleWaterStateSet(osg::Node* node, float alpha)
{ {
osg::ref_ptr<osg::StateSet> stateset (new osg::StateSet); osg::ref_ptr<osg::StateSet> stateset (new osg::StateSet);
osg::ref_ptr<osg::Material> material (new osg::Material); osg::ref_ptr<osg::Material> material (new osg::Material);
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 1.f)); material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 1.f));
material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1.f, 1.f, 1.f, 0.7f)); // Water_World_Alpha material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1.f, 1.f, 1.f, alpha));
material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(1.f, 1.f, 1.f, 1.f)); material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(1.f, 1.f, 1.f, 1.f));
material->setColorMode(osg::Material::OFF); material->setColorMode(osg::Material::OFF);
stateset->setAttributeAndModes(material, osg::StateAttribute::ON); stateset->setAttributeAndModes(material, osg::StateAttribute::ON);
@ -548,14 +550,18 @@ void Water::createSimpleWaterStateSet(osg::Node* node)
stateset->setRenderBinDetails(MWRender::RenderBin_Water, "RenderBin"); stateset->setRenderBinDetails(MWRender::RenderBin_Water, "RenderBin");
std::vector<osg::ref_ptr<osg::Texture2D> > textures; std::vector<osg::ref_ptr<osg::Texture2D> > textures;
for (int i=0; i<32; ++i) int frameCount = mFallback->getFallbackInt("Water_SurfaceFrameCount");
std::string texture = mFallback->getFallbackString("Water_SurfaceTexture");
for (int i=0; i<frameCount; ++i)
{ {
std::ostringstream texname; std::ostringstream texname;
texname << "textures/water/water" << std::setw(2) << std::setfill('0') << i << ".dds"; texname << "textures/water/" << texture << std::setw(2) << std::setfill('0') << i << ".dds";
textures.push_back(mResourceSystem->getTextureManager()->getTexture2D(texname.str(), osg::Texture::REPEAT, osg::Texture::REPEAT)); textures.push_back(mResourceSystem->getTextureManager()->getTexture2D(texname.str(), osg::Texture::REPEAT, osg::Texture::REPEAT));
} }
osg::ref_ptr<NifOsg::FlipController> controller (new NifOsg::FlipController(0, 2/32.f, textures)); float fps = mFallback->getFallbackFloat("Water_SurfaceFPS");
osg::ref_ptr<NifOsg::FlipController> controller (new NifOsg::FlipController(0, 1.f/fps, textures));
controller->setSource(boost::shared_ptr<SceneUtil::ControllerSource>(new SceneUtil::FrameTimeSource)); controller->setSource(boost::shared_ptr<SceneUtil::ControllerSource>(new SceneUtil::FrameTimeSource));
node->setUpdateCallback(controller); node->setUpdateCallback(controller);
node->setStateSet(stateset); node->setStateSet(stateset);

@ -50,6 +50,7 @@ namespace MWRender
osg::ref_ptr<osg::PositionAttitudeTransform> mWaterNode; osg::ref_ptr<osg::PositionAttitudeTransform> mWaterNode;
osg::ref_ptr<osg::Geode> mWaterGeode; osg::ref_ptr<osg::Geode> mWaterGeode;
Resource::ResourceSystem* mResourceSystem; Resource::ResourceSystem* mResourceSystem;
const MWWorld::Fallback* mFallback;
osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation; osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation;
std::auto_ptr<RippleSimulation> mSimulation; std::auto_ptr<RippleSimulation> mSimulation;
@ -66,7 +67,7 @@ namespace MWRender
osg::Vec3f getSceneNodeCoordinates(int gridX, int gridY); osg::Vec3f getSceneNodeCoordinates(int gridX, int gridY);
void updateVisible(); void updateVisible();
void createSimpleWaterStateSet(osg::Node* node); void createSimpleWaterStateSet(osg::Node* node, float alpha);
/// @param reflection the reflection camera (required) /// @param reflection the reflection camera (required)
/// @param refraction the refraction camera (optional) /// @param refraction the refraction camera (optional)

Loading…
Cancel
Save