Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Feedback Scriptable Culling in SRP Should be Much Easier to Work With

Discussion in 'General Graphics' started by equalsequals, Jun 25, 2021.

  1. equalsequals

    equalsequals

    Joined:
    Sep 27, 2010
    Posts:
    147
    I have been working on a subset of features for our custom SRP which has been heavily reliant on getting "special" CullingResults, and I have found a number of really frustrating pain points.

    First, it seems that no matter what, a Camera Component needs to be involved at some point during the Culling process. If I simply create a ScriptableCullingParameters without involving a Camera by way of TryGetCullingParameters, Unity will hard crash when I perform a Cull. I believe I have tracked this down to the CameraProperties in ScriptableCullingParameters not being able to be defined correctly without first getting it directly from a Camera. This feels very broken since I can query a Cull through the ScriptableRenderContext at any time outside of the scope of any Camera. I would assume that I should just be able to query based on a set of View & Projection Matrices (read: culling matrix) and the CullingOptions flag.

    Secondly, it appears that simply setting the cullingMatrix does NOT update the culling planes, and instead I must do the following, which I found in this thread:

    Code (CSharp):
    1. Plane[] planes = GeometryUtility.CalculateFrustumPlanes (cp.cullingMatrix);
    2.             for (int i = 0; i < 6; i++)
    3.                 cp.SetCullingPlane (i, planes[i]);
    Why? If these planes are clearly derivative of the cullingMatrix, setting this should do this for me!

    Another gripe I have is that the CullingResults are completely black box. I cannot even query the results for how many Renderers passed the Cull, let alone do anything with it other than pass it along to a couple of APIs to Draw. It would be great if I could have some native buffer access here to do something on.

    With the whole "screws on the top" methodology of SRP, the way this part of the pipeline is so closed off is very counterintuitive and makes for a lot of really bad hacky workarounds that I shouldn't have to be fighting with.

    Please fix this.
     
  2. equalsequals

    equalsequals

    Joined:
    Sep 27, 2010
    Posts:
    147
    I found this issue while trying to debug another issue with culling. Apparently isOrthographic is not set in ScriptableCullingParameters, even if the Camera which it was pulled from is?



    Seems like a bug?
     
  3. equalsequals

    equalsequals

    Joined:
    Sep 27, 2010
    Posts:
    147
    Upon further investigation, it seems like ScriptableCullingParameters.isOrthographic is completely irrelevant.

    Man, I love a good red herring.
     
  4. equalsequals

    equalsequals

    Joined:
    Sep 27, 2010
    Posts:
    147
    Bumping this thread because I have some additional input.

    A feature of Culling that I feel is lacking is the ability to use something like BatchRendererGroup.OnPerformCulling but for an arbitrary group of Renderers.

    Ideally, I would like to add any Renderers to a data structure, perhaps something like https://docs.unity3d.com/ScriptReference/CullingGroup.html where I receive a callback and can process them myself. These Renderers would then be flagged to be ignored by the core culling system because they will be handled by the delegate. This would allow me to process subsets of a given Scene's Renderers how I want for an effect without using workaround like multiple cameras.
     
unityunity