lightManager.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "lighting/lightManager.h"
  24. #include "console/console.h"
  25. #include "console/consoleTypes.h"
  26. #include "core/util/safeDelete.h"
  27. #include "console/sim.h"
  28. #include "console/simSet.h"
  29. #include "scene/sceneManager.h"
  30. #include "materials/materialManager.h"
  31. #include "materials/sceneData.h"
  32. #include "lighting/lightInfo.h"
  33. #include "lighting/lightingInterfaces.h"
  34. #include "T3D/gameBase/gameConnection.h"
  35. #include "gfx/gfxStringEnumTranslate.h"
  36. #include "console/engineAPI.h"
  37. #include "renderInstance/renderDeferredMgr.h"
  38. Signal<void(const char*,bool)> LightManager::smActivateSignal;
  39. LightManager *LightManager::smActiveLM = NULL;
  40. LinearColorF gFallbackAmbient;
  41. LightManager::LightManager( const char *name, const char *id )
  42. : mName( name ),
  43. mId( id ),
  44. mIsActive( false ),
  45. mDefaultLight( NULL ),
  46. mSceneManager( NULL ),
  47. mCullPos( Point3F::Zero ),
  48. mAvailableSLInterfaces( NULL )
  49. {
  50. _getLightManagers().insert( mName, this );
  51. dMemset( &mSpecialLights, 0, sizeof( mSpecialLights ) );
  52. }
  53. LightManager::~LightManager()
  54. {
  55. _getLightManagers().erase( mName );
  56. SAFE_DELETE( mAvailableSLInterfaces );
  57. SAFE_DELETE( mDefaultLight );
  58. }
  59. LightManagerMap& LightManager::_getLightManagers()
  60. {
  61. static LightManagerMap lightManagerMap;
  62. return lightManagerMap;
  63. }
  64. LightManager* LightManager::findByName( const char *name )
  65. {
  66. LightManagerMap &lightManagers = _getLightManagers();
  67. LightManagerMap::Iterator iter = lightManagers.find( name );
  68. if ( iter != lightManagers.end() )
  69. return iter->value;
  70. return NULL;
  71. }
  72. void LightManager::getLightManagerNames( String *outString )
  73. {
  74. LightManagerMap &lightManagers = _getLightManagers();
  75. LightManagerMap::Iterator iter = lightManagers.begin();
  76. for ( ; iter != lightManagers.end(); iter++ )
  77. *outString += iter->key + "\t";
  78. // TODO!
  79. //outString->rtrim();
  80. }
  81. LightInfo* LightManager::createLightInfo(LightInfo* light /* = NULL */)
  82. {
  83. LightInfo *outLight = (light != NULL) ? light : new LightInfo;
  84. LightManagerMap &lightManagers = _getLightManagers();
  85. LightManagerMap::Iterator iter = lightManagers.begin();
  86. for ( ; iter != lightManagers.end(); iter++ )
  87. {
  88. LightManager *lm = iter->value;
  89. lm->_addLightInfoEx( outLight );
  90. }
  91. return outLight;
  92. }
  93. void LightManager::initLightFields()
  94. {
  95. LightManagerMap &lightManagers = _getLightManagers();
  96. LightManagerMap::Iterator iter = lightManagers.begin();
  97. for ( ; iter != lightManagers.end(); iter++ )
  98. {
  99. LightManager *lm = iter->value;
  100. lm->_initLightFields();
  101. }
  102. }
  103. IMPLEMENT_GLOBAL_CALLBACK( onLightManagerActivate, void, ( const char *name ), ( name ),
  104. "A callback called by the engine when a light manager is activated.\n"
  105. "@param name The name of the light manager being activated.\n"
  106. "@ingroup Lighting\n" );
  107. void LightManager::activate( SceneManager *sceneManager )
  108. {
  109. AssertFatal( sceneManager, "LightManager::activate() - Got null scene manager!" );
  110. AssertFatal( mIsActive == false, "LightManager::activate() - Already activated!" );
  111. AssertFatal( smActiveLM == NULL, "LightManager::activate() - A previous LM is still active!" );
  112. mIsActive = true;
  113. mSceneManager = sceneManager;
  114. smActiveLM = this;
  115. onLightManagerActivate_callback( getName() );
  116. }
  117. IMPLEMENT_GLOBAL_CALLBACK( onLightManagerDeactivate, void, ( const char *name ), ( name ),
  118. "A callback called by the engine when a light manager is deactivated.\n"
  119. "@param name The name of the light manager being deactivated.\n"
  120. "@ingroup Lighting\n" );
  121. void LightManager::deactivate()
  122. {
  123. AssertFatal( mIsActive == true, "LightManager::deactivate() - Already deactivated!" );
  124. AssertFatal( smActiveLM == this, "LightManager::activate() - This isn't the active light manager!" );
  125. if( Sim::getRootGroup() ) // To protect against shutdown.
  126. onLightManagerDeactivate_callback( getName() );
  127. mIsActive = false;
  128. mSceneManager = NULL;
  129. smActiveLM = NULL;
  130. // Just in case... make sure we're all clear.
  131. unregisterAllLights();
  132. }
  133. LightInfo* LightManager::getDefaultLight()
  134. {
  135. // The sun is always our default light when
  136. // when its registered.
  137. if (mSpecialLights[LightManager::slSunLightType])
  138. {
  139. mSpecialLights[LightManager::slSunLightType]->setAmbient(gFallbackAmbient);
  140. return mSpecialLights[LightManager::slSunLightType];
  141. }
  142. // Else return a dummy special light.
  143. if (!mDefaultLight)
  144. {
  145. mDefaultLight = createLightInfo();
  146. }
  147. mDefaultLight->setAmbient(gFallbackAmbient);
  148. return mDefaultLight;
  149. }
  150. LightInfo* LightManager::getSpecialLight( LightManager::SpecialLightTypesEnum type, bool useDefault )
  151. {
  152. if (mSpecialLights[type])
  153. {
  154. mSpecialLights[LightManager::slSunLightType]->setAmbient(gFallbackAmbient);
  155. return mSpecialLights[type];
  156. }
  157. if ( useDefault )
  158. return getDefaultLight();
  159. return NULL;
  160. }
  161. void LightManager::setSpecialLight( LightManager::SpecialLightTypesEnum type, LightInfo *light )
  162. {
  163. if ( light && type == slSunLightType )
  164. {
  165. // The sun must be specially positioned and ranged
  166. // so that it can be processed like a point light
  167. // in the stock light shader used by Basic Lighting.
  168. light->setPosition( mCullPos - ( light->getDirection() * 10000.0f ) );
  169. light->setRange( 2000000.0f );
  170. }
  171. mSpecialLights[type] = light;
  172. registerGlobalLight( light, NULL );
  173. }
  174. void LightManager::registerGlobalLights( const Frustum *frustum, bool staticLighting, bool enableZoneLightCulling)
  175. {
  176. PROFILE_SCOPE( LightManager_RegisterGlobalLights );
  177. // TODO: We need to work this out...
  178. //
  179. // 1. Why do we register and unregister lights on every
  180. // render when they don't often change... shouldn't we
  181. // just register once and keep them?
  182. //
  183. // 2. If we do culling of lights should this happen as part
  184. // of registration or somewhere else?
  185. //
  186. // Grab the lights to process.
  187. Vector<SceneObject*> activeLights;
  188. const U32 lightMask = LightObjectType;
  189. if ( staticLighting || !frustum )
  190. {
  191. // We're processing static lighting or want all the lights
  192. // in the container registerd... so no culling.
  193. getSceneManager()->getContainer()->findObjectList( lightMask, &activeLights );
  194. }
  195. else
  196. {
  197. // Cull the lights using the frustum.
  198. getSceneManager()->getContainer()->findObjectList(*frustum, lightMask, &activeLights);
  199. /*
  200. for (U32 i = 0; i < activeLights.size(); ++i)
  201. {
  202. for (U32 i = 0; i < activeLights.size(); ++i)
  203. {
  204. if (!getSceneManager()->mRenderedObjectsList.contains(activeLights[i]))
  205. {
  206. activeLights.erase(i);
  207. --i;
  208. }
  209. }
  210. }
  211. */
  212. // Store the culling position for sun placement
  213. // later... see setSpecialLight.
  214. mCullPos = frustum->getPosition();
  215. // HACK: Make sure the control object always gets
  216. // processed as lights mounted to it don't change
  217. // the shape bounds and can often get culled.
  218. GameConnection *conn = GameConnection::getConnectionToServer();
  219. if (conn->getControlObject())
  220. {
  221. GameBase *conObject = conn->getControlObject();
  222. activeLights.push_back_unique(conObject);
  223. }
  224. }
  225. // Let the lights register themselves.
  226. for ( U32 i = 0; i < activeLights.size(); i++ )
  227. {
  228. ISceneLight *lightInterface = dynamic_cast<ISceneLight*>( activeLights[i] );
  229. if ( lightInterface )
  230. lightInterface->submitLights( this, staticLighting );
  231. }
  232. }
  233. void LightManager::registerGlobalLight( LightInfo *light, SimObject *obj )
  234. {
  235. AssertFatal( !mRegisteredLights.contains( light ),
  236. "LightManager::registerGlobalLight - This light is already registered!" );
  237. mRegisteredLights.push_back( light );
  238. }
  239. void LightManager::unregisterGlobalLight( LightInfo *light )
  240. {
  241. mRegisteredLights.unregisterLight( light );
  242. // If this is the sun... clear the special light too.
  243. if ( light == mSpecialLights[slSunLightType] )
  244. dMemset( mSpecialLights, 0, sizeof( mSpecialLights ) );
  245. }
  246. void LightManager::registerLocalLight( LightInfo *light )
  247. {
  248. // TODO: What should we do here?
  249. }
  250. void LightManager::unregisterLocalLight( LightInfo *light )
  251. {
  252. // TODO: What should we do here?
  253. }
  254. void LightManager::unregisterAllLights()
  255. {
  256. dMemset( mSpecialLights, 0, sizeof( mSpecialLights ) );
  257. mRegisteredLights.clear();
  258. }
  259. void LightManager::getAllUnsortedLights( Vector<LightInfo*> *list ) const
  260. {
  261. list->merge( mRegisteredLights );
  262. }
  263. void LightManager::_update4LightConsts( const SceneData &sgData,
  264. GFXShaderConstHandle *lightPositionSC,
  265. GFXShaderConstHandle *lightDiffuseSC,
  266. GFXShaderConstHandle *lightAmbientSC,
  267. GFXShaderConstHandle *lightConfigDataSC,
  268. GFXShaderConstHandle *lightSpotDirSC,
  269. GFXShaderConstHandle *lightSpotParamsSC,
  270. GFXShaderConstHandle* hasVectorLightSC,
  271. GFXShaderConstHandle* vectorLightDirectionSC,
  272. GFXShaderConstHandle* vectorLightColorSC,
  273. GFXShaderConstHandle* vectorLightBrightnessSC,
  274. GFXShaderConstBuffer *shaderConsts )
  275. {
  276. PROFILE_SCOPE( LightManager_Update4LightConsts );
  277. // Skip over gathering lights if we don't have to!
  278. if ( lightPositionSC->isValid() ||
  279. lightDiffuseSC->isValid() ||
  280. lightConfigDataSC->isValid() ||
  281. lightSpotDirSC->isValid() ||
  282. lightSpotParamsSC->isValid() )
  283. {
  284. PROFILE_SCOPE( LightManager_Update4LightConsts_setLights );
  285. //new setup
  286. const U32 MAX_FORWARD_LIGHTS = 4;
  287. static AlignedArray<Point4F> lightPositions(MAX_FORWARD_LIGHTS, sizeof(Point4F));
  288. static AlignedArray<Point4F> lightSpotDirs(MAX_FORWARD_LIGHTS, sizeof(Point4F));
  289. static AlignedArray<Point4F> lightColors(MAX_FORWARD_LIGHTS, sizeof(Point4F));
  290. static AlignedArray<Point4F> lightConfigData(MAX_FORWARD_LIGHTS, sizeof(Point4F)); //type, brightness, range, invSqrRange : rgba
  291. static AlignedArray<Point2F> lightSpotParams(MAX_FORWARD_LIGHTS, sizeof(Point2F));
  292. dMemset(lightPositions.getBuffer(), 0, lightPositions.getBufferSize());
  293. dMemset(lightSpotDirs.getBuffer(), 0, lightSpotDirs.getBufferSize());
  294. dMemset(lightColors.getBuffer(), 0, lightColors.getBufferSize());
  295. dMemset(lightConfigData.getBuffer(), 0, lightConfigData.getBufferSize());
  296. dMemset(lightSpotParams.getBuffer(), 0, lightSpotParams.getBufferSize());
  297. //sun-only
  298. F32 vectorLightBrightness;
  299. static Point4F vectorLightDirection;
  300. static Point4F vectorLightColor;
  301. static Point4F vectorLightAmbientColor;
  302. int hasVectorLight = 0;
  303. vectorLightBrightness = 0;
  304. vectorLightDirection = Point4F::Zero;
  305. vectorLightColor = Point4F::Zero;
  306. vectorLightAmbientColor = Point4F::Zero;
  307. // Gather the data for the first 4 lights.
  308. const LightInfo* light;
  309. for (U32 i = 0; i < MAX_FORWARD_LIGHTS; i++)
  310. {
  311. light = sgData.lights[i];
  312. if (!light)
  313. break;
  314. if (light->getType() == LightInfo::Vector)
  315. {
  316. if (hasVectorLight != 0)
  317. continue;
  318. vectorLightBrightness = light->getBrightness();
  319. vectorLightDirection = light->getDirection();
  320. vectorLightColor = Point4F(light->getColor());
  321. vectorLightAmbientColor = Point4F(light->getAmbient());
  322. hasVectorLight = 1;
  323. continue;
  324. }
  325. // The light positions and spot directions are
  326. // in SoA order to make optimal use of the GPU.
  327. const Point3F& lightPos = light->getPosition();
  328. lightPositions[i].x = lightPos.x;
  329. lightPositions[i].y = lightPos.y;
  330. lightPositions[i].z = lightPos.z;
  331. lightPositions[i].w = 0;
  332. const VectorF& lightDir = light->getDirection();
  333. lightSpotDirs[i].x = lightDir.x;
  334. lightSpotDirs[i].y = lightDir.y;
  335. lightSpotDirs[i].z = lightDir.z;
  336. lightSpotDirs[i].w = 0;
  337. lightColors[i] = Point4F(light->getColor());
  338. if (light->getType() == LightInfo::Point)
  339. {
  340. lightConfigData[i].x = 0;
  341. }
  342. else if (light->getType() == LightInfo::Spot)
  343. {
  344. lightConfigData[i].x = 1;
  345. const F32 outerCone = light->getOuterConeAngle();
  346. const F32 innerCone = getMin(light->getInnerConeAngle(), outerCone);
  347. const F32 outerCos = mCos(mDegToRad(outerCone / 2.0f));
  348. const F32 innerCos = mCos(mDegToRad(innerCone / 2.0f));
  349. Point2F spotParams(outerCos, innerCos - outerCos);
  350. lightSpotParams[i].x = spotParams.x;
  351. lightSpotParams[i].y = spotParams.y;
  352. }
  353. lightConfigData[i].y = light->getBrightness();
  354. F32 range = light->getRange().x;
  355. lightConfigData[i].z = range;
  356. lightConfigData[i].w = 1.0f / (range * range);
  357. }
  358. shaderConsts->setSafe(lightPositionSC, lightPositions);
  359. shaderConsts->setSafe(lightDiffuseSC, lightColors);
  360. shaderConsts->setSafe(lightSpotDirSC, lightSpotDirs);
  361. shaderConsts->setSafe(lightConfigDataSC, lightConfigData);
  362. shaderConsts->setSafe(lightSpotParamsSC, lightSpotParams);
  363. shaderConsts->setSafe(hasVectorLightSC, (int)hasVectorLight);
  364. shaderConsts->setSafe(vectorLightDirectionSC, vectorLightDirection);
  365. shaderConsts->setSafe(vectorLightColorSC, vectorLightColor);
  366. shaderConsts->setSafe(vectorLightBrightnessSC, vectorLightBrightness);
  367. //================================================================
  368. //old setup
  369. /*static AlignedArray<Point4F> lightPositions( 3, sizeof( Point4F ) );
  370. static AlignedArray<Point4F> lightSpotDirs( 3, sizeof( Point4F ) );
  371. static AlignedArray<Point4F> lightColors( 4, sizeof( Point4F ) );
  372. static Point4F lightInvRadiusSq;
  373. static Point4F lightSpotAngle;
  374. static Point4F lightSpotFalloff;
  375. F32 range;
  376. // Need to clear the buffers so that we don't leak
  377. // lights from previous passes or have NaNs.
  378. dMemset( lightPositions.getBuffer(), 0, lightPositions.getBufferSize() );
  379. dMemset( lightSpotDirs.getBuffer(), 0, lightSpotDirs.getBufferSize() );
  380. dMemset( lightColors.getBuffer(), 0, lightColors.getBufferSize() );
  381. lightInvRadiusSq = Point4F::Zero;
  382. lightSpotAngle.set( -1.0f, -1.0f, -1.0f, -1.0f );
  383. lightSpotFalloff.set( F32_MAX, F32_MAX, F32_MAX, F32_MAX );
  384. // Gather the data for the first 4 lights.
  385. const LightInfo *light;
  386. for ( U32 i=0; i < MAX_FORWARD_LIGHTS; i++ )
  387. {
  388. light = sgData.lights[i];
  389. if ( !light )
  390. break;
  391. // The light positions and spot directions are
  392. // in SoA order to make optimal use of the GPU.
  393. const Point3F &lightPos = light->getPosition();
  394. lightPositions[0][i] = lightPos.x;
  395. lightPositions[1][i] = lightPos.y;
  396. lightPositions[2][i] = lightPos.z;
  397. const VectorF &lightDir = light->getDirection();
  398. lightSpotDirs[0][i] = lightDir.x;
  399. lightSpotDirs[1][i] = lightDir.y;
  400. lightSpotDirs[2][i] = lightDir.z;
  401. if ( light->getType() == LightInfo::Spot )
  402. {
  403. lightSpotAngle[i] = mCos( mDegToRad( light->getOuterConeAngle() / 2.0f ) );
  404. lightSpotFalloff[i] = 1.0f / getMax( F32_MIN, mCos( mDegToRad( light->getInnerConeAngle() / 2.0f ) ) - lightSpotAngle[i] );
  405. }
  406. // Prescale the light color by the brightness to
  407. // avoid doing this in the shader.
  408. lightColors[i] = Point4F(light->getColor()) * light->getBrightness();
  409. // We need 1 over range^2 here.
  410. range = light->getRange().x;
  411. lightInvRadiusSq[i] = 1.0f / ( range * range );
  412. }
  413. shaderConsts->setSafe( lightPositionSC, lightPositions );
  414. shaderConsts->setSafe( lightDiffuseSC, lightColors );
  415. shaderConsts->setSafe( lightInvRadiusSqSC, lightInvRadiusSq );
  416. shaderConsts->setSafe( lightSpotDirSC, lightSpotDirs );
  417. shaderConsts->setSafe( lightSpotAngleSC, lightSpotAngle );
  418. shaderConsts->setSafe( lightSpotFalloffSC, lightSpotFalloff );*/
  419. }
  420. // Setup the ambient lighting from the first
  421. // light which is the directional light if
  422. // one exists at all in the scene.
  423. if ( lightAmbientSC->isValid() )
  424. shaderConsts->set( lightAmbientSC, sgData.ambientLightColor );
  425. }
  426. AvailableSLInterfaces* LightManager::getSceneLightingInterface()
  427. {
  428. if ( !mAvailableSLInterfaces )
  429. mAvailableSLInterfaces = new AvailableSLInterfaces();
  430. return mAvailableSLInterfaces;
  431. }
  432. bool LightManager::lightScene( const char* callback, const char* param )
  433. {
  434. BitSet32 flags = 0;
  435. if ( param )
  436. {
  437. if ( !dStricmp( param, "forceAlways" ) )
  438. flags.set( SceneLighting::ForceAlways );
  439. else if ( !dStricmp(param, "forceWritable" ) )
  440. flags.set( SceneLighting::ForceWritable );
  441. else if ( !dStricmp(param, "loadOnly" ) )
  442. flags.set( SceneLighting::LoadOnly );
  443. }
  444. // The SceneLighting object will delete itself
  445. // once the lighting process is complete.
  446. SceneLighting* sl = new SceneLighting( getSceneLightingInterface() );
  447. return sl->lightScene( callback, flags );
  448. }
  449. RenderDeferredMgr* LightManager::_findDeferredRenderBin()
  450. {
  451. RenderPassManager* rpm = getSceneManager()->getDefaultRenderPass();
  452. for( U32 i = 0; i < rpm->getManagerCount(); i++ )
  453. {
  454. RenderBinManager *bin = rpm->getManager( i );
  455. if( bin->getRenderInstType() == RenderDeferredMgr::RIT_Deferred )
  456. {
  457. return ( RenderDeferredMgr* ) bin;
  458. }
  459. }
  460. return NULL;
  461. }
  462. DefineEngineFunction( setLightManager, bool, ( const char *name ),,
  463. "Finds and activates the named light manager.\n"
  464. "@return Returns true if the light manager is found and activated.\n"
  465. "@ingroup Lighting\n" )
  466. {
  467. return gClientSceneGraph->setLightManager( name );
  468. }
  469. DefineEngineFunction( lightScene, bool, ( const char *completeCallbackFn, const char *mode ), ( nullAsType<const char*>(), nullAsType<const char*>() ),
  470. "Will generate static lighting for the scene if supported by the active light manager.\n\n"
  471. "If mode is \"forceAlways\", the lightmaps will be regenerated regardless of whether "
  472. "lighting cache files can be written to. If mode is \"forceWritable\", then the lightmaps "
  473. "will be regenerated only if the lighting cache files can be written.\n"
  474. "@param completeCallbackFn The name of the function to execute when the lighting is complete.\n"
  475. "@param mode One of \"forceAlways\", \"forceWritable\" or \"loadOnly\".\n"
  476. "@return Returns true if the scene lighting process was started.\n"
  477. "@ingroup Lighting\n" )
  478. {
  479. if ( !LIGHTMGR )
  480. return false;
  481. return LIGHTMGR->lightScene( completeCallbackFn, mode );
  482. }
  483. DefineEngineFunction( getLightManagerNames, String, (),,
  484. "Returns a tab seperated list of light manager names.\n"
  485. "@ingroup Lighting\n" )
  486. {
  487. String names;
  488. LightManager::getLightManagerNames( &names );
  489. return names;
  490. }
  491. DefineEngineFunction( getActiveLightManager, const char*, (),,
  492. "Returns the active light manager name.\n"
  493. "@ingroup Lighting\n" )
  494. {
  495. if ( !LIGHTMGR )
  496. return NULL;
  497. return LIGHTMGR->getName();
  498. }
  499. DefineEngineFunction( resetLightManager, void, (),,
  500. "@brief Deactivates and then activates the currently active light manager."
  501. "This causes most shaders to be regenerated and is often used when global "
  502. "rendering changes have occured.\n"
  503. "@ingroup Lighting\n" )
  504. {
  505. LightManager *lm = LIGHTMGR;
  506. if ( !lm )
  507. return;
  508. SceneManager *sm = lm->getSceneManager();
  509. lm->deactivate();
  510. lm->activate( sm );
  511. }