From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a02747.html | 1349 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1349 insertions(+) create mode 100644 docs/doxygen/nel/a02747.html (limited to 'docs/doxygen/nel/a02747.html') diff --git a/docs/doxygen/nel/a02747.html b/docs/doxygen/nel/a02747.html new file mode 100644 index 00000000..b4f5882e --- /dev/null +++ b/docs/doxygen/nel/a02747.html @@ -0,0 +1,1349 @@ + + +NeL: NL3D::CLightingManager class Reference + + + +
+

NL3D::CLightingManager Class Reference

#include <lighting_manager.h> +

+


Detailed Description

+Owned by CLightingTrav. This class compute modelContributions. It gets which dynamic light may influence a model, ask to ILogicInfo the contribution of staticLights then decides which light are best suitable to influence the model.

+

Author:
Lionel Berenguier

+Nevrax France

+
Date:
2001
+ +

+ +

+Definition at line 60 of file lighting_manager.h. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

 CLightingManager (bool bSmallScene)
 Constructor (bSmallScene is used to setup size of the grids).

void computeModelLightContributions (CTransform *model, CLightContribution &lightContrib, ILogicInfo *logicInfo=NULL)
Dynamic Lights localisation.
void addDynamicLight (CPointLight *light)
void clearDynamicLights ()
 clear for the pass all the lights.

const std::vector< CPointLight * > & getAllDynamicLightList () const
Static Lighted Objects Localisation. Used for lights to touch nearest static models.
CQGItLightedModel eraseStaticLightedModel (CQGItLightedModel ite)
CQGItLightedModel insertStaticLightedModel (CTransform *model)
Parameters
float getLightTransitionThreshold () const
uint getMaxLightContribution () const
float getNoAttLightRadius () const
float getOutOfAttLightInfFactor () const
void setLightTransitionThreshold (float lightTransitionThreshold)
void setMaxLightContribution (uint nlights)
void setNoAttLightRadius (float noAttLightRadius)
void setOutOfAttLightInfFactor (float outOfAttLightInfFactor)

Private Member Functions

void getDynamicPointLightList (const CVector &worldPos, std::vector< CPointLightInfluence > &lightList)
 get the list of dynamic light viewed from a position. append to lightList


Private Attributes

std::vector< CPointLight * > _DynamicLightList
CQuadGrid< CPointLightInfo_LightQuadGrid [4]
float _LightQuadGridRadiusLimit [4]
CQuadGrid< CTransform * > _StaticLightedModelQuadGrid [4]
Parameters.
float _LightTransitionThreshold
uint _MaxLightContribution
float _NoAttLightRadius
float _OutOfAttLightInfFactor
+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + + +
NL3D::CLightingManager::CLightingManager bool  bSmallScene  ) 
+
+ + + + + +
+   + + +

+Constructor (bSmallScene is used to setup size of the grids). +

+ +

+Definition at line 64 of file lighting_manager.cpp. +

+References _LightQuadGrid, _LightQuadGridRadiusLimit, _LightTransitionThreshold, _NoAttLightRadius, _OutOfAttLightInfFactor, _StaticLightedModelQuadGrid, NL3D::CQuadGrid< CTransform * >::create(), NL3D::CQuadGrid< CPointLightInfo >::create(), NL3D_DEFAULT_LIGHT_TRANSITION_THRESHOLD, NL3D_DEFAULT_NOATT_LIGHT_RADIUS, NL3D_DEFAULT_OUT_OF_ATT_LIGHT_INF_FACTOR, NL3D_LIGHT_QUAD_GRID_ELTSIZE, NL3D_LIGHT_QUAD_GRID_FACTOR, NL3D_LIGHT_QUAD_GRID_RADIUS_LIMIT, NL3D_LIGHT_QUAD_GRID_SIZE, NL3D_QUADGRID_LIGHT_NUM_LEVEL, setMaxLightContribution(), and uint. +

+

00065 {
+00066         // Init the lightQuadGrids and StaticLightedModelQuadGrid
+00067         // finer level.
+00068         uint    qgSize= NL3D_LIGHT_QUAD_GRID_SIZE;
+00069         float   eltSize= NL3D_LIGHT_QUAD_GRID_ELTSIZE;
+00070         float   radiusLimit= NL3D_LIGHT_QUAD_GRID_RADIUS_LIMIT;
+00071 
+00072         if (bSmallScene)
+00073         {
+00074                 qgSize = 4;
+00075         }
+00076 
+00077         // for all levels
+00078         for(uint i=0;i<NL3D_QUADGRID_LIGHT_NUM_LEVEL;i++)
+00079         {
+00080                 // init _LightQuadGrid and _StaticLightedModelQuadGrid
+00081                 _LightQuadGrid[i].create(qgSize, eltSize);
+00082                 _StaticLightedModelQuadGrid[i].create(qgSize, eltSize);
+00083                 _LightQuadGridRadiusLimit[i]= radiusLimit;
+00084 
+00085                 // coarser quadGrid level
+00086                 qgSize/= NL3D_LIGHT_QUAD_GRID_FACTOR;
+00087                 qgSize= max(qgSize, 1U);
+00088                 eltSize*= NL3D_LIGHT_QUAD_GRID_FACTOR;
+00089                 radiusLimit*= NL3D_LIGHT_QUAD_GRID_FACTOR;
+00090         }
+00091 
+00092 
+00093         // default paramters
+00094         _NoAttLightRadius= NL3D_DEFAULT_NOATT_LIGHT_RADIUS;
+00095         _OutOfAttLightInfFactor= NL3D_DEFAULT_OUT_OF_ATT_LIGHT_INF_FACTOR;
+00096         _LightTransitionThreshold= NL3D_DEFAULT_LIGHT_TRANSITION_THRESHOLD;
+00097 
+00098 
+00099         // Default number of pointLight on an object.
+00100         setMaxLightContribution(3);
+00101 }
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLightingManager::addDynamicLight CPointLight light  ) 
+
+ + + + + +
+   + + +

+temp add a dynamic light to the manager. light is added to the _LightQuadGrid. This method calls CTransform::resetLighting() for all models around the light.

+Additionaly light are added to a list (a vector of pointer), see getDynamicLightList() +

+Definition at line 151 of file lighting_manager.cpp. +

+References _LightQuadGrid, _LightQuadGridRadiusLimit, _NoAttLightRadius, _StaticLightedModelQuadGrid, NL3D::CQuadGrid< CTransform * >::begin(), NLMISC::CBSphere::Center, NL3D::CQuadGrid< T >::end(), NL3D::CPointLight::getAttenuationEnd(), NLMISC::CMatrix::getPos(), NL3D::CPointLight::getPosition(), NL3D::CTransform::getWorldMatrix(), NLMISC::CBSphere::include(), NL3D::CQuadGrid< CPointLightInfo >::insert(), NL3D::CLightingManager::CPointLightInfo::Light, NL3D_QUADGRID_LIGHT_NUM_LEVEL, NLMISC::CBSphere::Radius, NL3D::CTransform::resetLighting(), NL3D::CQuadGrid< CTransform * >::select(), NL3D::CLightingManager::CPointLightInfo::Sphere, and uint. +

+Referenced by NL3D::CPointLightModel::traverseLight(). +

+

00152 {
+00153 
+00154         // Insert the light in the quadGrid.
+00155         //----------
+00156         CPointLightInfo         plInfo;
+00157         plInfo.Light= light;
+00158 
+00159         // build the bounding sphere for this light, with the AttenuationEnd of the light
+00160         float   radius=light->getAttenuationEnd();
+00161         // if attenuation is disabled (ie getAttenuationEnd() return 0), then have a dummy radius
+00162         if(radius==0)
+00163                 radius= _NoAttLightRadius;
+00164         plInfo.Sphere.Center= light->getPosition();
+00165         plInfo.Sphere.Radius= radius;
+00166 
+00167         // build a bbox, so it includes the sphere
+00168         CVector bbmin= light->getPosition();
+00169         bbmin-= CVector(radius, radius, radius);
+00170         CVector bbmax= light->getPosition();
+00171         bbmax+= CVector(radius, radius, radius);
+00172 
+00173         // choose the correct quadgrid according to the radius of the light.
+00174         uint qgId;
+00175         for(qgId= 0; qgId<NL3D_QUADGRID_LIGHT_NUM_LEVEL-1; qgId++)
+00176         {
+00177                 // if radius is inferior to the requested radius for this quadGrid, ok!
+00178                 if(radius<_LightQuadGridRadiusLimit[qgId])
+00179                         break;
+00180         }
+00181         // insert this light in the correct quadgrid.
+00182         _LightQuadGrid[qgId].insert(bbmin, bbmax, plInfo);
+00183 
+00184 
+00185         // touch the objects around the lights.
+00186         //----------
+00187 
+00188         // Select the static lightedModels to update around this light.
+00189         // Use the same level of _StaticLightedModelQuadGrid than me to not select too many squares in the quadGrid
+00190         _StaticLightedModelQuadGrid[qgId].select(bbmin, bbmax);
+00191         // For all those models.
+00192         CQuadGrid<CTransform*>::CIterator       itModel= _StaticLightedModelQuadGrid[qgId].begin();
+00193         while(itModel != _StaticLightedModelQuadGrid[qgId].end() )
+00194         {
+00195                 CTransform      *model= *itModel;
+00196                 const CVector &modelPos= model->getWorldMatrix().getPos();
+00197 
+00198                 // test first if this model is in the area of the light.
+00199                 if( plInfo.Sphere.include(modelPos) )
+00200                 {
+00201                         // yes, then this model must recompute his lighting, because a dynamic light touch him.
+00202                         model->resetLighting();
+00203                 }
+00204 
+00205                 // next.
+00206                 itModel++;
+00207         }
+00208 
+00209 
+00210         // insert the light in the list.
+00211         //----------
+00212         _DynamicLightList.push_back(light);
+00213 
+00214 }
+
+

+ + + + +
+ + + + + + + + + +
void NL3D::CLightingManager::clearDynamicLights  ) 
+
+ + + + + +
+   + + +

+clear for the pass all the lights. +

+ +

+Definition at line 137 of file lighting_manager.cpp. +

+References _LightQuadGrid, NL3D::CQuadGrid< CPointLightInfo >::clear(), NL3D_QUADGRID_LIGHT_NUM_LEVEL, and uint. +

+Referenced by NL3D::CLightTrav::traverse(). +

+

00138 {
+00139         // for all levels
+00140         for(uint i=0;i<NL3D_QUADGRID_LIGHT_NUM_LEVEL;i++)
+00141         {
+00142                 // clear all the lights in the quadGrid.
+00143                 _LightQuadGrid[i].clear();
+00144         }
+00145 
+00146         // clear the list.
+00147         _DynamicLightList.clear();
+00148 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void NL3D::CLightingManager::computeModelLightContributions CTransform model,
CLightContribution lightContrib,
ILogicInfo logicInfo = NULL
+
+ + + + + +
+   + + +

+get the description of nearsest lights viewed for this model. Dynamic lights are parsed to get list of lights, and ILogicInfo->getStaticLightDesc() is parsed too. Then, maxLights are returned, which may be a blended result of max influence light.

+NB: model->_LightContribution is filled with real contributions of lights. NB: model is append to the _LightedModelList of each contributed light NB: this list is valid until model->isNeedUpdateLighting() is true. +

+Definition at line 256 of file lighting_manager.cpp. +

+References _LightTransitionThreshold, _MaxLightContribution, _OutOfAttLightInfFactor, NL3D::CPointLight::appendLightedModel(), NL3D::CLightContribution::AttFactor, NLMISC::CRGBA::B, NLMISC::CRGBAF::B, NLMISC::clamp(), NL3D::CPointLight::computeLinearAttenuation(), NL3D::CLightContribution::Factor, NL3D::CLightContribution::FrozenStaticLightSetup, NLMISC::CRGBA::G, NLMISC::CRGBAF::G, NL3D::CPointLight::getAmbient(), NL3D::CPointLight::getAttenuationBegin(), NL3D::CPointLight::getAttenuationEnd(), NL3D::CPointLight::getDiffuse(), getDynamicPointLightList(), NL3D::CTransform::getLightHotSpotInWorld(), NL3D::CPointLight::getPosition(), NL3D::ILogicInfo::getStaticLightSetup(), NL3D::CPointLight::getType(), NL3D::CLightContribution::LocalAmbient, NL3D::CLightContribution::MergedPointLight, NL3D_MAX_LIGHT_CONTRIBUTION, NL3D::CLightContribution::NumFrozenStaticLight, NLMISC::OptFastFloor(), NL3D::CLightContribution::PointLight, NLMISC::CRGBA::R, NLMISC::CRGBAF::R, NLMISC::CRGBA::set(), sint, NL3D::CLightContribution::SunContribution, NL3D::CLightContribution::TransformIterator, uint, uint8, NL3D::CLightContribution::UseMergedPointLight, and v. +

+Referenced by NL3D::CTransform::traverseLight(). +

+

00258 {
+00259         sint    i;
+00260 
+00261         // This is the list of light which touch this model.
+00262         static std::vector<CPointLightInfluence>        lightList;
+00263         // static, for malloc perf.
+00264         lightList.clear();
+00265 
+00266         // the position of the model.
+00267         CVector modelPos;
+00268         float   modelRadius;
+00269 
+00270         // depends on model
+00271         model->getLightHotSpotInWorld(modelPos, modelRadius);
+00272 
+00273         // First pass, fill the list of light which touch this model.
+00274         //=========
+00275         // get the dynamic lights around the model
+00276         getDynamicPointLightList(modelPos, lightList);
+00277 
+00278         // if not already precomputed, append staticLights to this list.
+00279         if( !lightContrib.FrozenStaticLightSetup )
+00280         {
+00281                 // If no logicInfo provided
+00282                 if(!logicInfo)
+00283                 {
+00284                         // Default: suppose full SunLight and no PointLights.
+00285                         lightContrib.SunContribution= 255;
+00286                         // Take full SunAmbient.
+00287                         lightContrib.LocalAmbient.set(0,0,0,0);
+00288                         // do not append any pointLight to the setup
+00289                 }
+00290                 else
+00291                 {
+00292                         // NB: SunContribution is computed by logicInfo
+00293                         logicInfo->getStaticLightSetup(lightList, lightContrib.SunContribution, lightContrib.LocalAmbient);
+00294                 }
+00295         }
+00296 
+00297         // Second pass, in the lightList, choose the best suited light to lit this model
+00298         //=========
+00299 
+00300         // for each light, modulate the factor of influence
+00301         for(i=0; i<(sint)lightList.size();i++)
+00302         {
+00303                 CPointLight     *pl= lightList[i].PointLight;
+00304 
+00305                 // get the distance from the light to the model
+00306                 float   dist= (pl->getPosition() - modelPos).norm();
+00307                 float   distMinusRadius= dist - modelRadius;
+00308 
+00309                 // modulate the factor by the distance and the attenuation distance.
+00310                 float    inf;
+00311                 float   attBegin= pl->getAttenuationBegin();
+00312                 float   attEnd= pl->getAttenuationEnd();
+00313                 // if no attenuation
+00314                 if( attEnd==0 )
+00315                 {
+00316                         // influence is awlays 1.
+00317                         inf= 1;
+00318 
+00319                         // If SpotLight, must modulate with SpotAttenuation.
+00320                         if(pl->getType() == CPointLight::SpotLight)
+00321                                 inf*= pl->computeLinearAttenuation(modelPos, dist, modelRadius);
+00322                 }
+00323                 else
+00324                 {
+00325                         // if correct attenuation radius
+00326                         if(distMinusRadius<attBegin)
+00327                         {
+00328                                 // NB: we are sure that attBegin>0, because dist>=0.
+00329                                 // if < attBegin, inf should be ==1, but must select the nearest lights; for better
+00330                                 // understanding of the scene
+00331                                 inf= 1 + _OutOfAttLightInfFactor * (attBegin - distMinusRadius);        // inf E [1, +oo[
+00332                                 // NB: this formula favour big lights (ie light with big attBegin).
+00333 
+00334                                 // If SpotLight, must modulate with SpotAttenuation.
+00335                                 if(pl->getType() == CPointLight::SpotLight)
+00336                                         inf*= pl->computeLinearAttenuation(modelPos, dist, modelRadius);
+00337                         }
+00338                         else if(distMinusRadius<attEnd)
+00339                         {
+00340                                 // we are sure attEnd-attBegin>0 because of the test
+00341                                 // compute influence of the light: attenuation and SpotAttenuation
+00342                                 inf= pl->computeLinearAttenuation(modelPos, dist, modelRadius);
+00343                         }
+00344                         else
+00345                         {
+00346                                 // if >= attEnd, inf should be ==0, but must select the nearest lights; for better
+00347                                 // understanding of the scene
+00348                                 inf= _OutOfAttLightInfFactor * (attEnd - distMinusRadius);              // inf E ]-oo, 0]
+00349                         }
+00350                 }
+00351 
+00352                 // modulate the influence with this factor
+00353                 lightList[i].BkupInfluence= lightList[i].Influence;
+00354                 lightList[i].Influence*= inf;
+00355 
+00356                 // Bkup distance to model.
+00357                 lightList[i].DistanceToModel= dist;
+00358         }
+00359 
+00360         // sort the light by influence
+00361         sort(lightList.begin(), lightList.end());
+00362 
+00363         // prepare Light Merging.
+00364         static std::vector<float>       lightToMergeWeight;
+00365         lightToMergeWeight.clear();
+00366         lightToMergeWeight.resize(lightList.size(), 1);
+00367 
+00368 
+00369         // and choose only max light.
+00370         uint    startId= 0;
+00371         uint    ligthSrcId= 0;
+00372         // skip already setuped light (statically)
+00373         if(lightContrib.FrozenStaticLightSetup)
+00374                 startId= lightContrib.NumFrozenStaticLight;
+00375 
+00376         // If there is still place for unFrozen static lights or dynamic lights.
+00377         if(startId < _MaxLightContribution)
+00378         {
+00379                 // setup the transition.
+00380                 float   deltaMinInfluence= _LightTransitionThreshold;
+00381                 float   minInfluence= 0;
+00382                 sint    doMerge= 0;
+00383                 sint    firstLightToMergeFull= _MaxLightContribution-startId;
+00384                 // If there is more light than we can accept in not merged mode, Must merge
+00385                 if((sint)lightList.size() > firstLightToMergeFull)
+00386                 {
+00387                         doMerge= 1;
+00388                         // the minInfluence is the influence of the first light not taken.
+00389                         minInfluence= lightList[firstLightToMergeFull].Influence;
+00390                         // but must still be >=0.
+00391                         minInfluence= max(minInfluence, 0.f);
+00392                 }
+00393                 // Any light under this minInfluence+deltaMinInfluence will be smoothly darken.
+00394                 float   minInfluenceStart = minInfluence + deltaMinInfluence;
+00395                 float   OOdeltaMinInfluence= 1.0f / deltaMinInfluence;
+00396                 /* NB: this is not an error if we have only 3 light for example (assuming _MaxLightContribution=3), 
+00397                         and still have minInfluenceStart>0.
+00398                         It's to have a continuity in the case of for example we have 3 lights in lightLists at frame T0, 
+00399                         resulting in "doMerge=0"  and at frame T1 we have 4 lights, the farthest having an influence of 0 
+00400                         or nearly 0.
+00401                 */
+00402 
+00403                 // fill maxLight at max.
+00404                 for(i=startId;i<(sint)_MaxLightContribution; i++)
+00405                 {
+00406                         // if not so many pointLights found, end!!
+00407                         if(ligthSrcId>=lightList.size())
+00408                                 break;
+00409                         else
+00410                         {
+00411                                 CPointLight     *pl= lightList[ligthSrcId].PointLight;
+00412                                 float           inf= lightList[ligthSrcId].Influence;
+00413                                 float           bkupInf= lightList[ligthSrcId].BkupInfluence;
+00414                                 float           distToModel= lightList[ligthSrcId].DistanceToModel;
+00415                                 // else fill it.
+00416                                 lightContrib.PointLight[i]= pl;
+00417 
+00418                                 // Compute the Final factor of influence of the light.
+00419                                 if(inf >= minInfluenceStart)
+00420                                 {
+00421                                         // For Static LightSetup BiLinear to work correctly, modulate with BkupInfluence
+00422                                         // don't worry about the precision of floor, because of *255.
+00423                                         lightContrib.Factor[i]= (uint8)NLMISC::OptFastFloor(bkupInf*255);
+00424                                         // Indicate that this light don't need to be merged at all!
+00425                                         lightToMergeWeight[ligthSrcId]= 0;
+00426                                 }
+00427                                 else
+00428                                 {
+00429                                         float   f= (inf-minInfluence) * OOdeltaMinInfluence;
+00430                                         // For Static LightSetup BiLinear to work correctly, modulate with BkupInfluence
+00431                                         // don't worry about the precision of floor, because of *255.
+00432                                         sint    fi= NLMISC::OptFastFloor( bkupInf*f*255 );
+00433                                         clamp(fi, 0, 255);
+00434                                         lightContrib.Factor[i]= fi;
+00435                                         // The rest of the light contribution is to be merged.
+00436                                         lightToMergeWeight[ligthSrcId]= 1-f;
+00437                                 }
+00438 
+00439                                 // Compute the Final Att factor for models using Global Attenuation. NB: modulate with Factor
+00440                                 // don't worry about the precision of floor, because of *255.
+00441                                 // NB: compute att on the center of the model => modelRadius==0
+00442                                 sint    attFactor= NLMISC::OptFastFloor( lightContrib.Factor[i] * pl->computeLinearAttenuation(modelPos, distToModel) );
+00443                                 lightContrib.AttFactor[i]= (uint8)attFactor;
+00444 
+00445                                 // must append this lightedModel to the list in the light.
+00446                                 lightContrib.TransformIterator[i]= pl->appendLightedModel(model);
+00447 
+00448                                 // next light.
+00449                                 ligthSrcId++;
+00450                         }
+00451                 }
+00452 
+00453                 // Compute LightToMerge.
+00454                 if(doMerge)
+00455                 {
+00456                         CRGBAF          mergedAmbient(0,0,0);
+00457                         uint            j;
+00458 
+00459                         // For all lights in the lightList, merge Diffuse and Ambient term to mergedAmbient.
+00460                         for(j=0;j<lightToMergeWeight.size();j++)
+00461                         {
+00462                                 if(lightToMergeWeight[j] && lightList[j].Influence>0)
+00463                                 {
+00464                                         CPointLight     *pl= lightList[j].PointLight;
+00465 
+00466                                         // Get the original influence (ie for static PLs, biLinear influence)
+00467                                         float           bkupInf= lightList[j].BkupInfluence;
+00468                                         // Get the attenuation of the pointLight to the model
+00469                                         float           distToModel= lightList[j].DistanceToModel;
+00470                                         float           attInf= pl->computeLinearAttenuation(modelPos, distToModel);
+00471                                         // Attenuate the color of the light by biLinear and distance/spot attenuation.
+00472                                         float           lightInf= attInf * bkupInf;
+00473                                         // Modulate also by the percentage to merge 
+00474                                         lightInf*= lightToMergeWeight[j];
+00475                                         // Add the full ambient term of the light, attenuated by light attenuation and WeightMerge
+00476                                         mergedAmbient.R+= pl->getAmbient().R * lightInf;
+00477                                         mergedAmbient.G+= pl->getAmbient().G * lightInf;
+00478                                         mergedAmbient.B+= pl->getAmbient().B * lightInf;
+00479                                         // Add 0.25f of the diffuse term of the light, attenuated by light attenuation and WeightMerge
+00480                                         // mul by 0.25f, because this is the averaged contribution of the diffuse part of a 
+00481                                         // light to a sphere (do the maths...).
+00482                                         float   f= lightInf*0.25f;
+00483                                         mergedAmbient.R+= pl->getDiffuse().R * f;
+00484                                         mergedAmbient.G+= pl->getDiffuse().G * f;
+00485                                         mergedAmbient.B+= pl->getDiffuse().B * f;
+00486                                 }
+00487                         }
+00488 
+00489 
+00490                         // Setup the merged Light
+00491                         CRGBA   amb;
+00492                         sint    v;
+00493                         // Because of floating point error, it appears that sometime result may be slightly below 0. 
+00494                         // => clamp necessary
+00495                         v= NLMISC::OptFastFloor(mergedAmbient.R);       fastClamp8(v);  amb.R= v;
+00496                         v= NLMISC::OptFastFloor(mergedAmbient.G);       fastClamp8(v);  amb.G= v;
+00497                         v= NLMISC::OptFastFloor(mergedAmbient.B);       fastClamp8(v);  amb.B= v;
+00498                         lightContrib.MergedPointLight= amb;
+00499 
+00500                         // Indicate we use the merged pointLight => the model must recompute lighting each frame
+00501                         lightContrib.UseMergedPointLight= true;
+00502                 }
+00503                 else
+00504                 {
+00505                         // If the model is freezeHRC(), need to test each frame only if MergedPointLight is used.
+00506                         lightContrib.UseMergedPointLight= false;
+00507                 }
+00508         }
+00509         else
+00510         {
+00511                 // point to end the list
+00512                 i= startId;
+00513         }
+00514 
+00515         // End the list.
+00516         if(i<NL3D_MAX_LIGHT_CONTRIBUTION)
+00517         {
+00518                 lightContrib.PointLight[i]= NULL;
+00519         }
+00520 
+00521 }
+
+

+ + + + +
+ + + + + + + + + + +
CLightingManager::CQGItLightedModel NL3D::CLightingManager::eraseStaticLightedModel CQGItLightedModel  ite  ) 
+
+ + + + + +
+   + + +

+erase a lighted object to the _StaticLightedModelQuadGrid. must do it at deletion of the model or when it leaves freeHRC state. NB: default CQGItLightedModel (ie NULL) can be passed in.

Returns:
quadgrid.end(), ie NULL iterator.
+ +

+Definition at line 217 of file lighting_manager.cpp. +

+References _StaticLightedModelQuadGrid, NL3D::CQuadGrid< CTransform * >::erase(), NL3D_QUADGRID_LIGHT_NUM_LEVEL, NL3D::CLightingManager::CQGItLightedModel::QgItes, and uint. +

+Referenced by NL3D::CTransform::unfreezeHRC(), NL3D::CTransform::update(), and NL3D::CTransform::~CTransform(). +

+

00218 {
+00219         // Erase the iterator for all levels
+00220         for(uint i=0;i<NL3D_QUADGRID_LIGHT_NUM_LEVEL;i++)
+00221         {
+00222                 // NB: it is possible here that the iterator is NULL (ie end()).
+00223                 _StaticLightedModelQuadGrid[i].erase(ite.QgItes[i]);
+00224         }
+00225 
+00226         // return end(), ie NULL iterators
+00227         return CQGItLightedModel();
+00228 }
+
+

+ + + + +
+ + + + + + + + + +
const std::vector<CPointLight*>& NL3D::CLightingManager::getAllDynamicLightList  )  const [inline]
+
+ + + + + +
+   + + +

+retrieve (for this pass only) list of all pointLights visible in scene +

+Definition at line 126 of file lighting_manager.h. +

+Referenced by NL3D::CLandscapeModel::clipAndRenderLandscape(). +

+

00126 {return _DynamicLightList;}
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NL3D::CLightingManager::getDynamicPointLightList const CVector worldPos,
std::vector< CPointLightInfluence > &  lightList
[private]
+
+ + + + + +
+   + + +

+get the list of dynamic light viewed from a position. append to lightList +

+ +

+Definition at line 525 of file lighting_manager.cpp. +

+References _LightQuadGrid, NL3D::CQuadGrid< T >::begin(), NL3D::CQuadGrid< T >::end(), NL3D::CPointLightInfluence::Influence, NL3D_QUADGRID_LIGHT_NUM_LEVEL, NL3D::CPointLightInfluence::PointLight, NL3D::CQuadGrid< T >::select(), and uint. +

+Referenced by computeModelLightContributions(). +

+

00526 {
+00527         // For all quadGrids.
+00528         for(uint qgId=0; qgId<NL3D_QUADGRID_LIGHT_NUM_LEVEL; qgId++)
+00529         {
+00530                 CQuadGrid<CPointLightInfo>      &quadGrid= _LightQuadGrid[qgId];
+00531 
+00532                 // select the lights around this position in the quadGrids.
+00533                 quadGrid.select(worldPos, worldPos);
+00534 
+00535                 // for all possible found lights
+00536                 CQuadGrid<CPointLightInfo>::CIterator   itLight;
+00537                 for(itLight= quadGrid.begin(); itLight!=quadGrid.end(); itLight++)
+00538                 {
+00539                         // verify it includes the entity
+00540                         if( (*itLight).Sphere.include(worldPos) )
+00541                         {
+00542                                 // ok, insert in list.
+00543                                 CPointLightInfluence    pli;
+00544                                 pli.PointLight= (*itLight).Light;
+00545                                 // No special Influence degradation scheme for Dynamic lighting
+00546                                 pli.Influence= 1;
+00547                                 lightList.push_back( pli );
+00548                         }
+00549                 }
+00550         }
+00551 }
+
+

+ + + + +
+ + + + + + + + + +
float NL3D::CLightingManager::getLightTransitionThreshold  )  const [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 109 of file lighting_manager.h. +

+References _LightTransitionThreshold. +

+Referenced by NL3D::CScene::getLightTransitionThreshold(). +

+

00109 {return _LightTransitionThreshold;}
+
+

+ + + + +
+ + + + + + + + + +
uint NL3D::CLightingManager::getMaxLightContribution  )  const [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 84 of file lighting_manager.h. +

+References _MaxLightContribution, and uint. +

+Referenced by NL3D::CScene::getMaxLightContribution(). +

+

00084 {return _MaxLightContribution;}
+
+

+ + + + +
+ + + + + + + + + +
float NL3D::CLightingManager::getNoAttLightRadius  )  const [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 91 of file lighting_manager.h. +

+References _NoAttLightRadius. +

+

00091 {return _NoAttLightRadius;}
+
+

+ + + + +
+ + + + + + + + + +
float NL3D::CLightingManager::getOutOfAttLightInfFactor  )  const [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 98 of file lighting_manager.h. +

+References _OutOfAttLightInfFactor. +

+

00098 {return _OutOfAttLightInfFactor;}
+
+

+ + + + +
+ + + + + + + + + + +
CLightingManager::CQGItLightedModel NL3D::CLightingManager::insertStaticLightedModel CTransform model  ) 
+
+ + + + + +
+   + + +

+insert a lighted object to the _StaticLightedModelQuadGrid. must not be inserted before must do it only for static objects, ie when freeHRC state is validated (see CTransform::update()) NB: only lightable models with no AncestorSkeletonModel should be inserted +

+Definition at line 231 of file lighting_manager.cpp. +

+References _StaticLightedModelQuadGrid, NLMISC::CMatrix::getPos(), NL3D::CTransform::getWorldMatrix(), NL3D::CQuadGrid< CTransform * >::insert(), NL3D_QUADGRID_LIGHT_NUM_LEVEL, NL3D::CLightingManager::CQGItLightedModel::QgItes, and uint. +

+Referenced by NL3D::CTransform::update(). +

+

00232 {
+00233         CQGItLightedModel       ite;
+00234         const CVector &worldPos= model->getWorldMatrix().getPos();
+00235 
+00236         // Insert the models in all levels, because addDynamicLight() may choose the best suited level to select
+00237         for(uint i=0;i<NL3D_QUADGRID_LIGHT_NUM_LEVEL;i++)
+00238         {
+00239                 ite.QgItes[i]= _StaticLightedModelQuadGrid[i].insert(worldPos, worldPos, model);
+00240         }
+00241 
+00242         // return the iterator
+00243         return ite;
+00244 }
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLightingManager::setLightTransitionThreshold float  lightTransitionThreshold  ) 
+
+ + + + + +
+   + + +

+Advanced. When a model is influenced by more light than allowed, or when it reach the limits of the light (attenuationEnd), the light can be darkened according to some threshold. The resultLightColor begin to fade when distModelToLight== attEnd- threshold*(attEnd-attBegin). when distModelToLight== 0, resultLightColor==Black. By default, this value is 0.1f. Setting higher values will smooth transition but will generally darken the global effects of lights. NB: clamp(value, 0, 1); +

+Definition at line 128 of file lighting_manager.cpp. +

+References _LightTransitionThreshold, and NLMISC::clamp(). +

+Referenced by NL3D::CScene::setLightTransitionThreshold(). +

+

00129 {
+00130         clamp(lightTransitionThreshold, 0.f, 1.f);
+00131         _LightTransitionThreshold= lightTransitionThreshold;
+00132 }
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLightingManager::setMaxLightContribution uint  nlights  ) 
+
+ + + + + +
+   + + +

+set the max number of point light that can influence a model. NB: clamped by NL3D_MAX_LIGHT_CONTRIBUTION Default is 3. NB: the sun contribution is not taken into account +

+Definition at line 105 of file lighting_manager.cpp. +

+References _MaxLightContribution, min, NL3D_MAX_LIGHT_CONTRIBUTION, and uint. +

+Referenced by CLightingManager(), and NL3D::CScene::setMaxLightContribution(). +

+

00106 {
+00107         _MaxLightContribution= min(nlights, (uint)NL3D_MAX_LIGHT_CONTRIBUTION);
+00108 }
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLightingManager::setNoAttLightRadius float  noAttLightRadius  ) 
+
+ + + + + +
+   + + +

+Advanced. When a light has no attenuation, it's still inserted in a quadgrid with some radius and won't influence models beyond. You can setup this radius with this method. Default is 1000m. NB: nlassert(noAttLightRadius>0); +

+Definition at line 112 of file lighting_manager.cpp. +

+References _NoAttLightRadius, and nlassert. +

+

00113 {
+00114         nlassert(noAttLightRadius>0);
+00115         _NoAttLightRadius= noAttLightRadius;
+00116 }
+
+

+ + + + +
+ + + + + + + + + + +
void NL3D::CLightingManager::setOutOfAttLightInfFactor float  outOfAttLightInfFactor  ) 
+
+ + + + + +
+   + + +

+Advanced. When a model is out of [AttBegin, AttEnd] of a light, the computed influence of the light used to choose "best lights" is not constant, and is a function of distance multiplied by a factor you can setup here. Default is 0.1f and is good for lights with att like (50, 100) (arbitrary). +

+Definition at line 120 of file lighting_manager.cpp. +

+References _OutOfAttLightInfFactor. +

+

00121 {
+00122         outOfAttLightInfFactor= max(0.f, outOfAttLightInfFactor);
+00123         _OutOfAttLightInfFactor= outOfAttLightInfFactor;
+00124 }
+
+


Field Documentation

+

+ + + + +
+ + +
std::vector<CPointLight*> NL3D::CLightingManager::_DynamicLightList [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 181 of file lighting_manager.h.

+

+ + + + +
+ + +
CQuadGrid<CPointLightInfo> NL3D::CLightingManager::_LightQuadGrid[ 4 ] [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 177 of file lighting_manager.h. +

+Referenced by addDynamicLight(), clearDynamicLights(), CLightingManager(), and getDynamicPointLightList().

+

+ + + + +
+ + +
float NL3D::CLightingManager::_LightQuadGridRadiusLimit[ 4 ] [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 179 of file lighting_manager.h. +

+Referenced by addDynamicLight(), and CLightingManager().

+

+ + + + +
+ + +
float NL3D::CLightingManager::_LightTransitionThreshold [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 188 of file lighting_manager.h. +

+Referenced by CLightingManager(), computeModelLightContributions(), getLightTransitionThreshold(), and setLightTransitionThreshold().

+

+ + + + +
+ + +
uint NL3D::CLightingManager::_MaxLightContribution [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 185 of file lighting_manager.h. +

+Referenced by computeModelLightContributions(), getMaxLightContribution(), and setMaxLightContribution().

+

+ + + + +
+ + +
float NL3D::CLightingManager::_NoAttLightRadius [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 186 of file lighting_manager.h. +

+Referenced by addDynamicLight(), CLightingManager(), getNoAttLightRadius(), and setNoAttLightRadius().

+

+ + + + +
+ + +
float NL3D::CLightingManager::_OutOfAttLightInfFactor [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 187 of file lighting_manager.h. +

+Referenced by CLightingManager(), computeModelLightContributions(), getOutOfAttLightInfFactor(), and setOutOfAttLightInfFactor().

+

+ + + + +
+ + +
CQuadGrid<CTransform*> NL3D::CLightingManager::_StaticLightedModelQuadGrid[ 4 ] [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 176 of file lighting_manager.h. +

+Referenced by addDynamicLight(), CLightingManager(), eraseStaticLightedModel(), and insertStaticLightedModel().

+


The documentation for this class was generated from the following files: +
Generated on Tue Mar 16 06:49:30 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1