Browse Source

Disable light buffer optimization if opaque objects with zero lightmask exist.

Lasse Öörni 14 years ago
parent
commit
8fcba14bfb
2 changed files with 11 additions and 3 deletions
  1. 9 3
      Engine/Graphics/View.cpp
  2. 2 0
      Engine/Graphics/View.h

+ 9 - 3
Engine/Graphics/View.cpp

@@ -711,6 +711,9 @@ void View::GetBatches()
     // Build base pass batches
     {
         PROFILE(GetBaseBatches);
+        
+        hasZeroLightMask_ = false;
+        
         for (PODVector<Drawable*>::ConstIterator i = geometries_.Begin(); i != geometries_.End(); ++i)
         {
             Drawable* drawable = *i;
@@ -744,6 +747,10 @@ void View::GetBatches()
                     pass = tech->GetPass(PASS_GBUFFER);
                     if (pass)
                     {
+                        // If the opaque object has a zero lightmask, have to skip light buffer optimization
+                        if (!hasZeroLightMask_ && (!(GetLightMask(drawable) & 0xff)))
+                            hasZeroLightMask_ = true;
+                        
                         // Allow G-buffer pass instancing only if lightmask matches zone lightmask
                         baseBatch.lightMask_ = GetLightMask(drawable);
                         FinalizeBatch(baseBatch, tech, pass, baseBatch.lightMask_ == (baseBatch.zone_->GetLightMask() & 0xff));
@@ -1112,8 +1119,8 @@ void View::RenderBatchesLightPrepass()
     }
     
     // Clear the light accumulation buffer. However, skip the clear if the first light is a directional light with full mask
-    bool optimizeLightBuffer = !lightQueues_.Empty() && lightQueues_.Front().light_->GetLightType() == LIGHT_DIRECTIONAL &&
-        (lightQueues_.Front().light_->GetLightMask() & 0xff) == 0xff;
+    bool optimizeLightBuffer = !hasZeroLightMask_ && !lightQueues_.Empty() && lightQueues_.Front().light_->GetLightType() ==
+        LIGHT_DIRECTIONAL && (lightQueues_.Front().light_->GetLightMask() & 0xff) == 0xff;
     
     Texture2D* lightBuffer = renderer_->GetLightBuffer();
     graphics_->ResetRenderTarget(1);
@@ -1164,7 +1171,6 @@ void View::RenderBatchesLightPrepass()
     graphics_->SetRenderTarget(0, renderTarget);
     graphics_->SetDepthStencil(depthStencil);
     graphics_->SetViewport(screenRect_);
-    
     graphics_->SetShaders(renderer_->GetVertexShader("Basic"), renderer_->GetPixelShader("Basic"));
     graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, farClipZone_->GetFogColor());
     graphics_->ClearParameterSource(PSP_MATDIFFCOLOR);

+ 2 - 0
Engine/Graphics/View.h

@@ -283,4 +283,6 @@ private:
     bool cameraZoneOverride_;
     /// Draw shadows flag.
     bool drawShadows_;
+    /// Whether objects with zero lightmask exist. In light pre-pass mode this means skipping some optimizations.
+    bool hasZeroLightMask_;
 };