Browse Source

Optimized away going through renderpath commands just to find the litbase-flag.

Lasse Öörni 12 years ago
parent
commit
0c4466d3f3
2 changed files with 12 additions and 17 deletions
  1. 9 16
      Source/Engine/Graphics/View.cpp
  2. 3 1
      Source/Engine/Graphics/View.h

+ 9 - 16
Source/Engine/Graphics/View.cpp

@@ -388,9 +388,10 @@ bool View::Define(RenderSurface* renderTarget, Viewport* viewport)
             lightPassName_ = command.pass_;
             lightPassName_ = command.pass_;
     }
     }
     
     
-    // Go through commands to check for deferred rendering
+    // Go through commands to check for deferred rendering and other flags
     deferred_ = false;
     deferred_ = false;
     deferredAmbient_ = false;
     deferredAmbient_ = false;
+    useLitBase_ = false;
     
     
     for (unsigned i = 0; i < renderPath_->commands_.Size(); ++i)
     for (unsigned i = 0; i < renderPath_->commands_.Size(); ++i)
     {
     {
@@ -404,13 +405,14 @@ bool View::Define(RenderSurface* renderTarget, Viewport* viewport)
             if (CheckViewportWrite(command))
             if (CheckViewportWrite(command))
                 deferredAmbient_ = true;
                 deferredAmbient_ = true;
         }
         }
-        
-        if (command.type_ == CMD_LIGHTVOLUMES)
+        else if (command.type_ == CMD_LIGHTVOLUMES)
         {
         {
             lightVolumeVSName_ = command.vertexShaderName_;
             lightVolumeVSName_ = command.vertexShaderName_;
             lightVolumePSName_ = command.pixelShaderName_;
             lightVolumePSName_ = command.pixelShaderName_;
             deferred_ = true;
             deferred_ = true;
         }
         }
+        else if (command.type_ == CMD_FORWARDLIGHTS)
+            useLitBase_ = command.useLitBase_;
     }
     }
     
     
     // Validate the rect and calculate size. If zero rect, use whole rendertarget size
     // Validate the rect and calculate size. If zero rect, use whole rendertarget size
@@ -754,15 +756,6 @@ void View::GetBatches()
     PODVector<Light*> vertexLights;
     PODVector<Light*> vertexLights;
     BatchQueue* alphaQueue = batchQueues_.Contains(alphaPassName_) ? &batchQueues_[alphaPassName_] : (BatchQueue*)0;
     BatchQueue* alphaQueue = batchQueues_.Contains(alphaPassName_) ? &batchQueues_[alphaPassName_] : (BatchQueue*)0;
     
     
-    // Check whether to use the lit base pass optimization
-    bool useLitBase = true;
-    for (unsigned i = 0; i < renderPath_->commands_.Size(); ++i)
-    {
-        const RenderPathCommand& command = renderPath_->commands_[i];
-        if (command.type_ == CMD_FORWARDLIGHTS)
-            useLitBase = command.useLitBase_;
-    }
-    
     // Process lit geometries and shadow casters for each light
     // Process lit geometries and shadow casters for each light
     {
     {
         PROFILE(ProcessLights);
         PROFILE(ProcessLights);
@@ -896,7 +889,7 @@ void View::GetBatches()
                     
                     
                     // If drawable limits maximum lights, only record the light, and check maximum count / build batches later
                     // If drawable limits maximum lights, only record the light, and check maximum count / build batches later
                     if (!drawable->GetMaxLights())
                     if (!drawable->GetMaxLights())
-                        GetLitBatches(drawable, lightQueue, alphaQueue, useLitBase);
+                        GetLitBatches(drawable, lightQueue, alphaQueue);
                     else
                     else
                         maxLightsDrawables_.Insert(drawable);
                         maxLightsDrawables_.Insert(drawable);
                 }
                 }
@@ -950,7 +943,7 @@ void View::GetBatches()
                 // Find the correct light queue again
                 // Find the correct light queue again
                 LightBatchQueue* queue = light->GetLightQueue();
                 LightBatchQueue* queue = light->GetLightQueue();
                 if (queue)
                 if (queue)
-                    GetLitBatches(drawable, *queue, alphaQueue, useLitBase);
+                    GetLitBatches(drawable, *queue, alphaQueue);
             }
             }
         }
         }
     }
     }
@@ -1142,7 +1135,7 @@ void View::UpdateGeometries()
     queue->Complete(M_MAX_UNSIGNED);
     queue->Complete(M_MAX_UNSIGNED);
 }
 }
 
 
-void View::GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQueue* alphaQueue, bool useLitBase)
+void View::GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQueue* alphaQueue)
 {
 {
     Light* light = lightQueue.light_;
     Light* light = lightQueue.light_;
     Zone* zone = GetZone(drawable);
     Zone* zone = GetZone(drawable);
@@ -1151,7 +1144,7 @@ void View::GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQ
     bool hasAmbientGradient = zone->GetAmbientGradient() && zone->GetAmbientStartColor() != zone->GetAmbientEndColor();
     bool hasAmbientGradient = zone->GetAmbientGradient() && zone->GetAmbientStartColor() != zone->GetAmbientEndColor();
     // Shadows on transparencies can only be rendered if shadow maps are not reused
     // Shadows on transparencies can only be rendered if shadow maps are not reused
     bool allowTransparentShadows = !renderer_->GetReuseShadowMaps();
     bool allowTransparentShadows = !renderer_->GetReuseShadowMaps();
-    bool allowLitBase = useLitBase && light == drawable->GetFirstLight() && drawable->GetVertexLights().Empty() && !hasAmbientGradient;
+    bool allowLitBase = useLitBase_ && light == drawable->GetFirstLight() && drawable->GetVertexLights().Empty() && !hasAmbientGradient;
     
     
     for (unsigned i = 0; i < batches.Size(); ++i)
     for (unsigned i = 0; i < batches.Size(); ++i)
     {
     {

+ 3 - 1
Source/Engine/Graphics/View.h

@@ -154,7 +154,7 @@ private:
     /// Update geometries and sort batches.
     /// Update geometries and sort batches.
     void UpdateGeometries();
     void UpdateGeometries();
     /// Get pixel lit batches for a certain light and drawable.
     /// Get pixel lit batches for a certain light and drawable.
-    void GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQueue* alphaQueue, bool useLitBase);
+    void GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQueue* alphaQueue);
     /// Execute render commands.
     /// Execute render commands.
     void ExecuteRenderPathCommands();
     void ExecuteRenderPathCommands();
     /// Set rendertargets for current render command.
     /// Set rendertargets for current render command.
@@ -300,6 +300,8 @@ private:
     bool deferred_;
     bool deferred_;
     /// Deferred ambient pass flag. This means that the destination rendertarget is being written to at the same time as albedo/normal/depth buffers, and needs to be RGBA on OpenGL.
     /// Deferred ambient pass flag. This means that the destination rendertarget is being written to at the same time as albedo/normal/depth buffers, and needs to be RGBA on OpenGL.
     bool deferredAmbient_;
     bool deferredAmbient_;
+    /// Forward light base pass optimization flag. If in use, combine the base pass and first light for all opaque objects.
+    bool useLitBase_;
     /// Renderpath.
     /// Renderpath.
     RenderPath* renderPath_;
     RenderPath* renderPath_;
     /// Per-thread octree query results.
     /// Per-thread octree query results.