Enabled terrain self shadows, implemented getHeightAt, some optimizations

This commit is contained in:
scrawl 2013-08-19 20:30:22 +02:00
parent d727b15580
commit ebf9debb80
22 changed files with 421 additions and 164 deletions

View file

@ -69,8 +69,8 @@ void OMW::Engine::setAnimationVerbose(bool animverbose)
bool OMW::Engine::frameStarted (const Ogre::FrameEvent& evt)
{
if (!MWBase::Environment::get().getWindowManager()->isGuiMode())
MWBase::Environment::get().getWorld()->frameStarted(evt.timeSinceLastFrame);
bool paused = MWBase::Environment::get().getWindowManager()->isGuiMode();
MWBase::Environment::get().getWorld()->frameStarted(evt.timeSinceLastFrame, paused);
MWBase::Environment::get().getWindowManager ()->frameStarted(evt.timeSinceLastFrame);
return true;
}
@ -91,12 +91,12 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
MWBase::Environment::get().getSoundManager()->update(frametime);
// global scripts
//MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();
MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();
bool changed = MWBase::Environment::get().getWorld()->hasCellChanged();
// local scripts
//executeLocalScripts(); // This does not handle the case where a global script causes a cell
executeLocalScripts(); // This does not handle the case where a global script causes a cell
// change, followed by a cell change in a local script during the same
// frame.

View file

@ -371,7 +371,7 @@ namespace MWBase
/// \todo this does not belong here
virtual void playVideo(const std::string& name, bool allowSkipping) = 0;
virtual void stopVideo() = 0;
virtual void frameStarted (float dt) = 0;
virtual void frameStarted (float dt, bool paused) = 0;
/// Find default position inside exterior cell specified by name
/// \return false if exterior with given name not exists, true otherwise

View file

@ -125,7 +125,7 @@ namespace MWGui
getWidget(mActorShadows, "ActorShadows");
getWidget(mStaticsShadows, "StaticsShadows");
getWidget(mMiscShadows, "MiscShadows");
getWidget(mShadowsDebug, "ShadowsDebug");
getWidget(mTerrainShadows, "TerrainShadows");
getWidget(mControlsBox, "ControlsBox");
getWidget(mResetControlsButton, "ResetControlsButton");
getWidget(mInvertYButton, "InvertYButton");
@ -161,7 +161,7 @@ namespace MWGui
mActorShadows->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled);
mStaticsShadows->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled);
mMiscShadows->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled);
mShadowsDebug->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled);
mTerrainShadows->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled);
mMasterVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition);
mVoiceVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition);
@ -238,7 +238,7 @@ namespace MWGui
mActorShadows->setCaptionWithReplacing(Settings::Manager::getBool("actor shadows", "Shadows") ? "#{sOn}" : "#{sOff}");
mStaticsShadows->setCaptionWithReplacing(Settings::Manager::getBool("statics shadows", "Shadows") ? "#{sOn}" : "#{sOff}");
mMiscShadows->setCaptionWithReplacing(Settings::Manager::getBool("misc shadows", "Shadows") ? "#{sOn}" : "#{sOff}");
mShadowsDebug->setCaptionWithReplacing(Settings::Manager::getBool("debug", "Shadows") ? "#{sOn}" : "#{sOff}");
mTerrainShadows->setCaptionWithReplacing(Settings::Manager::getBool("terrain shadows", "Shadows") ? "#{sOn}" : "#{sOff}");
float cameraSens = (Settings::Manager::getFloat("camera sensitivity", "Input")-0.2)/(5.0-0.2);
mCameraSensitivitySlider->setScrollPosition (cameraSens * (mCameraSensitivitySlider->getScrollRange()-1));
@ -394,8 +394,8 @@ namespace MWGui
Settings::Manager::setBool("statics shadows", "Shadows", newState);
else if (_sender == mMiscShadows)
Settings::Manager::setBool("misc shadows", "Shadows", newState);
else if (_sender == mShadowsDebug)
Settings::Manager::setBool("debug", "Shadows", newState);
else if (_sender == mTerrainShadows)
Settings::Manager::setBool("terrain shadows", "Shadows", newState);
else if (_sender == mInvertYButton)
Settings::Manager::setBool("invert y axis", "Input", newState);
else if (_sender == mCrosshairButton)

View file

@ -59,7 +59,7 @@ namespace MWGui
MyGUI::Button* mActorShadows;
MyGUI::Button* mStaticsShadows;
MyGUI::Button* mMiscShadows;
MyGUI::Button* mShadowsDebug;
MyGUI::Button* mTerrainShadows;
// audio
MyGUI::ScrollBar* mMasterVolumeSlider;

View file

@ -82,7 +82,7 @@ RenderingManager::RenderingManager(OEngine::Render::OgreRenderer& _rend, const b
Settings::Manager::setString("shader mode", "General", openGL ? (glES ? "glsles" : "glsl") : "hlsl");
}
mRendering.createScene("PlayerCam", Settings::Manager::getFloat("field of view", "General"), 50);
mRendering.createScene("PlayerCam", Settings::Manager::getFloat("field of view", "General"), 5);
mRendering.getWindow()->addListener(this);
mRendering.setWindowListener(this);
@ -248,8 +248,10 @@ void RenderingManager::cellAdded (MWWorld::Ptr::CellStore *store)
{
if (!mTerrain)
{
mTerrain = new Terrain::Terrain(mRendering.getScene(), new MWRender::TerrainStorage(), RV_Terrain);
mTerrain->update(mRendering.getCamera());
mTerrain = new Terrain::Terrain(mRendering.getScene(), new MWRender::TerrainStorage(), RV_Terrain,
Settings::Manager::getBool("distant land", "Terrain"),
Settings::Manager::getBool("shader", "Terrain"));
mTerrain->update(mRendering.getCamera()->getRealPosition());
}
}
waterAdded(store);
@ -554,13 +556,6 @@ void RenderingManager::setAmbientMode()
}
}
float RenderingManager::getTerrainHeightAt(Ogre::Vector3 worldPos)
{
assert(mTerrain);
return mTerrain->getHeightAt(worldPos);
}
void RenderingManager::configureAmbient(MWWorld::Ptr::CellStore &mCell)
{
mAmbientColor.setAsABGR (mCell.mCell->mAmbi.mAmbient);
@ -658,9 +653,14 @@ void RenderingManager::requestMap(MWWorld::Ptr::CellStore* cell)
{
if (cell->mCell->isExterior())
{
assert(mTerrain);
Ogre::AxisAlignedBox dims = mObjects.getDimensions(cell);
Ogre::Vector2 center(cell->mCell->getGridX() + 0.5, -cell->mCell->getGridY() + 1 - 0.5);
Ogre::Vector2 center(cell->mCell->getGridX() + 0.5, cell->mCell->getGridY() + 0.5);
dims.merge(mTerrain->getWorldBoundingBox(center));
mTerrain->update(dims.getCenter());
mLocalMap->requestMap(cell, dims.getMinimum().z, dims.getMaximum().z);
}
else
@ -992,12 +992,13 @@ void RenderingManager::updateWaterRippleEmitterPtr (const MWWorld::Ptr& old, con
mWater->updateEmitterPtr(old, ptr);
}
void RenderingManager::frameStarted(float dt)
void RenderingManager::frameStarted(float dt, bool paused)
{
if (mTerrain)
mTerrain->update(mRendering.getCamera());
mTerrain->update(mRendering.getCamera()->getRealPosition());
mWater->frameStarted(dt);
if (!paused)
mWater->frameStarted(dt);
}
void RenderingManager::resetCamera()
@ -1005,4 +1006,10 @@ void RenderingManager::resetCamera()
mCamera->reset();
}
float RenderingManager::getTerrainHeightAt(Ogre::Vector3 worldPos)
{
assert(mTerrain);
return mTerrain->getHeightAt(worldPos);
}
} // namespace

View file

@ -157,6 +157,8 @@ public:
bool occlusionQuerySupported() { return mOcclusionQuery->supported(); }
OcclusionQuery* getOcclusionQuery() { return mOcclusionQuery; }
float getTerrainHeightAt (Ogre::Vector3 worldPos);
Shadows* getShadows();
void switchToInterior();
@ -164,8 +166,6 @@ public:
void getTriangleBatchCount(unsigned int &triangles, unsigned int &batches);
float getTerrainHeightAt (Ogre::Vector3 worldPos);
void setGlare(bool glare);
void skyEnable ();
void skyDisable ();
@ -209,7 +209,7 @@ public:
void playVideo(const std::string& name, bool allowSkipping);
void stopVideo();
void frameStarted(float dt);
void frameStarted(float dt, bool paused);
protected:
virtual void windowResized(int x, int y);

View file

@ -107,7 +107,8 @@ void Shadows::recreate()
// Set visibility mask for the shadow render textures
int visibilityMask = RV_Actors * Settings::Manager::getBool("actor shadows", "Shadows")
+ (RV_Statics + RV_StaticsSmall) * Settings::Manager::getBool("statics shadows", "Shadows")
+ RV_Misc * Settings::Manager::getBool("misc shadows", "Shadows");
+ RV_Misc * Settings::Manager::getBool("misc shadows", "Shadows")
+ RV_Terrain * (Settings::Manager::getBool("terrain shadows", "Shadows"));
for (int i = 0; i < (split ? 3 : 1); ++i)
{
TexturePtr shadowTexture = mSceneMgr->getShadowTexture(i);

View file

@ -1,5 +1,7 @@
#include "scene.hpp"
#include <OgreSceneNode.h>
#include <components/nif/niffile.hpp>
#include <libs/openengine/ogre/fader.hpp>
@ -85,7 +87,6 @@ namespace MWWorld
std::cout << "Unloading cell\n";
ListAndResetHandles functor;
/*
(*iter)->forEach<ListAndResetHandles>(functor);
{
// silence annoying g++ warning
@ -96,7 +97,6 @@ namespace MWWorld
mPhysics->removeObject (node->getName());
}
}
*/
if ((*iter)->mCell->isExterior())
{
@ -150,7 +150,7 @@ namespace MWWorld
// ... then references. This is important for adjustPosition to work correctly.
/// \todo rescale depending on the state of a new GMST
//insertCell (*cell, true);
insertCell (*cell, true);
mRendering.cellAdded (cell);

View file

@ -835,7 +835,7 @@ namespace MWWorld
bool isPlayer = ptr == mPlayer->getPlayer();
bool haveToMove = isPlayer || mWorldScene->isCellActive(*currCell);
if (false ) //*currCell != newCell)
if (*currCell != newCell)
{
removeContainerScripts(ptr);
@ -1026,10 +1026,13 @@ namespace MWWorld
return;
}
float terrainHeight = -std::numeric_limits<float>().max();// mRendering->getTerrainHeightAt(pos);
if (ptr.getCell()->isExterior())
{
float terrainHeight = mRendering->getTerrainHeightAt(pos);
if (pos.z < terrainHeight)
pos.z = terrainHeight;
if (pos.z < terrainHeight)
pos.z = terrainHeight;
}
ptr.getRefData().getPosition().pos[2] = pos.z + 20; // place slightly above. will snap down to ground with code below
@ -1074,15 +1077,8 @@ namespace MWWorld
{
const int cellSize = 8192;
cellX = static_cast<int> (x/cellSize);
if (x<0)
--cellX;
cellY = static_cast<int> (y/cellSize);
if (y<0)
--cellY;
cellX = std::floor(x/cellSize);
cellY = std::floor(y/cellSize);
}
void World::doPhysics(const PtrMovementList &actors, float duration)
@ -1682,9 +1678,9 @@ namespace MWWorld
mRendering->stopVideo();
}
void World::frameStarted (float dt)
void World::frameStarted (float dt, bool paused)
{
mRendering->frameStarted(dt);
mRendering->frameStarted(dt, paused);
}
void World::activateDoor(const MWWorld::Ptr& door)

View file

@ -415,7 +415,7 @@ namespace MWWorld
/// \todo this does not belong here
virtual void playVideo(const std::string& name, bool allowSkipping);
virtual void stopVideo();
virtual void frameStarted (float dt);
virtual void frameStarted (float dt, bool paused);
/// Find center of exterior cell above land surface
/// \return false if exterior with given name not exists, true otherwise