Просмотр исходного кода

Fixed setting camera shader parameters redundantly in light prepass material pass.
Calculate number of instances more reliably from the batchgroup geometry type.

Lasse Öörni 13 лет назад
Родитель
Сommit
54dab6404f
3 измененных файлов с 8 добавлено и 11 удалено
  1. 5 8
      Engine/Graphics/Batch.cpp
  2. 3 0
      Engine/Graphics/Renderer.cpp
  3. 0 3
      Engine/Graphics/View.cpp

+ 5 - 8
Engine/Graphics/Batch.cpp

@@ -667,12 +667,12 @@ void BatchGroup::Draw(Graphics* graphics, Renderer* renderer) const
             
             for (unsigned i = 0; i < instances_.Size(); ++i)
             {
-                graphics->SetShaderParameter(VSP_MODEL, *instances_[i].worldTransform_);
+                if (graphics->NeedParameterUpdate(SP_OBJECTTRANSFORM, instances_[i].worldTransform_))
+                    graphics->SetShaderParameter(VSP_MODEL, *instances_[i].worldTransform_);
+                
                 graphics->Draw(geometry_->GetPrimitiveType(), geometry_->GetIndexStart(), geometry_->GetIndexCount(),
                     geometry_->GetVertexStart(), geometry_->GetVertexCount());
             }
-            
-            graphics->ClearTransformSources();
         }
         else
         {
@@ -947,18 +947,15 @@ void BatchQueue::Draw(Light* light, Graphics* graphics, Renderer* renderer) cons
 unsigned BatchQueue::GetNumInstances(Renderer* renderer) const
 {
     unsigned total = 0;
-    unsigned maxIndexCount = renderer->GetMaxInstanceTriangles() * 3;
     
-    // As this function is for the purpose of calculating how much space is needed in the instancing buffer, do not add groups
-    // that have too many triangles to be instanced
     for (HashMap<BatchGroupKey, BatchGroup>::ConstIterator i = baseBatchGroups_.Begin(); i != baseBatchGroups_.End(); ++i)
     {
-        if (i->second_.geometry_->GetIndexCount() <= maxIndexCount)
+        if (i->second_.geometryType_ == GEOM_INSTANCED)
             total += i->second_.instances_.Size();
     }
     for (HashMap<BatchGroupKey, BatchGroup>::ConstIterator i = batchGroups_.Begin(); i != batchGroups_.End(); ++i)
     {
-        if (i->second_.geometry_->GetIndexCount() <= maxIndexCount)
+       if (i->second_.geometryType_ == GEOM_INSTANCED)
             total += i->second_.instances_.Size();
     }
     

+ 3 - 0
Engine/Graphics/Renderer.cpp

@@ -1060,6 +1060,9 @@ void Renderer::SetBatchShaders(Batch& batch, Technique* tech, bool allowShadows)
             (unsigned)maxInstanceTriangles_ * 3))
             geomType = GEOM_STATIC;
         
+        if (geomType == GEOM_STATIC_NOINSTANCING)
+            geomType = GEOM_STATIC;
+        
         //  Check whether is a pixel lit forward pass. If not, there is only one pixel shader
         PassType type = batch.pass_->GetType();
         if (type == PASS_LIGHT || type == PASS_LITBASE)

+ 0 - 3
Engine/Graphics/View.cpp

@@ -2353,9 +2353,6 @@ void View::AddBatchToQueue(BatchQueue& batchQueue, Batch& batch, Technique* tech
         !batch.overrideView_)
         batch.geometryType_ = GEOM_INSTANCED;
     
-    if (batch.geometryType_ == GEOM_STATIC_NOINSTANCING)
-        batch.geometryType_ = GEOM_STATIC;
-    
     if (batch.geometryType_ == GEOM_INSTANCED)
     {
         HashMap<BatchGroupKey, BatchGroup>* groups = batch.isBase_ ? &batchQueue.baseBatchGroups_ : &batchQueue.batchGroups_;