Browse Source

For global per-frame light sorting, give priority to directional lights so that they will most likely be combined with the ambient pass.

Lasse Öörni 14 years ago
parent
commit
79c229b67e
1 changed files with 7 additions and 5 deletions
  1. 7 5
      Engine/Graphics/Light.cpp

+ 7 - 5
Engine/Graphics/Light.cpp

@@ -421,18 +421,20 @@ void Light::OnWorldBoundingBoxUpdate()
 
 
 void Light::SetIntensitySortValue(float distance)
 void Light::SetIntensitySortValue(float distance)
 {
 {
+    // When sorting lights globally, give priority to directional lights so that they will be combined into the ambient pass
     if (lightType_ != LIGHT_DIRECTIONAL)
     if (lightType_ != LIGHT_DIRECTIONAL)
-        sortValue_ = (distance + 1.0f) / color_.Intensity();
+        sortValue_ = Max(distance, M_MIN_NEARCLIP) / (color_.Intensity() + M_EPSILON);
     else
     else
-        sortValue_ = 1.0f / color_.Intensity();
+        sortValue_ = M_EPSILON / (color_.Intensity() + M_EPSILON);
 }
 }
 
 
 void Light::SetIntensitySortValue(const BoundingBox& box)
 void Light::SetIntensitySortValue(const BoundingBox& box)
 {
 {
+    // When sorting lights for object's maximum light cap, give priority based on attenuation and intensity
     switch (lightType_)
     switch (lightType_)
     {
     {
     case LIGHT_DIRECTIONAL:
     case LIGHT_DIRECTIONAL:
-        sortValue_ = 1.0f / (color_.Intensity() + 1.0f);
+        sortValue_ = 1.0f / (color_.Intensity() + M_EPSILON);
         break;
         break;
         
         
     case LIGHT_POINT:
     case LIGHT_POINT:
@@ -444,7 +446,7 @@ void Light::SetIntensitySortValue(const BoundingBox& box)
             float distance = lightRay.HitDistance(box);
             float distance = lightRay.HitDistance(box);
             float normDistance = distance / range_;
             float normDistance = distance / range_;
             float att = Max(1.0f - normDistance * normDistance, M_EPSILON);
             float att = Max(1.0f - normDistance * normDistance, M_EPSILON);
-            sortValue_ = 1.0f / (color_.Intensity() * att + 1.0f);
+            sortValue_ = 1.0f / (color_.Intensity() * att + M_EPSILON);
         }
         }
         break;
         break;
         
         
@@ -472,7 +474,7 @@ void Light::SetIntensitySortValue(const BoundingBox& box)
             float spotFactor = Min(spotAngle / maxAngle, 1.0f);
             float spotFactor = Min(spotAngle / maxAngle, 1.0f);
             // We do not know the actual range attenuation ramp, so take only spot attenuation into account
             // We do not know the actual range attenuation ramp, so take only spot attenuation into account
             float att = Max(1.0f - spotFactor * spotFactor, M_EPSILON);
             float att = Max(1.0f - spotFactor * spotFactor, M_EPSILON);
-            sortValue_ = 1.0f / (color_.Intensity() * att + 1.0f);
+            sortValue_ = 1.0f / (color_.Intensity() * att + M_EPSILON);
         }
         }
         break;
         break;
     }
     }