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

Fixed erroneous occlusion culling in orthographic mode.
Use two smaller Z-biases (before and after viewport transform) for occlusion instead of one large.

Lasse Öörni 13 лет назад
Родитель
Сommit
612a0c2dee
2 измененных файлов с 9 добавлено и 4 удалено
  1. 7 3
      Engine/Graphics/OcclusionBuffer.cpp
  2. 2 1
      Engine/Graphics/OcclusionBuffer.h

+ 7 - 3
Engine/Graphics/OcclusionBuffer.cpp

@@ -324,10 +324,14 @@ bool OcclusionBuffer::IsVisible(const BoundingBox& worldSpaceBox) const
     vertices[6] = ModelTransform(viewProj_, Vector3(worldSpaceBox.min_.x_, worldSpaceBox.max_.y_, worldSpaceBox.max_.z_));
     vertices[7] = ModelTransform(viewProj_, worldSpaceBox.max_);
     
+    // Apply a far clip relative bias
+    for (unsigned i = 0; i < 8; ++i)
+        vertices[i].z_ -= OCCLUSION_RELATIVE_BIAS;
+    
     // Transform to screen space. If any of the corners cross the near plane, assume visible
     float minX, maxX, minY, maxY, minZ;
     
-    if (vertices[0].w_ <= nearClip_)
+    if (vertices[0].z_ <= 0.0f)
         return true;
     
     Vector3 projected = ViewportTransform(vertices[0]);
@@ -338,7 +342,7 @@ bool OcclusionBuffer::IsVisible(const BoundingBox& worldSpaceBox) const
     // Project the rest
     for (unsigned i = 1; i < 8; ++i)
     {
-        if (vertices[i].w_ <= nearClip_)
+        if (vertices[i].z_ <= 0.0f)
             return true;
         
         projected = ViewportTransform(vertices[i]);
@@ -372,7 +376,7 @@ bool OcclusionBuffer::IsVisible(const BoundingBox& worldSpaceBox) const
     if (rect.bottom_ >= height_)
         rect.bottom_ = height_ - 1;
     
-    int z = (int)(minZ + 0.5f) - OCCLUSION_DEPTH_BIAS;
+    int z = (int)(minZ + 0.5f) - OCCLUSION_FIXED_BIAS;
     
     if (!depthHierarchyDirty_)
     {

+ 2 - 1
Engine/Graphics/OcclusionBuffer.h

@@ -48,7 +48,8 @@ struct DepthValue
 
 static const int OCCLUSION_MIN_SIZE = 8;
 static const int OCCLUSION_DEFAULT_MAX_TRIANGLES = 5000;
-static const int OCCLUSION_DEPTH_BIAS = 256;
+static const float OCCLUSION_RELATIVE_BIAS = 0.00001f;
+static const int OCCLUSION_FIXED_BIAS = 16;
 static const float OCCLUSION_X_SCALE = 65536.0f;
 static const float OCCLUSION_Z_SCALE = 16777216.0f;