Search Unity

GPU frustum culling is working now, but how to write LOD & occlusion culling?

Discussion in 'General Graphics' started by colin299, Jun 29, 2019.

  1. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    181
    this video is my test code's current state:


    ------------------------------
    The current goal is to write a GPU-driven rendering test.apk, which decides if openworld rendering in mobile is practical or not, and how difficult it is.

    my test code is now doing:
    Start(only do once):
    -put all cubes's world pos into float3 constant buffer

    Update(do once per frame):
    Step1 =
    Dispatch compute Shader to do frustum culling, if current cube is inside frustum , append it's world pos into an AppendStructuredBuffer<float3>
    Step2 = Copy Step1's AppendStructuredBuffer's counter value to an IndirectArgumentsBuffer's "Instances count" slot
    Step3 = use Step2's IndirectArgumentsBuffer to DrawMeshInstancedIndirect

    =========================================
    Question:
    if I want to extend the above code logic to do LOD & occlusion culling also, what should I do?

    ------------------------------------------
    For LOD:
    Let's say I need 5 "mesh & material LOD" base on distance.
    If in Step1 of the code logic above, instead of appending all visible cube pos into one single AppendStructuredBuffer, I now append them into 1 out of 5 AppendStructuredBuffers base on distance to camera, then I do Step2 5 times, and Step3(with different mesh & material)5 times, is this a practical method to do LOD?


    ------------------------------------------
    For occlusion culling:
    No idea what to do, but I will try to write down my thought:
    Insert the following between Step1&2, which do extra filtering after frustum culling:
    (a)
    .render a small amount of bounding box's depth (bounding boxes which are closest to camera and biggest in screen) into a small RenderTexture first ( but I am not sure how to find these "important occluders" in ComputeShader)
    (b).foreach bounding box which survives after GPU frustum culling, test each bounding box's depth to (a)'s small RenderTexture's depth. If any points of a bounding box(total of 8)'s depth is in front of (a)'s RenderTexture's depth(= closer to camera), then we append it's pos to another AppendStructuredBuffer(where at the end, this AppendStructuredBuffer is the replacement of Step1's result)

    Wonder if it sounds ok? or it is a completely wrong idea.
    I searched the internet, found a keyword "Hi-Z", seems like it is rendering depth into a power of 2 size RenderTexture, then downsample mip0 to all mips with a max() of 4 pixels, but why mips are useful? how to use depth mips to do occlusion culling?


    ==================================================
    Thank you for your help. Any suggestion are welcome.
     
    Last edited: Jun 29, 2019
  2. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    357
    See here;

     
    joshuacwilde and colin299 like this.
  3. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    181
    for the occlusion culling, now it is very clear what to do now, thanks @grizzly
     
  4. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    726
    Did you end up doing anything related to this? I am wanting to do something similar to the HiZ culling mentioned here, and wondering if you were able to get it working or if you ran into any problems.