Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Render custom set of Renderers from CullingResults using Context.DrawRenderers

Discussion in 'Graphics Experimental Previews' started by capkoh, Apr 30, 2020.

  1. capkoh


    Oct 1, 2016

    I'm switching to custom RP and investigating possibilities at the moment. One of the issues I have is that I would like to render a custom set of Renderers that I got after culling. But I do not see anything related to the list of renderers in the CullingResults. That's weird, it means that I generate results but the only thing I could do with "them" is just pass to context's DrawRenderers.

    I think that it's obvious that if someone decides to create custom RP they will want to customize things that are not possible to customize in predefined LWRP or HDPR.

    Of course, I could collect Renderers that I'm interested in manually in some array and then push them into a CommandBuffer using DrawRenderer. Then I could execute this command buffer on context. But I have two major issues with it. First, this way the classic dynamic batching does not work. Second, the new SRP Batcher does not work too.

    So, there is basically no other solution to this problem rather than separate Renderers with layers or pass tags. But it also has one major issue.

    Imagine I would like to break rendering when some particular object is about to render in the middle of the scene. For example, I could have N glass walls in the scene. I would like to draw all the things behind N-1 wall, then N-1 wall itself with some effect. Then everything between N-1 and N walls. And finally N wall with some effect. Now, if I had a fixed amount of walls, then it's fine, I could setup layers easily. But what if N could be changed at runtime and objects could move between walls? The easiest solution is just break rendering in multiple subsets at the points where Nth wall is rendered. This API it not available. Also, I think it's clear that rendering all transparency after all opaque will produce wrong results.

    This was just one example, but I'm sure there are more cases when it's needed.

    So, I would like to request two possibilities.

    The first is to get and to modify the list of Renderers that I get after culling in CullingResults. Of course it should also be possible to pass modified CullingResults to context's DrawRenderers. This way I still could use all the major advantages of the context's DrawRenderers, but render exactly what is needed.

    Please note again, FilteringSettings is not an option here.

    Edit: The second is to get and to modify the list of Renderers after SortingSettings and FilteringSettings have been applied. It's directly before drawing any Renderers. It should also be possible to use context's DrawRenderers function after changes have been made to the list of Renderers. It means that it is required to split context's DrawRenderers into two functions: ApplyFilteringAndSorting and ActuallyDrawRenderers. Both of them could use CullingResults as an input. In this case I could have the exact picture about what is going to be drawn and in what order. And I could patch this order at any point to implement any weird effect modern game could require!

    Also note that in both possibilities it's crucial to be able to get corresponding "real" Renderer (or game object) for each item in the list of renderers in CullingResults.

    Any chance to get these features?
    Last edited: May 1, 2020
    Dessix-Machina likes this.