1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:53:51 +00:00

Refactor lighting mask

This commit is contained in:
scrawl 2015-11-10 17:19:51 +01:00
parent 91583fc027
commit 35459f20d5
6 changed files with 42 additions and 21 deletions

View file

@ -1066,6 +1066,7 @@ namespace MWRender
osg::ref_ptr<SceneUtil::LightSource> lightSource = new SceneUtil::LightSource; osg::ref_ptr<SceneUtil::LightSource> lightSource = new SceneUtil::LightSource;
osg::Light* light = new osg::Light; osg::Light* light = new osg::Light;
lightSource->setLight(light); lightSource->setLight(light);
lightSource->setNodeMask(Mask_Lighting);
const MWWorld::Fallback* fallback = MWBase::Environment::get().getWorld()->getFallback(); const MWWorld::Fallback* fallback = MWBase::Environment::get().getWorld()->getFallback();

View file

@ -140,6 +140,7 @@ namespace MWRender
resourceSystem->getSceneManager()->setParticleSystemMask(MWRender::Mask_ParticleSystem); resourceSystem->getSceneManager()->setParticleSystemMask(MWRender::Mask_ParticleSystem);
osg::ref_ptr<SceneUtil::LightManager> lightRoot = new SceneUtil::LightManager; osg::ref_ptr<SceneUtil::LightManager> lightRoot = new SceneUtil::LightManager;
lightRoot->setLightingMask(Mask_Lighting);
mLightRoot = lightRoot; mLightRoot = lightRoot;
lightRoot->setStartLight(1); lightRoot->setStartLight(1);
@ -165,7 +166,7 @@ namespace MWRender
mViewer->setLightingMode(osgViewer::View::NO_LIGHT); mViewer->setLightingMode(osgViewer::View::NO_LIGHT);
osg::ref_ptr<osg::LightSource> source = new osg::LightSource; osg::ref_ptr<osg::LightSource> source = new osg::LightSource;
source->setNodeMask(SceneUtil::Mask_Lit); source->setNodeMask(Mask_Lighting);
mSunLight = new osg::Light; mSunLight = new osg::Light;
source->setLight(mSunLight); source->setLight(mSunLight);
mSunLight->setDiffuse(osg::Vec4f(0,0,0,1)); mSunLight->setDiffuse(osg::Vec4f(0,0,0,1));

View file

@ -15,16 +15,16 @@ namespace MWRender
Mask_Actor = (1<<3), Mask_Actor = (1<<3),
Mask_Player = (1<<4), Mask_Player = (1<<4),
Mask_Sky = (1<<5), Mask_Sky = (1<<5),
Mask_Water = (1<<6), Mask_Water = (1<<6), // choose Water or SimpleWater depending on detail required
Mask_Terrain = (1<<7), Mask_SimpleWater = (1<<7),
Mask_FirstPerson = (1<<8), Mask_Terrain = (1<<8),
Mask_FirstPerson = (1<<9),
// child of Sky // child of Sky
Mask_Sun = (1<<9), Mask_Sun = (1<<10),
Mask_WeatherParticles = (1<<10), Mask_WeatherParticles = (1<<11),
// child of Water // child of Water
Mask_SimpleWater = (1<<11),
// top level masks // top level masks
Mask_Scene = (1<<12), Mask_Scene = (1<<12),
@ -34,9 +34,10 @@ namespace MWRender
Mask_ParticleSystem = (1<<14), Mask_ParticleSystem = (1<<14),
// Set on cameras within the main scene graph // Set on cameras within the main scene graph
Mask_RenderToTexture = (1<<15) Mask_RenderToTexture = (1<<15),
// reserved: (1<<16) for SceneUtil::Mask_Lit // Set on a camera's cull mask to enable the LightManager
Mask_Lighting = (1<<16)
}; };
} }

View file

@ -302,7 +302,7 @@ public:
setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
setReferenceFrame(osg::Camera::RELATIVE_RF); setReferenceFrame(osg::Camera::RELATIVE_RF);
setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_Actor|Mask_ParticleSystem|Mask_Sky|Mask_Sun|Mask_Player|(1<<16)); setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_Actor|Mask_ParticleSystem|Mask_Sky|Mask_Sun|Mask_Player|Mask_Lighting);
setNodeMask(Mask_RenderToTexture); setNodeMask(Mask_RenderToTexture);
setViewport(0, 0, rttSize, rttSize); setViewport(0, 0, rttSize, rttSize);
@ -378,7 +378,7 @@ public:
setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
setReferenceFrame(osg::Camera::RELATIVE_RF); setReferenceFrame(osg::Camera::RELATIVE_RF);
setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_Actor|Mask_ParticleSystem|Mask_Sky|Mask_Player|(1<<16)); setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_Actor|Mask_ParticleSystem|Mask_Sky|Mask_Player|Mask_Lighting);
setNodeMask(Mask_RenderToTexture); setNodeMask(Mask_RenderToTexture);
unsigned int rttSize = Settings::Manager::getInt("rtt size", "Water"); unsigned int rttSize = Settings::Manager::getInt("rtt size", "Water");

View file

@ -131,6 +131,7 @@ namespace SceneUtil
LightManager::LightManager() LightManager::LightManager()
: mStartLight(0) : mStartLight(0)
, mLightingMask(~0u)
{ {
setUpdateCallback(new LightManagerUpdateCallback); setUpdateCallback(new LightManagerUpdateCallback);
} }
@ -138,10 +139,21 @@ namespace SceneUtil
LightManager::LightManager(const LightManager &copy, const osg::CopyOp &copyop) LightManager::LightManager(const LightManager &copy, const osg::CopyOp &copyop)
: osg::Group(copy, copyop) : osg::Group(copy, copyop)
, mStartLight(copy.mStartLight) , mStartLight(copy.mStartLight)
, mLightingMask(copy.mLightingMask)
{ {
} }
void LightManager::setLightingMask(unsigned int mask)
{
mLightingMask = mask;
}
unsigned int LightManager::getLightingMask() const
{
return mLightingMask;
}
void LightManager::update() void LightManager::update()
{ {
mLights.clear(); mLights.clear();
@ -237,7 +249,6 @@ namespace SceneUtil
LightSource::LightSource() LightSource::LightSource()
: mRadius(0.f) : mRadius(0.f)
{ {
setNodeMask(Mask_Lit);
setUpdateCallback(new CollectLightCallback); setUpdateCallback(new CollectLightCallback);
mId = sLightId++; mId = sLightId++;
} }
@ -260,12 +271,6 @@ namespace SceneUtil
{ {
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv); osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv);
if (!(cv->getCurrentCamera()->getCullMask()&Mask_Lit))
{
traverse(node, nv);
return;
}
if (!mLightManager) if (!mLightManager)
{ {
mLightManager = findLightManager(nv->getNodePath()); mLightManager = findLightManager(nv->getNodePath());
@ -276,6 +281,12 @@ namespace SceneUtil
} }
} }
if (!(cv->getCurrentCamera()->getCullMask() & mLightManager->getLightingMask()))
{
traverse(node, nv);
return;
}
// Possible optimizations: // Possible optimizations:
// - cull list of lights by the camera frustum // - cull list of lights by the camera frustum
// - organize lights in a quad tree // - organize lights in a quad tree

View file

@ -9,9 +9,6 @@
namespace SceneUtil namespace SceneUtil
{ {
// This mask should be included in the Cull and Update visitor's traversal mask if lighting is desired.
const int Mask_Lit = (1<<16);
/// LightSource managed by a LightManager. /// LightSource managed by a LightManager.
class LightSource : public osg::Node class LightSource : public osg::Node
{ {
@ -68,6 +65,14 @@ namespace SceneUtil
LightManager(const LightManager& copy, const osg::CopyOp& copyop); LightManager(const LightManager& copy, const osg::CopyOp& copyop);
/// @param mask This mask is compared with the current Camera's cull mask to determine if lighting is desired.
/// By default, it's ~0u i.e. always on.
/// If you have some views that do not require lighting, then set the Camera's cull mask to not include
/// the lightingMask for a much faster cull and rendering.
void setLightingMask (unsigned int mask);
unsigned int getLightingMask() const;
// Called automatically by the UpdateCallback // Called automatically by the UpdateCallback
void update(); void update();
@ -111,6 +116,8 @@ namespace SceneUtil
LightStateSetMap mStateSetCache; LightStateSetMap mStateSetCache;
int mStartLight; int mStartLight;
unsigned int mLightingMask;
}; };
/// @note Not thread safe for CullThreadPerCamera threading mode. /// @note Not thread safe for CullThreadPerCamera threading mode.