Search Unity

  1. We are looking for feedback on our SRP Rendering APIs through this Survey.
    Dismiss Notice
  2. Unity 2020.2 has been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted How to render multiple cameras in ScriptableRendererFeature and ScriptableRenderPass

Discussion in 'Universal Render Pipeline' started by Yashiz, Nov 24, 2020.

  1. Yashiz

    Yashiz

    Joined:
    Jul 9, 2015
    Posts:
    10
    Hi,

    I have a set of runtime cameras and I want to render each of camera view into a global texture atlas. The atlas will then be used when rendering the main camera. I would like this feature as general as possible.

    I am trying to introduce a Scriptable Renderer Feature to do this (Unity 2020.2.0b12). In my Scriptable Render Pass, I configure the texture atlas as the render target in OnCameraSetup. Then I call UniversalRenderPipeline.RenderSingleCamera(context, camera) for each of the cameras in Execute function. Unfortunately, UniversalRenderPipeline.RenderSingleCamera leads to crash in mono-2.0-bdwgc.dll. You can find the crash stack in the attachment.

    Therefore, I would like to know:
    1. Is it legal to call UniversalRenderPipeline.RenderSingleCamera in ScriptableRenderPass?
    2. what is the best practice to achieve "rendering multiple cameras into an atlas before main camera rendering" in Scriptable Renderer Feature?

    Thanks.

    Y.
     

    Attached Files:

  2. Yashiz

    Yashiz

    Joined:
    Jul 9, 2015
    Posts:
    10
    Any helps are welcome.
    Please.
     
  3. Oxeren

    Oxeren

    Joined:
    Aug 14, 2013
    Posts:
    91
    Scriptable Renderer Pass happens during camera rendering, so trying to render from one camera while already rendering from another is not gonna work.
    To render an atlas before main camera, you can set your additional camera's priority to be lower than that of the main camera, so it renders first. You can also create a separate renderer if you need and assign it to your additional camera (just don't forget to add this renderer to your pipeline asset's renderer list).
     
  4. Yashiz

    Yashiz

    Joined:
    Jul 9, 2015
    Posts:
    10
    Hi Oxeren,

    Thank you for the confirmation. Indeed, multiple cameras rendering in Scriptable Render Pass seems an error pose. Attaching separate renderer like you said or using RenderPipelineManager hooks are more decent solutions.

    In fact, I would prefer a more centralized solution if possible. That attaching only data wise script to game objects, then a global/centralized solver will collect and process these data. That's why I was looking into Scriptable Renderer Features. I have successfully achieved that with my custom render pipeline from scratch (I can generate virtual cameras without creating game objects, then render them into atlas in one render pass. As I know the entire data before rendering, I could do some optimizations as well). However, it seems more difficult to do similar things in URP.

    You know centralized solution (some people call it data oriented solution) may scale better when the data increases. Are there any possibilities to achieve it in URP?

    Thank you again.

    Y.
     
  5. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    150
    If I am right about what you are trying to achieve from the original post, you just need to set the viewport rects of each single camera into rects on the atlas and still have the renderer target at the atlas. The respective clear should only affect the pixels of target rect on the texture of the camera.

    So one of the alternative ways in which you could try without tapping into the camera viewport rect is that in the RenderPass, there is the CommandBuffer.SetPixelRect(Rect) to just focus on which pixels to affect.
     
  6. Yashiz

    Yashiz

    Joined:
    Jul 9, 2015
    Posts:
    10
    Hi weiping-toh,

    Thank you very much for your suggestion.
     
unityunity