From Sergey Polischuk, "this patch fixes light id in gl modes for osg::LightSource's readed from fbx (previously all lightsources were setting GL_LIGHT0 mode, while osg::Lights were using different id's), and enables GL_LIGHT# on root node for all lights contained in model

"
This commit is contained in:
Robert Osfield 2013-06-03 14:01:13 +00:00
parent ae2b6669ea
commit 05a1084e5c
2 changed files with 7 additions and 4 deletions

View File

@ -344,6 +344,9 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
resolveBindMatrices(*res.getNode(), reader.boneBindMatrices, reader.nodeMap);
osg::Node* osgNode = res.getNode();
for (int light = 0; light < nLightCount; ++light)
osgNode->getOrCreateStateSet()->setMode(GL_LIGHT0 + light, osg::StateAttribute::ON);
osgNode->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON);
osgNode->getOrCreateStateSet()->setMode(GL_NORMALIZE,osg::StateAttribute::ON);

View File

@ -22,8 +22,8 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxLight(KFbxNode* pNode, int&
osg::Light* osgLight = new osg::Light;
osg::LightSource* osgLightSource = new osg::LightSource;
osgLightSource->setLight(osgLight);
osgLight->setLightNum(nLightCount++);
osgLightSource->setLight(osgLight);
KFbxLight::ELightType fbxLightType = fbxLight->LightType.IsValid() ?
fbxLight->LightType.Get() : KFbxLight::ePOINT;
@ -39,11 +39,11 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxLight(KFbxNode* pNode, int&
osgLight->setSpotCutoff(static_cast<float>(coneAngle));
//Approximate the hotspot using the GL light exponent.
//This formula maps a hotspot of 180° to exponent 0 (uniform light
// distribution) and a hotspot of 45° to exponent 1 (effective light
//This formula maps a hotspot of 180 to exponent 0 (uniform light
// distribution) and a hotspot of 45 to exponent 1 (effective light
// intensity is attenuated by the cosine of the angle between the
// direction of the light and the direction from the light to the vertex
// being lighted). A hotspot close to 0° maps to exponent 128 (maximum).
// being lighted). A hotspot close to 0 maps to exponent 128 (maximum).
float exponent = (180.0f / (std::max)(static_cast<float>(hotSpot),
MIN_HOTSPOT) - 1.0f) / 3.0f;
osgLight->setSpotExponent(exponent);