Search Unity

BatchRendererGroup.OnPerformCulling called so many times!!!!!

Discussion in 'Scripting' started by DoubleThreeZhang, Sep 16, 2020.

  1. DoubleThreeZhang

    DoubleThreeZhang

    Joined:
    Aug 14, 2017
    Posts:
    10
    I found a problem when using BatchRendererGroup to draw multi instances.
    All of my camera in scene invoke OnPerformCulling no matter whether they need or not!!!
    For example:
    CameraA: cullingMask = Everything.
    CameraB: cullingMask = Nothing.
    TestBatch = BatchRendererGroup.AddBatch(xx, xx, xx, defaultLayer, ...).
    As I thought, TestBatch should have nothing to do with CameraB, because cameraB`s cullingMask is Nothing. But the profiler always list two OnPerformCulling, one for cameraA`s SceneCulling, one for cameraB`s SceneCulling. When I disactived cameraB, the second OnPerformCulling disappeared. Below is the example screenshot.

    123.png

    I dont`t know why this happened. I can not let OnPerformCulling called so many times every frame. For it contains a lot of logic for culling.

    Anyone can help me? Thanks a lot!!!!!
    Unity version is 2019.4.0f1
    Builtin render pipeline.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    I cannot find docs on this API. Is it really new? What do you base this statement on:

    Is the API not behaving according to what the documentation says it should?
     
  3. DoubleThreeZhang

    DoubleThreeZhang

    Joined:
    Aug 14, 2017
    Posts:
    10
    upload_2020-9-17_9-19-24.png
    upload_2020-9-17_9-20-3.png
    Yes, the 4th param layer has no use for culling by layer.
     
  4. SebastianAaltonen

    SebastianAaltonen

    Unity Technologies

    Joined:
    Feb 21, 2020
    Posts:
    112
    The culling callback is called once for every camera culling operation. In SRP script you can share CullResults with multiple DrawRenderers calls to multiple cameras (reducing the culling callback count), but this isn't possible with the built-in pipeline.

    You are responsible for doing the viewport culling for each camera separately. There is a callback for each. The layer mask is applied later in the process. Each culling result can be shared between multiple cameras with different layer masks (but IIRC this is only possible in SRP). At the point of doing the culling callbacks, there's yet no knowledge what cameras will use those CullResults, since the SRP script is able to do anything. Thus we can't avoid running the culling callbacks for cameras that don't match the layers. Culling callbacks are not directly tied to cameras. With built-in pipeline, there's likely 1:1 mapping, but BatchRendererGroup was not designed for built-in pipeline. For example local light sources and many other features don't properly work with BatchRendererGroup in built-in pipeline. I would advice against using it. This API was in extremely experimental state in 2019 based Unity versions. 2020 is better but still not production ready.
     
  5. DoubleThreeZhang

    DoubleThreeZhang

    Joined:
    Aug 14, 2017
    Posts:
    10
    Anyway, thanks buddy. We have switched the renderer pipeline to URP. BatchRendererGroup is still in use, but we do culling ourselves, any instance will be test visiblity before passed to BatchRendererGroup, leave OnPerformCulling empty.