Bläddra i källkod

Clamp light color to positive, as the result of negative color is erratic and depends on blend mode.
Exclude lights with zero intensity from rendering.

Lasse Öörni 14 år sedan
förälder
incheckning
8968ce2609
2 ändrade filer med 7 tillägg och 3 borttagningar
  1. 4 2
      Engine/Graphics/Light.cpp
  2. 3 1
      Engine/Graphics/View.cpp

+ 4 - 2
Engine/Graphics/Light.cpp

@@ -108,7 +108,7 @@ void Light::RegisterObject(Context* context)
     context->RegisterFactory<Light>();
     context->RegisterFactory<Light>();
     
     
     ENUM_ACCESSOR_ATTRIBUTE(Light, "Light Type", GetLightType, SetLightType, LightType, typeNames, DEFAULT_LIGHTTYPE, AM_DEFAULT);
     ENUM_ACCESSOR_ATTRIBUTE(Light, "Light Type", GetLightType, SetLightType, LightType, typeNames, DEFAULT_LIGHTTYPE, AM_DEFAULT);
-    ATTRIBUTE(Light, VAR_COLOR, "Color", color_, Color(), AM_DEFAULT);
+    REF_ACCESSOR_ATTRIBUTE(Light, VAR_COLOR, "Color", GetColor, SetColor, Color, Color(), AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(Light, VAR_FLOAT, "Specular Intensity", GetSpecularIntensity, SetSpecularIntensity, float, 0.0f, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(Light, VAR_FLOAT, "Specular Intensity", GetSpecularIntensity, SetSpecularIntensity, float, 0.0f, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(Light, VAR_FLOAT, "Range", GetRange, SetRange, float, DEFAULT_RANGE, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(Light, VAR_FLOAT, "Range", GetRange, SetRange, float, DEFAULT_RANGE, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(Light, VAR_FLOAT, "Spot FOV", GetFov, SetFov, float, DEFAULT_FOV, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(Light, VAR_FLOAT, "Spot FOV", GetFov, SetFov, float, DEFAULT_FOV, AM_DEFAULT);
@@ -271,7 +271,9 @@ void Light::SetPerVertex(bool enable)
 
 
 void Light::SetColor(const Color& color)
 void Light::SetColor(const Color& color)
 {
 {
-    color_ = color;
+    // Clamp RGB values to positive, as negative values behave erratically depending on whether the pass uses
+    // replace or additive blend mode
+    color_ = Color(Max(color.r_, 0.0f), Max(color.g_, 0.0f), Max(color.b_, 0.0f), 1.0f);
 }
 }
 
 
 void Light::SetRange(float range)
 void Light::SetRange(float range)

+ 3 - 1
Engine/Graphics/View.cpp

@@ -491,7 +491,9 @@ void View::GetDrawables()
         else if (flags & DRAWABLE_LIGHT)
         else if (flags & DRAWABLE_LIGHT)
         {
         {
             Light* light = static_cast<Light*>(drawable);
             Light* light = static_cast<Light*>(drawable);
-            lights_.Push(light);
+            // Skip lights with no intensity
+            if (light->GetColor().Intensity() > 0.0f)
+                lights_.Push(light);
         }
         }
     }
     }