mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-01 07:36:41 +00:00
Fix light state issue
GLSL does not respect gl_Disable(GL_LIGHTX), so we have to set unused lights to zero. Sadly, this change makes the applying of the modelView matrix less efficient. So far I couldn't find a better solution, osg's state tracker keeps getting in the way. :(
This commit is contained in:
parent
9376811213
commit
f93b7ec943
1 changed files with 21 additions and 22 deletions
|
@ -56,18 +56,6 @@ namespace SceneUtil
|
||||||
}
|
}
|
||||||
|
|
||||||
state.applyModelViewMatrix(modelViewMatrix);
|
state.applyModelViewMatrix(modelViewMatrix);
|
||||||
|
|
||||||
/*
|
|
||||||
for (int i=0; i<8; ++i)
|
|
||||||
{
|
|
||||||
osg::ref_ptr<osg::Light> defaultLight (new osg::Light(i));
|
|
||||||
defaultLight->setAmbient(osg::Vec4());
|
|
||||||
defaultLight->setDiffuse(osg::Vec4());
|
|
||||||
defaultLight->setSpecular(osg::Vec4());
|
|
||||||
defaultLight->setConstantAttenuation(0.f);
|
|
||||||
state.setGlobalDefaultAttribute(defaultLight);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -204,18 +192,18 @@ namespace SceneUtil
|
||||||
return found->second;
|
return found->second;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<osg::ref_ptr<osg::Light> > lights;
|
|
||||||
for (unsigned int i=0; i<lightList.size();++i)
|
|
||||||
lights.push_back(lightList[i]->mLightSource->getLight(frameNum));
|
|
||||||
|
|
||||||
osg::ref_ptr<LightStateAttribute> attr = new LightStateAttribute(mStartLight, lights);
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
|
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
|
||||||
|
|
||||||
// don't use setAttributeAndModes, that does not support light indices!
|
for (unsigned int i=0; i<lightList.size();++i)
|
||||||
stateset->setAttribute(attr, osg::StateAttribute::ON);
|
{
|
||||||
stateset->setAssociatedModes(attr, osg::StateAttribute::ON);
|
std::vector<osg::ref_ptr<osg::Light> > lights;
|
||||||
|
lights.push_back(lightList[i]->mLightSource->getLight(frameNum));
|
||||||
|
osg::ref_ptr<LightStateAttribute> attr = new LightStateAttribute(mStartLight+i, lights);
|
||||||
|
// don't use setAttributeAndModes, that does not support light indices!
|
||||||
|
stateset->setAttribute(attr, osg::StateAttribute::ON);
|
||||||
|
stateset->setAssociatedModes(attr, osg::StateAttribute::ON);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
stateSetCache.insert(std::make_pair(hash, stateset));
|
stateSetCache.insert(std::make_pair(hash, stateset));
|
||||||
return stateset;
|
return stateset;
|
||||||
|
@ -254,6 +242,17 @@ namespace SceneUtil
|
||||||
void LightManager::setStartLight(int start)
|
void LightManager::setStartLight(int start)
|
||||||
{
|
{
|
||||||
mStartLight = start;
|
mStartLight = start;
|
||||||
|
|
||||||
|
// Set default light state to zero
|
||||||
|
for (int i=start; i<8; ++i)
|
||||||
|
{
|
||||||
|
osg::ref_ptr<osg::Light> defaultLight (new osg::Light(i));
|
||||||
|
defaultLight->setAmbient(osg::Vec4());
|
||||||
|
defaultLight->setDiffuse(osg::Vec4());
|
||||||
|
defaultLight->setSpecular(osg::Vec4());
|
||||||
|
defaultLight->setConstantAttenuation(0.f);
|
||||||
|
getOrCreateStateSet()->setAttributeAndModes(defaultLight, osg::StateAttribute::OFF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int LightManager::getStartLight() const
|
int LightManager::getStartLight() const
|
||||||
|
|
Loading…
Reference in a new issue