| 83 | } |
| 84 | |
| 85 | void LightQuery::_scoreLights() |
| 86 | { |
| 87 | PROFILE_SCOPE( LightQuery_scoreLights ); |
| 88 | |
| 89 | if ( !LIGHTMGR ) |
| 90 | return; |
| 91 | |
| 92 | // Get all the lights. |
| 93 | LIGHTMGR->getAllUnsortedLights( &mLights ); |
| 94 | LightInfo *sun = LIGHTMGR->getSpecialLight( LightManager::slSunLightType ); |
| 95 | |
| 96 | const Point3F lumDot( 0.2125f, 0.7154f, 0.0721f ); |
| 97 | |
| 98 | Vector<LightInfo*>::iterator iter = mLights.begin(); |
| 99 | for ( ; iter != mLights.end(); iter++ ) |
| 100 | { |
| 101 | // Get the light. |
| 102 | LightInfo *light = (*iter); |
| 103 | |
| 104 | F32 luminace = 0.0f; |
| 105 | F32 dist = 0.0f; |
| 106 | F32 weight = 0.0f; |
| 107 | |
| 108 | const bool isSpot = light->getType() == LightInfo::Spot; |
| 109 | const bool isPoint = light->getType() == LightInfo::Point; |
| 110 | |
| 111 | if ( isPoint || isSpot ) |
| 112 | { |
| 113 | // Get the luminocity. |
| 114 | luminace = mDot( light->getColor(), lumDot ) * light->getBrightness(); |
| 115 | |
| 116 | // Get the distance to the light... score it 1 to 0 near to far. |
| 117 | F32 lenSq = ( mVolume.center - light->getPosition() ).lenSquared(); |
| 118 | |
| 119 | F32 radiusSq = mSquared( light->getRange().x + mVolume.radius ); |
| 120 | F32 distSq = radiusSq - lenSq; |
| 121 | |
| 122 | if ( distSq > 0.0f ) |
| 123 | dist = mClampF( distSq / ( 1000.0f * 1000.0f ), 0.0f, 1.0f ); |
| 124 | |
| 125 | // TODO: This culling is broken... it culls spotlights |
| 126 | // that are actually visible. |
| 127 | if ( false && isSpot && dist > 0.0f ) |
| 128 | { |
| 129 | // TODO: I cannot test to see if we're within |
| 130 | // the cone without a more detailed test... so |
| 131 | // just reject if we're behind the spot direction. |
| 132 | |
| 133 | Point3F toCenter = mVolume.center - light->getPosition(); |
| 134 | F32 angDot = mDot( toCenter, light->getDirection() ); |
| 135 | if ( angDot < 0.0f ) |
| 136 | dist = 0.0f; |
| 137 | } |
| 138 | |
| 139 | weight = light->getPriority(); |
| 140 | } |
| 141 | else |
| 142 | { |
nothing calls this directly
no test coverage detected