Refactor lighting mask

openmw-37
scrawl 9 years ago
parent 91583fc027
commit 35459f20d5

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

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

@ -15,16 +15,16 @@ namespace MWRender
Mask_Actor = (1<<3),
Mask_Player = (1<<4),
Mask_Sky = (1<<5),
Mask_Water = (1<<6),
Mask_Terrain = (1<<7),
Mask_FirstPerson = (1<<8),
Mask_Water = (1<<6), // choose Water or SimpleWater depending on detail required
Mask_SimpleWater = (1<<7),
Mask_Terrain = (1<<8),
Mask_FirstPerson = (1<<9),
// child of Sky
Mask_Sun = (1<<9),
Mask_WeatherParticles = (1<<10),
Mask_Sun = (1<<10),
Mask_WeatherParticles = (1<<11),
// child of Water
Mask_SimpleWater = (1<<11),
// top level masks
Mask_Scene = (1<<12),
@ -34,9 +34,10 @@ namespace MWRender
Mask_ParticleSystem = (1<<14),
// 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)
};
}

@ -302,7 +302,7 @@ public:
setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
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);
setViewport(0, 0, rttSize, rttSize);
@ -378,7 +378,7 @@ public:
setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
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);
unsigned int rttSize = Settings::Manager::getInt("rtt size", "Water");

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

@ -9,9 +9,6 @@
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.
class LightSource : public osg::Node
{
@ -68,6 +65,14 @@ namespace SceneUtil
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
void update();
@ -111,6 +116,8 @@ namespace SceneUtil
LightStateSetMap mStateSetCache;
int mStartLight;
unsigned int mLightingMask;
};
/// @note Not thread safe for CullThreadPerCamera threading mode.

Loading…
Cancel
Save