0

I have some issues with implementing occlusion culling. For me, it doesn't seem to work as intended. Basically, on images I have my view frustum and object right in front of the camera. Unfortunately, the objects are still being visible. Don't quite understand why. Debuging camera frustum view(right in front of the object) for easier debugging Just a closer look

Shadow map and its mipmaps are being generated correctly, I checked this one. For generating mipmaps I am using max function on texels.

The first compute shader program is being executed before any object rendering(frustum culling):

  uint DrawIndex = gl_GlobalInvocationID.x;
  if(DrawIndex >= MeshCullingCommonInput.DrawCount) return;

  if(!MeshDrawCommandData[DrawIndex].IsVisible)
  {
    return;

  // Frustum Culling and populating indirect commands if object is actually visible
        .....

After this shader I am rendering all visible objects. Then I am generating mipmaps for my depth buffer via Hierarchy-Z. After that next shader program is for occlusion culling:

  uint DrawIndex = gl_GlobalInvocationID.x;
  if(DrawIndex >= MeshCullingCommonInput.DrawCount) return;

  uint MeshIndex = MeshDrawCommandData[DrawIndex].MeshIndex - 1;

  mat4 Proj = MeshCullingCommonInput.Proj;
  mat4 View = MeshCullingCommonInput.View;

  vec3 BoxMin = MeshOffsets[MeshIndex].AABB.Min.xyz * MeshDrawCommandData[DrawIndex].Scale.xyz + MeshDrawCommandData[DrawIndex].Translate.xyz;
  vec3 BoxMax = MeshOffsets[MeshIndex].AABB.Max.xyz * MeshDrawCommandData[DrawIndex].Scale.xyz + MeshDrawCommandData[DrawIndex].Translate.xyz;
  vec4 TransBoxMin = Proj * View * vec4(BoxMin, 1);
  vec4 TransBoxMax = Proj * View * vec4(BoxMax, 1);
  BoxMin = TransBoxMin.xyz / TransBoxMin.w;
  BoxMax = TransBoxMax.xyz / TransBoxMax.w;
  float BoxWidth  = ((BoxMax - BoxMin).x *  0.5 + 0.5) * MeshCullingCommonInput.HiZWidth ;
  float BoxHeight = ((BoxMax - BoxMin).y * -0.5 + 0.5) * MeshCullingCommonInput.HiZHeight;

        bool IsVisible = true;
        // Frustum Culling
        ........

  // Occlusion Culling
  if(IsVisible && MeshCullingCommonInput.OcclusionCullingEnabled)
  {
    float Lod = floor(log2(max(BoxWidth, BoxHeight)));

    vec2  BoxCoord = (BoxMin + BoxMax).xy * 0.5;
    vec2  UVCoords = BoxCoord * vec2(0.5, -0.5) + 0.5;
    float PyramidDepth = textureLod(DepthPyramid, UVCoords, Lod).x;

    IsVisible = IsVisible && (BoxMax.z > PyramidDepth);
  }

  MeshDrawCommandData[DrawIndex].IsVisible = IsVisible;

The main issue is with the Occlusion Culling, as there is nothing being occluded really. Don't really understand what I've done wrong, as algorithm is looking more or less fine. The desired behavior expected by me is that all of the objects behind shouldn't be visible, but, as seen on the image, nothing happened.

Arheus
  • 21
  • 3

0 Answers0