Selaa lähdekoodia

Sort also the postalpha pass back to front.

Lasse Öörni 14 vuotta sitten
vanhempi
sitoutus
63f23313d6

+ 1 - 1
Bin/CoreData/Materials/BlueUnlit.xml

@@ -1,4 +1,4 @@
 <material>
-    <technique name="Techniques/BasicNoDepth.xml" />
+    <technique name="Techniques/NoTextureOverlay.xml" />
     <parameter name="MatDiffColor" value="0 0 0.5 1" />
 </material>

+ 1 - 1
Bin/CoreData/Materials/BrightBlueUnlit.xml

@@ -1,4 +1,4 @@
 <material>
-    <technique name="Techniques/BasicNoDepth.xml" />
+    <technique name="Techniques/NoTextureOverlay.xml" />
     <parameter name="MatDiffColor" value="0 0 1 1" />
 </material>

+ 1 - 1
Bin/CoreData/Materials/BrightGreenUnlit.xml

@@ -1,4 +1,4 @@
 <material>
-    <technique name="Techniques/BasicNoDepth.xml" />
+    <technique name="Techniques/NoTextureOverlay.xml" />
     <parameter name="MatDiffColor" value="0 1 0 1" />
 </material>

+ 1 - 1
Bin/CoreData/Materials/BrightRedUnlit.xml

@@ -1,4 +1,4 @@
 <material>
-    <technique name="Techniques/BasicNoDepth.xml" />
+    <technique name="Techniques/NoTextureOverlay.xml" />
     <parameter name="MatDiffColor" value="1 0 0 1" />
 </material>

+ 1 - 1
Bin/CoreData/Materials/GreenUnlit.xml

@@ -1,4 +1,4 @@
 <material>
-    <technique name="Techniques/BasicNoDepth.xml" />
+    <technique name="Techniques/NoTextureOverlay.xml" />
     <parameter name="MatDiffColor" value="0 0.5 0 1" />
 </material>

+ 1 - 1
Bin/CoreData/Materials/RedUnlit.xml

@@ -1,4 +1,4 @@
 <material>
-    <technique name="Techniques/BasicNoDepth.xml" />
+    <technique name="Techniques/NoTextureOverlay.xml" />
     <parameter name="MatDiffColor" value="0.5 0 0 1" />
 </material>

+ 0 - 3
Bin/CoreData/Techniques/BasicNoDepth.xml

@@ -1,3 +0,0 @@
-<technique>
-    <pass name="base" vs="Basic" ps="Basic" blend="alpha" depthtest="always" depthwrite="false"/>
-</technique>

+ 3 - 0
Bin/CoreData/Techniques/DiffOverlay.xml

@@ -0,0 +1,3 @@
+<technique>
+    <pass name="postalpha" vs="Basic_Diff" ps="Basic_Diff" depthtest="always" depthwrite="false"/>
+</technique>

+ 3 - 0
Bin/CoreData/Techniques/NoTextureOverlay.xml

@@ -0,0 +1,3 @@
+<technique>
+    <pass name="postalpha" vs="Basic" ps="Basic" depthtest="always" depthwrite="false"/>
+</technique>

+ 2 - 0
Docs/Reference.dox

@@ -520,6 +520,8 @@ The passes are:
 - postalpha: custom rendering pass after transparent geometry.
 - shadow: shadow map rendering pass. Renders depth only.
 
+By default draw calls within passes are sorted by render state, but transparent base and light passes, as well as the postalpha pass, are sorted by distance back to front.
+
 Note that the technique does not need to enumerate shaders used for different geometry types (non-skinned, skinned, instanced, billboard) and light types (directional, point and spot, specular and no specular, shadowed and non-shadowed.) Instead specific hardcoded shader variations are assumed to exist. See the file Forward.xml in either SourceAssets/HLSLShaders or SourceAssets/GLSLShaders for all the shader variations.
 
 

+ 2 - 2
Engine/Graphics/Batch.cpp

@@ -552,10 +552,10 @@ void BatchQueue::Clear()
     batchGroups_.Clear();
 }
 
-void BatchQueue::AddBatch(const Batch& batch, bool noInstancing)
+void BatchQueue::AddBatch(const Batch& batch, bool instancing)
 {
     // If batch is something else than static, has custom view, or has per-instance shader data defined, can not instance
-    if (noInstancing || batch.geometryType_ != GEOM_STATIC || batch.overrideView_ || batch.shaderData_)
+    if (!instancing || batch.geometryType_ != GEOM_STATIC || batch.overrideView_ || batch.shaderData_)
         batches_.Push(batch);
     else
     {

+ 1 - 1
Engine/Graphics/Batch.h

@@ -225,7 +225,7 @@ public:
     /// Clear everything.
     void Clear();
     /// Add a batch, with instancing if possible.
-    void AddBatch(const Batch& batch, bool noInstancing = false);
+    void AddBatch(const Batch& batch, bool instancing = true);
     /// Sort non-instanced draw calls back to front.
     void SortBackToFront();
     /// Sort instanced and non-instanced draw calls front to back.

+ 7 - 11
Engine/Graphics/View.cpp

@@ -194,8 +194,6 @@ void View::Render()
     
     graphics_->SetColorWrite(true);
     graphics_->SetFillMode(FILL_SOLID);
-    graphics_->SetScissorTest(false);
-    graphics_->SetStencilTest(false);
     
     // Bind the face selection and indirection cube maps for point light shadows
     graphics_->SetTexture(TU_FACESELECT, renderer_->GetFaceSelectCubeMap());
@@ -519,7 +517,7 @@ void View::GetBatches()
                     if (pass->GetBlendMode() == BLEND_REPLACE)
                         baseQueue_.AddBatch(baseBatch);
                     else
-                        alphaQueue_.AddBatch(baseBatch, true);
+                        alphaQueue_.AddBatch(baseBatch, false);
                     continue;
                 }
                 
@@ -536,7 +534,7 @@ void View::GetBatches()
                 if (pass)
                 {
                     renderer_->SetBatchShaders(baseBatch, tech, pass);
-                    postAlphaQueue_.AddBatch(baseBatch);
+                    postAlphaQueue_.AddBatch(baseBatch, false);
                     continue;
                 }
             }
@@ -1469,7 +1467,7 @@ void View::SortBatches()
     baseQueue_.SortFrontToBack();
     preAlphaQueue_.SortFrontToBack();
     alphaQueue_.SortBackToFront();
-    postAlphaQueue_.SortFrontToBack();
+    postAlphaQueue_.SortBackToFront();
     
     for (unsigned i = 0; i < lightQueues_.Size(); ++i)
     {
@@ -1487,7 +1485,6 @@ void View::PrepareInstancingBuffer()
     
     totalInstances += baseQueue_.GetNumInstances(renderer_);
     totalInstances += preAlphaQueue_.GetNumInstances(renderer_);
-    totalInstances += postAlphaQueue_.GetNumInstances(renderer_);
     
     for (unsigned i = 0; i < lightQueues_.Size(); ++i)
     {
@@ -1506,7 +1503,6 @@ void View::PrepareInstancingBuffer()
         {
             baseQueue_.SetTransforms(renderer_, lockedData, freeIndex);
             preAlphaQueue_.SetTransforms(renderer_, lockedData, freeIndex);
-            postAlphaQueue_.SetTransforms(renderer_, lockedData, freeIndex);
             
             for (unsigned i = 0; i < lightQueues_.Size(); ++i)
             {
@@ -1556,8 +1552,7 @@ void View::CalculateShaderParameters()
 
 void View::RenderBatchQueue(const BatchQueue& queue, bool useScissor)
 {
-    if (useScissor)
-        graphics_->SetScissorTest(false);
+    graphics_->SetScissorTest(false);
     graphics_->SetStencilTest(false);
     
     // Priority instanced
@@ -1586,7 +1581,6 @@ void View::RenderBatchQueue(const BatchQueue& queue, bool useScissor)
     for (PODVector<Batch*>::ConstIterator i = queue.sortedBatches_.Begin(); i != queue.sortedBatches_.End(); ++i)
     {
         Batch* batch = *i;
-        // For the transparent queue, both priority and non-priority batches are copied here, so check the flag
         if (useScissor)
         {
             if (!batch->hasPriority_ && batch->lightQueue_)
@@ -1641,7 +1635,9 @@ void View::RenderShadowMap(const LightBatchQueue& queue)
     
     Texture2D* shadowMap = queue.shadowMap_;
     
+    graphics_->SetStencilTest(false);
     graphics_->SetTexture(TU_SHADOWMAP, 0);
+    
     if (!graphics_->GetFallback())
     {
         graphics_->SetColorWrite(false);
@@ -1660,6 +1656,7 @@ void View::RenderShadowMap(const LightBatchQueue& queue)
     // Set shadow depth bias
     BiasParameters parameters = queue.light_->GetShadowBias();
     // Adjust the light's constant depth bias according to global shadow map resolution
+    /// \todo Should remove this adjustment and find a more flexible solution
     unsigned shadowMapSize = renderer_->GetShadowMapSize();
     if (shadowMapSize <= 512)
         parameters.constantBias_ *= 2.0f;
@@ -1695,5 +1692,4 @@ void View::RenderShadowMap(const LightBatchQueue& queue)
     
     graphics_->SetColorWrite(true);
     graphics_->SetDepthBias(0.0f, 0.0f);
-    graphics_->SetScissorTest(false);
 }