|
|
|
@ -1,4 +1,7 @@
|
|
|
|
|
#include "water.hpp"
|
|
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
|
|
|
|
|
|
using namespace Ogre;
|
|
|
|
|
|
|
|
|
|
namespace MWRender
|
|
|
|
|
{
|
|
|
|
@ -9,17 +12,17 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1);
|
|
|
|
|
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
|
|
|
|
CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1);
|
|
|
|
|
CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
|
|
|
|
} catch(...) {}
|
|
|
|
|
|
|
|
|
|
mTop = cell->water;
|
|
|
|
|
|
|
|
|
|
mIsUnderwater = false;
|
|
|
|
|
|
|
|
|
|
mWaterPlane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0);
|
|
|
|
|
mWaterPlane = Plane(Vector3::UNIT_Y, 0);
|
|
|
|
|
|
|
|
|
|
Ogre::MeshManager::getSingleton().createPlane("water", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, CELL_SIZE*5, CELL_SIZE * 5, 10, 10, true, 1, 3,5, Ogre::Vector3::UNIT_Z);
|
|
|
|
|
MeshManager::getSingleton().createPlane("water", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, CELL_SIZE*5, CELL_SIZE * 5, 10, 10, true, 1, 3,5, Vector3::UNIT_Z);
|
|
|
|
|
|
|
|
|
|
mWater = mSceneManager->createEntity("water");
|
|
|
|
|
|
|
|
|
@ -33,18 +36,41 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
|
|
|
|
mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY));
|
|
|
|
|
}
|
|
|
|
|
mWaterNode->attachObject(mWater);
|
|
|
|
|
|
|
|
|
|
// Create rendertargets for reflection and refraction
|
|
|
|
|
int rttsize = Settings::Manager::getInt("rtt size", "Water");
|
|
|
|
|
for (unsigned int i = 0; i < 2; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i==0 && !Settings::Manager::getBool("reflection", "Water")) continue;
|
|
|
|
|
if (i==1 && !Settings::Manager::getBool("refraction", "Water")) continue;
|
|
|
|
|
|
|
|
|
|
TexturePtr tex = TextureManager::getSingleton().createManual(i == 0 ? "WaterReflection" : "WaterRefraction",
|
|
|
|
|
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, rttsize, rttsize, 0, PF_R8G8B8, TU_RENDERTARGET);
|
|
|
|
|
|
|
|
|
|
RenderTarget* rtt = tex->getBuffer()->getRenderTarget();
|
|
|
|
|
Viewport* vp = rtt->addViewport(mCamera);
|
|
|
|
|
vp->setOverlaysEnabled(false);
|
|
|
|
|
vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f));
|
|
|
|
|
vp->setShadowsEnabled(false);
|
|
|
|
|
//vp->setVisibilityMask( ... );
|
|
|
|
|
rtt->addListener(this);
|
|
|
|
|
rtt->setActive(true);
|
|
|
|
|
|
|
|
|
|
if (i == 0) mReflectionTarget = rtt;
|
|
|
|
|
else mRefractionTarget = rtt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Water::~Water()
|
|
|
|
|
{
|
|
|
|
|
Ogre::MeshManager::getSingleton().remove("water");
|
|
|
|
|
MeshManager::getSingleton().remove("water");
|
|
|
|
|
|
|
|
|
|
mWaterNode->detachObject(mWater);
|
|
|
|
|
mSceneManager->destroyEntity(mWater);
|
|
|
|
|
mSceneManager->destroySceneNode(mWaterNode);
|
|
|
|
|
|
|
|
|
|
Ogre::CompositorManager::getSingleton().removeCompositorChain(mViewport);
|
|
|
|
|
CompositorManager::getSingleton().removeCompositorChain(mViewport);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Water::changeCell(const ESM::Cell* cell)
|
|
|
|
@ -73,7 +99,7 @@ void Water::checkUnderwater(float y)
|
|
|
|
|
if ((mIsUnderwater && y > mTop) || !mWater->isVisible() || mCamera->getPolygonMode() != Ogre::PM_SOLID)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
|
|
|
|
CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
|
|
|
|
|
} catch(...) {}
|
|
|
|
|
mIsUnderwater = false;
|
|
|
|
|
}
|
|
|
|
@ -81,15 +107,37 @@ void Water::checkUnderwater(float y)
|
|
|
|
|
if (!mIsUnderwater && y < mTop && mWater->isVisible() && mCamera->getPolygonMode() == Ogre::PM_SOLID)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", true);
|
|
|
|
|
CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", true);
|
|
|
|
|
} catch(...) {}
|
|
|
|
|
mIsUnderwater = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ogre::Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY)
|
|
|
|
|
Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY)
|
|
|
|
|
{
|
|
|
|
|
return Vector3(gridX * CELL_SIZE + (CELL_SIZE / 2), mTop, -gridY * CELL_SIZE - (CELL_SIZE / 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Water::preRenderTargetUpdate(const RenderTargetEvent& evt)
|
|
|
|
|
{
|
|
|
|
|
return Ogre::Vector3(gridX * CELL_SIZE + (CELL_SIZE / 2), mTop, -gridY * CELL_SIZE - (CELL_SIZE / 2));
|
|
|
|
|
mWater->setVisible(false);
|
|
|
|
|
|
|
|
|
|
if (evt.source == mReflectionTarget)
|
|
|
|
|
{
|
|
|
|
|
mCamera->enableCustomNearClipPlane(mWaterPlane);
|
|
|
|
|
mCamera->enableReflection(Plane(Vector3::UNIT_Y, mWaterNode->_getDerivedPosition().y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Water::postRenderTargetUpdate(const RenderTargetEvent& evt)
|
|
|
|
|
{
|
|
|
|
|
mWater->setVisible(true);
|
|
|
|
|
|
|
|
|
|
if (evt.source == mReflectionTarget)
|
|
|
|
|
{
|
|
|
|
|
mCamera->disableReflection();
|
|
|
|
|
mCamera->disableCustomNearClipPlane();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|